libushang 5 天之前
父节点
当前提交
4368e7d03a

+ 50 - 1
models/resource_provision_base.py

@@ -774,4 +774,53 @@ class TransportCommunicationMaterial(Base):
     update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间')
     create_by = Column(BigInteger, default=None, comment='创建者')
     update_by = Column(BigInteger, default=None, comment='更新者')
-    del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
+    del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
+
+
+class RescueMateriaTransfer(Base):
+    __tablename__ = 'rescue_materia_transfer'
+
+
+    id = Column(Integer, primary_key=True, autoincrement=True)
+    application_time = Column(DateTime, default=datetime.now, comment='申请时间')
+    applicant = Column(String, comment='申请单位')
+    processing_person = Column(String, comment='处理人')
+    transfer_unit = Column(String, comment='调拨单位')
+    transferred_unit = Column(String, comment='调入单位')
+    reason_transfer = Column(String, comment='调拨原因')
+    book_value = Column(String, comment='账面价值(元)')
+    receiving_unit = Column(String, comment='接收单位')
+    receiving_location = Column(String, comment='接收地点')
+    use = Column(String, comment='出动物资用处')
+    contact_person = Column(String, comment='接收联系人')
+    contact_phone = Column(String, comment='接收联系人电话')
+    notes = Column(String, comment='备注')
+    reason = Column(String, comment='审批意见')
+    treatment = Column(String, comment='调拨处理办法:1无偿调拨  2 有偿调拨')
+    apply_status = Column(String, default='0', comment='审批状态 0 待审批 1 审批通过 2 审批不通过')
+    apply_time = Column(DateTime, comment='审批时间')
+
+    class Config:
+        orm_mode = True
+
+    
+class RescueMateriaTransferDetail(Base):
+    __tablename__ = 'rescue_materia_transfer_detail'
+
+
+    id = Column(Integer, primary_key=True, autoincrement=True)
+    pid = Column(Integer, comment='主表ID')
+    materia_name = Column(String, comment='资产名称')
+    materia_type = Column(String, comment='类型')
+    materia_unit = Column(String, comment='单位')
+    materia_num = Column(Integer, comment='数量')
+    num = Column(Integer, comment='数量')
+    price = Column(Float, comment='单价')
+    purchase_time = Column(DateTime, comment='购买时间')
+    order_num = Column(Integer)
+    area = Column(String, comment='地区')
+    management_unit = Column(String, comment='地区')
+    fuzeren = Column(String, comment='地区')
+
+    class Config:
+        orm_mode = True

+ 5 - 0
routers/api/resourceProvison/MaterialReserveManagement/__init__.py

@@ -13,6 +13,9 @@ from . import dispatch
 from . import warehouse_movement
 from . import warehouse_inbound
 from . import warehouse_outbound
+
+from . import transfer
+
 router = APIRouter()
 
 
@@ -26,3 +29,5 @@ router.include_router(dispatch.router, prefix="/dispatch", tags=["物资调度"]
 router.include_router(warehouse_movement.router, prefix="/warehouse_movement", tags=["库存明细"])
 router.include_router(warehouse_inbound.router, prefix="/warehouse_inbound", tags=["入库"])
 router.include_router(warehouse_outbound.router, prefix="/warehouse_outbound", tags=["出库"])
+
+router.include_router(transfer.router, prefix="/transfer", tags=["调拨"])

+ 126 - 0
routers/api/resourceProvison/MaterialReserveManagement/transfer.py

@@ -0,0 +1,126 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from fastapi import APIRouter, Request, Depends, Query, HTTPException, status,WebSocket,WebSocketDisconnect
+from common.security import valid_access_token,valid_websocket_token
+from fastapi.responses import JSONResponse
+from sqlalchemy.orm import Session
+from sqlalchemy.sql import func
+from sqlalchemy import text, exists, and_, or_, not_
+from common.auth_user import *
+from sqlalchemy import  text
+from pydantic import BaseModel
+from common.BigDataCenterAPI import *
+from database import get_db
+from typing import List
+from models import *
+from utils import *
+from utils.spatial import *
+from utils.ry_system_util import *
+from utils.resource_provision_util import *
+from common.db import db_yzy, db_msg_center
+from common import YzyApi
+import json
+import traceback
+from config import settings
+
+router = APIRouter()
+
+
+@router.post("/create")
+async def create(
+    user_id=Depends(valid_access_token),
+    body = Depends(remove_xss_json),
+    db: Session = Depends(get_db)
+):
+    try:
+        user_info = db.query(SysUser).filter(and_(SysUser.phonenumber == mpfun.enc_data(body['contact_phone']), SysUser.del_flag == '0')).first()
+        if user_info is None:
+            return {"code": 500, "msg": "联系方式无法匹配到粤政易账号", "data": None}
+        
+        new_trans = RescueMateriaTransfer(
+            application_time = datetime.now(),
+            applicant = body['applicant'],
+            # processing_person = '',
+            # transfer_unit = body['transfer_unit'],
+            # transferred_unit = body['transferred_unit'],
+            # reason_transfer = body['reason_transfer'],
+            # book_value = body['application_time'],
+            receiving_unit = body['receiving_unit'],
+            receiving_location = body['receiving_location'],
+            use = body['use'],
+            contact_person = body['contact_person'],
+            contact_phone = body['contact_phone'],
+            notes = body['notes'],
+            # reason = body['reason'],
+            treatment = body['treatment'],
+            apply_status = '0',
+            apply_time = None
+        )
+        db.add(new_trans)
+        db.commit()
+        db.refresh(new_trans)
+
+        i = 0
+        for n in body['items']:
+            i += 1
+            new_detail = RescueMateriaTransferDetail(
+                pid = new_trans.id,
+                materia_name = n['materia_name'],
+                materia_type = n['materia_type'],
+                materia_unit = n['materia_unit'],
+                materia_num = n['materia_num'],
+                num = n['num'],
+                area = n['area'],
+                management_unit = n['management_unit'],
+                fuzeren = n['fuzeren'],
+                order_num = i                
+            )
+            db.add(new_detail)
+
+        db.commit()
+
+        # 信息中心
+        to_user_id = user_info.user_id
+        yzy_account = user_info.yzy_account
+        task_title = '物资调配审批'
+        description = f"你有一个{task_title}任务需要处理,点击处理"
+        detail_url = "{}/yjxp/#/worker/rescueMateriaTranferApply".format(settings.YZY_WEB_ROOT)
+        foreign_key = str(new_trans.id)
+        from_scenario = "rescue_materia_tranfer"
+        db_msg_center.add_message(db, task_title, to_user_id, task_title, description, foreign_key, from_scenario)
+
+        # 发送粤政易消息
+        data = {
+            "yzy_userid": yzy_account,
+            "mobile": body['contact_phone'],
+            "content": description,
+            "recorded_by": user_id,
+            "detail_url": detail_url,
+            "foreign_key": foreign_key,
+            "from_scenario": from_scenario,
+            "title": "物资调配审批"
+        }
+        YzyApi.add_to_msg_queue(db, data)
+
+        return {"code": 200, "msg": "创建成功", "data": None}
+    
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+
+# 发送粤政易消息
+def send_yzy_msg(db: Session, msg_type: str, to_user_id: int, yzy_account: str, mobile, description: str, detail_url: str, foreign_key:str, from_scenario: str) -> None:
+    data = {
+        "yzy_userid": yzy_account,
+        "mobile": mobile,
+        "content": description,
+        "recorded_by": 0,
+        "detail_url": detail_url,
+        "foreign_key": foreign_key,
+        "from_scenario": from_scenario,
+        "title": "物资调配审批"
+    }
+    YzyApi.add_to_msg_queue(db, data)
+
+    db_msg_center.add_message(db, msg_type, to_user_id, "物资调配审批", description, foreign_key, from_scenario)