自动化立体仓库 - WMS系统
#
luxiaotao1123
2022-04-25 a200f95a99b59b695fc81ebe3cc2ec14bcd51c8a
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -14,8 +14,10 @@
import com.zy.asrs.entity.param.StockOutParam;
import com.zy.asrs.service.*;
import com.zy.common.model.*;
import com.zy.common.model.enums.IoWorkType;
import com.zy.common.model.enums.WorkNoType;
import com.zy.common.service.CommonService;
import com.zy.common.web.WcsController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -65,6 +67,8 @@
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private WcsController wcsController;
    @Override
    @Transactional
@@ -165,7 +169,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<>();
@@ -184,13 +188,16 @@
                dtos.add(new OutLocDto(locNo, locDetlDto));
            }
        }
        Integer ioType = null;
        // 生成工作档
        for (OutLocDto dto : dtos) {
            // 判断入出库类型:101.全板出库 or 103.拣料出库
            if (ioType == null) {
            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());
            // 获取路径
@@ -225,6 +232,7 @@
                if (detlDto.getCount()==null || detlDto.getCount() <= 0.0D) {continue;}
                WrkDetl wrkDetl = new WrkDetl();
                wrkDetl.sync(detlDto.getLocDetl());
                wrkDetl.setOrderNo(""); // 手动出库不需要带出库存中的单据编号
                wrkDetl.setWrkNo(workNo);
                wrkDetl.setIoTime(now);
                Double anfme = ioType==101?detlDto.getLocDetl().getAnfme():detlDto.getCount();
@@ -266,7 +274,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));
        // 生成工作档
@@ -296,6 +304,9 @@
        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.setIoTime(now);
@@ -462,7 +473,7 @@
        }
        if (!locDetlDtos.isEmpty()) {
            // 启动出库开始 107.盘点出库
            stockOut(staNo, locDetlDtos, 107, userId);
            stockOut(staNo, locDetlDtos, IoWorkType.CHECK_OUT, userId);
        } else {
            throw new CoolException("库位物料不存在");
        }
@@ -472,6 +483,7 @@
    @Transactional
    public void locMove(String sourceLocNo, String locNo, Long userId) {
        LocMast sourceLoc = locMastService.selectById(sourceLocNo);
        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
        if (Cools.isEmpty(sourceLoc)){
            throw new CoolException("未找到库位");
        }
@@ -494,7 +506,7 @@
        wrkMast.setCrnNo(sourceLoc.getCrnNo());
        wrkMast.setSourceLocNo(sourceLocNo); // 源库位
        wrkMast.setLocNo(locNo); // 目标库位
        wrkMast.setFullPlt("N"); // 满板:Y
        wrkMast.setFullPlt(Cools.isEmpty(locDetls)?"N":"Y"); // 满板:Y
        wrkMast.setPicking("N"); // 拣料
        wrkMast.setExitMk("N"); // 退出
        wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 空板
@@ -509,7 +521,6 @@
            throw new CoolException("保存工作档失败");
        }
        // 工作档明细保存
        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
        for (LocDetl locDetl : locDetls) {
            WrkDetl wrkDetl = new WrkDetl();
            wrkDetl.sync(locDetl);
@@ -580,6 +591,7 @@
    @Override
    @Transactional
    public void adjustLocDetl(LocDetlAdjustParam param, Long userId) {
        param.integrate();
        LocMast locMast = locMastService.selectById(param.getLocNo());
        if (Cools.isEmpty(locMast)) {
            throw new CoolException("库位不存在");
@@ -607,7 +619,7 @@
                        // todo 盘点记录
                        // 修改库存
                        if (!locDetlService.updateAnfme(adjust.getCount(), locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch())) {
                            throw new CoolException(locDetl.getLocNo() + "库位," + locDetl.getMatnr() + "商品," + locDetl.getBatch() + "批号修改数量失败");
                            throw new CoolException(locDetl.getLocNo() + "库位," + locDetl.getMatnr() + "商品," + locDetl.getBatch() + "序列码修改数量失败");
                        }
                        // 保存调整记录
                        AdjDetl adjDetl = new AdjDetl();
@@ -632,7 +644,7 @@
        for (LocDetl locDetl : locDetls) {
            // todo 盘点记录
            if (!locDetlService.updateAnfme(-1.0D, locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch())) {
                throw new CoolException("删除" + locDetl.getLocNo() + "库位," + locDetl.getMatnr() + "商品," + locDetl.getBatch() + "批号库存明细失败");
                throw new CoolException("删除" + locDetl.getLocNo() + "库位," + locDetl.getMatnr() + "商品," + locDetl.getBatch() + "序列码库存明细失败");
            }
            // 保存调整记录
            AdjDetl adjDetl = new AdjDetl();
@@ -654,6 +666,7 @@
            Mat mat = matService.selectByMatnr(adjust.getMatnr());
            LocDetl locDetl = new LocDetl();
            locDetl.sync(mat);
            locDetl.setBatch(adjust.getBatch());
            locDetl.setLocNo(locMast.getLocNo());
            locDetl.setAnfme(adjust.getCount()); // 数量
            locDetl.setModiUser(userId); // 操作人员信息
@@ -661,7 +674,7 @@
            locDetl.setAppeUser(userId);
            locDetl.setAppeTime(now);
            if (!locDetlService.insert(locDetl)) {
                throw new CoolException("保存库存明细失败");
                throw new CoolException("添加" + locDetl.getLocNo() + "库位," + locDetl.getMatnr() + "商品," + locDetl.getBatch() + "序列码库存明细失败");
            }
            // 保存调整记录
            AdjDetl adjDetl = new AdjDetl();
@@ -736,7 +749,7 @@
                locSts = "D";
            // 库位转移 ===>> D.空桶/空栈板
            } else if (wrkMast.getIoType() == 11) {
                locSts = "F";
                locSts = wrkMast.getFullPlt().equalsIgnoreCase("N")?"F":"D";
                // 库位转移:目标库位
                LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
                if (Cools.isEmpty(locMast)) {
@@ -778,7 +791,7 @@
        if (wrkMast.getIoType() != 10 && wrkMast.getIoType() != 110) {
            // 保存工作明细档历史档
            if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
                throw new CoolException("保存工作明细历史档失败, workNo = " + wrkMast.getWrkNo());
//                throw new CoolException("保存工作明细历史档失败, workNo = " + wrkMast.getWrkNo());
            }
            // 删除工作档明细
            boolean wrkDetlRes = wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("wrk_no", workNo));
@@ -854,4 +867,14 @@
        }
    }
    @Override
    public StartupDto createWaitPainWrkMastStart(List<WaitPakin> list, Long userId) {
        if (Cools.isEmpty(list)) {
            throw new CoolException("入库通知档不能为空");
        }
        LocTypeDto locTypeDto = new LocTypeDto();
        locTypeDto.setLocType1((short) 1);
        return wcsController.startupFullPutStore(301, list.get(0).getZpallet(), locTypeDto, list);
    }
}