1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import pymysql;
- from DBUtils.PooledDB import PooledDB;
- pool = PooledDB(pymysql,10,host='localhost',user='root',passwd='root',db='crt',port=3306,charset="utf8");
- import logApi
- logger = logApi.logger
- import os
- from ini_op import Config;
- import json
- import time
- import requests
- base_dir = os.path.dirname(os.path.abspath(__file__))
- config = Config(base_dir+"/config.ini");
- tokenApiUrl = config.get("baseconf", "tokenApiUrl");
- class DbController():
- def getToken(self):
- token = ""
- headers = {"Content-Type": "application/json",
- "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8"}
- param = {
- "grant_type": config.get("baseconf", "grant_type"),
- "client_id": config.get("baseconf", "client_id"),
- "client_secret": config.get("baseconf", "client_secret"),
- "tenant_id": config.get("baseconf", "tenant_id"),
- "timestamp": int(int(round(time.time() * 1000))),
- "nonce": config.get("baseconf", "nonce")
- }
- try:
- result = requests.post(tokenApiUrl, json=param, headers=headers, timeout=10)
- data = json.loads(result.text)
- errorCode = data["errcode"];
- if errorCode == '0':
- token = data["data"]["access_token"];
- except:
- logger.error("获取token失败 ")
- return token;
- def getBussinessNum(self,cerf_id):
- business_num = "";
- try:
- self.conn = pool.connection();
- self.cursor = self.conn.cursor()
- sql = "select business_num from querycustomer where cerf_id='"+cerf_id+"' order by biz_id desc";
- res = self.cursor.execute(sql);
- data = self.cursor.fetchone();
- if len(data)>0:
- business_num = data[0]
- except:
- logger.error(" getBussinessNum error")
- self.cursor.close();
- self.conn.close();
- return business_num;
- def updateParseInd(self,cerf_id,parseInd):
- try:
- self.conn = pool.connection();
- self.cursor = self.conn.cursor()
- sql = "update querycustomer set parse_ind='"+parseInd+"' where cerf_id='"+cerf_id+"'";
- res = self.cursor.execute(sql);
- self.conn.commit()
- except:
- logger.error(" updateParseInd error")
- finally:
- self.cursor.close();
- self.conn.close();
- def getParseInd(self,cerf_id):
- parse_ind = "";
- try:
- self.conn = pool.connection();
- self.cursor = self.conn.cursor()
- sql = "select parse_ind from querycustomer where cerf_id='"+cerf_id+"' order by biz_id desc";
- res = self.cursor.execute(sql);
- data = self.cursor.fetchone();
- if len(data)>0:
- parse_ind = data[0]
- except:
- logger.error(" getBussinessNum error")
- finally:
- self.cursor.close();
- self.conn.close();
- return parse_ind;
|