99 lines
3.4 KiB
Python
99 lines
3.4 KiB
Python
# inventory-backend/app/api/v1/inbound/semi.py
|
|
from flask import Blueprint, request, jsonify
|
|
from app.services.inbound.semi_service import SemiInboundService
|
|
import traceback
|
|
|
|
# 定义蓝图
|
|
inbound_semi_bp = Blueprint('inbound_semi', __name__)
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
# 0. 基础物料搜索
|
|
# ------------------------------------------------------------------
|
|
@inbound_semi_bp.route('/search-base', methods=['GET'])
|
|
def search_base():
|
|
"""
|
|
供前端下拉框远程搜索使用 (搜索半成品类型的基础物料)
|
|
Query Param: keyword (名称或规格)
|
|
"""
|
|
try:
|
|
keyword = request.args.get('keyword', '')
|
|
data = SemiInboundService.search_base_material(keyword)
|
|
return jsonify({
|
|
"code": 200,
|
|
"msg": "success",
|
|
"data": data
|
|
})
|
|
except Exception as e:
|
|
traceback.print_exc()
|
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
# 1. 获取半成品列表
|
|
# ------------------------------------------------------------------
|
|
@inbound_semi_bp.route('/list', methods=['GET'])
|
|
def get_list():
|
|
try:
|
|
page = request.args.get('page', 1, type=int)
|
|
limit = request.args.get('pageSize', 15, type=int)
|
|
keyword = request.args.get('keyword', '')
|
|
|
|
# 获取状态列表参数
|
|
statuses_str = request.args.get('statuses', '')
|
|
statuses = statuses_str.split(',') if statuses_str else []
|
|
|
|
result = SemiInboundService.get_list(page, limit, keyword, statuses)
|
|
return jsonify({"code": 200, "msg": "success", "data": result})
|
|
except Exception as e:
|
|
traceback.print_exc()
|
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
# 2. 新增半成品入库
|
|
# ------------------------------------------------------------------
|
|
@inbound_semi_bp.route('/submit', methods=['POST'])
|
|
def submit():
|
|
try:
|
|
data = request.get_json()
|
|
if not data:
|
|
return jsonify({"code": 400, "msg": "No data"}), 400
|
|
|
|
new_stock = SemiInboundService.handle_inbound(data)
|
|
|
|
return jsonify({
|
|
"code": 200,
|
|
"msg": "入库成功",
|
|
"data": new_stock.to_dict()
|
|
})
|
|
except Exception as e:
|
|
traceback.print_exc()
|
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
# 3. 更新半成品入库信息
|
|
# ------------------------------------------------------------------
|
|
@inbound_semi_bp.route('/<int:id>', methods=['PUT'])
|
|
def update_semi(id):
|
|
try:
|
|
data = request.get_json()
|
|
SemiInboundService.update_inbound(id, data)
|
|
return jsonify({"code": 200, "msg": "更新成功"})
|
|
except Exception as e:
|
|
traceback.print_exc()
|
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
# 4. 删除半成品入库记录
|
|
# ------------------------------------------------------------------
|
|
@inbound_semi_bp.route('/<int:id>', methods=['DELETE'])
|
|
def delete_semi(id):
|
|
try:
|
|
SemiInboundService.delete_inbound(id)
|
|
return jsonify({"code": 200, "msg": "删除成功"})
|
|
except Exception as e:
|
|
traceback.print_exc()
|
|
return jsonify({"code": 500, "msg": str(e)}), 500 |