自动化立体仓库 - WMS系统
src/main/java/com/zy/asrs/controller/BasDevpController.java
@@ -6,13 +6,17 @@
import com.baomidou.mybatisplus.mapper.Wrapper;
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.*;
@@ -23,6 +27,32 @@
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private BasCrnpService basCrnpService;
    @RequestMapping(value = "/basDevp/init/auth")
    @ManagerAuth(memo = "初始化站点")
    public R init(BasDevpInitParam param) {
        List<BasDevp> list = new ArrayList<>();
        for (int devNo = param.getStartDev() ; devNo<=param.getEndDev() ; devNo++){
            BasDevp basDevp = basDevpService.selectById(devNo);
            if (Cools.isEmpty(basDevp)){
                BasDevp basDevp1 = new BasDevp();
                basDevp1.setDevNo(devNo);
                basDevp1.setInEnable("Y");
                basDevp1.setOutEnable("Y");
                basDevp1.setAutoing("Y");
                basDevp1.setLoading("Y");
                basDevp1.setCanining("Y");
                basDevp1.setCanouting("Y");
                basDevp1.setModiUser(getUserId());
                basDevp1.setModiTime(new Date());
                list.add(basDevp1);
            }
        }
        basDevpService.insertBatch(list);
        return R.ok("初始化成功");
    }
    @RequestMapping(value = "/basDevp/{id}/auth")
    @ManagerAuth
@@ -44,14 +74,15 @@
        return R.ok(basDevpService.selectPage(new Page<>(curr, limit), wrapper));
    }
    private void convert(Map<String, Object> map, EntityWrapper wrapper){
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
        for (Map.Entry<String, Object> entry : map.entrySet()){
            if (entry.getKey().endsWith(">")) {
                wrapper.ge(Cools.deleteChar(entry.getKey()), DateUtils.convert(String.valueOf(entry.getValue())));
            } else if (entry.getKey().endsWith("<")) {
                wrapper.le(Cools.deleteChar(entry.getKey()), DateUtils.convert(String.valueOf(entry.getValue())));
            String val = String.valueOf(entry.getValue());
            if (val.contains(RANGE_TIME_LINK)){
                String[] dates = val.split(RANGE_TIME_LINK);
                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
                wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
            } else {
                wrapper.eq(entry.getKey(), String.valueOf(entry.getValue()));
                wrapper.like(entry.getKey(), val);
            }
        }
    }
@@ -59,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());
@@ -73,10 +105,15 @@
        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);
        return R.ok();
        return R.ok("修改完成");
    }
    @RequestMapping(value = "/basDevp/delete/auth")
@@ -129,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;
    }
}