futian.liu
2023-12-09 2af69a47b08aa4988cc9733a361a733a671a5f81
consum-base/src/main/java/com/consum/base/core/DepUsingFormBackCoreServiceImpl.java
@@ -1,26 +1,14 @@
package com.consum.base.core;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import cn.hutool.core.convert.Convert;
import com.consum.base.core.service.LWhWarningCoreServiceImpl;
import com.consum.base.core.utils.IdUtil;
import com.consum.base.core.utils.LockManage;
import com.consum.base.service.GoodsBaseServiceImpl;
import com.consum.base.service.LWarehouseFlowService;
import com.consum.base.service.impl.LWhGoodsRecordDetailsService;
import com.consum.base.service.LWhGoodsRecordService;
import com.consum.base.service.LWhGoodsService;
import com.consum.base.service.impl.LWhGoodsRecordDetailsService;
import com.consum.model.po.BaseWarehouse;
import com.consum.model.po.LWarehouseFlow;
import com.consum.model.po.LWhGoodsRecord;
@@ -28,9 +16,18 @@
import com.iplatform.model.po.S_user_core;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.web.ResponseValue;
import cn.hutool.core.convert.Convert;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * @ClassName DepFormScrappedCoreServiceImpl
@@ -138,7 +135,7 @@
                    // 根据分发单、型号、使用人信息查询物品信息
                    List<Map<String, Object>> scrappedGoodsList = lWhGoodsService.queryScrappedGoods(warehouseType, warehouseId, transBusinessId, nowUserName, baseGoodsModelsId, (short) 2, counts);
                    if (CollectionUtils.isEmpty(scrappedGoodsList) || scrappedGoodsList.size() < counts) {
                        log.error("要报废的物品数量不足!");
                        log.error("要退回的物品数量不足!");
                        // 手动回滚
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        throw new RuntimeException("报废失败!型号数量不足");
@@ -210,6 +207,31 @@
        }
        goodsBaseService.execBatchUpdate("update DEP_FORM_SCRAPPED_MODEL set TOTAL_AMOUNT=? where id=?", parameterList);
        //如果是A类物品,则更新 分发物品使用人【L_WH_PROCURE_MODEL_USER】 中 根据id 更新 在用数量(USE_COUNT)
        List<Object[]> procureModelUserIdList = new ArrayList<>();
        for (Map<String, Object> itemMap : bfModelList) {
            Long procureModelUserId = Convert.toLong(itemMap.get("PROCURE_MODEL_USER_ID"));
            if (procureModelUserId==null){
                continue;
            }
            Integer counts = Convert.toInt(itemMap.get("COUNTS"));
//            StringBuilder sb = new StringBuilder("update L_WH_PROCURE_MODEL_USER set USE_COUNT=USE_COUNT-").append(counts);
//            sb.append(" where id=").append(procureModelUserId);
//            sb.append(" and USE_COUNT-").append(counts).append(" >=0");
//            goodsBaseService.update(sb.toString());
            Object[] one = new Object[3];
            one[0] = counts;
            one[1] = procureModelUserId;
            one[2] = counts;
            procureModelUserIdList.add(one);
        }
        if (!CollectionUtils.isEmpty(procureModelUserIdList)) {
            goodsBaseService.execBatchUpdate("update L_WH_PROCURE_MODEL_USER set USE_COUNT=USE_COUNT- ?  where id= ? and USE_COUNT- ? >=0", procureModelUserIdList);
        }
        //采购、调拨、出库等的物品型号【L_WH_PROCURE_MODEL】中 根据调拨单+型号 更新 在用数量
        List<Object[]> procureModelParameterList = new ArrayList<>();
        for (Map.Entry<String, Integer> entry : procureModelMap.entrySet()) {