123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- # -*- coding: utf-8 -*-
- from fastapi import APIRouter, Depends
- from config import settings
- from pydantic import BaseModel
- from sqlalchemy.orm import Session
- from sqlalchemy.sql import func
- from sqlalchemy import text, exists, and_, or_, not_
- from database import get_db
- import time
- import datetime
- from utils import *
- from extensions import logger
- from datetime import datetime, timedelta
- from models import *
- router = APIRouter()
- '''
- 在浏览器打开如下链接,并替换对应参数值,参数占位符为{xxx}。返回正确代码即基础校验通过。
- 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}
- '''
- class DaibanQueryReq(BaseModel):
- # 访问Token
- accessToken: str
- # 当前页码
- pageNum: int
- # 每页显示记录数
- pageSize: int
- # 开始时间
- startTime: str
- # 结束时间
- endTime: str
- # 来源系统标识
- sourceSystemId: str = ''
- # 申请人类型
- applyerType: str = ''
- # 申请人证件类型
- applyerIdType: str = ''
- # 申请人证件号码
- applyerIdNum: str = ''
- # 申请人统一身份认证平台账号
- applyerUid: str = ''
- # 事项状态
- state: str = ''
- @router.post('/query', summary="待办查询接口")
- def index(
- req: DaibanQueryReq,
- db: Session = Depends(get_db)
- ):
- logger.info(req)
- if settings.IS_DEV and req.accessToken != '4356e0de-c26a-11ef-895f-0242ac140002':
- return {
- "errcode": 1,
- "errmsg": "accessToken异常"
- }
-
- elif settings.IS_PROD and req.accessToken != '45c04f6c-c26a-11ef-895f-0242ac140002':
- return {
- "errcode": 1,
- "errmsg": "accessToken异常"
- }
- state = req.state
- applyerIdNum = req.sfzh
- startTime = req.startTime
- endTime = req.endTime
- pageNum = req.pageNum
- pageSize = req.pageSize
- startTime = time.strptime(startTime, "%Y-%m-%d %H:%M:%S")
- endTime = time.strptime(endTime, "%Y-%m-%d %H:%M:%S")
-
- where = and_(VwYstDaiban.update_time >= startTime, VwYstDaiban.update_time <= endTime)
-
- if applyerIdNum != '':
- applyerIdNum = applyerIdNum
- where = and_(where, VwYstDaiban.sfzh == applyerIdNum)
-
- if state == '01': # 待办
- where = and_(where, VwYstDaiban.status == 2)
-
- elif state == '02': # 办理中
- where = and_(where, VwYstDaiban.status == 1)
-
- elif state == '03': # 办结
- where = and_(where, VwYstDaiban.status == 2)
-
- elif state == '04': # 已过期
- where = and_(where, VwYstDaiban.update_time < (datetime.now() - timedelta(days=180)))
-
- elif state == '09': # 已删除
- where = and_(where, VwYstDaiban.update_time < (datetime.now() - timedelta(days=365)))
- else:
- where = and_(where, VwYstDaiban.status > 0)
- # 条数
- q = db.query(func.count(VwYstDaiban.ghid))
- model_count = q.filter(where).scalar()
- print("model_count:", state, model_count)
- # 明细
- q = db.query(VwYstDaiban)
- q = q.filter(where).order_by(VwYstDaiban.ghsj.desc())
- q = q.limit(pageSize).offset((int(pageNum) - 1) * pageSize)
- rows = q.all()
- records = []
- for row in rows:
- rec = new_record(get_model_dict(row))
- if rec is not None:
- records.append(rec)
- pageCount = len(records)
- pages = 1
- hasNextPage = pageCount >= pageSize
- logger.info(records)
- return {
- "errcode": 0,
- "errmsg": "成功",
- "data": {
- "pageNum": pageNum,
- "pageSize": pageSize,
- "size": pageCount,
- "pages": pages,
- "total": model_count,
- "hasNextPage": hasNextPage,
- "records": records
- }
- }
- def new_record(data: dict):
- shixiang = data['sxmc']
- projectNo = data['bzid']
- systemId = settings.YST_PASS_ID
- sourceSystemId = settings.YST_PASS_ID
- taskCodeLocal = shixiang
- applyTime = from_timestamp(data['create_time'])
- update_time = get_datetime_str(data['update_time'])
- cid = data['sfzh']
- name = data['xm']
-
- H5_HOST = "https://yjxp.mmsyjj.cn:8086"
- if settings.IS_DEV:
- H5_HOST = "http://120.241.74.139:8086"
- if shixiang == 'qyjcxx':
- taskTitle = '应急企业基础信息'
- detailURL = H5_HOST + '/mmh5_yjxm_yst/#/pages/mmyj/qyjcxx/index/index?id=' + data['bzid']
-
- elif shixiang == 'qyyjya':
- taskTitle = '应急预案上报'
- detailURL = H5_HOST + '/mmh5_yjxm_yst/#/pages/mmyj/qyyjya/index/index?id=' + data['bzid']
-
- elif shixiang == 'yjylzj':
- taskTitle = '应急演练总结'
- detailURL = H5_HOST + '/mmh5_yjxm_yst/#/pages/mmyj/yjylzj/index/index?id=' + data['bzid']
- state = '10'
- businessState = '待办'
- if data['status'] == 1:
- state = '02'
- businessState = '审核中'
- elif data['status'] == 2:
- state = '03'
- businessState = '审核通过'
- elif data['status'] == 3:
- state = '03'
- businessState = '审核不通过'
- #elif data['status'] == 2:
- # state = '01'
- # businessState = '待办'
-
- if data['update_time'] < (datetime.now() - timedelta(days=365)):
- state = '09'
- businessState = '已删除'
- if data['update_time'] < (datetime.now() - timedelta(days=180)):
- state = '04'
- businessState = '已过期'
-
- taskNameLocal = taskTitle
- return {
- # 办件编号
- 'projectNo': projectNo,
- # 业务系统标识
- 'systemId': systemId,
- # 来源系统标识
- 'sourceSystemId': sourceSystemId,
- # 办件标题
- 'taskTitle': taskTitle,
- # 事项名称(可选)
- 'taskName': '' + taskTitle, # 标题来的,很重要
- # 事项编码(可选)
- 'taskCode': '',
- # 业务系统自编事项名称
- 'taskNameLocal': taskNameLocal,
- # 业务系统自编事项编码
- 'taskCodeLocal': taskCodeLocal,
- # 事项版本号
- 'taskVersion': '',
- # 事项状态
- 'state': state,
- # 业务状态
- 'businessState': businessState,
- # 受理部门编码(可选)
- 'orgCode': '',
- # 受理部门名称(可选)
- 'orgName': '',
- # 地市区划编码
- 'zoneCode': '4414',
- # 办件提交时间
- 'applyTime': applyTime,
- # 办件详细信息URL
- 'detailURL': detailURL,
- # 更新时间
- 'update_time': update_time,
- # 申请人信息
- 'applyerInfo': {
- # 申请人类型
- 'applyerType': '1', # 自然人
- # 申请人名称
- 'applyerName': name,
- # 申请人证件类型
- 'applyerIdType': '10', # 身份证
- # 申请人证件号码
- 'applyerIdNum': cid,
- # 申请人统一身份认证平台账号(可选)
- 'applyerUid': '',
- # 法定代表人(可选)
- 'legal': ''
- },
- # 联系人信息
- 'contactInfo': {
- # 联系人/代理人姓名
- 'contactName': '',
- # 联系人/代理人证件类型
- 'contactIdType': '',
- # 联系人/代理人证件号码
- 'contactIdNum': '',
- # 联系人手机号码
- 'contactMobile': '',
- # 通讯地址
- 'address': '',
- # 联系人统一身份认证平台账号
- 'contactUid': ''
- }
- }
|