Browse Source

no message

libushang 1 month ago
parent
commit
badafa8776

+ 1 - 1
common/db/db_area.py

@@ -18,7 +18,7 @@ def id_get_area_info(db: Session,id):
     return query.first()
 def id_get_area_parent_list(db: Session,id,li:list = []):
     area = id_get_area_info(db,id)
-    print({"id":id,'label':area.area_name})
+    # print({"id":id,'label':area.area_name})
     li.append({"id":id,'label':area.area_name})
     if area.parent_id<=1:
         return li[::-1]

+ 106 - 0
common/enc/chemical_company_data.py

@@ -0,0 +1,106 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from . import mpfun
+from models import *
+from sqlalchemy.orm import Session
+from database import get_local_db
+
+# 危化企业信息表
+
+# 加密和HMAC签名
+def sign_row(db: Session, row: ChemicalCompany) -> None:
+    if row.sign != '':
+        return
+    
+    province = mpfun.base64_data(row.province) # 省
+    city = mpfun.base64_data(row.city) # 地市
+    area = mpfun.base64_data(row.area) # 区县
+    company_name = mpfun.base64_data(row.company_name) # 企业名称
+    company_code = mpfun.base64_data(row.company_code) # 企业编码
+    company_type = mpfun.base64_data(row.company_type) # 企业类型
+    credit_code = mpfun.base64_data(row.credit_code) # 统一社会信用代码
+    industry_classification = mpfun.base64_data(row.industry_classification) # 行业分类
+    
+    emergency_contact_number = mpfun.enc_data(row.emergency_contact_number) # 安全值班电话
+    emergency_response_hotline = mpfun.enc_data(row.emergency_response_hotline) # 应急咨询服务电话
+    qyagjgfzr_phone = mpfun.enc_data(row.qyagjgfzr_phone) # 企业安管机构负责人手机号
+    qyfgaqfzr_phone = mpfun.enc_data(row.qyfgaqfzr_phone) # 企业分管安全负责人手机号
+
+    xkzbh = mpfun.base64_data(row.xkzbh) # 许可证编号
+    issuance_date = mpfun.base64_data(row.issuance_date) # 发证日期
+    company_registration_number = mpfun.base64_data(row.company_registration_number) # 证书有效期
+    factory_address = mpfun.base64_data(row.factory_address) # 厂区地址
+    formatted_address = mpfun.base64_data(row.formatted_address) # 地址
+    safe_level = mpfun.base64_data(row.safe_level) # 安全标准化等级
+
+    sign_data = ",".join([province, city, area, company_name, company_code, company_type, credit_code, industry_classification, emergency_contact_number, emergency_response_hotline, 
+                          qyagjgfzr_phone, qyfgaqfzr_phone, xkzbh, issuance_date, company_registration_number, factory_address, formatted_address, safe_level])
+    sign_hmac = mpfun.sign_data(sign_data)
+    # print('sign_tbl_user sign_data:', sign_data)
+    # print('sign_tbl_user sign_hmac:', sign_hmac)
+
+    row.emergency_contact_number = emergency_contact_number
+    row.emergency_response_hotline = emergency_response_hotline
+    row.qyagjgfzr_phone = qyagjgfzr_phone
+    row.qyfgaqfzr_phone = qyfgaqfzr_phone
+    
+    row.sign = sign_hmac
+    
+    db.commit()
+
+# 比较字段合并字符串是否和MAC值匹配上,调用密码服务器[验证HMAC]接口
+def sign_valid_row(row: ChemicalCompany) -> bool:
+    if row.sign == '':
+        return True
+
+    # 关键字段合并字符串
+    sign_data = get_sign_str(row)
+    # print('sys_user sign_data:', sign_data)
+    
+    # 原HMACSM3数值
+    sign_hmac = row.sign
+    # print('sign_hmac:', sign_hmac)
+
+    return mpfun.hmac_verify(sign_data, sign_hmac)
+
+# 生成待签名的字符串
+def get_sign_str(row: ChemicalCompany) -> str:
+    province = mpfun.base64_data(row.province) # 省
+    city = mpfun.base64_data(row.city) # 地市
+    area = mpfun.base64_data(row.area) # 区县
+    company_name = mpfun.base64_data(row.company_name) # 企业名称
+    company_code = mpfun.base64_data(row.company_code) # 企业编码
+    company_type = mpfun.base64_data(row.company_type) # 企业类型
+    credit_code = mpfun.base64_data(row.credit_code) # 统一社会信用代码
+    industry_classification = mpfun.base64_data(row.industry_classification) # 行业分类
+    
+    emergency_contact_number = mpfun.enc_data(row.emergency_contact_number) # 安全值班电话
+    emergency_response_hotline = mpfun.enc_data(row.emergency_response_hotline) # 应急咨询服务电话
+    emergency_contacqyagjgfzr_phonet_number = mpfun.enc_data(row.qyagjgfzr_phone) # 企业安管机构负责人手机号
+    qyfgaqfzr_phone = mpfun.enc_data(row.qyfgaqfzr_phone) # 企业分管安全负责人手机号
+
+    xkzbh = mpfun.base64_data(row.xkzbh) # 许可证编号
+    issuance_date = mpfun.base64_data(row.issuance_date) # 发证日期
+    company_registration_number = mpfun.base64_data(row.company_registration_number) # 证书有效期
+    factory_address = mpfun.base64_data(row.factory_address) # 厂区地址
+    formatted_address = mpfun.base64_data(row.formatted_address) # 地址
+    safe_level = mpfun.base64_data(row.safe_level) # 安全标准化等级
+
+    # 关键字段合并字符串
+    sign_data = ",".join([province, city, area, company_name, company_code, company_type, credit_code, industry_classification, emergency_contact_number, emergency_response_hotline, 
+                          emergency_contacqyagjgfzr_phonet_number, qyfgaqfzr_phone, xkzbh, issuance_date, company_registration_number, factory_address, formatted_address, safe_level])
+    return sign_data
+
+# 生成HAMC签名值
+def get_sign_hmac(row: ChemicalCompany) -> str:
+    sign_data = get_sign_str(row)
+    return mpfun.sign_data(sign_data) 
+
+# 对所有数据进行签名
+def sign_table():
+    print('sign_chemical_company table =====>>>')
+    with get_local_db() as db:
+        rows = db.query(ChemicalCompany).filter(ChemicalCompany.sign == '').all()
+        for row in rows:
+            sign_row(db, row)

+ 78 - 0
common/enc/govdata_disaster_info_officer_data.py

@@ -0,0 +1,78 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from . import mpfun
+from models import *
+from sqlalchemy.orm import Session
+from database import get_local_db
+
+# 灾害信息员信息表
+
+# 加密和HMAC签名
+def sign_row(db: Session, row: GovdataDisasterInfoOfficer) -> None:
+    if row.sign != '':
+        return
+    
+    name = mpfun.base64_data(row.name) # 姓名
+    gender = mpfun.base64_data(row.gender) # 性别
+    work_unit = mpfun.base64_data(row.work_unit) # 工作单位
+    cellphone = mpfun.enc_data(row.cellphone) # 手机号码
+    location = mpfun.base64_data(row.location) # 所处位置
+    area = mpfun.base64_data(row.area) # 区县
+    longitude = str(row.longitude) # 经度
+    latitude = str(row.latitude) # 纬度
+    del_flag = row.del_flag # 是否已删除
+
+    sign_data = ",".join([name, gender, work_unit, cellphone, location, area, longitude, latitude, del_flag])
+    sign_hmac = mpfun.sign_data(sign_data)
+    # print('sign_data:', sign_data)
+    # print('sign_hmac:', sign_hmac)
+
+    row.cellphone = cellphone
+    row.sign = sign_hmac
+    
+    db.commit()
+
+# 比较字段合并字符串是否和MAC值匹配上,调用密码服务器[验证HMAC]接口
+def sign_valid_row(row: GovdataDisasterInfoOfficer) -> bool:
+    if row.sign == '':
+        return True
+
+    # 关键字段合并字符串
+    sign_data = get_sign_str(row)
+    # print('sys_user sign_data:', sign_data)
+    
+    # 原HMACSM3数值
+    sign_hmac = row.sign
+    # print('sign_hmac:', sign_hmac)
+
+    return mpfun.hmac_verify(sign_data, sign_hmac)
+
+# 生成待签名的字符串
+def get_sign_str(row: GovdataDisasterInfoOfficer) -> str:
+    name = mpfun.base64_data(row.name) # 姓名
+    gender = mpfun.base64_data(row.gender) # 性别
+    work_unit = mpfun.base64_data(row.work_unit) # 工作单位
+    cellphone = mpfun.enc_data(row.cellphone) # 手机号码
+    location = mpfun.base64_data(row.location) # 所处位置
+    area = mpfun.base64_data(row.area) # 区县
+    longitude = str(row.longitude) # 经度
+    latitude = str(row.latitude) # 纬度
+    del_flag = row.del_flag # 是否已删除
+
+    # 关键字段合并字符串
+    sign_data = ",".join([name, gender, work_unit, cellphone, location, area, longitude, latitude, del_flag])
+    return sign_data
+
+# 生成HAMC签名值
+def get_sign_hmac(row: GovdataDisasterInfoOfficer) -> str:
+    sign_data = get_sign_str(row)
+    return mpfun.sign_data(sign_data) 
+
+# 对所有数据进行签名
+def sign_table():
+    print('sign_govdata_disaster_info_officer table =====>>>')
+    with get_local_db() as db:
+        rows = db.query(GovdataDisasterInfoOfficer).filter(GovdataDisasterInfoOfficer.sign == '').all()
+        for row in rows:
+            sign_row(db, row)

+ 8 - 0
jobs/sign_data_job.py

@@ -12,6 +12,8 @@ from common.enc import sys_user_role_data, sys_user_post_data, sys_role_dept_dat
 from common.enc import sys_czrz_data
 from common.enc import emergency_contact_info_data
 from common.enc import three_proofing_responsible_person_data
+from common.enc import govdata_disaster_info_officer_data
+from common.enc import chemical_company_data
 
 
 # 对数据进行加密处理
@@ -54,6 +56,12 @@ def sign_data_proc():
 
     # 三防责任人管理人员信息表
     three_proofing_responsible_person_data.sign_table()
+
+    # 灾害信息员信息表
+    govdata_disaster_info_officer_data.sign_table()
+
+    # 危化企业信息表
+    chemical_company_data.sign_table()
     
     # 操作日志表
     sys_czrz_data.sign_table()

+ 29 - 1
models/city_base.py

@@ -18,6 +18,8 @@ class GovdataCity(Base):
     pinyin = Column(String(40), comment='拼音')
     status = Column(Enum('0', '1'), default='1', comment='状态')
 
+    class Config:
+        orm_mode = True
 
 class GovdataArea(Base):
     __tablename__ = 'govdata_area'
@@ -28,4 +30,30 @@ class GovdataArea(Base):
     parent_code = Column(String(20),  nullable=True, comment='父级区划编码')
     parent_id = Column(Integer, nullable=True, comment='父级ID')
     status = Column(String(2),  nullable=True, comment='状态')
-    create_time = Column(String(255),  nullable=True, comment='创建时间')
+    create_time = Column(String(255),  nullable=True, comment='创建时间')
+
+    class Config:
+        orm_mode = True
+
+# 灾害信息员
+class GovdataDisasterInfoOfficer(Base):
+    __tablename__ = 'govdata_disaster_info_officer'
+
+    id = Column(Integer, primary_key=True, autoincrement=True)
+    name = Column(String, nullable=False, comment='姓名')
+    gender = Column(String, nullable=False, comment='性别')
+    work_unit = Column(String, nullable=False, comment='工作单位')
+    cellphone = Column(String, nullable=False, comment='手机号码')
+    location = Column(String, nullable=True, comment='所处位置')
+    area = Column(String,  comment='区县')
+    longitude = Column(Float,  comment='经度')
+    latitude = Column(Float,  comment='纬度')
+    create_time = Column(DateTime, default=datetime.now, comment='数据创建时间')
+    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间')
+    create_dept = Column(BigInteger, default=None, comment='创建部门')
+    create_by = Column(BigInteger, default=None, comment='创建者')
+    del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
+    sign = Column(String, server_default='', default='', comment='HMACSM3数值')
+
+    class Config:
+        orm_mode = True

+ 22 - 3
models/resource_provision_base.py

@@ -78,8 +78,8 @@ class Unit(Base):
     address = Column(String(255), nullable=False, comment='地址')
     equipment = Column(String(255), comment='装备')
     training = Column(String(255), comment='训练')
-    responsible_person = Column(String(100), comment='负责人')
-    contact_number = Column(String(20), comment='联系电话')
+    responsible_person = Column(String(100), comment='队伍负责人')
+    contact_number = Column(String(20), comment='值班电话')
     longitude = Column(Float, comment='经度')
     latitude = Column(Float, comment='纬度')
     is_delete = Column(Integer, comment='删除标识')
@@ -88,6 +88,16 @@ class Unit(Base):
     supervisor_unit = Column(String(100), comment='主管单位')
     add_time = Column(DateTime, comment='插入时间')
 
+    unit_prop = Column(String, comment='队伍属性')
+    unit_level = Column(String, comment='队伍级别')
+    unit_favor = Column(String, comment='队伍特长')
+    
+    supervisor_unit_phone = Column(String, comment='主管单位联系人电话')
+    supervisor_unit_contact = Column(String, comment='主管单位联系人')
+    responsible_person_phone = Column(String, comment='队伍负责人移动电话')
+    area = Column(String, comment='所属行政区域')
+    founding_time = Column(String, comment='成立时间')
+
     def to_dict(self):
         return {
             "id": self.id,
@@ -103,7 +113,16 @@ class Unit(Base):
             "position": self.position,  # 新增字段:负责人职务
             "team_size": self.team_size,  # 新增字段:队伍人数
             "supervisor_unit": self.supervisor_unit,  # 新增字段:主管单位
-            "add_time": self.add_time
+            "add_time": self.add_time,
+            "unit_prop": self.unit_prop,
+            "unit_level": self.unit_level,
+            "unit_favor": self.unit_favor,
+            "supervisor_unit_phone": self.supervisor_unit_phone,
+            "supervisor_unit_contact": self.supervisor_unit_contact,
+            "responsible_person_phone": self.responsible_person_phone,
+            "area": self.area,
+            "founding_time": self.founding_time,            
+
             # "is_delete": self.is_delete
         }
     class Config:

+ 2 - 0
models/sharedb.py

@@ -5,6 +5,7 @@ from sqlalchemy.sql import func
 from database import Base
 from datetime import datetime
 
+# 危化企业信息表
 class ChemicalCompany(Base):
     __tablename__ = 'chemical_company'
 
@@ -47,6 +48,7 @@ class ChemicalCompany(Base):
     latitude = Column(Float, comment='纬度')
     formatted_address = Column(String, default='', comment='地址')
     s_last_updatetime = Column(DateTime, comment='更新时间')
+    sign = Column(String, server_default='', default='', comment='HMACSM3数值')
 
     class Config:
         orm_mode = True

+ 1 - 1
routers/api/ThreeProofingResponsible/person.py

@@ -639,7 +639,7 @@ def import_data(db,file_path,user_id,file_info):
             area_code2=area_code2,
             area_code=area_code,
             position=position,
-            phone=phone,
+            phone=phone.replace,
             telephone=telephone,
             user_id=user_id_1,
             order_num=order_num,

+ 4 - 0
routers/api/gateway/__init__.py

@@ -21,8 +21,12 @@ import time, os
 import math
 import uuid
 import re
+from . import sign_api
+
 router = APIRouter()
 
+router.include_router(sign_api.router)
+
 def contains_special_characters(input_string, special_characters=";|&|$|#|'|@| "):
     """
     判断字符串是否包含特殊符号。

+ 82 - 0
routers/api/gateway/sign_api.py

@@ -0,0 +1,82 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from fastapi import APIRouter, Request
+from database import get_db, get_share_db
+from sqlalchemy.orm import Session
+from utils import *
+from models import *
+from common.enc import mpfun, govdata_disaster_info_officer_data, chemical_company_data
+from exceptions import HmacException
+
+
+router = APIRouter()
+
+# 灾害信息员详情
+@router.post('/v2/get_point_info_emergency_disaster_info_officer')
+async def getEmergencyDisasterInfoOfficerDetails(
+    request: Request,
+    id: str,
+    db: Session = Depends(get_db)
+):
+    try:
+        row = db.query(GovdataDisasterInfoOfficer).filter(GovdataDisasterInfoOfficer.id == id).first()
+        info = get_model_dict(row)
+        info['cellphone'] = mpfun.dec_data(info['cellphone'])
+
+        if govdata_disaster_info_officer_data.sign_valid_row(row) == False:
+            raise HmacException(500, "应急预案人员信息表验证异常,已被非法篡改")
+        
+        return {
+            'code': 0,
+            'msg': 'success',
+            'rows': [info]
+        }
+    
+    except HmacException as e:
+        return {
+            'code': 500,
+            'msg': e.msg
+        }
+
+    except Exception as e:
+        return {
+            'code': 410,
+            'msg': '接口对应数据库暂不支持'
+        }
+
+# 危化企业详情
+@router.post('/v2/get_point_info_chemical_company')
+async def getChemicalcompanyDetails(
+    request: Request,
+    id: str,
+    db: Session = Depends(get_db)
+):
+    try:
+        row = db.query(ChemicalCompany).filter(ChemicalCompany.id == id).first()
+        info = get_model_dict(row)
+        info['emergency_contact_number'] = mpfun.dec_data(info['emergency_contact_number'])
+        info['emergency_response_hotline'] = mpfun.dec_data(info['emergency_response_hotline'])
+        info['qyagjgfzr_phone'] = mpfun.dec_data(info['qyagjgfzr_phone'])
+        info['qyfgaqfzr_phone'] = mpfun.dec_data(info['qyfgaqfzr_phone'])
+
+        if chemical_company_data.sign_valid_row(row) == False:
+            raise HmacException(500, "危化企业信息表验证异常,已被非法篡改")
+        
+        return {
+            'code': 0,
+            'msg': 'success',
+            'rows': [info]
+        }
+    
+    except HmacException as e:
+        return {
+            'code': 500,
+            'msg': e.msg
+        }
+
+    except Exception as e:
+        return {
+            'code': 410,
+            'msg': '接口对应数据库暂不支持'
+        }

+ 15 - 2
routers/api/resourceProvison/emergency_resources.py

@@ -9,6 +9,11 @@ from pydantic import BaseModel,Extra, Field
 import uuid
 from common.security import valid_access_token
 from pydantic import BaseModel
+from common.enc import mpfun, sys_menu_data, sys_menu_layer_data
+from common.auth_user import *
+from common.db import db_czrz
+import traceback
+from exceptions import HmacException
 
 from sqlalchemy import create_engine, Column, Integer, String, Boolean, MetaData, Table, \
     inspect, exists,or_,text,insert,asc,desc
@@ -164,7 +169,15 @@ class UnitSchema(BaseModel):
     latitude: float = None,
     position:str = None,
     team_size:int = None,
-    supervisor_unit:str=None,
+    supervisor_unit:str=None
+    unit_propt:str=None
+    unit_levelt:str=None
+    unit_favort:str=None
+    supervisor_unit_phonet:str=None
+    supervisor_unit_contactt:str=None
+    responsible_person_phonet:str=None
+    areat:str=None
+    founding_timet:str=None
     is_delete: int = 0
 
 class UnitListSchema(BaseModel):
@@ -277,7 +290,7 @@ def update_unit(unit_id: int, update_data: UnitSchema, db: Session = Depends(get
         db.refresh(unit)
         return {"code": 200, "msg": "更新成功", "unit": unit.to_dict()}
     except Exception as e:
-        db.rollback()
+        traceback.print_exc()
         raise HTTPException(status_code=400, detail=str(e))
 
 

+ 1 - 1
routers/prod_api/auth.py

@@ -167,7 +167,7 @@ async def login(
             'user_name': username
         })
 
-        db_czrz.log_username(db, row.user_id, auth['user_name'], row.nick_name, "登录", "后台管理账号+密码登录成功", request.client.host)
+        db_czrz.log_username(db, row.user_id, auth['user_name'], row.nick_name, "登录", "后台管理登录成功", request.client.host)
         row.login_date = datetime.now()
         row.login_ip = request.client.host
         row.login = row.login + 1

+ 2 - 1
routers/prod_api/system/__init__.py

@@ -13,6 +13,7 @@ from . import config
 from . import role
 from . import area
 from . import post
+from . import czrz
 
 import json
 
@@ -28,6 +29,6 @@ router.include_router(role.router, prefix="/role")
 router.include_router(area.router, prefix="/area")
 router.include_router(config.router, prefix="/config")
 router.include_router(post.router, prefix="/post")
-
+router.include_router(czrz.router, prefix="/czrz")
 
 

+ 73 - 0
routers/prod_api/system/czrz/__init__.py

@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from fastapi import APIRouter, Request, Depends, Query, HTTPException, status
+from common.security import valid_access_token
+from pydantic import BaseModel
+from database import get_db
+from sqlalchemy.orm import Session
+from typing import List
+from models import *
+from utils import *
+from utils.ry_system_util import *
+import json
+from sqlalchemy.sql import func
+from common.enc import mpfun, sys_dept_data
+from common.auth_user import *
+from common.db import db_czrz
+import traceback
+
+router = APIRouter()
+
+@router.get('/list')
+async def get_list(
+    # request: Request,
+    operIp: str = Query(None, max_length=100),
+    operName:str = Query(None, max_length=100),
+    title: str =  Query(None, max_length=100),
+    params: str =  Query(None, max_length=100),
+    dateRange: str =  Query(None, max_length=100),
+    pageNum: int = Query(1, gt=0, description="页码"),
+    pageSize: int = Query(10, gt=0, le=100, description="每页大小"),
+    db: Session = Depends(get_db),
+    user_id = Depends(valid_access_token),
+):
+    print(params)
+    query = db.query(CzrzEntity)
+    if operIp:
+        query = query.filter(CzrzEntity.ip.like(f'%{operIp}%'))
+    if operName:
+        query = query.filter(CzrzEntity.nick_name.like(f'%{operName}%'))
+    if title:
+        query = query.filter(CzrzEntity.action.like(f'%{title}%'))
+    if dateRange:
+        start_date, end_date = dateRange.split('-')
+        # start_date = datetime.strptime(start_date, "%Y-%m-%d")
+        # end_date = datetime.strptime(end_date, "%Y-%m-%d") + timedelta(days=1)
+        query = query.filter(CzrzEntity.gxsj.between(start_date, end_date))
+
+    total_count = query.count()
+
+    offset = (pageNum - 1) * pageSize
+    query = query.order_by(CzrzEntity.gxsj.desc()).offset(offset).limit(pageSize)
+    czrz_list = query.all()
+
+    # 将模型实例转换为字典
+    czrz_list_dict = [{
+            "operIp": item.ip,
+            "operName": item.nick_name,
+            "title": item.action,
+            "czrz": item.czrz,
+            "operTime": item.gxsj.strftime('%Y-%m-%d %H:%M:%S') if item.gxsj else '',
+        } for item in czrz_list]
+
+
+    return {
+        "code": 200,
+        "msg": "操作成功",
+        "rows": czrz_list_dict,
+        'pages': (total_count + pageSize - 1) // pageSize,
+        'total': total_count,
+        "currentPage": pageNum,
+        "pageSize": pageSize,
+    }