Sfoglia il codice sorgente

[task-5919] 试剂耗材出库登记增加流程,相应增加库存一览表预扣量接口

huangws 3 settimane fa
parent
commit
c1cca9a7e4

+ 2 - 1
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/reagent/api/ILingYongService.java

@@ -78,5 +78,6 @@ public interface ILingYongService {
 	 */
 	@RequestMapping(value = "/save", method = { RequestMethod.POST })
 	public APIResult<Void> save(
- 			@RequestBody(required = true) @Valid LingYongPo lingYongPo);
+ 			@RequestBody(required = true) @Valid LingYongPo lingYongPo,
+			@RequestParam(required = false) String operate);
 }

+ 109 - 2
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/reagent/provider/LingYongProvider.java

@@ -98,11 +98,118 @@ public class LingYongProvider extends GenericProvider implements ILingYongServic
 			})
 	@Override
 	public APIResult<Void> save(
+			@ApiParam(name = "lingYongPo", value = "试剂耗材领用主表对象", required = true)
+			@RequestBody(required = true) LingYongPo lingYongPo,
+			@RequestParam(required = false) String operate) {
+		APIResult<Void> result = new APIResult<Void>();
+		// 默认操作类型,如果为空则视为正常领用开始
+		if (operate == null) {
+			operate = "not";
+		}
+		try {
+			logger.info(" com.lc.ibps.components.provider.LingYongProvider.save()--->lingYongPo: {}, operate: {}", lingYongPo.toString(), operate);
+			String sids = "";
+			// 判断是否为正常领用流程
+			boolean isNormalFlow = !"back".equalsIgnoreCase(operate) && !"end".equalsIgnoreCase(operate);
+			if (!lingYongPo.getLingYongDetailPoList().isEmpty()) {
+				if (isNormalFlow) {
+					// --- 原有逻辑开始 (正常领用) ---
+					sids = lingYongPo.getWeiZhiLingYong();
+					/**  把流水id转换为库存id */
+					ReagentConsumabConvertAndPadId(lingYongPo);
+					List<Map<String, Object>> records = new ArrayList<>(lingYongPo.getLingYongDetailPoList().size());
+					for (LingYongDetailPo bean : lingYongPo.getLingYongDetailPoList()) {
+						Map<String, Object> map = new HashMap<>();
+						String id = UniqueIdUtil.getId();
+						map.put("id_", id);
+						bean.setTaiZhangId(id);
+						map.put("ming_cheng_", StrUtil.str(bean.getShiJiMingCheng()));
+						map.put("pi_hao_", StrUtil.str(bean.getPiHao()));
+						map.put("bian_ma_", StrUtil.str(bean.getBianMa()));
+						map.put("inventory_id", StrUtil.str(bean.getInventoryId()));
+						map.put("shu_liang_", StrUtil.str(bean.getShuLiang()));
+						map.put("you_xiao_qi_", StrUtil.str(bean.getYouXiaoQi()));
+						records.add(map);
+					}
+					// 扣减库存 ("not", "领用")
+					inventoryService.handleOperation(operate, "领用", records);
+					// --- 原有逻辑结束 ---
+				} else {
+					// --- 新增逻辑: back 或 end (回退/归还) ---
+					// 不再新创建主子表数据,主表无需额外操作
+					// 子表获取库存id和数量,更新库存表
+
+					for (LingYongDetailPo bean : lingYongPo.getLingYongDetailPoList()) {
+						String kcId = bean.getInventoryId();
+						if (kcId == null || kcId.trim().isEmpty()) {
+							logger.warn("忽略一条没有库存ID的明细记录: {}", bean);
+							continue;
+						}
+						// 获取数量
+						String quantityStr = StrUtil.str(bean.getShuLiang());
+						List<Map<String, Object>> records2 = new ArrayList<>(lingYongPo.getLingYongDetailPoList().size());
+						for (LingYongDetailPo bean2 : lingYongPo.getLingYongDetailPoList()) {
+							Map<String, Object> map = new HashMap<>();
+							map.put("id_", StrUtil.str(bean.getId()));
+							map.put("ming_cheng_", StrUtil.str(bean.getShiJiMingCheng()));
+							map.put("pi_hao_", StrUtil.str(bean.getPiHao()));
+							map.put("bian_ma_", StrUtil.str(bean.getBianMa()));
+							map.put("inventory_id", StrUtil.str(bean.getInventoryId()));
+							map.put("shu_liang_", StrUtil.str(bean.getShuLiang()));
+							map.put("you_xiao_qi_", StrUtil.str(bean.getYouXiaoQi()));
+							records2.add(map);
+						}
+						// 调用库存服务查询
+						// 假设 queryInventoryById 返回 List<Inventory> 或类似对象
+						inventoryService.handleOperation(operate, "领用",records2);
+					}
+				}
+			}
+
+			// 只有在正常流程下才保存主表和级联子表数据
+			if (isNormalFlow) {
+				LingYong domain = lingYongRepository.newInstance(lingYongPo);
+				domain.saveCascade();
+
+				// 【新增逻辑】获取保存后回填的主表ID
+				// 假设 LingYongPo 类中有 getId() 方法,且 saveCascade() 执行后该值已被填充
+				String mainTableId = "";
+				if (lingYongPo.getId() != null) {
+					mainTableId = lingYongPo.getId().toString();
+				} else {
+					// 如果 ID 是字符串类型直接获取,或者需要其他处理方式,请根据实际情况调整
+					// 某些框架可能需要 domain.getId(),这里假设 po 对象已被更新
+					logger.warn("保存后未获取到主表ID,请检查实体类映射配置");
+				}
+
+				/** 新增 恒生医院试剂耗材出库hrp接入逻辑 */
+				ReagentConsumabOutputForHSYY(sids);
+
+				// 【修改】在成功消息中追加主表ID
+				if (!mainTableId.isEmpty()) {
+					result.setMessage("保存试剂耗材领用主表成功,主表ID:" + mainTableId);
+				} else {
+					result.setMessage("保存试剂耗材领用主表成功 (未获取到ID)");
+				}
+			} else {
+				// 回退模式下的成功消息
+				result.setMessage("试剂耗材领用回退/结束处理成功");
+			}
+
+		} catch (Exception e) {
+			result.setMessage("保存试剂耗材领用失败!" + StateEnum.ERROR.getText());
+			setExceptionResult(result, StateEnum.ERROR.getCode(), StateEnum.ERROR.getText(), e);
+		}
+		return result;
+	}
+
+	public APIResult<Void> saveold(
 			@ApiParam(name = "lingYongPo", value = "试剂耗材领用主表对象", required = true)  
-			@RequestBody(required = true) LingYongPo lingYongPo) {
+			@RequestBody(required = true) LingYongPo lingYongPo,
+			@RequestParam(required = false) String operate) {
 		APIResult<Void> result = new APIResult<Void>();
 		try {
-			logger.info(" com.lc.ibps.components.provider.LingYongProvider.save()--->lingYongPo: {}", lingYongPo.toString());
+			logger.info(" com.lc.ibps.components.provider.LingYongProvider.save()--->lingYongPo: {},operate: {}", lingYongPo.toString(), operate.toString());
 			String sids = "";
 			if(!lingYongPo.getLingYongDetailPoList().isEmpty()){
 				sids = lingYongPo.getWeiZhiLingYong();

+ 55 - 2
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/reagent/service/InventoryService.java

@@ -106,7 +106,8 @@ public class InventoryService extends GenericProvider {
         }
     }
 
-    public void handleOperation(String status, String operationType, List<Map<String, Object>> records) throws Exception {
+    public String handleOperation(String status, String operationType, List<Map<String, Object>> records) throws Exception {
+        String retVal = "";
         if (records == null || records.isEmpty()) {
             throw new Exception("未查询到对应的 "+operationType+" 记录,操作失败!");
         }
@@ -136,6 +137,35 @@ public class InventoryService extends GenericProvider {
                 handleMultipleInventories(inventoryList, record);
             }
         }
+        return retVal;
+    }
+
+    public void handleBackOrEndOperation(String status, List<Map<String, Object>> records) throws Exception {
+
+        for(Map<String, Object> record : records){
+            record.put("status", status);
+            String name1 = StrUtil.str(record.get("ming_cheng_"));
+            String name2 = StrUtil.str(record.get("shi_ji_ming_cheng"));
+            String reagentName = !name1.isEmpty() ? name1 : !name2.isEmpty() ? name2 : "";
+            record.put("ming_cheng_", reagentName);
+            String kcId = StrUtil.str(record.get("inventory_id"));
+            String batchNum = StrUtil.str(record.get("pi_hao_"));
+            String reagentCode = StrUtil.str(record.get("bian_ma_"));
+
+            List<Map<String, Object>> inventoryList;
+            if (BeanUtils.isNotEmpty(kcId)) {
+                inventoryList = storeService.queryInventoryById(kcId);
+            }else {
+                inventoryList = storeService.queryInventoryByPhAndCode(batchNum, reagentCode);
+            }
+            if (inventoryList.size() == 1) {
+                handleSingleInventory(inventoryList.get(0), record);
+            } else {
+                handleMultipleInventories(inventoryList, record);
+            }
+
+        }
+
     }
 
     private void handleSingleInventory(Map<String, Object> inventory, Map<String, Object> record) throws Exception {
@@ -153,8 +183,19 @@ public class InventoryService extends GenericProvider {
         if ("start".equals(status)) {
             linYongService.updateWithhold(inventoryId, currentWithhold + quantity);
         } else if ("end".equals(status)) {
+            if(currentQuantity < quantity){
+                throw new Exception(record.get("ming_cheng_") + " 可用量不足!可用量:" + currentWithhold + ",需要:" + quantity);
+            }
+            if(currentWithhold < quantity){
+                throw new Exception(record.get("ming_cheng_") + " 预扣量不足!预扣量:" + currentWithhold + ",需要:" + quantity);
+            }
             linYongService.updateWithholdAndInventory(inventoryId, currentQuantity - quantity, currentWithhold - quantity);
-        } else {
+        } else if ("back".equals(status)) {
+            if(currentWithhold < quantity){
+                throw new Exception(record.get("ming_cheng_") + " 预扣量不足!预扣量:" + currentWithhold + ",需要:" + quantity);
+            }
+            linYongService.updateWithhold(inventoryId, currentWithhold - quantity);
+        }else {
             linYongService.updateInventory(inventoryId, currentQuantity - quantity);
         }
         record.put("inventory_id", inventoryId);
@@ -195,8 +236,20 @@ public class InventoryService extends GenericProvider {
                 actualDeduction = Math.min(available, remainingQuantity);
                 linYongService.updateWithhold(inventoryId, currentWithhold + actualDeduction);
             } else if ("end".equals(status)) {
+                if(currentQuantity < quantity){
+                    throw new Exception(record.get("ming_cheng_") + " 可用量不足!可用量:" + currentWithhold + ",需要:" + quantity);
+                }
+                if(currentWithhold < quantity){
+                    throw new Exception(record.get("ming_cheng_") + " 预扣量不足!预扣量:" + currentWithhold + ",需要:" + quantity);
+                }
                 actualDeduction = Math.min(available, remainingQuantity);
                 linYongService.updateWithholdAndInventory(inventoryId, currentQuantity - actualDeduction, currentWithhold - actualDeduction);
+            } else if ("back".equals(status)) {
+                if (currentWithhold < quantity) {
+                    throw new Exception(record.get("ming_cheng_") + " 预扣量不足!预扣量:" + currentWithhold + ",需要:" + quantity);
+                }
+                actualDeduction = Math.min(available, remainingQuantity);
+                linYongService.updateWithhold(inventoryId, currentWithhold - quantity);
             } else {
                 actualDeduction = Math.min(available, remainingQuantity);
                 linYongService.updateInventory(inventoryId, currentQuantity - actualDeduction);