|
@@ -3,7 +3,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 fastapi.responses import JSONResponse,StreamingResponse
|
|
|
+from common.db import db_czrz
|
|
|
from sqlalchemy.orm import Session
|
|
|
from sqlalchemy.sql import func
|
|
|
from common.auth_user import *
|
|
@@ -357,6 +358,125 @@ async def get_pattern_list(
|
|
|
traceback.print_exc()
|
|
|
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
|
|
|
|
|
+
|
|
|
+@router.get("/list")
|
|
|
+async def get_pattern_list(
|
|
|
+ request: Request,
|
|
|
+ user_id=Depends(valid_access_token),
|
|
|
+ material_id: str = Query(None, description='名称'),
|
|
|
+ material_name: str = Query(None, description='名称'),
|
|
|
+ warehouse_id: str = Query(None, description='名称'),
|
|
|
+ from_sys: str = Query(None, description='名称'),
|
|
|
+ auth_user: AuthUser = Depends(find_auth_user),
|
|
|
+ db: Session = Depends(get_db)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ query = db.query(ResourceProvisionMaterialInfo)
|
|
|
+ query = query.filter_by(del_flag='0')
|
|
|
+ if material_id:
|
|
|
+ query = query.filter(ResourceProvisionMaterialInfo.material_id.like(f'%{material_id}%'))
|
|
|
+ if material_name:
|
|
|
+ query = query.filter(ResourceProvisionMaterialInfo.material_name.like(f'%{material_name}%'))
|
|
|
+ if warehouse_id:
|
|
|
+ query = query.filter(ResourceProvisionMaterialInfo.warehouse_id==warehouse_id)
|
|
|
+ if from_sys:
|
|
|
+ query = query.filter(ResourceProvisionMaterialInfo.from_sys==from_sys)
|
|
|
+ # 排序
|
|
|
+ query = query.order_by(ResourceProvisionMaterialInfo.create_time.desc())
|
|
|
+ # 执行分页查询
|
|
|
+ lists = query.all()
|
|
|
+ data = []
|
|
|
+ for info in lists:
|
|
|
+ warehouse_info = warehouse_id_get_warehouse_info(db, info.warehouse_id)
|
|
|
+ if warehouse_info:
|
|
|
+ warehouse_name = warehouse_info.warehouse_name
|
|
|
+ else:
|
|
|
+ warehouse_name = None
|
|
|
+ material_type_info = type_id_get_material_type_info(db, info.material_type)
|
|
|
+ if material_type_info:
|
|
|
+ material_category_name = material_type_info.material_category_name
|
|
|
+ else:
|
|
|
+ material_category_name = None
|
|
|
+ warehouse_room_info = warehouse_room_id_get_warehouse_room_info(db, info.room_id)
|
|
|
+ if warehouse_room_info:
|
|
|
+ room_name = warehouse_room_info.room_name
|
|
|
+ else:
|
|
|
+ room_name = None
|
|
|
+ data.append({
|
|
|
+ "物资编码": info.material_id,
|
|
|
+ "物资名称": info.material_name,
|
|
|
+ "仓库id": info.warehouse_id,
|
|
|
+ "仓库": warehouse_name,
|
|
|
+ "库存": info.inventory,
|
|
|
+ "规格": info.specification,
|
|
|
+ "型号": info.model,
|
|
|
+ "分类名称": info.category_name,
|
|
|
+ "物资类型id": info.material_type,
|
|
|
+ "物资类型": material_category_name,
|
|
|
+ "计量单位名称": info.unit_name,
|
|
|
+ "品牌名称": info.brand_name,
|
|
|
+ "长(厘米)": info.length,
|
|
|
+ "宽(厘米)": info.width,
|
|
|
+ "高(厘米)": info.height,
|
|
|
+ "体积(立方厘米)": info.volume,
|
|
|
+ "毛重(kg)": info.gross_weight,
|
|
|
+ "净重(kg)": info.net_weight,
|
|
|
+ "生产厂商": info.manufacturer,
|
|
|
+ "产地": info.origin,
|
|
|
+ "状态": info.status,
|
|
|
+ "库房id": info.room_id,
|
|
|
+ "库房":room_name,
|
|
|
+ "包装数量": info.package_quantity,
|
|
|
+ "包装体积(立方厘米)": info.package_volume,
|
|
|
+ "包装重量(kg)": info.package_weight,
|
|
|
+ "价格": info.price,
|
|
|
+ "售卖价格": info.selling_price,
|
|
|
+ "价值": info.value,
|
|
|
+ "成本价格": info.cost_price,
|
|
|
+ "适用灾种": info.disaster_types,
|
|
|
+ "使用保养": info.maintenance,
|
|
|
+ "供应商名称": info.supplier_name,
|
|
|
+ "特殊运输要求": info.special_transportation_requirements,
|
|
|
+ "材质": info.material,
|
|
|
+ "保质期": info.shelf_life,
|
|
|
+ "库存预警推送人": info.inventory_warning_pusher,
|
|
|
+ "库存预警数量": info.inventory_warning_quantity,
|
|
|
+ "保质期到期预警天数": info.shelf_life_warning_days,
|
|
|
+ "保质期预警推送人": info.shelf_life_warning_pusher,
|
|
|
+ "来源系统": info.from_sys,
|
|
|
+ "数据创建时间":info.create_time})
|
|
|
+ # "fileList": get_resource_provision_file_query_fun(db=db,from_scenario='ResourceProvisionMaterialInfo', foreign_key=info.material_id)})
|
|
|
+
|
|
|
+ # 返回结果
|
|
|
+ import pandas as pd
|
|
|
+ from io import BytesIO
|
|
|
+ # 将查询结果转换为 DataFrame
|
|
|
+ df = pd.DataFrame(data)
|
|
|
+
|
|
|
+ # 将 DataFrame 导出为 Excel 文件
|
|
|
+ output = BytesIO()
|
|
|
+ with pd.ExcelWriter(output, engine='openpyxl') as writer:
|
|
|
+ df.to_excel(writer, index=False)
|
|
|
+
|
|
|
+ # 设置响应头
|
|
|
+ output.seek(0)
|
|
|
+ from urllib.parse import quote
|
|
|
+ encoded_filename = f'物资明细{datetime.now().strftime("%Y%m%d%H%mi%s")}.xlsx'
|
|
|
+ encoded_filename = quote(encoded_filename, encoding='utf-8')
|
|
|
+ headers = {
|
|
|
+ 'Content-Disposition': f'attachment; filename*=UTF-8\'\'{encoded_filename}',
|
|
|
+ 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
|
+ }
|
|
|
+
|
|
|
+ db_czrz.log(db, auth_user, "物资储备管理", f"物资储备管理物资明细导出数据成功", request.client.host)
|
|
|
+
|
|
|
+ # 返回文件流
|
|
|
+ return StreamingResponse(output, headers=headers)
|
|
|
+
|
|
|
+ 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,
|
|
@@ -428,6 +548,70 @@ async def get_pattern_list(
|
|
|
traceback.print_exc()
|
|
|
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
|
|
|
|
|
+@router.get("/barcode/export")
|
|
|
+async def get_pattern_list(
|
|
|
+ request: Request,
|
|
|
+ user_id=Depends(valid_access_token),
|
|
|
+ name: str = Query(None, description='名称'),
|
|
|
+ auth_user: AuthUser = Depends(find_auth_user),
|
|
|
+ db: Session = Depends(get_db)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ material_code_list=None
|
|
|
+ if name:
|
|
|
+ query_1 = db.query(ResourceProvisionMaterialInfo.material_id)
|
|
|
+ query_1 = query_1.filter(ResourceProvisionMaterialInfo.del_flag=='0')
|
|
|
+ query_1 = query_1.filter(ResourceProvisionMaterialInfo.material_name.like(f'%{name}%'))
|
|
|
+ material_code_list =[i.material_id for i in query_1.all()]
|
|
|
+ query = db.query(ResourceProvisionMaterialBarcode)
|
|
|
+ query = query.filter_by(del_flag='0')
|
|
|
+ if material_code_list is not None:
|
|
|
+ query = query.filter(ResourceProvisionMaterialBarcode.material_code.in_(material_code_list))
|
|
|
+ total_items = query.count()
|
|
|
+ # 排序
|
|
|
+ query = query.order_by(ResourceProvisionMaterialBarcode.create_time.desc())
|
|
|
+ # 执行分页查询
|
|
|
+ lists = query.all()
|
|
|
+ data = []
|
|
|
+ for info in lists:
|
|
|
+ material_info = material_id_get_material_info(db, info.material_code)
|
|
|
+ data.append({"id": info.id,
|
|
|
+ "物资名称": material_info.material_name,
|
|
|
+ "物资编号": info.material_code,
|
|
|
+ "条形码": info.barcode,
|
|
|
+ "二维码": info.qr_code,
|
|
|
+ "条码状态": info.status,
|
|
|
+ "创建时间": info.create_time} )
|
|
|
+
|
|
|
+ # 返回结果
|
|
|
+ import pandas as pd
|
|
|
+ from io import BytesIO
|
|
|
+ # 将查询结果转换为 DataFrame
|
|
|
+ df = pd.DataFrame(data)
|
|
|
+
|
|
|
+ # 将 DataFrame 导出为 Excel 文件
|
|
|
+ output = BytesIO()
|
|
|
+ with pd.ExcelWriter(output, engine='openpyxl') as writer:
|
|
|
+ df.to_excel(writer, index=False)
|
|
|
+
|
|
|
+ # 设置响应头
|
|
|
+ output.seek(0)
|
|
|
+ from urllib.parse import quote
|
|
|
+ encoded_filename = f'条码管理{datetime.now().strftime("%Y%m%d%H%mi%s")}.xlsx'
|
|
|
+ encoded_filename = quote(encoded_filename, encoding='utf-8')
|
|
|
+ headers = {
|
|
|
+ 'Content-Disposition': f'attachment; filename*=UTF-8\'\'{encoded_filename}',
|
|
|
+ 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
|
+ }
|
|
|
+
|
|
|
+ db_czrz.log(db, auth_user, "物资储备管理", f"物资储备管理条码管理导出数据成功", request.client.host)
|
|
|
+
|
|
|
+ # 返回文件流
|
|
|
+ return StreamingResponse(output, headers=headers)
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
|
|
+
|
|
|
@router.put('/barcode/changeStatus')
|
|
|
async def change_barcode_status(
|
|
|
db: Session = Depends(get_db),
|