daiban.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. # -*- coding: utf-8 -*-
  2. from fastapi import APIRouter, Depends
  3. from config import settings
  4. from pydantic import BaseModel
  5. from sqlalchemy.orm import Session
  6. from sqlalchemy.sql import func
  7. from sqlalchemy import text, exists, and_, or_, not_
  8. from database import get_db
  9. import time
  10. import datetime
  11. from utils import *
  12. from extensions import logger
  13. from datetime import datetime, timedelta
  14. from models import *
  15. router = APIRouter()
  16. '''
  17. 在浏览器打开如下链接,并替换对应参数值,参数占位符为{xxx}。返回正确代码即基础校验通过。
  18. https://bs-test.digitalgd.com.cn/yqt_back/scg/yst-ec/ec-task-record/checkTaskParam?accessToken={access_token}&accessApi={access_api}&accessPaasId={access_paasid}&accessPaasIdToken={access_paasid_token}&startTime={start_time}&endTime={end_time}
  19. '''
  20. class DaibanQueryReq(BaseModel):
  21. # 访问Token
  22. accessToken: str
  23. # 当前页码
  24. pageNum: int
  25. # 每页显示记录数
  26. pageSize: int
  27. # 开始时间
  28. startTime: str
  29. # 结束时间
  30. endTime: str
  31. # 来源系统标识
  32. sourceSystemId: str = ''
  33. # 申请人类型
  34. applyerType: str = ''
  35. # 申请人证件类型
  36. applyerIdType: str = ''
  37. # 申请人证件号码
  38. applyerIdNum: str = ''
  39. # 申请人统一身份认证平台账号
  40. applyerUid: str = ''
  41. # 事项状态
  42. state: str = ''
  43. @router.post('/query', summary="待办查询接口")
  44. def index(
  45. req: DaibanQueryReq,
  46. db: Session = Depends(get_db)
  47. ):
  48. logger.info(req)
  49. if settings.IS_DEV and req.accessToken != '4356e0de-c26a-11ef-895f-0242ac140002':
  50. return {
  51. "errcode": 1,
  52. "errmsg": "accessToken异常"
  53. }
  54. elif settings.IS_PROD and req.accessToken != '45c04f6c-c26a-11ef-895f-0242ac140002':
  55. return {
  56. "errcode": 1,
  57. "errmsg": "accessToken异常"
  58. }
  59. state = req.state
  60. applyerIdNum = req.sfzh
  61. startTime = req.startTime
  62. endTime = req.endTime
  63. pageNum = req.pageNum
  64. pageSize = req.pageSize
  65. startTime = time.strptime(startTime, "%Y-%m-%d %H:%M:%S")
  66. endTime = time.strptime(endTime, "%Y-%m-%d %H:%M:%S")
  67. where = and_(VwYstDaiban.update_time >= startTime, VwYstDaiban.update_time <= endTime)
  68. if applyerIdNum != '':
  69. applyerIdNum = applyerIdNum
  70. where = and_(where, VwYstDaiban.sfzh == applyerIdNum)
  71. if state == '01': # 待办
  72. where = and_(where, VwYstDaiban.status == 2)
  73. elif state == '02': # 办理中
  74. where = and_(where, VwYstDaiban.status == 1)
  75. elif state == '03': # 办结
  76. where = and_(where, VwYstDaiban.status == 2)
  77. elif state == '04': # 已过期
  78. where = and_(where, VwYstDaiban.update_time < (datetime.now() - timedelta(days=180)))
  79. elif state == '09': # 已删除
  80. where = and_(where, VwYstDaiban.update_time < (datetime.now() - timedelta(days=365)))
  81. else:
  82. where = and_(where, VwYstDaiban.status > 0)
  83. # 条数
  84. q = db.query(func.count(VwYstDaiban.ghid))
  85. model_count = q.filter(where).scalar()
  86. print("model_count:", state, model_count)
  87. # 明细
  88. q = db.query(VwYstDaiban)
  89. q = q.filter(where).order_by(VwYstDaiban.ghsj.desc())
  90. q = q.limit(pageSize).offset((int(pageNum) - 1) * pageSize)
  91. rows = q.all()
  92. records = []
  93. for row in rows:
  94. rec = new_record(get_model_dict(row))
  95. if rec is not None:
  96. records.append(rec)
  97. pageCount = len(records)
  98. pages = 1
  99. hasNextPage = pageCount >= pageSize
  100. logger.info(records)
  101. return {
  102. "errcode": 0,
  103. "errmsg": "成功",
  104. "data": {
  105. "pageNum": pageNum,
  106. "pageSize": pageSize,
  107. "size": pageCount,
  108. "pages": pages,
  109. "total": model_count,
  110. "hasNextPage": hasNextPage,
  111. "records": records
  112. }
  113. }
  114. def new_record(data: dict):
  115. shixiang = data['sxmc']
  116. projectNo = data['bzid']
  117. systemId = settings.YST_PASS_ID
  118. sourceSystemId = settings.YST_PASS_ID
  119. taskCodeLocal = shixiang
  120. applyTime = from_timestamp(data['create_time'])
  121. update_time = get_datetime_str(data['update_time'])
  122. cid = data['sfzh']
  123. name = data['xm']
  124. H5_HOST = "https://yjxp.mmsyjj.cn:8086"
  125. if settings.IS_DEV:
  126. H5_HOST = "http://120.241.74.139:8086"
  127. if shixiang == 'qyjcxx':
  128. taskTitle = '应急企业基础信息'
  129. detailURL = H5_HOST + '/mmh5_yjxm_yst/#/pages/mmyj/qyjcxx/index/index?id=' + data['bzid']
  130. elif shixiang == 'qyyjya':
  131. taskTitle = '应急预案上报'
  132. detailURL = H5_HOST + '/mmh5_yjxm_yst/#/pages/mmyj/qyyjya/index/index?id=' + data['bzid']
  133. elif shixiang == 'yjylzj':
  134. taskTitle = '应急演练总结'
  135. detailURL = H5_HOST + '/mmh5_yjxm_yst/#/pages/mmyj/yjylzj/index/index?id=' + data['bzid']
  136. state = '10'
  137. businessState = '待办'
  138. if data['status'] == 1:
  139. state = '02'
  140. businessState = '审核中'
  141. elif data['status'] == 2:
  142. state = '03'
  143. businessState = '审核通过'
  144. elif data['status'] == 3:
  145. state = '03'
  146. businessState = '审核不通过'
  147. #elif data['status'] == 2:
  148. # state = '01'
  149. # businessState = '待办'
  150. if data['update_time'] < (datetime.now() - timedelta(days=365)):
  151. state = '09'
  152. businessState = '已删除'
  153. if data['update_time'] < (datetime.now() - timedelta(days=180)):
  154. state = '04'
  155. businessState = '已过期'
  156. taskNameLocal = taskTitle
  157. return {
  158. # 办件编号
  159. 'projectNo': projectNo,
  160. # 业务系统标识
  161. 'systemId': systemId,
  162. # 来源系统标识
  163. 'sourceSystemId': sourceSystemId,
  164. # 办件标题
  165. 'taskTitle': taskTitle,
  166. # 事项名称(可选)
  167. 'taskName': '' + taskTitle, # 标题来的,很重要
  168. # 事项编码(可选)
  169. 'taskCode': '',
  170. # 业务系统自编事项名称
  171. 'taskNameLocal': taskNameLocal,
  172. # 业务系统自编事项编码
  173. 'taskCodeLocal': taskCodeLocal,
  174. # 事项版本号
  175. 'taskVersion': '',
  176. # 事项状态
  177. 'state': state,
  178. # 业务状态
  179. 'businessState': businessState,
  180. # 受理部门编码(可选)
  181. 'orgCode': '',
  182. # 受理部门名称(可选)
  183. 'orgName': '',
  184. # 地市区划编码
  185. 'zoneCode': '4414',
  186. # 办件提交时间
  187. 'applyTime': applyTime,
  188. # 办件详细信息URL
  189. 'detailURL': detailURL,
  190. # 更新时间
  191. 'update_time': update_time,
  192. # 申请人信息
  193. 'applyerInfo': {
  194. # 申请人类型
  195. 'applyerType': '1', # 自然人
  196. # 申请人名称
  197. 'applyerName': name,
  198. # 申请人证件类型
  199. 'applyerIdType': '10', # 身份证
  200. # 申请人证件号码
  201. 'applyerIdNum': cid,
  202. # 申请人统一身份认证平台账号(可选)
  203. 'applyerUid': '',
  204. # 法定代表人(可选)
  205. 'legal': ''
  206. },
  207. # 联系人信息
  208. 'contactInfo': {
  209. # 联系人/代理人姓名
  210. 'contactName': '',
  211. # 联系人/代理人证件类型
  212. 'contactIdType': '',
  213. # 联系人/代理人证件号码
  214. 'contactIdNum': '',
  215. # 联系人手机号码
  216. 'contactMobile': '',
  217. # 通讯地址
  218. 'address': '',
  219. # 联系人统一身份认证平台账号
  220. 'contactUid': ''
  221. }
  222. }