瀏覽代碼

添加数据库查询工具类

syh 4 年之前
父節點
當前提交
36613b733e
共有 4 個文件被更改,包括 74 次插入3 次删除
  1. 7 2
      .idea/ai_ads.iml
  2. 1 1
      .idea/misc.xml
  3. 35 0
      mysql_search_utils.py
  4. 31 0
      server.py

+ 7 - 2
.idea/ai_ads.iml

@@ -1,10 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
 <module type="PYTHON_MODULE" version="4">
 <module type="PYTHON_MODULE" version="4">
   <component name="NewModuleRootManager">
   <component name="NewModuleRootManager">
-    <content url="file://$MODULE_DIR$" />
-    <orderEntry type="inheritedJdk" />
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/venv" />
+    </content>
+    <orderEntry type="jdk" jdkName="Python 3.8 (base)" jdkType="Python SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>
   </component>
+  <component name="PyDocumentationSettings">
+    <option name="renderExternalDocumentation" value="true" />
+  </component>
   <component name="TestRunnerService">
   <component name="TestRunnerService">
     <option name="PROJECT_TEST_RUNNER" value="pytest" />
     <option name="PROJECT_TEST_RUNNER" value="pytest" />
   </component>
   </component>

+ 1 - 1
.idea/misc.xml

@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
 <project version="4">
-  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (base)" project-jdk-type="Python SDK" />
 </project>
 </project>

+ 35 - 0
mysql_search_utils.py

@@ -0,0 +1,35 @@
+import pymysql
+
+class mysqlSearchUtils():
+    def __init__(self):
+        try:
+            self.conn = pymysql.connect(host="139.186.27.96",port=4000,user="data",passwd="hcst@2021",db="jeecg-boot",charset="utf8mb4")
+            self.cursor = self.conn.cursor()
+        except pymysql.err as e:
+            print("error"% e)
+    def get_one(self):
+        sql = "select * from ctop_user_allocation where account_id = %s order by id desc"
+        self.cursor.execute(sql, ('9556344',))
+        rest = self.cursor.fetchone()
+        result = dict(zip([k[0] for k in self.cursor.description], rest))
+        self.cursor.close()
+        return result
+
+    def get_all(self):
+        sql = "select * from ctop_user_allocation where project_id = %s order by id desc"
+        self.cursor.execute(sql, ('458',))
+        rest = self.cursor.fetchall()
+        result = [dict(zip([k[0] for k in self.cursor.description], row)) for row in rest]
+        self.cursor.close()
+        return result
+
+    def db_close(self):
+        self.conn.close()
+
+if __name__ == '__main__':
+    obj = mysqlSearchUtils()
+    reslt = obj.get_all()
+    for item in reslt:
+        print(item)
+        print("-" * 10)
+    obj.db_close()

+ 31 - 0
server.py

@@ -0,0 +1,31 @@
+from flask import Flask,request
+import mysql_search_utils
+
+app = Flask(__name__)
+
+@app.route('/hello')
+def helloWord():
+    print(request.path)
+    print(request.full_path)
+    return 'hello world'
+
+
+@app.route('/getOne')
+def getJson():
+    mysql = mysql_search_utils.mysqlSearchUtils()
+    responseDict = {}
+    data = mysql_search_utils.mysqlSearchUtils.get_one(mysql)
+    responseDict["data"] = data
+    return responseDict
+
+@app.route('/getList')
+def getList():
+    mysql = mysql_search_utils.mysqlSearchUtils();
+    responseDict = {}
+    list = mysql_search_utils.mysqlSearchUtils.get_all(mysql)
+    responseDict["list"] = list
+    return responseDict
+
+
+if __name__ == '__main__':
+    app.run(host='0.0.0.0',port=8079,debug=True)