Bläddra i källkod

[BUG-3736]试剂耗材流程(退货、报废、盘点)等流程退回、终止流程预扣量未同步更新

szjbdgzl 1 år sedan
förälder
incheckning
4a410ace6e

+ 6 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/reagent/api/IReagentConsumablesInventoryService.java

@@ -100,4 +100,10 @@ public interface IReagentConsumablesInventoryService {
 			@RequestParam(name = "date", required = false) String date,
 			@RequestParam(name = "type", required = false) String type);
 
+	@RequestMapping(value = "/back", method = { RequestMethod.POST })
+	public APIResult<Void> back(
+			@RequestParam(name = "id", required = true) String id,
+			@RequestParam(name = "type", required = true) String type,
+			@RequestParam(name = "operate", required = true) String operate);
+
 }

+ 29 - 5
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/reagent/provider/ReagentConsumablesInventoryProvider.java

@@ -168,7 +168,7 @@ public class ReagentConsumablesInventoryProvider extends GenericProvider impleme
 		return result;
 	}
 
-	@ApiOperation(value = "领用/退货/报废", notes = "领用/退货/报废",
+	@ApiOperation(value = "试剂耗材退货报废", notes = "试剂耗材退货报废",
 			extensions = {
 					@Extension(properties = {
 							@ExtensionProperty(name = "submitCtrl", value = StringPool.Y)
@@ -176,12 +176,12 @@ public class ReagentConsumablesInventoryProvider extends GenericProvider impleme
 			})
 	@Override
 	public APIResult<Void> issue(
-			@ApiParam(name = "id", value = "领用/退货/报废记录id", required = true)
+			@ApiParam(name = "id", value = "退货/报废记录id", required = true)
 			@RequestParam(name = "id", required = true) String id,
-			@ApiParam(name = "type", value = "操作类型(领用-withdraw/退货-return/报废-scrap)", required = true)
+			@ApiParam(name = "type", value = "业务类型(退货-return;报废-scrap)", required = true)
 			@RequestParam(name = "type", required = true) String type,
-			@ApiParam(name = "status", value = "流程状态(start/end),非必要参数,不传表示没有流程提交直接扣减库存", required = false)
-			@RequestParam(name = "status", required = false) String status) {
+			@ApiParam(name = "status", value = "流程状态(start/end)", required = true)
+			@RequestParam(name = "status", required = true) String status) {
 		APIResult<Void> result = new APIResult<>();
 		try {
 			inventoryService.issue(id,type,status);
@@ -192,6 +192,30 @@ public class ReagentConsumablesInventoryProvider extends GenericProvider impleme
 		return result;
 	}
 
+	@ApiOperation(value = "试剂耗材退回终止", notes = "试剂耗材退回终止",
+			extensions = {
+					@Extension(properties = {
+							@ExtensionProperty(name = "submitCtrl", value = StringPool.Y)
+					})
+			})
+	@Override
+	public APIResult<Void> back(
+			@ApiParam(name = "id", value = "退货/报废记录id", required = true)
+			@RequestParam(name = "id", required = true) String id,
+			@ApiParam(name = "type", value = "业务类型(退货-return;报废-scrap)", required = true)
+			@RequestParam(name = "type", required = true) String type,
+			@ApiParam(name = "operate", value = "操作类型(退回-back;终止-stop)", required = true)
+			@RequestParam(name = "operate", required = true) String operate) {
+		APIResult<Void> result = new APIResult<>();
+		try {
+			inventoryService.back(id,type,operate);
+			result.setMessage("保存成功!");
+		} catch (Exception e) {
+			setExceptionResult(result, StateEnum.ERROR.getCode(), StateEnum.ERROR.getText(), e);
+		}
+		return result;
+	}
+
 	@ApiOperation(value = "试剂耗材盘点", notes = "试剂耗材盘点",
 			extensions = {
 					@Extension(properties = {

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

@@ -66,6 +66,7 @@ public class InventoryService extends GenericProvider {
             ReagentConsumablesTransaction transaction = reagentConsumablesTransactionRepository.newInstance();
             item.getTransaction().setInventoryId(inventory.getId());
             item.getTransaction().setFlow("not");
+            item.getTransaction().setStatus("入库");
             transaction.setData(item.getTransaction());
             transaction.save();
         }
@@ -73,39 +74,38 @@ public class InventoryService extends GenericProvider {
     }
 
     public void issue(String id, String type, String status) throws Exception {
+        logger.warn("com.lc.ibps.components.reagent.service.InventoryService.issue()--->id={},status={},type={}", id, status, type);
         status = StrUtil.str(status);
         if ("return".equals(type)) {
-            returnStock(id, status,"退货");
+            type = "退货";
+            handleOperation(status , type , storeService.queryThRecord(id));
         } else if ("scrap".equals(type)) {
-            scrap(id, status,"报废");
-        } else if ("withdraw".equals(type)) {
-            decrementStock(id, status,"领用");
+            type = "报废";
+            handleOperation(status , type , storeService.queryBfRecord(id));
         }
     }
 
-    public void scrap(String id, String status,String type) throws Exception {
-        logger.warn("com.lc.ibps.components.reagent.service.InventoryService.scrap()--->id={},status={},type={}", id, status, type);
-        handleOperation(status, type, storeService.queryBfRecord(id));
-    }
-
-    public void returnStock(String id, String status,String type) throws Exception {
-        logger.warn("com.lc.ibps.components.reagent.service.InventoryService.returnStock()--->id={},status={},type={}", id, status, type);
-        handleOperation(status, type, storeService.queryThRecord(id));
-    }
-
-    public void decrementStock(String id, String status,String type) throws Exception {
-        logger.warn("com.lc.ibps.components.reagent.service.InventoryService.decrementStock()--->id={},status={},type={}", id, status, type);
-        handleOperation(status, type, storeService.queryLingYongRecord(id));
+    public void back(String id, String type, String operate) throws Exception {
+        logger.warn("com.lc.ibps.components.reagent.service.InventoryService.back()--->id={},type={},operate={}", id, type, operate);
+        List<Map<String,Object>> records = new ArrayList<>();
+        if ("return".equals(type)) {
+            type = "退货";
+            records = storeService.queryThRecord(id);
+        } else if ("scrap".equals(type)) {
+            type = "报废";
+            records = storeService.queryBfRecord(id);
+        }
+        if ("back".equals(operate) || "stop".equals(operate)) {
+            List<String> ids = records.stream().map(record -> record.get("id_").toString()).collect(Collectors.toList());
+            String quotedIds = ids.stream().map(currentId  -> "'" + currentId  + "'").collect(Collectors.joining(","));
+            returnService.updateBillAndInventory(quotedIds,type);
+        }
     }
 
     public void handleOperation(String status, String operationType, List<Map<String, Object>> records) throws Exception {
         if (records == null || records.isEmpty()) {
-            throw new Exception("未查询到对应的" + operationType + "记录,操作失败!");
+            throw new Exception("未查询到对应的 "+operationType+" 记录,操作失败!");
         }
-
-        List<String> ids = records.stream().map(record -> record.get("id_").toString()).collect(Collectors.toList());
-        returnService.updateBillAndInventory(String.join(",",ids),operationType);
-
         for (Map<String, Object> record : records) {
             record.put("type", operationType);
             record.put("status", status);
@@ -115,19 +115,12 @@ public class InventoryService extends GenericProvider {
             record.put("ming_cheng_", reagentName);
             String batchNum = StrUtil.str(record.get("pi_hao_"));
             String reagentCode = StrUtil.str(record.get("bian_ma_"));
-            String position = operationType.equals("领用") ? StrUtil.str(record.get("cang_ku_id_")) : "";
             String kcId = StrUtil.str(record.get("inventory_id"));
 
             List<Map<String, Object>> inventoryList;
             if (BeanUtils.isNotEmpty(kcId)) {
                 inventoryList = storeService.queryInventoryById(kcId);
-            }else if (operationType.equals("领用")) {
-                Map<String, Object> queryParams = new HashMap<>();
-                queryParams.put("batch_num", batchNum);
-                queryParams.put("reagent_code", reagentCode);
-                queryParams.put("position", position);
-                inventoryList = storeService.queryInventoryByLingYong(queryParams);
-            } else {
+            }else {
                 inventoryList = storeService.queryInventoryByPhAndCode(batchNum, reagentCode);
             }
 
@@ -246,7 +239,7 @@ public class InventoryService extends GenericProvider {
     }
 
     public void updateStock(StockDto stockDto) throws Exception {
-        logger.warn("com.lc.ibps.components.reagent.service.InventoryService.updateStock()--->stockDto={}", stockDto);
+        logger.warn("com.lc.ibps.components.reagent.service.InventoryService.updateStock()--->type={},kcList={}", stockDto.getType(),stockDto.getKcList());
         if (Collections.isEmpty(stockDto.getKcList())){
             return;
         }

+ 1 - 1
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/reagent/service/LinYongService.java

@@ -46,7 +46,7 @@ public class LinYongService implements OperationService{
     }
 
     public void updateInventoryAndStatus(String id,long quantity){
-        String sql = "update t_reagent_inventory set enable_='是' quantity=%s where id_='%s'";
+        String sql = "update t_reagent_inventory set enable_='是',quantity=%s where id_='%s'";
         commonDao.execute(String.format(sql,Math.max(quantity,0),id));
     }
 

+ 5 - 6
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/reagent/service/ReturnService.java

@@ -5,8 +5,6 @@ import com.lc.ibps.base.framework.table.ICommonDao;
 import com.lc.ibps.components.reagent.dto.InventoryDTO;
 import com.lc.ibps.untils.StrUtil;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.Collections;
@@ -34,15 +32,15 @@ public class ReturnService implements OperationService{
         return Policy.minus;
     }
 
-    @Transactional(propagation = Propagation.REQUIRES_NEW)
     public void updateBillAndInventory(String id, String type) throws Exception {
         // 查询是否已经存在台账记录  查询到的结果 减去预扣量、删除台账记录
         String sql= "SELECT *from t_reagent_trans WHERE flow_='start' and status_='%s' and bo_id in (%s) ";
-        List<Map<String, Object>> bills = commonDao.query(String.format( sql, type, id ));
+        sql = String.format( sql, type, id );
+        List<Map<String, Object>> bills = commonDao.query(sql);
         if(com.lc.ibps.base.core.util.Collections.isNotEmpty(bills)){
             for (Map<String, Object> bill : bills) {
                 if (BeanUtils.isNotEmpty(bill.get("inventory_id")) && BeanUtils.isNotEmpty(bill.get("status_"))){
-                    String kcId = StrUtil.str(bill.get("id_"));
+                    String kcId = StrUtil.str(bill.get("inventory_id"));
                     long count = StrUtil.parseLongSafe(bill.get("quantity"));
                     updateWithholdByDel(kcId,count);
                     deleteTaiZhangRecord(bill.get("id_").toString());
@@ -53,7 +51,8 @@ public class ReturnService implements OperationService{
 
     private void updateWithholdByDel(String id, long withhold) {
         String sql = "update t_reagent_inventory set withhold=GREATEST(0,withhold - %s) where id_='%s'";
-        commonDao.execute(String.format(sql,Math.max(withhold,0),id));
+        sql = String.format(sql,Math.max(withhold,0),id);
+        commonDao.execute(sql);
     }
 
     private void deleteTaiZhangRecord(String id){

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

@@ -4,6 +4,8 @@ import com.lc.ibps.base.core.util.BeanUtils;
 import com.lc.ibps.base.framework.table.ICommonDao;
 import com.lc.ibps.components.reagent.dto.InventoryDTO;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.HashMap;