自动化立体仓库 - WMS系统
#
luxiaotao1123
2022-06-28 58ef3b74f315d7f38ed017971e9da720a7ac6489
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -13,8 +13,11 @@
import com.zy.asrs.entity.param.LocDetlAdjustParam;
import com.zy.asrs.entity.param.StockOutParam;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.*;
import com.zy.common.model.enums.IoWorkType;
import com.zy.common.model.enums.WorkNoType;
import com.zy.common.properties.SlaveProperties;
import com.zy.common.service.CommonService;
import com.zy.common.web.WcsController;
import lombok.extern.slf4j.Slf4j;
@@ -68,6 +71,10 @@
    private OrderDetlService orderDetlService;
    @Autowired
    private WcsController wcsController;
    @Autowired
    private RowLastnoService rowLastnoService;
    @Autowired
    private SlaveProperties slaveProperties;
    @Override
    @Transactional
@@ -168,7 +175,7 @@
    @Override
    @Transactional
    public void stockOut(BasDevp staNo, List<LocDetlDto> locDetlDtos, Integer ioType, Long userId) {
    public void stockOut(BasDevp staNo, List<LocDetlDto> locDetlDtos, IoWorkType ioWorkType, Long userId) {
        Date now = new Date();
        // 合并同类项
        Set<String> locNos = new HashSet<>();
@@ -187,13 +194,24 @@
                dtos.add(new OutLocDto(locNo, locDetlDto));
            }
        }
        Integer ioType = null;
        // 生成工作档
        for (OutLocDto dto : dtos) {
            // 判断入出库类型:101.全板出库 or 103.拣料出库
            if (ioType == null) {
                ioType = dto.isAll() ? 101 : 103;
            // 如果为深库位,且对应浅库位为X.禁用,则略过此库位
            if (Utils.isDeepLoc(slaveProperties, dto.getLocNo())) {
                String shallowLoc = Utils.getShallowLoc(slaveProperties, dto.getLocNo());
                if (locMastService.selectById(shallowLoc).getLocSts().equals("X")) {
                    continue;
                }
            }
            // 判断入出库类型:101.全板出库 or 103.拣料出库
            if (ioWorkType == null) {
                ioType = dto.isAll() ? 101 : 103;
            } else if (ioWorkType.equals(IoWorkType.CHECK_OUT)) {
                ioType = 107;
            }
            assert ioType != null;
            // 获取库位
            LocMast locMast = locMastService.selectById(dto.getLocNo());
            // 获取路径
@@ -216,6 +234,7 @@
            wrkMast.setExitMk("N"); // 退出
            wrkMast.setEmptyMk("N"); // 空板
            wrkMast.setLinkMis("N");
            wrkMast.setBarcode(locMast.getBarcode());
            wrkMast.setAppeUser(userId); // 操作人员数据
            wrkMast.setAppeTime(now);
            wrkMast.setModiUser(userId);
@@ -270,7 +289,7 @@
        LocMast locMast = locMastService.selectById(taskDto.getLocNo());
        // 获取路径
        int ioType = taskDto.isAll() ? 101 : 103;
        StaDesc staDesc = staDescService.queryCrnStn(ioType, locMast.getCrnNo(), staNo.getDevNo());
        StaDesc staDesc = staDescService.queryCrnStnAuto(ioType, locMast.getCrnNo(), staNo.getDevNo());
        // 生成工作号
        int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType));
        // 生成工作档
@@ -289,6 +308,7 @@
        wrkMast.setExitMk("N"); // 退出
        wrkMast.setEmptyMk("N"); // 空板
        wrkMast.setLinkMis("N");
        wrkMast.setBarcode(locMast.getBarcode());
        wrkMast.setAppeUser(userId); // 操作人员数据
        wrkMast.setAppeTime(now);
        wrkMast.setModiUser(userId);
@@ -300,8 +320,12 @@
        for (LocDto locDto : taskDto.getLocDtos()) {
            if (locDto.getAnfme()==null || locDto.getAnfme() <= 0.0D) { continue; }
            OrderDetl orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), locDto.getBatch());
            if (orderDetl == null) {
                orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), null);
            }
            WrkDetl wrkDetl = new WrkDetl();
            wrkDetl.sync(orderDetl);
            wrkDetl.setZpallet(wrkMast.getBarcode());
            wrkDetl.setIoTime(now);
            wrkDetl.setWrkNo(workNo);
            wrkDetl.setBatch(locDto.getBatch());
@@ -398,6 +422,13 @@
            throw new CoolException("站点不存在");
        }
        for (String locNo : param.getLocNos()) {
            // 如果为深库位,且对应浅库位为X.禁用,则略过此库位
            if (Utils.isDeepLoc(slaveProperties, locNo)) {
                String shallowLoc = Utils.getShallowLoc(slaveProperties, locNo);
                if (locMastService.selectById(shallowLoc).getLocSts().equals("X")) {
                    continue;
                }
            }
            // 获取工作号
            int workNo = commonService.getWorkNo(WorkNoType.PAKOUT.type);
            // 获取库位
@@ -466,7 +497,7 @@
        }
        if (!locDetlDtos.isEmpty()) {
            // 启动出库开始 107.盘点出库
            stockOut(staNo, locDetlDtos, 107, userId);
            stockOut(staNo, locDetlDtos, IoWorkType.CHECK_OUT, userId);
        } else {
            throw new CoolException("库位物料不存在");
        }
@@ -715,11 +746,8 @@
        if (wrkMast.getWrkSts() < 4) {
            locNo = wrkMast.getLocNo();
            locSts = "O";
            /**
             * 库位转移
             * 取消后 源库位 ==>> F.在库
             *       目标库位 ===>> O.空库位
             **/
            // 库位转移
            if (wrkMast.getIoType() == 11) {
                // 库位转移:源库位
                LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());
@@ -742,7 +770,7 @@
                locSts = "D";
            // 库位转移 ===>> D.空桶/空栈板
            } else if (wrkMast.getIoType() == 11) {
                locSts = wrkMast.getFullPlt().equalsIgnoreCase("N")?"F":"D";
                locSts = wrkMast.getFullPlt().equalsIgnoreCase("N")?"D":"F";
                // 库位转移:目标库位
                LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
                if (Cools.isEmpty(locMast)) {
@@ -820,9 +848,9 @@
            throw new CoolException("当前工作状态无法进行操作");
        }
        // 保存工作明细档历史档
        if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
            throw new CoolException("保存工作明细档历史档失败");
        }
//        if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
//            throw new CoolException("保存工作明细档历史档失败");
//        }
        // 保存工作主档历史档
        if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
            throw new CoolException("保存工作主档历史档失败");
@@ -870,4 +898,99 @@
        return wcsController.startupFullPutStore(301, list.get(0).getZpallet(), locTypeDto, list);
    }
    @Override
    @Transactional
    public String dealPreHaveStart(Integer wrkNo, Long userId) {
        WrkMast wrkMast = wrkMastService.selectById(wrkNo);
        if (wrkMast == null) {
            throw new CoolException("任务已失效");
        }
        String locNo = wrkMast.getLocNo();
        LocMast locMast = locMastService.selectById(locNo);
        assert locMast != null;
        RowLastno rowLastno = rowLastnoService.findBySection(locMast.getRow1());
        assert rowLastno != null;
        // 目标库位
        LocMast targetLoc = null;
        for (int curRow = rowLastno.getsRow(); curRow<=rowLastno.geteRow(); curRow++) {
            if (Utils.isShallowLoc(slaveProperties, curRow)) {
                Integer deepRow = Utils.getDeepRow(slaveProperties, curRow);
                targetLoc = locMastService.queryFreeLocMast(deepRow, locMast.getLocType1());
                // 因库位移转、需预留空库位
                if (!locMastService.checkEmptyCount(targetLoc)) {
                    continue;
                }
            }
            if (Cools.isEmpty(targetLoc)) {
                targetLoc = locMastService.queryFreeLocMast(curRow, locMast.getLocType1());
                // 因库位移转、需预留空库位
                if (!locMastService.checkEmptyCount(targetLoc)) {
                    continue;
                }
                // 目标库位 ===>> 浅库位, 则校验其深库位是否为 F D X
                if (null != targetLoc && Utils.isShallowLoc(slaveProperties, targetLoc.getLocNo())) {
                    LocMast deepLoc = locMastService.selectById(Utils.getDeepLoc(slaveProperties, targetLoc.getLocNo()));
                    if (!deepLoc.getLocSts().equals("F") && !deepLoc.getLocSts().equals("D") && !deepLoc.getLocSts().equals("X")) {
                        continue;
                    }
                }
                // 目标库位 ===>> 深库位, 则校验其浅库位是否为 O
                if (null != targetLoc && Utils.isDeepLoc(slaveProperties, targetLoc.getLocNo())) {
                    LocMast shallowLoc = locMastService.selectById(Utils.getShallowLoc(slaveProperties, targetLoc.getLocNo()));
                    if (!shallowLoc.getLocSts().equals("O")) {
                        continue;
                    }
                }
            }
            if (!Cools.isEmpty(targetLoc)) {
                break;
            }
        }
        if (targetLoc == null) {
            throw new CoolException("操作失败,当前仓库找不到空库位");
        }
        Date now = new Date();
        // 修改工作档
        StaDesc staDesc = staDescService.queryCrnStn(targetLoc.getCrnNo());
        if (Cools.isEmpty(staDesc)) {
            throw new CoolException("入库路径不存在");
        }
        wrkMast.setWrkSts(2L);
        wrkMast.setLocNo(targetLoc.getLocNo());
        wrkMast.setStaNo(staDesc.getCrnStn());
        wrkMast.setCrnNo(targetLoc.getCrnNo());
        wrkMast.setModiTime(now);
        wrkMast.setModiUser(userId);
        wrkMast.setPreHave("N");
        if (!wrkMastService.updateById(wrkMast)) {
            throw new CoolException("修改工作档失败");
        }
        // 修改库位状态 O ===>>> S
        if (targetLoc.getLocSts().equals("O")){
            targetLoc.setLocSts("S"); // S.入库预约
            targetLoc.setModiUser(userId);
            targetLoc.setModiTime(now);
            if (!locMastService.updateById(targetLoc)){
                throw new CoolException("改变库位状态失败");
            }
        } else {
            throw new CoolException(targetLoc.getLocNo()+"目标库位已被占用");
        }
        // 禁用异常库位
//        locMast.setLocSts("X"); // X.禁用
//        locMast.setModiUser(userId);
//        locMast.setModiTime(now);
//        if (!locMastService.updateById(locMast)){
//            throw new CoolException("改变库位状态失败");
//        }
        return targetLoc.getLocNo();
    }
}