自动化立体仓库 - WMS系统
#
lty
4 天以前 f4d88f2a2317c2f08391173856b81ec3083ae29a
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -2,10 +2,7 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.SnowflakeIdWorker;
import com.core.common.*;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.EmptyPlateOutParam;
@@ -30,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.*;
@@ -47,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;
@@ -459,7 +458,7 @@
                .eq("dev_no", basDevice.getType()).orderBy("order_no"));
        if (Objects.isNull(binds)) {
            log.error("没有可用机台");
            log.error(deviceNo+"---"+basDevice.getType()+"--没有可用机台");
            return;
        }
//
@@ -538,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());
@@ -952,8 +952,14 @@
            throw new CoolException("当前工作档已完成");
        }
        // 入库 + 库位转移
        if (wrkMast.getWrkSts() < 4 || (wrkMast.getWrkSts() > 10 && wrkMast.getIoType() == 11)) {
        if (wrkMast.getWrkSts() < 4 ) {
            wrkMast.setWrkSts(4L);
            WrkMast mast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", wrkMast.getBarcode()).eq("wrk_sts",15L));
            if (!Cools.isEmpty(wrkMast) &&(wrkMast.getIoType()==1||wrkMast.getIoType()==11||wrkMast.getIoType()==10)) {
                mast.setOveMk("Y");
                wrkMast.setModiTime(new  Date());
                wrkMastService.updateById(mast);
            }
            // 出库
        } else if (wrkMast.getWrkSts() > 10) {
            wrkMast.setWrkSts(14L);
@@ -1445,13 +1451,13 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void backLocOperation(String workNo, Long userId) {
    public R backLocOperation(String workNo, Long userId) {
        WrkMast wrkMast = wrkMastService.selectById(workNo);
        if (Cools.isEmpty(wrkMast)) {
            throw new CoolException(workNo + "工作档不存在");
            return R.error(workNo+"工作档不存在");
        }
        if (wrkMast.getWrkSts() != 15) {
            throw new CoolException("当前任务状态不能执行此操作!");
            return R.error("当前任务状态不能执行此操作!");
        }
        Integer ioType = wrkMast.getIoType() - 50;
@@ -1463,7 +1469,7 @@
//            ioType = 10;
//        }
        if (Objects.isNull(wrkMast.getIsSuplus())) {
            throw new CoolException("回库类型不能为空!!");
            return R.error("回库类型不能为空!!");
        }
        if (wrkMast.getIsSuplus() == 0) {
@@ -1481,12 +1487,12 @@
                .eq("crn_no", locMast1.getCrnNo()); // 堆垛机号
        StaDesc staDesc = staDescService.selectOne(wrapper);
        if (Cools.isEmpty(staDesc)) {
            throw new CoolException("入库路径不存在");
            return R.error("入库路径不存在");
        }
        int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("barcode", wrkMast.getBarcode()));
        if (count >= 2) {
            throw new CoolException("任务档已生成,不可以重复生成相同的子任务!!");
            return R.error("任务档已生成,不可以重复生成相同的子任务!!");
        }
        WrkDetl detl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
@@ -1500,6 +1506,11 @@
        LocTypeDto locTypeDto = new LocTypeDto(sourceStaNo);
        StartupDto locNo = commonService.getLocNo1(locMast1.getCrnNo());
        if(Cools.isEmpty(locNo)) {
            return R.error("没有空库位");
        }
//        if()
        Date now = new Date();
        // 堆垛机站点(目标站)
        Integer staNo = staDesc.getCrnStn();
@@ -1507,20 +1518,22 @@
        BeanUtils.copyProperties(wrkMast, mast);
        mast.setWrkNo(wokNo);
        // 更新工作档数据状态
        mast.setIoType(ioType); // 入出库类型: 103->53,104->54,107->57
        mast.setWrkSts(1L); // 工作状态: 2.设备上走
        mast.setIoType(ioType); // 1余料回库,10空轴回库
        mast.setWrkSts(1L); // 生成回库id
        mast.setSourceStaNo(""); // 源站
        mast.setStaNo(""); // 目标站
        mast.setSourceLocNo(wrkMast.getLocNo());
        mast.setLocNo(locNo.getLocNo()); // 目标库位 = 出库时的源库位
        mast.setModiTime(now);
        mast.setExitMk("Y");
        mast.setWrkCode(workNo);
        mast.setModiUser(userId);
        if (!wrkMastService.insert(mast)) {
            throw new CoolException("更新工作档数据状态失败");
            return R.error("更新工作档数据状态失败");
        }
        List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
        if (Cools.isEmpty(wrkDetls)) {
            throw new CoolException("数据错误,任务档明细不存在 !!");
            return R.error("数据错误,任务档明细不存在 !!");
        }
        // 修改库位状态 Q.拣料/盘点/并板再入库
@@ -1529,14 +1542,14 @@
        inLoc.setModiTime(now);
        inLoc.setModiUser(userId);
        if (!locMastService.updateById(inLoc)) {
            throw new CoolException("修改库位状态失败");
            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)) {
                throw new CoolException("工位状态修改失败!!");
                return R.error("工位状态修改失败!!");
            }
        }
@@ -1559,7 +1572,7 @@
        locMast.setModiTime(now);
        locMast.setModiUser(userId);
        if (!locMastService.updateById(locMast)) {
            throw new CoolException("修改库位状态失败");
            return R.error("修改库位状态失败");
        }
//        wrkMast.setWrkCode(null);
@@ -1567,6 +1580,146 @@
//        if (!wrkMastService.updateById(wrkMast)) {
//            throw new CoolException("任务档更新失败!!");
//        }
        if (Cools.isEmpty(mast)) {
            return R.error("没有生成任务");
        }
        return R.ok("生成回库任务成功!!");
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R backLocOperationV2(String workNo, Long userId) {
        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 + "工作档不存在");
            }
            if (!Objects.equals(wrkMast.getWrkSts(), 15L)) {
                return R.error("当前任务状态不能执行此操作!");
            }
            if (Objects.isNull(wrkMast.getIsSuplus())) {
                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);
        }
    }