rewrite company
This commit is contained in:
parent
844455758c
commit
15896baa15
Binary file not shown.
@ -19,6 +19,7 @@ parser.add_argument('contact')
|
||||
parser.add_argument('appid')
|
||||
parser.add_argument('appkey')
|
||||
parser.add_argument('status')
|
||||
parser.add_argument('tel')
|
||||
|
||||
|
||||
# # 操作(put / get / delete)单一资源Todo
|
||||
@ -31,16 +32,15 @@ class Company(Resource):
|
||||
status = self.args['status']
|
||||
all_data = []
|
||||
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)
|
||||
|
||||
log.info(f"get data from db was {data}")
|
||||
if data:
|
||||
company = {}
|
||||
for line in data:
|
||||
if line:
|
||||
company['id'], company['name'], company['contact'], company['appid'], company['appkey'], company[
|
||||
'status'] = line
|
||||
company = {}
|
||||
company['id'], company['name'], company['contact'], company['tel'], company['appid'], company['appkey'], company['status'] = line
|
||||
all_data.append(company)
|
||||
del company
|
||||
else:
|
||||
@ -69,7 +69,7 @@ class Company(Resource):
|
||||
def get_appid(self):
|
||||
appid = self.get_random()
|
||||
# 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)
|
||||
if data:
|
||||
self.get_appid()
|
||||
@ -78,10 +78,12 @@ class Company(Resource):
|
||||
def get_companyid(self):
|
||||
max_id = f"select id from company order by id desc limit 1"
|
||||
data = mydb.query(max_id)
|
||||
|
||||
log.info(f"1 {data}")
|
||||
try:
|
||||
max = data[0] + 1
|
||||
max = int(data[0][0]) + 1
|
||||
log.info(f"max id was {max}!")
|
||||
except Exception:
|
||||
log.error(f"error with get company id ",exc_info=True)
|
||||
max = 1001
|
||||
return max
|
||||
|
||||
@ -94,6 +96,7 @@ class Company(Resource):
|
||||
company['tel'] = self.args['tel']
|
||||
company['id'] = self.get_companyid()
|
||||
company['appid'] = self.get_appid()
|
||||
company['appkey'] = 'undefined'
|
||||
mydb.insert("company", company)
|
||||
except Exception:
|
||||
log.error("set values to company mysql/redis failed!", exc_info=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user