自动化立体仓库 - WMS系统
#
lty
4 天以前 f4d88f2a2317c2f08391173856b81ec3083ae29a
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -27,6 +27,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import javax.annotation.Resource;
import java.util.*;
@@ -44,6 +45,7 @@
    private static final int DEFAULT_WORK_NO_TYPE = 0;
    // 库位排号分配默认类别
    private static final int DEFAULT_ROW_NO_TYPE = 1;
    private static final String BACK_LOC_OPERATION_V2_SCENE = "跨巷道回库出库";
    @Autowired
    private MatService matService;
@@ -535,7 +537,8 @@
        }
        // 生成工作档明细
        for (LocDto locDto : taskDto.getLocDtos()) {
            if (locDto.getAnfme() == null || locDto.getAnfme() <= 0.0D) {
            //TODO明细消失原因
            if (locDto.getAnfme() == null || locDto.getAnfme() == 0.0D) {
                continue;
            }
//            OrderDetl orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), locDto.getBatch());
@@ -1522,6 +1525,7 @@
        mast.setSourceLocNo(wrkMast.getLocNo());
        mast.setLocNo(locNo.getLocNo()); // 目标库位 = 出库时的源库位
        mast.setModiTime(now);
        mast.setExitMk("Y");
        mast.setWrkCode(workNo);
        mast.setModiUser(userId);
        if (!wrkMastService.insert(mast)) {
@@ -1585,110 +1589,137 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R backLocOperationV2(String workNo, Long userId) {
        WrkMast wrkMast = wrkMastService.selectById(workNo);
        if (Cools.isEmpty(wrkMast)) {
            return R.error(workNo+"工作档不存在");
        }
        if (wrkMast.getWrkSts() != 15) {
            return R.error("当前任务状态不能执行此操作!");
        }
        Integer ioType = 101;
        Integer wokNo;
        if (Objects.isNull(wrkMast.getIsSuplus())) {
            return R.error("回库类型不能为空!!");
        }
        wokNo = commonService.getWorkNo(0);
        LocMast locMast1 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", wrkMast.getLocNo()));
        // 获取目标站
        Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                .eq("type_no", ioType)
                .eq("stn_no", 1070) // 1070
                .eq("crn_no", locMast1.getCrnNo()); // 堆垛机号
        StaDesc staDesc = staDescService.selectOne(wrapper);
        if (Cools.isEmpty(staDesc)) {
            return R.error("出库路径不存在");
        }
        int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("barcode", wrkMast.getBarcode()));
        if (count >= 2) {
            return R.error("任务档已生成,不可以重复生成相同的子任务!!");
        }
        WrkDetl detl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
        LocDetl locDetl = new LocDetl();
        BeanUtils.copyProperties(detl, locDetl);
        FindLocNoAttributeVo findLocNoAttributeVo = new FindLocNoAttributeVo(locDetl);
        // 源站点状态检测
        BasDevp sourceStaNo = basDevpService.checkSiteStatus(staDesc.getCrnStn(), false);
        sourceStaNo.setLocType1((short) 1);
        LocTypeDto locTypeDto = new LocTypeDto(sourceStaNo);
        String locNo = wrkMast.getSourceLocNo();
        if(Cools.isEmpty(locNo)) {
            return R.error("没有空库位");
        }
        Date now = new Date();
        // 堆垛机站点(目标站)
        Integer staNo = staDesc.getCrnStn();
        WrkMast mast = new WrkMast();
        BeanUtils.copyProperties(wrkMast, mast);
        mast.setWrkNo(wokNo);
        // 更新工作档数据状态
        mast.setIoType(ioType); // 110先出库到1070
        mast.setWrkSts(11L); // 生成出库id
        mast.setSourceStaNo(String.valueOf(staDesc.getCrnStn())); // 源站
        mast.setStaNo(String.valueOf(staDesc.getStnNo())); // 目标站
        mast.setSourceLocNo(wrkMast.getLocNo()); //出库位
        mast.setLocNo(locNo); // 目标库位 = 出库时的源库位,用于判断巷道
        mast.setModiTime(now);
        mast.setWrkCode(null);
        mast.setPacked(workNo);
        mast.setModiUser(userId);
        if (!wrkMastService.insert(mast)) {
            return R.error("更新工作档数据状态失败");
        }
        List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
        if (Cools.isEmpty(wrkDetls)) {
            return R.error("数据错误,任务档明细不存在 !!");
        }
        LocAroundBind aroundBind = locAroundBindService.selectOne(new EntityWrapper<LocAroundBind>().eq("b_loc_no", mast.getSourceLocNo()));
        if (!Objects.isNull(aroundBind)) {
            aroundBind.setLocType(LocStsType.LOC_STS_TYPE_R.type);
            if (!locAroundBindService.updateById(aroundBind)) {
                return R.error("工位状态修改失败!!");
        final String scene = BACK_LOC_OPERATION_V2_SCENE;
        String locNo = null;
        String sourceLocNo = null;
        String barcode = null;
        Integer sourceStaNo = null;
        Integer staNo = null;
        try {
            WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", workNo));
            if (Cools.isEmpty(wrkMast)) {
                return R.error(workNo + "工作档不存在");
            }
        }
        wrkDetls.forEach(wrkDetl -> {
            WrkDetl wrkDetl1 = new WrkDetl();
            BeanUtils.copyProperties(wrkDetl, wrkDetl1);
            wrkDetl1.setAnfme(wrkDetl.getStockQty() - wrkDetl.getAnfme());
            wrkDetl1.setWrkNo(wokNo);
            if (!wrkDetlService.insert(wrkDetl1)) {
                throw new CoolException("任务档明细保存失败!!");
            if (!Objects.equals(wrkMast.getWrkSts(), 15L)) {
                return R.error("当前任务状态不能执行此操作!");
            }
        });
            if (Objects.isNull(wrkMast.getIsSuplus())) {
                return R.error("回库类型不能为空!!");
            }
        //修改作业库位状态
        LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
        locMast.setLocSts("R");
        locMast.setModiTime(now);
        locMast.setModiUser(userId);
        if (!locMastService.updateById(locMast)) {
            return R.error("修改库位状态失败");
            barcode = wrkMast.getBarcode();
            sourceLocNo = wrkMast.getLocNo();
            LocMast sourceLoc = locMastService.selectById(sourceLocNo);
            if (Cools.isEmpty(sourceLoc)) {
                return R.error("作业库位不存在");
            }
            List<Integer> outStaNos = staDescService.queryOutStaNosByLocNo(sourceLocNo, 101);
            if (Cools.isEmpty(outStaNos)) {
                return R.error("出库路径不存在");
            }
            sourceStaNo = outStaNos.get(0);
            LocTypeDto locTypeDto = new LocTypeDto();
            locTypeDto.setLocType1((short) 1);
            StartupDto dto = commonService.getLocNoV2(1, sourceStaNo, wrkMast, locTypeDto);
            if (Cools.isEmpty(dto) || Cools.isEmpty(dto.getLocNo())) {
                throw new CoolException("没有找到库位");
            }
            locNo = dto.getLocNo();
            List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo());
            if (Cools.isEmpty(wrkDetls)) {
                throw new CoolException("工作明细不存在");
            }
            List<Integer> inStaNos = staDescService.queryOutStaNosByLocNo(locNo, 1);
            if (Cools.isEmpty(inStaNos)) {
                throw new CoolException("入库路径不存在");
            }
            staNo = inStaNos.get(0);
            int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("barcode", barcode));
            if (count >= 2) {
                return R.error("任务档已生成,不可以重复生成相同的子任务!!");
            }
            WrkDetl detl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
            if (Cools.isEmpty(detl)) {
                return R.error("数据错误,任务档明细不存在 !!");
            }
            LocDetl locDetl = new LocDetl();
            BeanUtils.copyProperties(detl, locDetl);
            new FindLocNoAttributeVo(locDetl);
            int newWorkNo = dto.getWorkNo();
            Date now = new Date();
            WrkMast mast = new WrkMast();
            BeanUtils.copyProperties(wrkMast, mast);
            mast.setWrkNo(newWorkNo);
            mast.setIoType(101);
            mast.setWrkSts(11L);
            mast.setSourceStaNo(String.valueOf(sourceStaNo));
            mast.setStaNo(String.valueOf(staNo));
            mast.setSourceLocNo(sourceLocNo);
            mast.setLocNo(locNo);
            mast.setOnlineYn("N");
            mast.setExitMk("Y");
            mast.setModiTime(now);
            mast.setWrkCode(null);
            mast.setPacked(workNo);
            mast.setModiUser(userId);
            if (!wrkMastService.insert(mast)) {
                return R.error("更新工作档数据状态失败");
            }
            LocAroundBind aroundBind = locAroundBindService.selectOne(new EntityWrapper<LocAroundBind>().eq("b_loc_no", mast.getSourceLocNo()));
            if (!Objects.isNull(aroundBind)) {
                aroundBind.setLocType(LocStsType.LOC_STS_TYPE_R.type);
                if (!locAroundBindService.updateById(aroundBind)) {
                    return R.error("工位状态修改失败!!");
                }
            }
            for (WrkDetl wrkDetl : wrkDetls) {
                WrkDetl wrkDetl1 = new WrkDetl();
                BeanUtils.copyProperties(wrkDetl, wrkDetl1);
                wrkDetl1.setAnfme(wrkDetl.getStockQty() - wrkDetl.getAnfme());
                wrkDetl1.setWrkNo(newWorkNo);
                if (!wrkDetlService.insert(wrkDetl1)) {
                    throw new CoolException("任务档明细保存失败!!");
                }
            }
            LocMast locMast1 = locMastService.selectById(sourceLocNo);
            locMast1.setLocSts("R");
            locMast1.setModiTime(now);
            locMast1.setModiUser(userId);
            LocMast locMast2 = locMastService.selectById(locNo);
            locMast2.setLocSts("S");
            locMast2.setModiTime(now);
            locMast2.setModiUser(userId);
            if (!locMastService.updateById(locMast1)) {
                return R.error("修改出库库位状态失败");
            }
            if (!locMastService.updateById(locMast2)) {
                return R.error("修改入库库位状态失败");
            }
            if (Cools.isEmpty(mast)) {
                return R.error("没有生成任务");
            }
            return R.ok("生成回库任务成功!!");
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            String reason = Cools.isEmpty(e.getMessage()) ? e.getClass().getSimpleName() : e.getMessage();
            log.error("{}失败[workNo={}, barcode={}, sourceLocNo={}, locNo={}, sourceStaNo={}, staNo={}, userId={}],原因: {}",
                    scene, workNo, barcode, sourceLocNo, locNo, sourceStaNo, staNo, userId, reason, e);
            return R.error(reason);
        }
        if (Cools.isEmpty(mast)) {
            return R.error("没有生成任务");
        }
        return R.ok("生成回库任务成功!!");
    }