自动化立体仓库 - WMS系统
src/main/java/com/zy/asrs/controller/BasDevpController.java
@@ -7,13 +7,16 @@
import com.baomidou.mybatisplus.plugins.Page;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.param.BasDevpInitParam;
import com.zy.asrs.service.BasCrnpService;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.utils.Utils;
import com.zy.common.web.BaseController;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.exception.CoolException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -24,6 +27,8 @@
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private BasCrnpService basCrnpService;
    @RequestMapping(value = "/basDevp/init/auth")
    @ManagerAuth(memo = "初始化站点")
@@ -85,6 +90,7 @@
    @RequestMapping(value = "/basDevp/add/auth")
    @ManagerAuth(memo = "站点添加")
    public R add(BasDevp basDevp) {
        normalizeInboundPriority(basDevp, null);
        basDevp.setModiUser(getUserId());
        basDevp.setModiTime(new Date());
        basDevp.setAppeUser(getUserId());
@@ -99,6 +105,11 @@
        if (Cools.isEmpty(basDevp) || null==basDevp.getDevNo()){
            return R.error();
        }
        BasDevp existing = basDevpService.selectById(basDevp.getDevNo());
        if (existing == null) {
            return R.error("站点不存在");
        }
        normalizeInboundPriority(basDevp, existing);
        basDevp.setModiUser(getUserId());
        basDevp.setModiTime(new Date());
        basDevpService.updateById(basDevp);
@@ -155,4 +166,65 @@
        return R.ok();
    }
    private void normalizeInboundPriority(BasDevp basDevp, BasDevp existing) {
        if (basDevp == null) {
            return;
        }
        String firstCsv = resolveCsvValue(basDevp.getInFirstCrnCsv(), existing == null ? null : existing.getInFirstCrnCsv());
        String secondCsv = resolveCsvValue(basDevp.getInSecondCrnCsv(), existing == null ? null : existing.getInSecondCrnCsv());
        List<Integer> firstCrnNos = parseCrnPool("第一优先池", firstCsv);
        List<Integer> secondCrnNos = parseCrnPool("第二优先池", secondCsv);
        Set<Integer> duplicateCrnNos = new LinkedHashSet<>(firstCrnNos);
        duplicateCrnNos.retainAll(secondCrnNos);
        if (!duplicateCrnNos.isEmpty()) {
            throw new CoolException("第一优先池和第二优先池不能重复配置同一台堆垛机:" + duplicateCrnNos);
        }
        basDevp.setInFirstCrnCsv(Utils.normalizeCrnCsv(firstCrnNos));
        basDevp.setInSecondCrnCsv(Utils.normalizeCrnCsv(secondCrnNos));
        if (existing == null) {
            basDevp.setInFirstCrnCurrentNo(null);
            basDevp.setInSecondCrnCurrentNo(null);
            return;
        }
        basDevp.setInFirstCrnCurrentNo(resolveCurrentNo(existing.getInFirstCrnCurrentNo(), firstCrnNos));
        basDevp.setInSecondCrnCurrentNo(resolveCurrentNo(existing.getInSecondCrnCurrentNo(), secondCrnNos));
    }
    private String resolveCsvValue(String incoming, String existing) {
        if (incoming == null) {
            return existing;
        }
        return incoming;
    }
    private List<Integer> parseCrnPool(String label, String csv) {
        List<Integer> crnNos;
        try {
            crnNos = Utils.parseCrnNos(csv);
        } catch (CoolException e) {
            throw new CoolException(label + e.getMessage());
        }
        List<Integer> distinctCrnNos = Utils.distinctCrnNos(crnNos);
        if (crnNos.size() != distinctCrnNos.size()) {
            throw new CoolException(label + "存在重复堆垛机号");
        }
        for (Integer crnNo : distinctCrnNos) {
            if (basCrnpService.selectById(crnNo) == null) {
                throw new CoolException(label + "包含不存在的堆垛机号:" + crnNo);
            }
        }
        return distinctCrnNos;
    }
    private Integer resolveCurrentNo(Integer currentNo, List<Integer> crnNos) {
        if (currentNo == null || Cools.isEmpty(crnNos) || !crnNos.contains(currentNo)) {
            return null;
        }
        return currentNo;
    }
}