|
@@ -16,7 +16,7 @@ from models import *
|
|
|
from utils import *
|
|
|
from utils.spatial import *
|
|
|
from utils.ry_system_util import *
|
|
|
-from common.websocketManager import *
|
|
|
+from common.barcode import create_bar,create_qr
|
|
|
import json
|
|
|
import traceback
|
|
|
|
|
@@ -38,6 +38,14 @@ 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 material_id_get_material_barcode_info(db,id):
|
|
|
+ query = db.query(ResourceProvisionMaterialBarcode)
|
|
|
+ query = query.filter_by(material_code = id,del_flag = '0')
|
|
|
+ return query.first()
|
|
|
+def material_barcode_id_get_material_barcode_info(db,id):
|
|
|
+ query = db.query(ResourceProvisionMaterialBarcode)
|
|
|
+ query = query.filter_by(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')
|
|
@@ -127,6 +135,16 @@ async def create_pattern(
|
|
|
status=status
|
|
|
)
|
|
|
db.add(new_file)
|
|
|
+ bar_fileanme = new_guid()+'.png'
|
|
|
+ qr_fileanme = new_guid()+'.png'
|
|
|
+ if create_bar(str(new_material.material_id),bar_fileanme) and create_qr(str(new_material.material_id),qr_fileanme):
|
|
|
+ barcode = ResourceProvisionMaterialBarcode(
|
|
|
+ id=new_guid(),
|
|
|
+ material_code = new_material.material_id,
|
|
|
+ barcode = bar_fileanme,
|
|
|
+ qr_code = qr_fileanme
|
|
|
+ )
|
|
|
+ db.add(barcode)
|
|
|
db.commit()
|
|
|
return {"code": 200, "msg": "创建成功", "data": None}
|
|
|
except Exception as e:
|
|
@@ -391,10 +409,84 @@ async def delete_pattern(
|
|
|
info = material_id_get_material_info(db, id)
|
|
|
if not info:
|
|
|
return JSONResponse(status_code=404, content={"code": 404, "msg": "warehouse room not found"})
|
|
|
+ bar_info = material_id_get_material_barcode_info(db,id)
|
|
|
info.del_flag='2'
|
|
|
+ bar_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)}")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@router.get("/barcode/list")
|
|
|
+async def get_pattern_list(
|
|
|
+ name: str = Query(None, description='名称'),
|
|
|
+ page: int = Query(1, gt=0, description='页码'),
|
|
|
+ pageSize: int = Query(None, gt=0, description='每页条目数量'),
|
|
|
+ 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()
|
|
|
+ # 排序
|
|
|
+ if pageSize is None:
|
|
|
+ pageSize=total_items
|
|
|
+ query = query.order_by(ResourceProvisionMaterialBarcode.create_time.desc())
|
|
|
+ # 执行分页查询
|
|
|
+ lists = query.offset((page - 1) * pageSize).limit(pageSize).all()
|
|
|
+ data = []
|
|
|
+ for info in lists:
|
|
|
+ material_info = material_id_get_material_info(db, info.material_code)
|
|
|
+ data.append({"id": info.id,
|
|
|
+ "material_name": material_info.material_name,
|
|
|
+ "material_code": info.material_code,
|
|
|
+ "barcode": info.barcode,
|
|
|
+ "qr_code": info.qr_code,
|
|
|
+ "status": info.status,
|
|
|
+ "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.put('/barcode/changeStatus')
|
|
|
+async def change_barcode_status(
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+ body=Depends(remove_xss_json),
|
|
|
+ user_id=Depends(valid_access_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ barcode_id = body['id']
|
|
|
+ status = body['status']
|
|
|
+ info = material_barcode_id_get_material_barcode_info(db, barcode_id)
|
|
|
+ if not info:
|
|
|
+ return JSONResponse(status_code=404, content={"code": 404, "msg": "barcode not found"})
|
|
|
+ info.status= status
|
|
|
+ info.update_by=user_id
|
|
|
+ db.commit()
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "操作成功"
|
|
|
+ }
|
|
|
+ except Exception as e:
|
|
|
+ # 处理异常
|
|
|
+ traceback.print_exc()
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|