From ec16ef8d2052df05fc6d079117d9c8f136c194b1 Mon Sep 17 00:00:00 2001 From: dxc Date: Wed, 11 Feb 2026 08:38:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E4=BA=8E=E9=87=87=E8=B4=AD=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AE=B9=E8=BF=9B=E8=A1=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E5=85=B6=E5=A1=AB=E5=86=99=E6=9B=B4=E5=8A=A0?= =?UTF-8?q?=E4=BE=BF=E5=88=A9=E5=8A=A0=E4=B8=8A=E5=BA=93=E4=BD=8D=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8A=A0=E8=BD=BD=E4=B8=8A=E4=B8=80=E6=AC=A1=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inventory-backend/app/api/v1/inbound/buy.py | 53 ++++++++++++++-- .../app/services/inbound/buy_service.py | 30 +++++++-- inventory-web/src/api/inbound/buy.ts | 15 ++++- inventory-web/src/views/stock/inbound/buy.vue | 62 ++++++++++++------- 4 files changed, 124 insertions(+), 36 deletions(-) diff --git a/inventory-backend/app/api/v1/inbound/buy.py b/inventory-backend/app/api/v1/inbound/buy.py index a60e658..6ff7a46 100644 --- a/inventory-backend/app/api/v1/inbound/buy.py +++ b/inventory-backend/app/api/v1/inbound/buy.py @@ -5,19 +5,29 @@ import traceback inbound_buy_bp = Blueprint('stock_buy', __name__) + # ------------------------------------------------------------------ # 0. 基础物料搜索 # ------------------------------------------------------------------ @inbound_buy_bp.route('/search-base', methods=['GET']) def search_base(): + """ + 供前端下拉框远程搜索使用 + Query Param: keyword (名称或规格) + """ try: keyword = request.args.get('keyword', '') data = BuyInboundService.search_base_material(keyword) - return jsonify({"code": 200, "msg": "success", "data": data}) + return jsonify({ + "code": 200, + "msg": "success", + "data": data + }) except Exception as e: traceback.print_exc() return jsonify({"code": 500, "msg": str(e)}), 500 + # ------------------------------------------------------------------ # 1. 获取列表 # ------------------------------------------------------------------ @@ -27,6 +37,8 @@ def get_list(): page = request.args.get('page', 1, type=int) limit = request.args.get('pageSize', 15, type=int) keyword = request.args.get('keyword', '') + + # 获取状态列表参数,前端传参格式: statuses=在库,借库 statuses_str = request.args.get('statuses', '') statuses = statuses_str.split(',') if statuses_str else [] @@ -36,6 +48,7 @@ def get_list(): traceback.print_exc() return jsonify({"code": 500, "msg": str(e)}), 500 + # ------------------------------------------------------------------ # 2. 新增入库 # ------------------------------------------------------------------ @@ -45,12 +58,19 @@ def submit(): data = request.get_json() if not data: return jsonify({"code": 400, "msg": "No data"}), 400 + new_stock = BuyInboundService.handle_inbound(data) - return jsonify({"code": 200, "msg": "入库成功", "data": new_stock.to_dict()}) + + 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. 更新入库 # ------------------------------------------------------------------ @@ -63,6 +83,7 @@ def update_buy(id): except Exception as e: return jsonify({"code": 500, "msg": str(e)}), 500 + # ------------------------------------------------------------------ # 4. 删除 # ------------------------------------------------------------------ @@ -74,8 +95,18 @@ def delete_buy(id): except Exception as e: return jsonify({"code": 500, "msg": str(e)}), 500 + # ------------------------------------------------------------------ -# 5. 供应商建议 (基于 base_id) +# 5. 获取关联的出库历史 (如果有) +# ------------------------------------------------------------------ +@inbound_buy_bp.route('//history', methods=['GET']) +def get_history(id): + # 如果没有出库模块,这个接口可能为空,但为保持兼容性保留 + return jsonify({"code": 200, "msg": "success", "data": []}) + + +# ------------------------------------------------------------------ +# 6. 供应商建议 # ------------------------------------------------------------------ @inbound_buy_bp.route('/suggestions/suppliers', methods=['GET']) def get_supplier_suggestions(): @@ -85,8 +116,9 @@ def get_supplier_suggestions(): data = BuyInboundService.get_history_suppliers(base_id) return jsonify({"code": 200, "msg": "success", "data": data}) + # ------------------------------------------------------------------ -# 6. 采购人建议 (全局,基于 stock_buy 表) +# 7. 采购人建议 (全局) # ------------------------------------------------------------------ @inbound_buy_bp.route('/suggestions/users', methods=['GET']) def get_user_suggestions(): @@ -95,7 +127,7 @@ def get_user_suggestions(): return jsonify({"code": 200, "msg": "success", "data": data}) # ------------------------------------------------------------------ -# 7. 链接建议 (基于 base_id) +# 8. 链接建议 # ------------------------------------------------------------------ @inbound_buy_bp.route('/suggestions/links', methods=['GET']) def get_link_suggestions(): @@ -104,4 +136,15 @@ def get_link_suggestions(): if not base_id: return jsonify({"code": 400, "msg": "base_id required"}), 400 data = BuyInboundService.get_history_links(base_id, link_type) + return jsonify({"code": 200, "msg": "success", "data": data}) + +# ------------------------------------------------------------------ +# 9. [新增] 库位建议 +# ------------------------------------------------------------------ +@inbound_buy_bp.route('/suggestions/locations', methods=['GET']) +def get_location_suggestions(): + base_id = request.args.get('base_id', type=int) + if not base_id: + return jsonify({"code": 400, "msg": "base_id required"}), 400 + data = BuyInboundService.get_history_locations(base_id) return jsonify({"code": 200, "msg": "success", "data": data}) \ No newline at end of file diff --git a/inventory-backend/app/services/inbound/buy_service.py b/inventory-backend/app/services/inbound/buy_service.py index 0698d6a..53745e7 100644 --- a/inventory-backend/app/services/inbound/buy_service.py +++ b/inventory-backend/app/services/inbound/buy_service.py @@ -51,7 +51,8 @@ class BuyInboundService: query = query.filter( or_( MaterialBase.name.ilike(f'%{keyword}%'), - MaterialBase.spec_model.ilike(f'%{keyword}%') + MaterialBase.spec_model.ilike(f'%{keyword}%'), + MaterialBase.pinyin.ilike(f'%{keyword}%') ) ) query = query.order_by(MaterialBase.id.desc()).limit(20) @@ -336,22 +337,20 @@ class BuyInboundService: # ============================================================ @staticmethod def get_history_suppliers(base_id): - """返回该物料在 stock_buy 表中关联过的供应商列表""" + """返回该物料关联的供应商列表(去重)""" try: - # 去重查询 query = db.session.query(StockBuy.supplier_name).filter( StockBuy.base_id == base_id, StockBuy.supplier_name.isnot(None), StockBuy.supplier_name != '' ).distinct().order_by(StockBuy.supplier_name) - suppliers = [row[0] for row in query.all()] return suppliers except Exception: return [] # ============================================================ - # 7. 采购人/邮箱历史查询 (全局,从 stock_buy 获取) + # 7. 采购人建议 (全局,基于 stock_buy 表) # ============================================================ @staticmethod def get_history_purchasers(keyword): @@ -371,7 +370,7 @@ class BuyInboundService: StockBuy.buyer_email.ilike(kw) )) - # 按名字去重,取最新的记录(这里简单做 distinct,具体业务如果一个人有多个邮箱可能需要更复杂逻辑,这里简化为 distinct 组合) + # 按名字去重,取最新的记录(这里简单做 distinct) results = query.distinct().limit(20).all() users = [] @@ -401,5 +400,24 @@ class BuyInboundService: links = [row[0] for row in query.all()] return links + except Exception: + return [] + + # ============================================================ + # 9. [新增] 库位建议 (基于 base_id) + # ============================================================ + @staticmethod + def get_history_locations(base_id): + """查询该物料的历史存放库位,方便复用""" + try: + query = db.session.query(StockBuy.warehouse_location).filter( + StockBuy.base_id == base_id, + StockBuy.warehouse_location.isnot(None), + StockBuy.warehouse_location != '' + ).distinct().limit(10) + + # 简单去重列表 + locs = [row[0] for row in query.all()] + return locs except Exception: return [] \ No newline at end of file diff --git a/inventory-web/src/api/inbound/buy.ts b/inventory-web/src/api/inbound/buy.ts index 845cdd5..def37e0 100644 --- a/inventory-web/src/api/inbound/buy.ts +++ b/inventory-web/src/api/inbound/buy.ts @@ -47,17 +47,17 @@ export function searchMaterialBase(keyword: string) { // 6. 文件上传 (用于图片/拍照) export function uploadFile(data: FormData) { return request({ - url: '/common/upload', + url: '/common/upload', // 对应后端 /api/v1/common/upload method: 'post', data, headers: { 'Content-Type': 'multipart/form-data' } }) } -// 7. 文件删除 +// 7. [新增] 文件删除 export function deleteFile(filename: string) { return request({ - url: `/common/files/${filename}`, + url: `/common/files/${filename}`, // 对应后端 /api/v1/common/files/ method: 'delete' }) } @@ -87,4 +87,13 @@ export function getLinkSuggestions(params: any) { method: 'get', params }) +} + +// 11. [新增] 库位建议 +export function getLocationSuggestions(params: any) { + return request({ + url: '/inbound/buy/suggestions/locations', + method: 'get', + params + }) } \ No newline at end of file diff --git a/inventory-web/src/views/stock/inbound/buy.vue b/inventory-web/src/views/stock/inbound/buy.vue index b1420f4..53c7eea 100644 --- a/inventory-web/src/views/stock/inbound/buy.vue +++ b/inventory-web/src/views/stock/inbound/buy.vue @@ -98,6 +98,13 @@ + + +