|
@@ -0,0 +1,189 @@
|
|
|
+#!/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_id_get_warehouse_info(db,id):
|
|
|
+ query = db.query(ResourceProvisionWarehouseInfo)
|
|
|
+ query = query.filter_by(warehouse_id = id,del_flag = '0')
|
|
|
+ return query.first()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@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_type = ResourceProvisionWarehouseInfo(
|
|
|
+ warehouse_id = new_guid(),
|
|
|
+ warehouse_name=body['warehouse_name'],
|
|
|
+ status=body['status'],
|
|
|
+ contact_person=body['contact_person'],
|
|
|
+ contact_phone=body['contact_phone'],
|
|
|
+ address=body['address'],
|
|
|
+ type=body['type'],
|
|
|
+ level=body['level'],
|
|
|
+ storage_dept_id=body['storage_dept_id'],
|
|
|
+ storage_dept_name=body['storage_dept_name'],
|
|
|
+ area_name=body['area_name'],
|
|
|
+ longitude=body['longitude'],
|
|
|
+ latitude=body['latitude'],
|
|
|
+ area =body['area'],
|
|
|
+ remark=body['remark'],
|
|
|
+ create_id = user_id
|
|
|
+ )
|
|
|
+ db.add(new_type)
|
|
|
+ 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:
|
|
|
+ update_warehouse = warehouse_id_get_warehouse_info(db,id)
|
|
|
+ if not update_warehouse:
|
|
|
+ return JSONResponse(status_code=404,content={"code":404,"msg":"warehouse not found"})
|
|
|
+ update_warehouse.warehouse_name = body['warehouse_name']
|
|
|
+ update_warehouse.status = body['status']
|
|
|
+ update_warehouse.contact_person = body['contact_person']
|
|
|
+ update_warehouse.contact_phone = body['contact_phone']
|
|
|
+ update_warehouse.address = body['address']
|
|
|
+ update_warehouse.type = body['type']
|
|
|
+ update_warehouse.level = body['level']
|
|
|
+ update_warehouse.storage_dept_id = body['storage_dept_id']
|
|
|
+ update_warehouse.storage_dept_name = body['storage_dept_name']
|
|
|
+ update_warehouse.area_name = body['area_name']
|
|
|
+ update_warehouse.longitude = body['longitude']
|
|
|
+ update_warehouse.latitude = body['latitude']
|
|
|
+ update_warehouse.area = body['area']
|
|
|
+ update_warehouse.remark = body['remark']
|
|
|
+ update_warehouse.update_by = user_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)}")
|
|
|
+
|
|
|
+@router.get("/info/{id}")
|
|
|
+async def get_pattern_info(
|
|
|
+ id: str,
|
|
|
+ db: Session = Depends(get_db)
|
|
|
+):
|
|
|
+ try:
|
|
|
+
|
|
|
+ info = warehouse_id_get_warehouse_info(db,id)
|
|
|
+ if not info:
|
|
|
+ return JSONResponse(status_code=404,content={"code":404,"msg":"warehouse not found"})
|
|
|
+ data = {"warehouse_id": info.warehouse_id,
|
|
|
+ "warehouse_name": info.warehouse_name,
|
|
|
+ "status": info.status,
|
|
|
+ "contact_person": info.contact_person,
|
|
|
+ "contact_phone": info.contact_phone,
|
|
|
+ "address": info.address,
|
|
|
+ "remark": info.remark,
|
|
|
+ "type": info.type,
|
|
|
+ "level": info.level,
|
|
|
+ "storage_dept_id": info.storage_dept_id,
|
|
|
+ "storage_dept_name": info.storage_dept_name,
|
|
|
+ "area_name": info.area_name,
|
|
|
+ "longitude": info.longitude,
|
|
|
+ "latitude": info.latitude,
|
|
|
+ "create_by": info.create_by,
|
|
|
+ "area":info.area,
|
|
|
+ "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(ResourceProvisionWarehouseInfo)
|
|
|
+ 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(ResourceProvisionWarehouseInfo.create_time.desc())
|
|
|
+ # 执行分页查询
|
|
|
+ lists = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
+ data = [{"warehouse_id": info.warehouse_id,
|
|
|
+ "warehouse_name": info.warehouse_name,
|
|
|
+ "status": info.status,
|
|
|
+ "contact_person": info.contact_person,
|
|
|
+ "contact_phone": info.contact_phone,
|
|
|
+ "address": info.address,
|
|
|
+ "remark": info.remark,
|
|
|
+ "type": info.type,
|
|
|
+ "level": info.level,
|
|
|
+ "storage_dept_id": info.storage_dept_id,
|
|
|
+ "storage_dept_name": info.storage_dept_name,
|
|
|
+ "area_name": info.area_name,
|
|
|
+ "longitude": info.longitude,
|
|
|
+ "latitude": info.latitude,
|
|
|
+ "create_by": info.create_by,
|
|
|
+ "area":info.area,
|
|
|
+ "create_time":info.create_time} for info in lists]
|
|
|
+ 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 = warehouse_id_get_warehouse_info(db, id)
|
|
|
+ if not info:
|
|
|
+ return JSONResponse(status_code=404, content={"code": 404, "msg": "warehouse not found"})
|
|
|
+ info.del_flag='2'
|
|
|
+ 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)}")
|