dbController.py0604 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import pymysql;
  2. from DBUtils.PooledDB import PooledDB;
  3. pool = PooledDB(pymysql,10,host='localhost',user='root',passwd='root',db='crt',port=3306,charset="utf8");
  4. import logApi
  5. logger = logApi.logger
  6. import os
  7. from ini_op import Config;
  8. import json
  9. import time
  10. import requests
  11. base_dir = os.path.dirname(os.path.abspath(__file__))
  12. config = Config(base_dir+"/config.ini");
  13. tokenApiUrl = config.get("baseconf", "tokenApiUrl");
  14. class DbController():
  15. def getToken(self):
  16. token = ""
  17. headers = {"Content-Type": "application/json",
  18. "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8"}
  19. param = {
  20. "grant_type": config.get("baseconf", "grant_type"),
  21. "client_id": config.get("baseconf", "client_id"),
  22. "client_secret": config.get("baseconf", "client_secret"),
  23. "tenant_id": config.get("baseconf", "tenant_id"),
  24. "timestamp": int(int(round(time.time() * 1000))),
  25. "nonce": config.get("baseconf", "nonce")
  26. }
  27. try:
  28. result = requests.post(tokenApiUrl, json=param, headers=headers, timeout=10)
  29. data = json.loads(result.text)
  30. errorCode = data["errcode"];
  31. if errorCode == '0':
  32. token = data["data"]["access_token"];
  33. except:
  34. logger.error("获取token失败 ")
  35. return token;
  36. def getBussinessNum(self,cerf_id):
  37. business_num = "";
  38. try:
  39. self.conn = pool.connection();
  40. self.cursor = self.conn.cursor()
  41. sql = "select business_num from querycustomer where cerf_id='"+cerf_id+"' order by biz_id desc";
  42. res = self.cursor.execute(sql);
  43. data = self.cursor.fetchone();
  44. if len(data)>0:
  45. business_num = data[0]
  46. except:
  47. logger.error(" getBussinessNum error")
  48. self.cursor.close();
  49. self.conn.close();
  50. return business_num;
  51. def updateParseInd(self,cerf_id,parseInd):
  52. try:
  53. self.conn = pool.connection();
  54. self.cursor = self.conn.cursor()
  55. sql = "update querycustomer set parse_ind='"+parseInd+"' where cerf_id='"+cerf_id+"'";
  56. res = self.cursor.execute(sql);
  57. self.conn.commit()
  58. except:
  59. logger.error(" updateParseInd error")
  60. finally:
  61. self.cursor.close();
  62. self.conn.close();
  63. def getParseInd(self,cerf_id):
  64. parse_ind = "";
  65. try:
  66. self.conn = pool.connection();
  67. self.cursor = self.conn.cursor()
  68. sql = "select parse_ind from querycustomer where cerf_id='"+cerf_id+"' order by biz_id desc";
  69. res = self.cursor.execute(sql);
  70. data = self.cursor.fetchone();
  71. if len(data)>0:
  72. parse_ind = data[0]
  73. except:
  74. logger.error(" getBussinessNum error")
  75. finally:
  76. self.cursor.close();
  77. self.conn.close();
  78. return parse_ind;