feat(repair): implement backend CRUD services and API routes with RBAC permissions for repair module
This commit is contained in:
@ -10,6 +10,7 @@ from .base import inbound_base_bp
|
||||
from .product import inbound_product_bp
|
||||
from .inbound_summary import bp as inbound_summary_bp
|
||||
from .stock import bp as inbound_stock_bp
|
||||
from .repair import inbound_repair_bp
|
||||
|
||||
# 导入 service 模块,使其路由装饰器可以正常注册到 inbound_bp 上
|
||||
from . import service
|
||||
@ -21,5 +22,6 @@ inbound_bp.register_blueprint(inbound_base_bp, url_prefix='/base')
|
||||
inbound_bp.register_blueprint(inbound_product_bp, url_prefix='/product')
|
||||
inbound_bp.register_blueprint(inbound_summary_bp, url_prefix='/summary')
|
||||
inbound_bp.register_blueprint(inbound_stock_bp, url_prefix='/stock')
|
||||
inbound_bp.register_blueprint(inbound_repair_bp, url_prefix='/repair')
|
||||
|
||||
# service 模块的路由已经直接附加到 inbound_bp,无需再注册子蓝图
|
||||
|
||||
137
inventory-backend/app/api/v1/inbound/repair.py
Normal file
137
inventory-backend/app/api/v1/inbound/repair.py
Normal file
@ -0,0 +1,137 @@
|
||||
# inventory-backend/app/api/v1/inbound/repair.py
|
||||
from flask import Blueprint, request, jsonify
|
||||
from app.services.inbound.repair_service import RepairInboundService
|
||||
from app.utils.decorators import permission_required, audit_log
|
||||
import traceback
|
||||
|
||||
inbound_repair_bp = Blueprint('inbound_repair', __name__)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 1. 获取维修单列表
|
||||
# ------------------------------------------------------------------
|
||||
@inbound_repair_bp.route('/list', methods=['GET'])
|
||||
@permission_required('inbound_repair:list')
|
||||
def get_list():
|
||||
try:
|
||||
params = {
|
||||
'page': request.args.get('page', 1, type=int),
|
||||
'page_size': request.args.get('page_size', 20, type=int),
|
||||
'repair_no': request.args.get('repair_no'),
|
||||
'sku': request.args.get('sku'),
|
||||
'material_name': request.args.get('material_name'),
|
||||
'serial_number': request.args.get('serial_number'),
|
||||
'repair_status': request.args.get('repair_status'),
|
||||
}
|
||||
result = RepairInboundService.get_list(params)
|
||||
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_repair_bp.route('/submit', methods=['POST'])
|
||||
@permission_required('inbound_repair:add')
|
||||
@audit_log(
|
||||
module='维修管理',
|
||||
action='新增',
|
||||
get_target_name_fn=lambda: request.get_json().get('repair_no') if request.get_json() else None
|
||||
)
|
||||
def create():
|
||||
try:
|
||||
data = request.get_json()
|
||||
result = RepairInboundService.create(data)
|
||||
return jsonify({'code': 200, 'msg': 'success', 'data': result})
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return jsonify({'code': 500, 'msg': str(e)}), 500
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 3. 更新维修单
|
||||
# ------------------------------------------------------------------
|
||||
@inbound_repair_bp.route('/<int:id>', methods=['PUT'])
|
||||
@permission_required('inbound_repair:edit')
|
||||
@audit_log(
|
||||
module='维修管理',
|
||||
action='更新',
|
||||
get_target_name_fn=lambda: f"维修单ID:{request.view_args.get('id')}"
|
||||
)
|
||||
def update(id):
|
||||
try:
|
||||
data = request.get_json()
|
||||
result = RepairInboundService.update(id, data)
|
||||
if not result:
|
||||
return jsonify({'code': 404, 'msg': '维修单不存在'}), 404
|
||||
return jsonify({'code': 200, 'msg': 'success', 'data': result})
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return jsonify({'code': 500, 'msg': str(e)}), 500
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 4. 更新维修状态
|
||||
# ------------------------------------------------------------------
|
||||
@inbound_repair_bp.route('/update-status', methods=['POST'])
|
||||
@permission_required('inbound_repair:edit')
|
||||
@audit_log(
|
||||
module='维修管理',
|
||||
action='更新状态',
|
||||
get_target_name_fn=lambda: f"维修单ID:{request.get_json().get('id')}"
|
||||
)
|
||||
def update_status():
|
||||
try:
|
||||
data = request.get_json()
|
||||
id = data.get('id')
|
||||
status = data.get('status')
|
||||
repair_log = data.get('repair_log')
|
||||
if not id or not status:
|
||||
return jsonify({'code': 400, 'msg': 'id 和 status 不能为空'}), 400
|
||||
|
||||
result = RepairInboundService.update_status(id, status, repair_log)
|
||||
if not result:
|
||||
return jsonify({'code': 404, 'msg': '维修单不存在'}), 404
|
||||
return jsonify({'code': 200, 'msg': 'success', 'data': result})
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return jsonify({'code': 500, 'msg': str(e)}), 500
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 5. 删除维修单
|
||||
# ------------------------------------------------------------------
|
||||
@inbound_repair_bp.route('/<int:id>', methods=['DELETE'])
|
||||
@permission_required('inbound_repair:delete')
|
||||
@audit_log(
|
||||
module='维修管理',
|
||||
action='删除',
|
||||
get_target_name_fn=lambda: f"维修单ID:{request.view_args.get('id')}"
|
||||
)
|
||||
def delete(id):
|
||||
try:
|
||||
success = RepairInboundService.delete(id)
|
||||
if not success:
|
||||
return jsonify({'code': 404, 'msg': '维修单不存在'}), 404
|
||||
return jsonify({'code': 200, 'msg': '删除成功'})
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return jsonify({'code': 500, 'msg': str(e)}), 500
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 6. 获取维修单详情
|
||||
# ------------------------------------------------------------------
|
||||
@inbound_repair_bp.route('/<int:id>', methods=['GET'])
|
||||
@permission_required('inbound_repair:list')
|
||||
def get_detail(id):
|
||||
try:
|
||||
result = RepairInboundService.get_by_id(id)
|
||||
if not result:
|
||||
return jsonify({'code': 404, 'msg': '维修单不存在'}), 404
|
||||
return jsonify({'code': 200, 'msg': 'success', 'data': result})
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return jsonify({'code': 500, 'msg': str(e)}), 500
|
||||
Reference in New Issue
Block a user