瀏覽代碼

no message

libushang 2 月之前
父節點
當前提交
093fd21257

+ 7 - 2
routers/api/yst/__init__.py

@@ -1,17 +1,22 @@
 #!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 from fastapi import APIRouter
+from . import yhxx
 from . import param
 from . import qyjcxx
 from . import file
 from . import yhpcsb
 from . import qyyjya
-from . import ylzj
+from . import yjylzj
+from . import daiban
 
 router = APIRouter()
+
+router.include_router(yhxx.router, prefix="/yhxx")
 router.include_router(param.router, prefix="/param")
 router.include_router(file.router, prefix="/file")
 router.include_router(qyjcxx.router, prefix="/qyjcxx")
 router.include_router(yhpcsb.router, prefix="/yhpcsb")
 router.include_router(qyyjya.router, prefix="/qyyjya")
-router.include_router(ylzj.router, prefix="/ylzj")
+router.include_router(yjylzj.router, prefix="/yjylzj")
+router.include_router(daiban.router, prefix="/daiban")

+ 252 - 0
routers/api/yst/daiban.py

@@ -0,0 +1,252 @@
+# -*- 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_RANQI_PASS_ID
+    sourceSystemId = settings.YST_RANQI_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': ''
+        }
+    }

+ 4 - 2
routers/api/yst/file.py

@@ -28,6 +28,8 @@ router = APIRouter()
 
 FILE_ALIAS_MAP = {
     'yyzz': '隐患点图片',
+    'yjya': '预案附件',
+    'ylzj': '演练总结',
 }
 
 @router.post('/upload')
@@ -48,7 +50,7 @@ async def upload(
     # 文件后续名校验
     suffix = os.path.splitext(file_name)[-1]
     if suffix.find('.') != -1:
-        if suffix.lower() not in ['.png', '.jpg', '.jpeg']:
+        if suffix.lower() not in ['.jpg', '.jpeg', '.png', '.pdf']:
             return {
                 'fileName': '',
                 'basePath': ''
@@ -125,7 +127,7 @@ def show(
             if os.path.exists(file_type_path) and os.path.isdir(file_type_path):
                 file_list = []
                 for file_name in os.listdir(file_type_path):
-                    file_list.append("/api/yst/file/show?thumb=&file_name={}".format(file_name))    
+                    file_list.append("/mmh5_yjxm_yst/ebus/yst_mmzhyj/api/yst/file/show?thumb=&file_name={}".format(file_name))    
                 valueMap = {
                     'fileType': file_type,
                     'imageUrls': file_list

+ 163 - 2
routers/api/yst/qyjcxx.py

@@ -5,7 +5,10 @@ from database import get_db
 from sqlalchemy.orm import Session
 from utils.sg_auth import *
 from models import *
+from utils import *
 from sqlalchemy import text, exists, and_, or_, not_
+from exceptions import *
+import traceback
 
 router = APIRouter()
 
@@ -16,8 +19,166 @@ async def accept(
     param: dict = Depends(yst_request_param),
     db: Session = Depends(get_db)
 ):
+    logger.info(param)
+
+    try:
+        uuid_str = get_req_param(param, 'uuid')
+        qydz = get_req_param(param, 'qydz')
+        qymc = get_req_param(param, 'qymc')
+        qyjb = get_req_param(param, 'qyjb')
+
+        szdq = get_req_param(param, 'szdq')
+        xxdz = get_req_param(param, 'xxdz')
+        zrrxm = get_req_param(param, 'zrrxm')
+        zrrdh = get_req_param(param, 'zrrdh')
+
+        sfzh = ext_info['cid']
+    
+        redis_key = "mmyj_yhxx_" + uuid_str
+        yhxx_info = redis_get_json(redis_key)
+        if yhxx_info is None:
+            raise AppException(code=1, msg="数据异常")
+        
+        db_entity = db.query(YstQyjcxxEntity).filter(YstQyjcxxEntity.bzid == uuid_str).filter(YstQyjcxxEntity.status == 1).first()
+        if db_entity is not None:
+            result =  {
+                'ret': 0,
+                'msg': '您的应急企业基础信息已提交成功,请耐心等待审核。',
+                'data': {
+                    'ywid': db_entity.bzid
+                }
+            }
+            return pt_sg_response(result)
+        
+        db.query(YstQyjcxxEntity).filter(YstQyjcxxEntity.bzid == uuid_str).filter(YstQyjcxxEntity.status == 0).delete()
+        db.commit()
+
+        db_entity = YstQyjcxxEntity()
+        db_entity.bzid = uuid_str
+        db_entity.sfzh = sfzh
+        db_entity.qymc = qymc
+        db_entity.qydz = qydz
+        db_entity.qyjb = qyjb
+        db_entity.szdq = szdq
+        db_entity.xxdz = xxdz
+        db_entity.zrrxm = zrrxm
+        db_entity.zrrdh = zrrdh
+        db_entity.status = 1
+        db_entity.create_time = datetime.now()
+        db.add(db_entity)
+        db.commit()
+    
+        # 已提交状态
+        jdsm = '您的应急企业基础信息已提交成功,请耐心等待茂名市应急管理局审核。'
+        process_entity = YstProcessEntity(bzid=uuid_str, sfzh=sfzh, sqly='yss', zt=0, ztsm='已提交', jdsm=jdsm, djsj=unixstamp(), bzlx='应急企业基础信息') 
+        db.add(process_entity)
+        db.commit()
+
+        # 审核中
+        jdsm = '茂名市应急管理局正在审核您所递交的申请材料。'
+        process_entity = YstProcessEntity(bzid=uuid_str, sfzh=sfzh, sqly='yst', zt=10, ztsm='审核中', jdsm=jdsm, djsj=unixstamp()+1, bzlx='应急企业基础信息') 
+        db.add(process_entity)
+        db.commit()
+
+        result =  {
+            'ret': 0,
+            'msg': '您的应急企业基础信息已提交成功,请耐心等待审核。',
+            'data': {
+                'ywid': uuid_str
+            }
+        }
+        return yst_response(result)
+    
+    except AppException as e:
+        traceback.print_exc()
+        result =  {
+            'ret': 1,
+            'msg': "服务异常,本次办理提交失败,您可尝试重新提交。"
+        }
+        return pt_sg_response(result)
+    
+@router.post("/detail")
+async def detail(
+    request: Request,
+    ext_info: str = Depends(yst_pass_ext),
+    param: dict = Depends(yst_request_param),
+    db: Session = Depends(get_db)
+):
+    sfzh = ext_info['cid']
+    bzid = get_req_param(param, 'bzid')
+
+    q = db.query(YstProcessEntity)
+    rows = q.filter(YstProcessEntity.bzid == bzid).order_by(YstProcessEntity.djsj.desc()).all()
+    
+    # 进度页
+    timeline = []
+    row_count = len(rows)
+    for i in range(0, row_count):
+        timeline.append(format_process_rec(i, row_count, rows[i]))
+
+    # 详情页
+    row = db.query(YstQyjcxxEntity).filter(YstQyjcxxEntity.bzid == bzid).first()
+    if row is None:
+        resp = {
+            'ret': 1,
+            'msg': '记录为空'
+        }
+        return yst_response(resp)
+
+    data = get_model_dict(row)
+    qyxxMap = {
+        '企业名称': data['qymc'], 
+        '企业级别': data['qyjb'], 
+        '企业地址': data['qydz']
+    }
+
+    jcxxMap = {
+        '所在地区': data['szdq'],
+        '详细地址': data['xxdz'],
+        '责任人姓名': xm_tuomin(data['zrrxm']),
+        '责任人电话': sj_tuomin(data['zrrdh'])
+    }
+
     resp = {
         'ret': 0,
-        'msg': "您的企业基本信息已成功提交。"
+        'timeline': timeline,
+        'qyxxMap': qyxxMap,
+        'jcxxMap': jcxxMap
+    }
+    return yst_response(resp)
+
+
+def format_process_rec(i: int, count: int, row: YstProcessEntity):
+    icon = ''
+    title = row.ztsm
+    desc = row.jdsm
+    time_str = from_timestamp(row.djsj)
+    action = 0
+    action_text = ''
+    active = 0
+
+    if i == 0 and row.zt == 10: # 审核中
+        icon = 'pending'
+    elif i == 0 and row.zt == 1: # 审核通过
+        icon = ''
+    elif i == 0 and row.zt == 4: # 已办结
+        icon = 'success'
+    elif i == 0 and row.zt == 9: # 拒绝
+        icon = 'warn'
+        action = 1
+        action_text = '重新提交'
+    elif i == 0 and row.zt == 3: # 再次申请
+        icon = 'warn'
+        action = 1
+        action_text = '重新提交'
+    
+
+    return {
+        'icon': icon,
+        'title':title,
+        'desc': desc,
+        'time': time_str,
+        'action': action,
+        'action_text': action_text,
+        'active': active
     }
-    return yst_response(resp)

+ 183 - 2
routers/api/yst/qyyjya.py

@@ -3,9 +3,13 @@
 from fastapi import APIRouter, Request, Depends
 from database import get_db
 from sqlalchemy.orm import Session
+from utils import *
 from utils.sg_auth import *
 from models import *
 from sqlalchemy import text, exists, and_, or_, not_
+from exceptions import *
+import traceback
+
 
 router = APIRouter()
 
@@ -16,8 +20,185 @@ async def accept(
     param: dict = Depends(yst_request_param),
     db: Session = Depends(get_db)
 ):
+    try:
+        bzid = get_req_param(param, 'uuid')
+        print(param)
+
+        sfzh = ext_info['cid']
+
+        redis_key = "mmyj_yhxx_" + bzid
+        yhxx_info = redis_get_json(redis_key)
+        if yhxx_info is None:
+            raise AppException(code=1, msg="数据异常")
+
+        db_entity = db.query(YstQyyjyaEntity).filter(YstQyyjyaEntity.bzid == bzid).filter(YstQyyjyaEntity.status == 1).first()
+        if db_entity is not None:
+            result =  {
+                'ret': 0,
+                'msg': '您的应急预案上报已提交成功,请耐心等待审核。',
+                'data': {
+                    'ywid': db_entity.bzid
+                }
+            }
+            return pt_sg_response(result)
+        
+        db.query(YstQyyjyaEntity).filter(YstQyyjyaEntity.bzid == bzid).filter(YstQyyjyaEntity.status == 0).delete()
+        db.commit()
+
+        new_yhpcsb = YstQyyjyaEntity(
+            bzid = bzid,
+            sfzh = sfzh,
+            qymc = get_req_param(param, 'qymc'),
+            qydz = get_req_param(param, 'qydz'),
+            qyjb = get_req_param(param, 'qyjb'),
+
+            bzmd = get_req_param(param, 'bzmd'),
+            bzyj = get_req_param(param, 'bzyj'),
+            qygk = get_req_param(param, 'qygk'),
+            wxxfx = get_req_param(param, 'wxxfx'),
+            syfw = get_req_param(param, 'syfw'),
+            yjjyyz = get_req_param(param, 'yjjyyz'),
+            yjczcs = get_req_param(param, 'yjczcs'),
+            yjxy = get_req_param(param, 'yjxy'),
+            
+            status = 1,
+            create_time = datetime.now()
+        )
+        db.add(new_yhpcsb)
+        db.commit()
+
+        db.query(YssYstUploadFileEntity).filter(YssYstUploadFileEntity.uuid == bzid).update({"bzid": bzid})
+        db.commit()
+
+        # 已提交状态
+        jdsm = '您的应急企业基础信息已提交成功,请耐心等待茂名市应急管理局审核。'
+        process_entity = YstProcessEntity(bzid=bzid, sfzh=sfzh, sqly='yss', zt=0, ztsm='已提交', jdsm=jdsm, djsj=unixstamp(), bzlx='应急预案上报') 
+        db.add(process_entity)
+        db.commit()
+
+        # 审核中
+        jdsm = '茂名市应急管理局正在审核您所递交的申请材料。'
+        process_entity = YstProcessEntity(bzid=bzid, sfzh=sfzh, sqly='yst', zt=10, ztsm='审核中', jdsm=jdsm, djsj=unixstamp()+1, bzlx='应急预案上报') 
+        db.add(process_entity)
+        db.commit()
+
+        result =  {
+            'ret': 0,
+            'msg': '您的应急预案上报已提交成功,请耐心等待审核。',
+            'data': {
+                'ywid': bzid
+            }
+        }
+        return yst_response(result)
+    
+    except AppException as e:
+        traceback.print_exc()
+        result =  {
+            'ret': 1,
+            'msg': "服务异常,本次办理提交失败,您可尝试重新提交。",
+            'data': {
+                'ywid': db_entity.bzid
+            }
+        }
+        return pt_sg_response(result)
+    
+
+@router.post("/detail")
+async def detail(
+    request: Request,
+    ext_info: str = Depends(yst_pass_ext),
+    param: dict = Depends(yst_request_param),
+    db: Session = Depends(get_db)
+):
+    sfzh = ext_info['cid']
+    bzid = get_req_param(param, 'bzid')
+
+    q = db.query(YstProcessEntity)
+    rows = q.filter(YstProcessEntity.bzid == bzid).order_by(YstProcessEntity.djsj.desc()).all()
+    
+    # 进度页
+    timeline = []
+    row_count = len(rows)
+    for i in range(0, row_count):
+        timeline.append(format_process_rec(i, row_count, rows[i]))
+
+    # 详情页
+    row = db.query(YstQyyjyaEntity).filter(YstQyyjyaEntity.bzid == bzid).first()
+    if row is None:
+        resp = {
+            'ret': 1,
+            'msg': '记录为空'
+        }
+        return yst_response(resp)
+
+    data = get_model_dict(row)
+    qyxxMap = {
+        '企业名称': data['qymc'], 
+        '企业级别': data['qyjb'], 
+        '企业地址': data['qydz']
+    }
+
+    yjyaMap = {
+        '编制目的': data['bzmd'],
+        '编制依据': data['bzyj'],
+        '企业概况': data['qygk'],
+        '危险性分析': data['wxxfx'],
+        '适用范围': data['syfw'],
+        '应急救援原则': data['yjjyyz'],
+        '应急处置措施': data['yjczcs'],
+        '应急响应': data['yjxy']
+    }
+
+    qtFile = []
+    imageUrls = []
+    rows = db.query(YssYstUploadFileEntity).filter(and_(YssYstUploadFileEntity.bzid == bzid, YssYstUploadFileEntity.file_type == 'yjya')).all()
+    for row in rows:
+        imageUrls.append(row.file_name)
+
+    if len(imageUrls) > 0:
+        qtFile.append({'fileName': '预案附件', 'imageUrls': imageUrls})
+
     resp = {
         'ret': 0,
-        'msg': "您的企业应急预案已成功提交。"
+        'timeline': timeline,
+        'qyxxMap': qyxxMap,
+        'yjyaMap': yjyaMap,
+        'qtFile': qtFile
+    }
+    return yst_response(resp)
+
+
+def format_process_rec(i: int, count: int, row: YstProcessEntity):
+    icon = ''
+    title = row.ztsm
+    desc = row.jdsm
+    time_str = from_timestamp(row.djsj)
+    action = 0
+    action_text = ''
+    active = 0
+
+    if i == 0 and row.zt == 10: # 审核中
+        icon = 'pending'
+    elif i == 0 and row.zt == 1: # 审核通过
+        icon = ''
+    elif i == 0 and row.zt == 4: # 已办结
+        icon = 'success'
+    elif i == 0 and row.zt == 9: # 拒绝
+        icon = 'warn'
+        action = 1
+        action_text = '重新提交'
+    elif i == 0 and row.zt == 3: # 再次申请
+        icon = 'warn'
+        action = 1
+        action_text = '重新提交'
+    
+
+    return {
+        'icon': icon,
+        'title':title,
+        'desc': desc,
+        'time': time_str,
+        'action': action,
+        'action_text': action_text,
+        'active': active
     }
-    return yst_response(resp)

+ 99 - 39
routers/api/yst/yhpcsb.py

@@ -7,6 +7,8 @@ from utils import *
 from utils.sg_auth import *
 from models import *
 from sqlalchemy import text, exists, and_, or_, not_
+from exceptions import *
+import traceback
 
 router = APIRouter()
 
@@ -17,37 +19,73 @@ async def accept(
     param: dict = Depends(yst_request_param),
     db: Session = Depends(get_db)
 ):
-    bzid = get_req_param(param, 'uuid')
-    print(param)
+    try:
+        bzid = get_req_param(param, 'uuid')
+        print(param)
 
-    new_yhpcsb = YstYhpcsbEntity(
-        bzid = bzid,
-        fzdc = get_req_param(param, 'fzdc'),
-        fzr = get_req_param(param, 'fzr'),
-        fzrdh = get_req_param(param, 'fzrdh'),
-        gm = get_req_param(param, 'gm'),
-        gzcs = get_req_param(param, 'gzcs'),
-        qzjjss = get_req_param(param, 'qzjjss'),
-        swxrs = get_req_param(param, 'swxrs'),
-        szdq = get_req_param(param, 'szdq'),
-        xxdz = get_req_param(param, 'xxdz'),
-        yhdmc = get_req_param(param, 'yhdmc'),
-        yhdzt = get_req_param(param, 'yhdzt'),
-        ywfzya = get_req_param(param, 'ywfzya'),
-        zhlx = get_req_param(param, 'zhlx'),
-        create_time = datetime.now()
-    )
-    db.add(new_yhpcsb)
-    db.commit()
+        sfzh = ext_info['cid']
 
-    db.query(YssYstUploadFileEntity).filter(YssYstUploadFileEntity.uuid == bzid).update({"bzid": bzid})
-    db.commit()
+        redis_key = "mmyj_yhxx_" + bzid
+        yhxx_info = redis_get_json(redis_key)
+        if yhxx_info is None:
+            raise AppException(code=1, msg="数据异常")
 
-    resp = {
-        'ret': 0,
-        'msg': "您的隐患排查上报已成功提交。"
-    }
-    return yst_response(resp)
+        db_entity = db.query(YstQyjcxxEntity).filter(YstQyjcxxEntity.bzid == bzid).filter(YstQyjcxxEntity.status == 1).first()
+        if db_entity is not None:
+            result =  {
+                'ret': 0,
+                'msg': '您的隐患排查上报已成功提交。',
+                'data': {
+                    'ywid': db_entity.bzid
+                }
+            }
+            return pt_sg_response(result)
+        
+        db.query(YstYhpcsbEntity).filter(YstYhpcsbEntity.bzid == bzid).filter(YstYhpcsbEntity.status == 0).delete()
+        db.commit()
+
+        new_yhpcsb = YstYhpcsbEntity(
+            bzid = bzid,
+            sfzh = sfzh,
+            qymc = get_req_param(param, 'qymc'),
+            qydz = get_req_param(param, 'qydz'),
+            qyjb = get_req_param(param, 'qyjb'),
+
+            fzdc = get_req_param(param, 'fzdc'),
+            fzr = get_req_param(param, 'fzr'),
+            fzrdh = get_req_param(param, 'fzrdh'),
+            gm = get_req_param(param, 'gm'),
+            gzcs = get_req_param(param, 'gzcs'),
+            qzjjss = get_req_param(param, 'qzjjss'),
+            swxrs = get_req_param(param, 'swxrs'),
+            szdq = get_req_param(param, 'szdq'),
+            xxdz = get_req_param(param, 'xxdz'),
+            yhdmc = get_req_param(param, 'yhdmc'),
+            yhdzt = get_req_param(param, 'yhdzt'),
+            ywfzya = get_req_param(param, 'ywfzya'),
+            zhlx = get_req_param(param, 'zhlx'),
+            status = 1,
+            create_time = datetime.now()
+        )
+        db.add(new_yhpcsb)
+        db.commit()
+
+        db.query(YssYstUploadFileEntity).filter(YssYstUploadFileEntity.uuid == bzid).update({"bzid": bzid})
+        db.commit()
+
+        resp = {
+            'ret': 0,
+            'msg': "您的隐患排查上报已成功提交。"
+        }
+        return yst_response(resp)
+    
+    except AppException as e:
+        traceback.print_exc()
+        result =  {
+            'ret': 1,
+            'msg': "服务异常,本次办理提交失败,您可尝试重新提交。"
+        }
+        return pt_sg_response(result)
 
 
 @router.post("/query")
@@ -57,12 +95,14 @@ async def query(
     param: dict = Depends(yst_request_param),
     db: Session = Depends(get_db)
 ):
-    rows = db.query(YstYhpcsbEntity).all()
+    sfzh = ext_info['cid']
+    rows = db.query(YstYhpcsbEntity).filter(YstYhpcsbEntity.sfzh == sfzh).filter(YstYhpcsbEntity.status == 1).order_by(YstYhpcsbEntity.create_time.desc()).all()
     data = [
         {
             "id": row.id,
             "yhdmc": row.yhdmc,
             "yhdzt": row.yhdzt,
+            "xxdz": row.xxdz,
             "szdq": row.szdq,
             "create_time": get_datetime_str(row.create_time)
         }
@@ -82,14 +122,34 @@ async def detail(
     param: dict = Depends(yst_request_param),
     db: Session = Depends(get_db)
 ):
-    id = get_req_param(param, 'id')
-    row = db.query(YstYhpcsbEntity).filter(YstYhpcsbEntity.id == id).first()
-    data = get_model_dict(row)
-    data["create_time"] = get_datetime_str(row.create_time)
+    try:
+        sfzh = ext_info['cid']
+        id = get_req_param(param, 'id')
+        row = db.query(YstYhpcsbEntity).filter(YstYhpcsbEntity.sfzh == sfzh).filter(YstYhpcsbEntity.id == id).first()
+        bzid = row.bzid
+        data = get_model_dict(row)
+        data["create_time"] = get_datetime_str(row.create_time)
 
-    resp = {
-        'ret': 0,
-        'msg': '',
-        'data': data
-    }
-    return yst_response(resp)
+        qtFile = []
+        imageUrls = []
+        rows = db.query(YssYstUploadFileEntity).filter(and_(YssYstUploadFileEntity.bzid == bzid, YssYstUploadFileEntity.file_type == 'yyzz')).all()
+        for row in rows:
+            imageUrls.append("/mmh5_yjxm_yst/ebus/yst_mmzhyj/api/yst/file/show?thumb=&file_name={}".format(row.file_name))
+
+        if len(imageUrls) > 0:
+            qtFile.append({'fileName': '隐患点图片', 'imageUrls': imageUrls})
+        resp = {
+            'ret': 0,
+            'msg': '',
+            'data': data,
+            'qtFile': qtFile
+        }
+        return yst_response(resp)
+    
+    except AppException as e:
+        traceback.print_exc()
+        result =  {
+            'ret': 1,
+            'msg': "服务异常"
+        }
+        return pt_sg_response(result)

+ 178 - 0
routers/api/yst/yhxx.py

@@ -0,0 +1,178 @@
+# -*- coding: utf-8 -*-
+from fastapi import APIRouter, Depends, Request
+from fastapi.responses import PlainTextResponse
+from sqlalchemy.orm import Session
+from database import get_db
+from utils.sg_auth import *
+from utils.redis_util import *
+from models import *
+from utils import *
+from extensions import logger
+from config import settings
+
+router = APIRouter()
+
+# 获取登录态数据
+# https://dgmpaas.yuque.com/appshell/yst/bgo7tx?#sjJu1
+@router.post("/get_yst_user_info", response_class=PlainTextResponse)
+def get_yst_user_info(
+    request: Request,
+    x_tif_signature: str = Header(None),
+    x_tif_nonce: str = Header(None),
+    x_tif_timestamp: str = Header(None),
+    x_tif_uid: str = Header(None),
+    x_tif_uinfo: str = Header(None),
+    x_tif_ext: str = Header(None),
+):
+    return yst_user_info_response(json.dumps({
+        "account_type": "human",
+        "corp": {
+            "level": "L2"
+        },
+        "tokenid": "ccb7fb65a9ca5a2d74c2afeed928c522"
+    }))
+
+    '''
+    {
+        "account": "DGD440782197706290318",
+        "account_type": "human",
+        "cid": "440782197706290318",
+        "corp": {
+            "account": "50b50b6d",
+            "address": "",
+            "cid": "91440705354627820H",
+            "ctype": "49",
+            "level": "L2",
+            "link_person_name": "李步尚",
+            "mobile": "13426789046",
+            "name": "江门市新会区尚软网络科技有限公司",
+            "role_type": "parent_linked",
+            "social_credit_code": "91440705354627820H",
+            "uid": "359a7db835994a7ebd147f09c5b9ae5d"
+        },
+        "ctype": "10",
+        "face_authtime": 1733726217276,
+        "level": "L2",
+        "login_type": "SG-GASMHS",
+        "mobile": "13426789046",
+        "name": "李步尚",
+        "origin": "SG",
+        "sex": "1",
+        "tokenid": "ccb7fb65a9ca5a2d74c2afeed928c522",
+        "uid": "5b8f1a3e774d4ba8b7ccb2b2d51a38cd",
+        "uversion": "10.0"
+    }
+    '''
+    
+    pass_token = "123" # settings.YST_RANQI_PASS_TOKEN
+    token_exception = TokenException()
+
+    if x_tif_signature is None or x_tif_nonce is None or x_tif_timestamp is None or x_tif_uid is None or x_tif_uinfo is None or x_tif_ext is None:
+        logger.error('========================>>>>>>>>>>>>>>>>>>>>>>> yst authentication err: 1')
+        raise token_exception
+
+    if authentication(x_tif_timestamp, pass_token, x_tif_nonce, x_tif_uid, x_tif_uinfo, x_tif_ext, x_tif_signature) == False:
+        logger.error('========================>>>>>>>>>>>>>>>>>>>>>>> yst authentication err: 2')
+        raise token_exception
+
+    json_str = base64.b64decode(x_tif_ext)
+    json_str = json_str.decode(encoding='utf-8')
+    x_tif_ext = json.loads(json_str) 
+
+    logger.info('========================>>>>>>>>>>>>>>>>>>>>>>> yst authentication ok: {}', x_tif_ext)
+    logger.info('========================>>>>>>>>>>>>>>>>>>>>>>> yst account_type: {}', x_tif_ext['account_type'])
+
+    tokenid = x_tif_ext['tokenid']
+    redis_key = "yst_token_" + tokenid
+    redis_set_json(redis_key, x_tif_ext)
+
+    corp = x_tif_ext["corp"]
+    if corp is not None:
+        corp = {
+            "level": x_tif_ext["corp"]["level"]
+        }
+
+    return yst_user_info_response(json.dumps({
+        "account_type": x_tif_ext["account_type"],
+        "corp": corp,
+        "tokenid": tokenid
+    }))
+
+# 用户信息查询接口
+@router.post('/query')
+def yhxx(
+    request: Request,
+    token: str,
+    ext_info: str = Depends(yst_pass_ext),
+    param: dict = Depends(yst_request_param),
+    db: Session = Depends(get_db)
+):
+    sfzh = ext_info['cid']
+    uuid_str = new_guid()
+    
+    '''
+    if settings.IS_DEV == True:
+        logger.info("使用测试身份证号 341181198809150011")
+        sfzh = "341181198809150011"
+    '''
+    
+    redis_key = "mmyj_yhxx_" + uuid_str
+    redis_set_json(redis_key, {
+        "custcode": "3101893742",
+        "compcode": "compcode",
+        "compname": "compname"
+    })
+
+    resp = {
+        'ret': 0,
+        'msg': '',
+        'data': {
+            'token': token,
+            'custcode':'3101893742', 
+            'uuid': uuid_str, 
+            'xm': xm_tuomin(ext_info['name']), 
+            'zjlx':'居民身份证', 
+            'zjhm': sfz_tuomin(sfzh),
+            'lxdh': ext_info['mobile']
+        }
+    }
+    return yst_response(resp)
+    
+
+    req = GetCustCodeListByIdReq()
+    req.custId = sfzh
+    result = requestApi.getCustCodeListById(req)
+    if result is None:
+        return yst_response({
+            "ret": 1,
+            "msg": "提交到应用服务器失败"
+        })
+    
+    if len(result['data']) == 0:
+        resp = {
+            'ret': 1,
+            'msg': '您在梅州中燃没有燃气账户'
+        }
+        return yst_response(resp)
+    
+    redis_key = "ranqi_yhxx_" + uuid_str
+    redis_set_json(redis_key, result['data'])
+
+    return_data = []
+    data = result['data']
+    for n in data:
+        return_data.append({
+            'token': token,
+            'custcode': n['custcode'], 
+            'uuid': uuid_str, 
+            'xm': xm_tuomin(ext_info['name']), 
+            'zjlx':'居民身份证', 
+            'zjhm': sfzh_tuomin(sfzh),
+            'lxdh': ext_info['mobile']
+        })
+    resp = {
+        'ret': 0,
+        'msg': '',
+        'data': return_data
+    }
+    return yst_response(resp)

+ 194 - 0
routers/api/yst/yjylzj.py

@@ -0,0 +1,194 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+from fastapi import APIRouter, Request, Depends
+from database import get_db
+from sqlalchemy.orm import Session
+from utils import *
+from utils.sg_auth import *
+from models import *
+from sqlalchemy import text, exists, and_, or_, not_
+from exceptions import *
+import traceback
+
+
+router = APIRouter()
+
+@router.post("/accept")
+async def accept(
+    request: Request,
+    ext_info: str = Depends(yst_pass_ext),
+    param: dict = Depends(yst_request_param),
+    db: Session = Depends(get_db)
+):
+    try:
+        bzid = get_req_param(param, 'uuid')
+        print(param)
+
+        sfzh = ext_info['cid']
+
+        redis_key = "mmyj_yhxx_" + bzid
+        yhxx_info = redis_get_json(redis_key)
+        if yhxx_info is None:
+            raise AppException(code=1, msg="数据异常")
+
+        db_entity = db.query(YstYjylzjEntity).filter(YstYjylzjEntity.bzid == bzid).filter(YstYjylzjEntity.status == 1).first()
+        if db_entity is not None:
+            result =  {
+                'ret': 0,
+                'msg': '您的应急演练总结已提交成功,请耐心等待审核。',
+                'data': {
+                    'ywid': db_entity.bzid
+                }
+            }
+            return pt_sg_response(result)
+        
+        db.query(YstYjylzjEntity).filter(YstYjylzjEntity.bzid == bzid).filter(YstYjylzjEntity.status == 0).delete()
+        db.commit()
+
+        new_yhpcsb = YstYjylzjEntity(
+            bzid = bzid,
+            sfzh = sfzh,
+            qymc = get_req_param(param, 'qymc'),
+            qydz = get_req_param(param, 'qydz'),
+            qyjb = get_req_param(param, 'qyjb'),
+
+            xmmc = get_req_param(param, 'xmmc'),
+            yllx = get_req_param(param, 'yllx'),
+            zzdw = get_req_param(param, 'zzdw'),
+            
+            status = 1,
+            create_time = datetime.now()
+        )
+        db.add(new_yhpcsb)
+        db.commit()
+
+        db.query(YssYstUploadFileEntity).filter(YssYstUploadFileEntity.uuid == bzid).update({"bzid": bzid})
+        db.commit()
+
+        # 已提交状态
+        jdsm = '您的应急演练总结已提交成功,请耐心等待茂名市应急管理局审核。'
+        process_entity = YstProcessEntity(bzid=bzid, sfzh=sfzh, sqly='yss', zt=0, ztsm='已提交', jdsm=jdsm, djsj=unixstamp(), bzlx='应急演练总结') 
+        db.add(process_entity)
+        db.commit()
+
+        # 审核中
+        jdsm = '茂名市应急管理局正在审核您所递交的申请材料。'
+        process_entity = YstProcessEntity(bzid=bzid, sfzh=sfzh, sqly='yst', zt=10, ztsm='审核中', jdsm=jdsm, djsj=unixstamp()+1, bzlx='应急演练总结') 
+        db.add(process_entity)
+        db.commit()
+
+        result =  {
+            'ret': 0,
+            'msg': '您的应急演练总结已提交成功,请耐心等待审核。',
+            'data': {
+                'ywid': bzid
+            }
+        }
+        return yst_response(result)
+    
+    except AppException as e:
+        traceback.print_exc()
+        result =  {
+            'ret': 1,
+            'msg': "服务异常,本次办理提交失败,您可尝试重新提交。",
+            'data': {
+                'ywid': db_entity.bzid
+            }
+        }
+        return pt_sg_response(result)
+    
+
+@router.post("/detail")
+async def detail(
+    request: Request,
+    ext_info: str = Depends(yst_pass_ext),
+    param: dict = Depends(yst_request_param),
+    db: Session = Depends(get_db)
+):
+    sfzh = ext_info['cid']
+    bzid = get_req_param(param, 'bzid')
+
+    q = db.query(YstProcessEntity)
+    rows = q.filter(YstProcessEntity.bzid == bzid).order_by(YstProcessEntity.djsj.desc()).all()
+    
+    # 进度页
+    timeline = []
+    row_count = len(rows)
+    for i in range(0, row_count):
+        timeline.append(format_process_rec(i, row_count, rows[i]))
+
+    # 详情页
+    row = db.query(YstYjylzjEntity).filter(YstYjylzjEntity.bzid == bzid).first()
+    if row is None:
+        resp = {
+            'ret': 1,
+            'msg': '记录为空'
+        }
+        return yst_response(resp)
+
+    data = get_model_dict(row)
+    qyxxMap = {
+        '企业名称': data['qymc'], 
+        '企业级别': data['qyjb'], 
+        '企业地址': data['qydz']
+    }
+
+    ylzjMap = {
+        '演练项目名称': data['xmmc'],
+        '演练类型名称': data['yllx'],
+        '组织单位': data['zzdw']
+    }
+
+    qtFile = []
+    imageUrls = []
+    rows = db.query(YssYstUploadFileEntity).filter(and_(YssYstUploadFileEntity.bzid == bzid, YssYstUploadFileEntity.file_type == 'ylzj')).all()
+    for row in rows:
+        imageUrls.append(row.file_name)
+
+    if len(imageUrls) > 0:
+        qtFile.append({'fileName': '演练总结', 'imageUrls': imageUrls})
+
+    resp = {
+        'ret': 0,
+        'timeline': timeline,
+        'qyxxMap': qyxxMap,
+        'ylzjMap': ylzjMap,
+        'qtFile': qtFile
+    }
+    return yst_response(resp)
+
+
+def format_process_rec(i: int, count: int, row: YstProcessEntity):
+    icon = ''
+    title = row.ztsm
+    desc = row.jdsm
+    time_str = from_timestamp(row.djsj)
+    action = 0
+    action_text = ''
+    active = 0
+
+    if i == 0 and row.zt == 10: # 审核中
+        icon = 'pending'
+    elif i == 0 and row.zt == 1: # 审核通过
+        icon = ''
+    elif i == 0 and row.zt == 4: # 已办结
+        icon = 'success'
+    elif i == 0 and row.zt == 9: # 拒绝
+        icon = 'warn'
+        action = 1
+        action_text = '重新提交'
+    elif i == 0 and row.zt == 3: # 再次申请
+        icon = 'warn'
+        action = 1
+        action_text = '重新提交'
+    
+
+    return {
+        'icon': icon,
+        'title':title,
+        'desc': desc,
+        'time': time_str,
+        'action': action,
+        'action_text': action_text,
+        'active': active
+    }

+ 0 - 23
routers/api/yst/ylzj.py

@@ -1,23 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-from fastapi import APIRouter, Request, Depends
-from database import get_db
-from sqlalchemy.orm import Session
-from utils.sg_auth import *
-from models import *
-from sqlalchemy import text, exists, and_, or_, not_
-
-router = APIRouter()
-
-@router.post("/accept")
-async def accept(
-    request: Request,
-    ext_info: str = Depends(yst_pass_ext),
-    param: dict = Depends(yst_request_param),
-    db: Session = Depends(get_db)
-):
-    resp = {
-        'ret': 0,
-        'msg': "您的演练总结已成功提交。"
-    }
-    return yst_response(resp)