From 747d8ed2f6926581f2ead16d13478914728a9ffa Mon Sep 17 00:00:00 2001 From: lixiangyu <lixiangyu@xalxzn.com> Date: 星期日, 31 八月 2025 12:36:23 +0800 Subject: [PATCH] refactor(cms): 优化刀具入库提交流程并添加性能计时 --- src/main/java/org/jeecg/modules/cms/controller/CuttingInboundController.java | 169 +++++++++++++++++++++++++++++++++++++++++--------------- src/main/java/org/jeecg/modules/cms/mapper/xml/CuttingInventoryMapper.xml | 7 + 2 files changed, 129 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/jeecg/modules/cms/controller/CuttingInboundController.java b/src/main/java/org/jeecg/modules/cms/controller/CuttingInboundController.java index 173d574..932e249 100644 --- a/src/main/java/org/jeecg/modules/cms/controller/CuttingInboundController.java +++ b/src/main/java/org/jeecg/modules/cms/controller/CuttingInboundController.java @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import io.micrometer.core.annotation.Timed; import org.jeecg.common.api.vo.Result; import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.modules.cms.entity.CuttingInbound; @@ -284,77 +285,155 @@ // 鏉$爜鐢熸垚瑙勫垯绀轰緥锛氬垁鍏稩D + 搴忓彿(4浣�) + 闅忔満鏁� return cuttingId + String.format("%04d", index + 1) + (int) (Math.random() * 10000); } +// @GetMapping("/submit") +// public Result<?> submit(@RequestParam("orderId") String orderId) { +// // cuttingInboundService.submit(orderId); +// // return Result.ok("鎻愪氦鎴愬姛"); +// try { +// // 1. 鏇存柊鍏ュ簱鍗曠姸鎬� +// CuttingInbound cuttingInbound = cuttingInboundService.getById(orderId); +// if (cuttingInbound == null) { +// return Result.error("鏈壘鍒板搴旂殑鍏ュ簱鍗�"); +// } +// +// // 妫�鏌ュ叆搴撳崟鐘舵�侊紝鍙厑璁哥姸鎬佷负"1"鐨勫叆搴撳崟鎻愪氦 +// if (!"1".equals(cuttingInbound.getOrderStatus())) { +// return Result.error("鍙湁鐘舵�佷负鏈彁浜ょ殑鍏ュ簱鍗曟墠鑳芥墽琛屾彁浜ゆ搷浣�"); +// } +// +// // 2. 鏇存柊鐘舵�佷负宸叉彁浜� +// cuttingInbound.setOrderStatus("2"); +// boolean updateResult = cuttingInboundService.updateById(cuttingInbound); +// if (!updateResult) { +// return Result.error("鏇存柊鍏ュ簱鍗曠姸鎬佸け璐�"); +// } +// +// // 3. 鑾峰彇鍏ュ簱鏄庣粏 +// List<CuttingInboundDetail> detailList = cuttingInboundDetailService.lambdaQuery() +// .eq(CuttingInboundDetail::getOrderId, orderId) +// .list(); +// +// // 鐢ㄤ簬缁熻鎬绘暟閲� +// int totalSubmitted = 0; +// +// // 鎵归噺淇濆瓨鐨勫垪琛� +// List<CuttingInventory> inventoryList = new ArrayList<>(); +// List<CuttingInboundInventory> inboundInventoryList = new ArrayList<>(); +// +// // 4. 鏍规嵁鏄庣粏鏁伴噺鐢熸垚搴撳瓨璁板綍鍜屾潯鐮� +// for (CuttingInboundDetail detail : detailList) { +// // 鏍规嵁鏄庣粏涓殑鏁伴噺鐢熸垚瀵瑰簲鏁伴噺鐨勫簱瀛樿褰時eceive_number +// int quantity = detail.getReceiveNumber() != null ? detail.getReceiveNumber() : 0; +// for (int i = 0; i < quantity; i++) { +// totalSubmitted++; +// // 涓烘瘡涓垁鍏风敓鎴愮嫭绔嬬殑搴撳瓨璁板綍 +// CuttingInventory cuttingInventory = new CuttingInventory(); +// String inventoryId = UUID.randomUUID().toString().replace("-", ""); +// cuttingInventory.setId(inventoryId); +// cuttingInventory.setCuttingId(detail.getCuttingId()); +// // 涓烘瘡涓垁鍏风敓鎴愬敮涓�鏉$爜 +// cuttingInventory.setCuttingBarcode(generateUniqueBarcode(detail.getCuttingId(), i)); +// // 璁剧疆搴撳瓨鐘舵�佷负鍦ㄥ簱 +// cuttingInventory.setInventoryStatus("姝e父"); +// // 璁剧疆褰撳墠瀵垮懡涓�100 +// cuttingInventory.setCurrentLife(BigDecimal.valueOf(100)); +// // 娣诲姞鍒版壒閲忎繚瀛樺垪琛� +// inventoryList.add(cuttingInventory); +// +// // 寤虹珛鍏ュ簱鍗曚笌搴撳瓨鐨勫叧鑱斿叧绯� +// CuttingInboundInventory cuttingInboundInventory = new CuttingInboundInventory(); +// cuttingInboundInventory.setOrderId(orderId); +// cuttingInboundInventory.setInventoryId(inventoryId); +// // 娣诲姞鍒版壒閲忎繚瀛樺垪琛� +// inboundInventoryList.add(cuttingInboundInventory); +// } +// } +// +// // 鎵归噺淇濆瓨搴撳瓨璁板綍 +// if (!inventoryList.isEmpty()) { +// boolean saveResult = cuttingInventoryService.saveBatch(inventoryList); +// if (!saveResult) { +// throw new RuntimeException("淇濆瓨搴撳瓨璁板綍澶辫触"); +// } +// } +// +// // 鎵归噺淇濆瓨鍏宠仈鍏崇郴 +// if (!inboundInventoryList.isEmpty()) { +// boolean relationSaveResult = cuttingInboundInventoryService.saveBatch(inboundInventoryList); +// if (!relationSaveResult) { +// throw new RuntimeException("淇濆瓨鍏宠仈鍏崇郴澶辫触"); +// } +// } +// +// Map<String, Object> result = new HashMap<>(); +// result.put("message", "鎻愪氦鎴愬姛"); +// result.put("totalSubmitted", totalSubmitted); +// return Result.ok(result); +// } catch (Exception e) { +// log.error("鎻愪氦鍏ュ簱鍗曞け璐ワ紝orderId: " + orderId, e); +// throw new RuntimeException("鎻愪氦澶辫触: " + e.getMessage(), e); +// } +// } + @GetMapping("/submit") + @Timed(value = "cutting.inbound.submit", description = "鍒�鍏峰叆搴撴彁浜よ�楁椂") public Result<?> submit(@RequestParam("orderId") String orderId) { - // cuttingInboundService.submit(orderId); - // return Result.ok("鎻愪氦鎴愬姛"); + long startTime = System.currentTimeMillis(); try { // 1. 鏇存柊鍏ュ簱鍗曠姸鎬� CuttingInbound cuttingInbound = cuttingInboundService.getById(orderId); if (cuttingInbound == null) { return Result.error("鏈壘鍒板搴旂殑鍏ュ簱鍗�"); } - - // 妫�鏌ュ叆搴撳崟鐘舵�侊紝鍙厑璁哥姸鎬佷负"1"鐨勫叆搴撳崟鎻愪氦 - if (!"1".equals(cuttingInbound.getOrderStatus())) { - return Result.error("鍙湁鐘舵�佷负鏈彁浜ょ殑鍏ュ簱鍗曟墠鑳芥墽琛屾彁浜ゆ搷浣�"); - } - - // 2. 鏇存柊鐘舵�佷负宸叉彁浜� cuttingInbound.setOrderStatus("2"); - boolean updateResult = cuttingInboundService.updateById(cuttingInbound); - if (!updateResult) { - return Result.error("鏇存柊鍏ュ簱鍗曠姸鎬佸け璐�"); - } + cuttingInboundService.updateById(cuttingInbound); - // 3. 鑾峰彇鍏ュ簱鏄庣粏 + // 2. 鑾峰彇鍏ュ簱鏄庣粏 List<CuttingInboundDetail> detailList = cuttingInboundDetailService.lambdaQuery() .eq(CuttingInboundDetail::getOrderId, orderId) .list(); - // 鐢ㄤ簬缁熻鎬绘暟閲� + // 3. 鏀堕泦鎵�鏈夐渶瑕佷繚瀛樼殑鏁版嵁 + List<CuttingInventory> inventoryList = new ArrayList<>(); + List<CuttingInboundInventory> inboundInventoryList = new ArrayList<>(); - // 4. 鏍规嵁鏄庣粏鏁伴噺鐢熸垚搴撳瓨璁板綍鍜屾潯鐮� - int totalSubmitted = 0; for (CuttingInboundDetail detail : detailList) { - // 鏍规嵁鏄庣粏涓殑鏁伴噺鐢熸垚瀵瑰簲鏁伴噺鐨勫簱瀛樿褰時eceive_number - int quantity = detail.getReceiveNumber() != null ? detail.getReceiveNumber() : 0; - totalSubmitted = 0; + int quantity = detail.getReceiveNumber() != null ? detail.getReceiveNumber().intValue() : 0; + for (int i = 0; i < quantity; i++) { - totalSubmitted += quantity; - // 涓烘瘡涓垁鍏风敓鎴愮嫭绔嬬殑搴撳瓨璁板綍 + // 鐢熸垚搴撳瓨璁板綍 CuttingInventory cuttingInventory = new CuttingInventory(); cuttingInventory.setCuttingId(detail.getCuttingId()); - // 涓烘瘡涓垁鍏风敓鎴愬敮涓�鏉$爜 cuttingInventory.setCuttingBarcode(generateUniqueBarcode(detail.getCuttingId(), i)); - // 璁剧疆搴撳瓨鐘舵�佷负鍦ㄥ簱 cuttingInventory.setInventoryStatus("姝e父"); - // 璁剧疆褰撳墠瀵垮懡涓�100 cuttingInventory.setCurrentLife(BigDecimal.valueOf(100)); - // 淇濆瓨鍒板簱瀛樿〃 - boolean saveResult = cuttingInventoryService.save(cuttingInventory); - if (!saveResult) { - return Result.error("淇濆瓨搴撳瓨璁板綍澶辫触"); - } - - // 寤虹珛鍏ュ簱鍗曚笌搴撳瓨鐨勫叧鑱斿叧绯� - CuttingInboundInventory cuttingInboundInventory = new CuttingInboundInventory(); - cuttingInboundInventory.setOrderId(orderId); - cuttingInboundInventory.setInventoryId(cuttingInventory.getId()); - - // 淇濆瓨鍏宠仈鍏崇郴 - boolean relationSaveResult = cuttingInboundInventoryService.save(cuttingInboundInventory); - if (!relationSaveResult) { - return Result.error("淇濆瓨鍏宠仈鍏崇郴澶辫触"); - } + inventoryList.add(cuttingInventory); } } - Map<String, Object> result = new HashMap<>(); - result.put("message", "鎻愪氦鎴愬姛"); - result.put("totalSubmitted", totalSubmitted); + + // 4. 鎵归噺淇濆瓨搴撳瓨璁板綍锛堜竴娆℃�ф搷浣滐級 + if (!inventoryList.isEmpty()) { + cuttingInventoryService.saveBatch(inventoryList); + + // 5. 涓烘瘡涓繚瀛樼殑搴撳瓨璁板綍鍒涘缓鍏宠仈鍏崇郴 + for (CuttingInventory inventory : inventoryList) { + CuttingInboundInventory cuttingInboundInventory = new CuttingInboundInventory(); + cuttingInboundInventory.setOrderId(orderId); + cuttingInboundInventory.setInventoryId(inventory.getId()); + inboundInventoryList.add(cuttingInboundInventory); + } + + // 6. 鎵归噺淇濆瓨鍏宠仈鍏崇郴锛堜竴娆℃�ф搷浣滐級 + cuttingInboundInventoryService.saveBatch(inboundInventoryList); + } + + long endTime = System.currentTimeMillis(); + log.info("鍒�鍏峰叆搴撴彁浜ゅ畬鎴愶紝鑰楁椂: {} s", (endTime - startTime)/1000); return Result.ok("鎻愪氦鎴愬姛"); + } catch (Exception e) { - log.error("鎻愪氦鍏ュ簱鍗曞け璐ワ紝orderId: " + orderId, e); + long endTime = System.currentTimeMillis(); + log.error("鎻愪氦鍏ュ簱鍗曞け璐ワ紝orderId: " + orderId + "锛岃�楁椂: " + (endTime - startTime) + " ms", e); return Result.error("鎻愪氦澶辫触: " + e.getMessage()); } } diff --git a/src/main/java/org/jeecg/modules/cms/mapper/xml/CuttingInventoryMapper.xml b/src/main/java/org/jeecg/modules/cms/mapper/xml/CuttingInventoryMapper.xml index 0c9424a..d19863b 100644 --- a/src/main/java/org/jeecg/modules/cms/mapper/xml/CuttingInventoryMapper.xml +++ b/src/main/java/org/jeecg/modules/cms/mapper/xml/CuttingInventoryMapper.xml @@ -6,10 +6,13 @@ t1.cutting_id as cuttingId, count(*) AS cuttingIdNumber, t1.inventory_status as inventoryStatus, - t2.cutting_code AS cuttingCode + t2.cutting_code AS cuttingCode, + SUM(SUM(CASE WHEN t1.inventory_status = '姝e父' THEN 1 ELSE 0 END)) OVER() AS normalTotal, + SUM(SUM(CASE WHEN t1.inventory_status = '宸插嚭搴�' THEN 1 ELSE 0 END)) OVER() AS outboundTotal, + SUM(count(*)) OVER() AS totalNumber FROM cms_cutting_inventory t1 - LEFT JOIN cms_cutting_tool t2 ON t1.cutting_id = t2.id AND t2.del_flag = 0 + LEFT JOIN cms_cutting_tool t2 ON t1.cutting_id = t2.id AND t2.del_flag = 0 GROUP BY cutting_id, inventory_status, cutting_code </select> </mapper> \ No newline at end of file -- Gitblit v1.9.3