rewrite company

This commit is contained in:
root 2019-07-09 17:45:38 +08:00
parent 844455758c
commit 15896baa15
2 changed files with 10 additions and 7 deletions

View File

@ -19,6 +19,7 @@ parser.add_argument('contact')
parser.add_argument('appid') parser.add_argument('appid')
parser.add_argument('appkey') parser.add_argument('appkey')
parser.add_argument('status') parser.add_argument('status')
parser.add_argument('tel')
# # 操作put / get / delete单一资源Todo # # 操作put / get / delete单一资源Todo
@ -31,16 +32,15 @@ class Company(Resource):
status = self.args['status'] status = self.args['status']
all_data = [] all_data = []
try: try:
sql = f"select id,name,contact,appid,appkey,status from company where status={status};" sql = f"select id,name,contact,tel,appid,appkey,status from company where status={status};"
data = mydb.query(sql) data = mydb.query(sql)
log.info(f"get data from db was {data}") log.info(f"get data from db was {data}")
if data: if data:
company = {}
for line in data: for line in data:
if line: if line:
company['id'], company['name'], company['contact'], company['appid'], company['appkey'], company[ company = {}
'status'] = line company['id'], company['name'], company['contact'], company['tel'], company['appid'], company['appkey'], company['status'] = line
all_data.append(company) all_data.append(company)
del company del company
else: else:
@ -69,7 +69,7 @@ class Company(Resource):
def get_appid(self): def get_appid(self):
appid = self.get_random() appid = self.get_random()
# check appid not in db # check appid not in db
check_appid = f"select appid from company where appid={appid}" check_appid = f"select appid from company where appid='{appid}'"
data = mydb.query(check_appid) data = mydb.query(check_appid)
if data: if data:
self.get_appid() self.get_appid()
@ -78,10 +78,12 @@ class Company(Resource):
def get_companyid(self): def get_companyid(self):
max_id = f"select id from company order by id desc limit 1" max_id = f"select id from company order by id desc limit 1"
data = mydb.query(max_id) data = mydb.query(max_id)
log.info(f"1 {data}")
try: try:
max = data[0] + 1 max = int(data[0][0]) + 1
log.info(f"max id was {max}!")
except Exception: except Exception:
log.error(f"error with get company id ",exc_info=True)
max = 1001 max = 1001
return max return max
@ -94,6 +96,7 @@ class Company(Resource):
company['tel'] = self.args['tel'] company['tel'] = self.args['tel']
company['id'] = self.get_companyid() company['id'] = self.get_companyid()
company['appid'] = self.get_appid() company['appid'] = self.get_appid()
company['appkey'] = 'undefined'
mydb.insert("company", company) mydb.insert("company", company)
except Exception: except Exception:
log.error("set values to company mysql/redis failed!", exc_info=True) log.error("set values to company mysql/redis failed!", exc_info=True)