|
@@ -0,0 +1,373 @@
|
|
|
+#!/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 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 common.websocketManager import *
|
|
|
+import json
|
|
|
+import traceback
|
|
|
+
|
|
|
+router = APIRouter()
|
|
|
+
|
|
|
+def warehouse_room_id_get_warehouse_room_info(db,id):
|
|
|
+ query = db.query(ResourceProvisionWarehouseRoomInfo)
|
|
|
+ query = query.filter_by(id = id,del_flag = '0')
|
|
|
+ return query.first()
|
|
|
+def warehouse_id_get_warehouse_info(db,id):
|
|
|
+ query = db.query(ResourceProvisionWarehouseInfo)
|
|
|
+ query = query.filter_by(warehouse_id = id,del_flag = '0')
|
|
|
+ return query.first()
|
|
|
+def type_id_get_material_type_info(db,id):
|
|
|
+ query = db.query(ResourceProvisionMaterialType)
|
|
|
+ query = query.filter_by(id = id,del_flag = '0')
|
|
|
+ return query.first()
|
|
|
+def material_id_get_material_info(db,id):
|
|
|
+ query = db.query(ResourceProvisionMaterialInfo)
|
|
|
+ query = query.filter_by(material_id = id,del_flag = '0')
|
|
|
+ return query.first()
|
|
|
+def delete_resource_provision_file(db,from_scenario,foreign_key):
|
|
|
+ file_query = db.query(ResourceProvisionFile)
|
|
|
+ file_query = file_query.filter(ResourceProvisionFile.del_flag != '2')
|
|
|
+ file_query = file_query.filter(ResourceProvisionFile.from_scenario == from_scenario)
|
|
|
+ file_query = file_query.filter(ResourceProvisionFile.foreign_key == foreign_key)
|
|
|
+ files = file_query.all()
|
|
|
+ for file in files:
|
|
|
+ file.del_flag = '2'
|
|
|
+
|
|
|
+@router.post("/create")
|
|
|
+async def create_pattern(
|
|
|
+ user_id=Depends(valid_access_token),
|
|
|
+ body = Depends(remove_xss_json),
|
|
|
+ db: Session = Depends(get_db)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ new_material = ResourceProvisionMaterialInfo(
|
|
|
+ # id = new_guid(),
|
|
|
+ material_name=body['material_name'],
|
|
|
+ warehouse_id=body['warehouse_id'],
|
|
|
+ inventory=body['inventory'],
|
|
|
+ specification=body['specification'],
|
|
|
+ model=body['model'],
|
|
|
+ category_name=body['category_name'],
|
|
|
+ material_type=body['material_type_id'],
|
|
|
+ unit_name=body['unit_name'],
|
|
|
+ brand_name=body['brand_name'],
|
|
|
+ length=body['length'],
|
|
|
+ width=body['width'],
|
|
|
+ height=body['height'],
|
|
|
+ volume=body['volume'],
|
|
|
+ gross_weight=body['gross_weight'],
|
|
|
+ net_weight=body['net_weight'],
|
|
|
+ manufacturer=body['manufacturer'],
|
|
|
+ origin=body['origin'],
|
|
|
+ status=body['status'],
|
|
|
+ room_id=body['room_id'],
|
|
|
+ package_quantity=body['package_quantity'],
|
|
|
+ package_volume=body['package_volume'],
|
|
|
+ package_weight=body['package_weight'],
|
|
|
+ price=body['price'],
|
|
|
+ selling_price=body['selling_price'],
|
|
|
+ value=body['value'],
|
|
|
+ cost_price=body['cost_price'],
|
|
|
+ disaster_types=body['disaster_types'],
|
|
|
+ maintenance=body['maintenance'],
|
|
|
+ supplier_name=body['supplier_name'],
|
|
|
+ special_transportation_requirements=body['special_transportation_requirements'],
|
|
|
+ material=body['material'],
|
|
|
+ shelf_life=body['shelf_life'],
|
|
|
+ inventory_warning_pusher=body['inventory_warning_pusher'],
|
|
|
+ inventory_warning_quantity=body['inventory_warning_quantity'],
|
|
|
+ shelf_life_warning_days=body['shelf_life_warning_days'],
|
|
|
+ shelf_life_warning_pusher=body['shelf_life_warning_pusher'],
|
|
|
+ from_sys=body['from_sys'],
|
|
|
+ create_id = user_id
|
|
|
+ )
|
|
|
+
|
|
|
+ db.add(new_material)
|
|
|
+ new_file_list = body['fileList']
|
|
|
+
|
|
|
+ for file in new_file_list:
|
|
|
+ file_name = file['file_name']
|
|
|
+ file_name_desc = file['file_name_desc']
|
|
|
+ status = file['status']
|
|
|
+ new_file = ResourceProvisionFile(
|
|
|
+ file_id=new_guid(),
|
|
|
+ foreign_key=new_material.material_id,
|
|
|
+ from_scenario='ResourceProvisionMaterialInfo',
|
|
|
+ file_name=file_name,
|
|
|
+ file_name_desc=file_name_desc,
|
|
|
+ status=status
|
|
|
+ )
|
|
|
+ db.add(new_file)
|
|
|
+ db.commit()
|
|
|
+ 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)}")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@router.put("/update/{id}")
|
|
|
+async def update_pattern(
|
|
|
+ id :str ,
|
|
|
+ user_id=Depends(valid_access_token),
|
|
|
+ body=Depends(remove_xss_json),
|
|
|
+ db: Session = Depends(get_db)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ info = material_id_get_material_info(db,id)
|
|
|
+ if not info:
|
|
|
+ return JSONResponse(status_code=404,content={"code":404,"msg":"warehouse room not found"})
|
|
|
+ # info.room_name = body['room_name']
|
|
|
+ info.material_name = body['material_name']
|
|
|
+ info.warehouse_id = body['warehouse_id']
|
|
|
+ info.inventory = body['inventory']
|
|
|
+ info.specification = body['specification']
|
|
|
+ info.model = body['model']
|
|
|
+ info.category_name = body['category_name']
|
|
|
+ info.material_type = body['material_type_id']
|
|
|
+ info.unit_name = body['unit_name']
|
|
|
+ info.brand_name = body['brand_name']
|
|
|
+ info.length = body['length']
|
|
|
+ info.width = body['width']
|
|
|
+ info.height = body['height']
|
|
|
+ info.volume = body['volume']
|
|
|
+ info.gross_weight = body['gross_weight']
|
|
|
+ info.net_weight = body['net_weight']
|
|
|
+ info.manufacturer = body['manufacturer']
|
|
|
+ info.origin = body['origin']
|
|
|
+ info.status = body['status']
|
|
|
+ info.room_id = body['room_id']
|
|
|
+ info.package_quantity = body['package_quantity']
|
|
|
+ info.package_volume = body['package_volume']
|
|
|
+ info.package_weight = body['package_weight']
|
|
|
+ info.price = body['price']
|
|
|
+ info.selling_price = body['selling_price']
|
|
|
+ info.value = body['value']
|
|
|
+ info.cost_price = body['cost_price']
|
|
|
+ info.disaster_types = body['disaster_types']
|
|
|
+ info.maintenance = body['maintenance']
|
|
|
+ info.supplier_name = body['supplier_name']
|
|
|
+ info.special_transportation_requirements = body['special_transportation_requirements']
|
|
|
+ info.material = body['material']
|
|
|
+ info.shelf_life = body['shelf_life']
|
|
|
+ info.inventory_warning_pusher = body['inventory_warning_pusher']
|
|
|
+ info.inventory_warning_quantity = body['inventory_warning_quantity']
|
|
|
+ info.shelf_life_warning_days = body['shelf_life_warning_days']
|
|
|
+ info.shelf_life_warning_pusher = body['shelf_life_warning_pusher']
|
|
|
+ info.from_sys = body['from_sys']
|
|
|
+ info.update_by = user_id
|
|
|
+
|
|
|
+ delete_resource_provision_file(db,'ResourceProvisionMaterialInfo',id)
|
|
|
+
|
|
|
+
|
|
|
+ new_file_list = body['fileList']
|
|
|
+ for file in new_file_list:
|
|
|
+ file_name = file['file_name']
|
|
|
+ file_name_desc = file['file_name_desc']
|
|
|
+ status = file['status']
|
|
|
+ new_file = ResourceProvisionFile(
|
|
|
+ file_id=new_guid(),
|
|
|
+ foreign_key=id,
|
|
|
+ from_scenario='ResourceProvisionMaterialInfo',
|
|
|
+ file_name=file_name,
|
|
|
+ file_name_desc=file_name_desc,
|
|
|
+ status=status
|
|
|
+ )
|
|
|
+ db.add(new_file)
|
|
|
+ db.commit()
|
|
|
+ return {"code": 200, "msg": "更新成功"}
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
|
|
+
|
|
|
+@router.get("/info/{id}")
|
|
|
+async def get_pattern_info(
|
|
|
+ id: str,
|
|
|
+ db: Session = Depends(get_db)
|
|
|
+):
|
|
|
+ try:
|
|
|
+
|
|
|
+ info = material_id_get_material_info(db,id)
|
|
|
+ if not info:
|
|
|
+ return JSONResponse(status_code=404,content={"code":404,"msg":"warehouse room not found"})
|
|
|
+ warehouse_info = warehouse_id_get_warehouse_info(db,info.warehouse_id)
|
|
|
+ if not warehouse_info:
|
|
|
+ warehouse_name=None
|
|
|
+ else:
|
|
|
+ warehouse_name = warehouse_info.warehouse_name
|
|
|
+ material_type_info = type_id_get_material_type_info(db,info.material_type)
|
|
|
+ if not material_type_info:
|
|
|
+ material_category_name=None
|
|
|
+ else:
|
|
|
+ material_category_name = material_type_info.material_category_name
|
|
|
+ warehouse_room_info = type_id_get_material_type_info(db, info.room_id)
|
|
|
+ if not warehouse_room_info:
|
|
|
+ room_name = None
|
|
|
+ else:
|
|
|
+ room_name = warehouse_room_info.room_name
|
|
|
+ data = {
|
|
|
+ "id": info.id,
|
|
|
+ "material_name": info.material_name,
|
|
|
+ "warehouse_id": info.warehouse_id,
|
|
|
+ "warehouse_name": warehouse_name,
|
|
|
+ "inventory": info.inventory,
|
|
|
+ "specification": info.specification,
|
|
|
+ "model": info.model,
|
|
|
+ "category_name": info.category_name,
|
|
|
+ "material_type_id": info.material_type,
|
|
|
+ "material_type_name": material_category_name,
|
|
|
+ "unit_name": info.unit_name,
|
|
|
+ "brand_name": info.brand_name,
|
|
|
+ "length": info.length,
|
|
|
+ "width": info.width,
|
|
|
+ "height": info.height,
|
|
|
+ "volume": info.volume,
|
|
|
+ "gross_weight": info.gross_weight,
|
|
|
+ "net_weight": info.net_weight,
|
|
|
+ "manufacturer": info.manufacturer,
|
|
|
+ "origin": info.origin,
|
|
|
+ "status": info.status,
|
|
|
+ "room_id": info.room_id,
|
|
|
+ "room_name":room_name,
|
|
|
+ "package_quantity": info.package_quantity,
|
|
|
+ "package_volume": info.package_volume,
|
|
|
+ "package_weight": info.package_weight,
|
|
|
+ "price": info.price,
|
|
|
+ "selling_price": info.selling_price,
|
|
|
+ "value": info.value,
|
|
|
+ "cost_price": info.cost_price,
|
|
|
+ "disaster_types": info.disaster_types,
|
|
|
+ "maintenance": info.maintenance,
|
|
|
+ "supplier_name": info.supplier_name,
|
|
|
+ "special_transportation_requirements": info.special_transportation_requirements,
|
|
|
+ "material": info.material,
|
|
|
+ "shelf_life": info.shelf_life,
|
|
|
+ "inventory_warning_pusher": info.inventory_warning_pusher,
|
|
|
+ "inventory_warning_quantity": info.inventory_warning_quantity,
|
|
|
+ "shelf_life_warning_days": info.shelf_life_warning_days,
|
|
|
+ "shelf_life_warning_pusher": info.shelf_life_warning_pusher,
|
|
|
+ "from_sys": info.from_sys,
|
|
|
+ "create_time":info.create_time}
|
|
|
+ return {"code": 200, "msg": "获取成功", "data": data}
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
|
|
+
|
|
|
+@router.get("/list")
|
|
|
+async def get_pattern_list(
|
|
|
+ # name: str = Query(None, description='名称'),
|
|
|
+ page: int = Query(1, gt=0, description='页码'),
|
|
|
+ pageSize: int = Query(10, gt=0, description='每页条目数量'),
|
|
|
+ db: Session = Depends(get_db)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ query = db.query(ResourceProvisionWarehouseRoomInfo)
|
|
|
+ query = query.filter_by(del_flag='0')
|
|
|
+ # if name:
|
|
|
+ # query = query.filter(ResourceProvisionWarehouseInfo.material_category_name.like(f'%{name}%'))
|
|
|
+ total_items = query.count()
|
|
|
+ # 排序
|
|
|
+ query = query.order_by(ResourceProvisionWarehouseRoomInfo.create_time.desc())
|
|
|
+ # 执行分页查询
|
|
|
+ lists = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
+ data = []
|
|
|
+ for info in lists:
|
|
|
+ warehouse_info = warehouse_id_get_warehouse_info(db, info.warehouse_id)
|
|
|
+ if not warehouse_info:
|
|
|
+ warehouse_name = None
|
|
|
+ else:
|
|
|
+ warehouse_name = warehouse_info.warehouse_name
|
|
|
+ material_type_info = type_id_get_material_type_info(db, info.material_type)
|
|
|
+ if not material_type_info:
|
|
|
+ material_category_name = None
|
|
|
+ else:
|
|
|
+ material_category_name = material_type_info.material_category_name
|
|
|
+ warehouse_room_info = type_id_get_material_type_info(db, info.room_id)
|
|
|
+ if not warehouse_room_info:
|
|
|
+ room_name = None
|
|
|
+ else:
|
|
|
+ room_name = warehouse_room_info.room_name
|
|
|
+ data.append({
|
|
|
+ "id": info.id,
|
|
|
+ "material_name": info.material_name,
|
|
|
+ "warehouse_id": info.warehouse_id,
|
|
|
+ "warehouse_name": warehouse_name,
|
|
|
+ "inventory": info.inventory,
|
|
|
+ "specification": info.specification,
|
|
|
+ "model": info.model,
|
|
|
+ "category_name": info.category_name,
|
|
|
+ "material_type_id": info.material_type,
|
|
|
+ "material_type_name": material_category_name,
|
|
|
+ "unit_name": info.unit_name,
|
|
|
+ "brand_name": info.brand_name,
|
|
|
+ "length": info.length,
|
|
|
+ "width": info.width,
|
|
|
+ "height": info.height,
|
|
|
+ "volume": info.volume,
|
|
|
+ "gross_weight": info.gross_weight,
|
|
|
+ "net_weight": info.net_weight,
|
|
|
+ "manufacturer": info.manufacturer,
|
|
|
+ "origin": info.origin,
|
|
|
+ "status": info.status,
|
|
|
+ "room_id": info.room_id,
|
|
|
+ "room_name":room_name,
|
|
|
+ "package_quantity": info.package_quantity,
|
|
|
+ "package_volume": info.package_volume,
|
|
|
+ "package_weight": info.package_weight,
|
|
|
+ "price": info.price,
|
|
|
+ "selling_price": info.selling_price,
|
|
|
+ "value": info.value,
|
|
|
+ "cost_price": info.cost_price,
|
|
|
+ "disaster_types": info.disaster_types,
|
|
|
+ "maintenance": info.maintenance,
|
|
|
+ "supplier_name": info.supplier_name,
|
|
|
+ "special_transportation_requirements": info.special_transportation_requirements,
|
|
|
+ "material": info.material,
|
|
|
+ "shelf_life": info.shelf_life,
|
|
|
+ "inventory_warning_pusher": info.inventory_warning_pusher,
|
|
|
+ "inventory_warning_quantity": info.inventory_warning_quantity,
|
|
|
+ "shelf_life_warning_days": info.shelf_life_warning_days,
|
|
|
+ "shelf_life_warning_pusher": info.shelf_life_warning_pusher,
|
|
|
+ "from_sys": info.from_sys,
|
|
|
+ "create_time":info.create_time})
|
|
|
+ return {"code": 200, "msg": "查询成功", "data": data,
|
|
|
+ "total": total_items,
|
|
|
+ "page": page,
|
|
|
+ "pageSize": pageSize,
|
|
|
+ "totalPages": (total_items + pageSize - 1) // pageSize
|
|
|
+ }
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
|
|
+
|
|
|
+@router.delete("/delete/{id}")
|
|
|
+async def delete_pattern(
|
|
|
+ id: str,
|
|
|
+ db: Session = Depends(get_db)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ # 检查图案是否存在
|
|
|
+ info = material_id_get_material_info(db, id)
|
|
|
+ if not info:
|
|
|
+ return JSONResponse(status_code=404, content={"code": 404, "msg": "warehouse room not found"})
|
|
|
+ info.del_flag='2'
|
|
|
+ delete_resource_provision_file(db, 'ResourceProvisionMaterialInfo', id)
|
|
|
+ db.commit()
|
|
|
+ return {"code": 200, "msg": "删除成功"}
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|