|
@@ -720,72 +720,72 @@ async def v2(serviceid:str,request: Request, db: Session = Depends(get_db)):
|
|
|
data = []
|
|
|
|
|
|
# 数据库类型为mysql情况下
|
|
|
- if database_info.dbtype == 'pymysql':
|
|
|
- # 数据库连接
|
|
|
+ if database_info.dbtype == 'pymysql':
|
|
|
+ # 数据库连接
|
|
|
|
|
|
- conn = pymysql.connect(host=database_info.host,
|
|
|
- user=database_info.user,
|
|
|
- password=database_info.password,
|
|
|
- database=database_info.database,
|
|
|
- port=database_info.port,
|
|
|
- charset=database_info.charset)
|
|
|
- cur = conn.cursor()
|
|
|
+ conn = pymysql.connect(host=database_info.host,
|
|
|
+ user=database_info.user,
|
|
|
+ password=database_info.password,
|
|
|
+ database=database_info.database,
|
|
|
+ port=database_info.port,
|
|
|
+ charset=database_info.charset)
|
|
|
+ cur = conn.cursor()
|
|
|
|
|
|
- # 查总数据量,分页数据处理
|
|
|
- totalsql = f'select count(*) from ({sql})t'
|
|
|
- print(totalsql)
|
|
|
- cur.execute(totalsql)
|
|
|
- total = cur.fetchone()[0]
|
|
|
+ # 查总数据量,分页数据处理
|
|
|
+ totalsql = f'select count(*) from ({sql})t'
|
|
|
+ print(totalsql)
|
|
|
+ cur.execute(totalsql)
|
|
|
+ total = cur.fetchone()[0]
|
|
|
|
|
|
- pages,pagesmod = divmod(total, size)
|
|
|
- print(total,pages,pagesmod)
|
|
|
- if pagesmod!=0:
|
|
|
- pages+=1
|
|
|
- print(pages,pagesmod)
|
|
|
- if total <size :
|
|
|
- size = total
|
|
|
+ pages,pagesmod = divmod(total, size)
|
|
|
+ print(total,pages,pagesmod)
|
|
|
+ if pagesmod!=0:
|
|
|
+ pages+=1
|
|
|
+ print(pages,pagesmod)
|
|
|
+ if total <size :
|
|
|
+ size = total
|
|
|
|
|
|
|
|
|
- # 正式查询
|
|
|
- sql = sql+f' limit {size*(current-1)}, {size};'
|
|
|
- print(sql,size)
|
|
|
- cur.execute(sql)
|
|
|
- rows = cur.fetchall()
|
|
|
- colnames = [desc[0] for desc in cur.description]
|
|
|
- for row in range(size):
|
|
|
- item = {}
|
|
|
- for col in range(len(colnames)):
|
|
|
- field_name = colnames[col]
|
|
|
- item[field_name] = rows[row][col]
|
|
|
- data.append(item)
|
|
|
-
|
|
|
- # 数据库关闭
|
|
|
- cur.close()
|
|
|
- conn.close()
|
|
|
+ # 正式查询
|
|
|
+ sql = sql+f' limit {size*(current-1)}, {size};'
|
|
|
+ print(sql,size)
|
|
|
+ cur.execute(sql)
|
|
|
+ rows = cur.fetchall()
|
|
|
+ colnames = [desc[0] for desc in cur.description]
|
|
|
+ for row in range(len(rows)):
|
|
|
+ item = {}
|
|
|
+ for col in range(len(colnames)):
|
|
|
+ field_name = colnames[col]
|
|
|
+ item[field_name] = rows[row][col]
|
|
|
+ data.append(item)
|
|
|
|
|
|
+ # 数据库关闭
|
|
|
+ cur.close()
|
|
|
+ conn.close()
|
|
|
|
|
|
|
|
|
- else:
|
|
|
- return JSONResponse(status_code=410, content={
|
|
|
- 'code': 410,
|
|
|
- 'msg': '接口对应数据库暂不支持'
|
|
|
- })
|
|
|
-
|
|
|
- return {
|
|
|
- 'code': 0,
|
|
|
- 'msg': 'success',
|
|
|
- 'rows': data,
|
|
|
- 'pages': pages, # 总页数
|
|
|
- 'currentPage': current, # 当前页数
|
|
|
- # 'current':current,
|
|
|
- # 'total' : total,
|
|
|
- 'total': total, # 总数据量
|
|
|
- # 'size':size,
|
|
|
- 'pageSize': size # 页码
|
|
|
- }
|
|
|
|
|
|
else:
|
|
|
return JSONResponse(status_code=410, content={
|
|
|
- 'code': 410,
|
|
|
- 'msg': 'body不能为空'
|
|
|
- })
|
|
|
+ 'code': 410,
|
|
|
+ 'msg': '接口对应数据库暂不支持'
|
|
|
+ })
|
|
|
+
|
|
|
+ return {
|
|
|
+ 'code': 0,
|
|
|
+ 'msg': 'success',
|
|
|
+ 'rows': data,
|
|
|
+ 'pages': pages, # 总页数
|
|
|
+ 'currentPage': current, # 当前页数
|
|
|
+ # 'current':current,
|
|
|
+ # 'total' : total,
|
|
|
+ 'total': total, # 总数据量
|
|
|
+ # 'size':size,
|
|
|
+ 'pageSize': size # 页码
|
|
|
+ }
|
|
|
+
|
|
|
+ # else:
|
|
|
+ # return JSONResponse(status_code=410, content={
|
|
|
+ # 'code': 410,
|
|
|
+ # 'msg': 'body不能为空'
|
|
|
+ # })
|