自动化立体仓库 - WMS系统
#
luxiaotao1123
2020-06-18 ebc766304439d72c69b580eaef83681096e4ee3d
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -8,8 +8,10 @@
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.EmptyPlateOutParam;
import com.zy.asrs.entity.param.FullStoreParam;
import com.zy.asrs.entity.param.LocDetlAdjustParam;
import com.zy.asrs.entity.param.StockOutParam;
import com.zy.asrs.service.*;
import com.zy.common.model.LocDetlDto;
import com.zy.common.model.OutLocDto;
import com.zy.common.model.StartupDto;
import com.zy.common.service.CommonService;
@@ -42,6 +44,8 @@
    private StaDescService staDescService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private MatCodeService matCodeService;
    @Override
    @Transactional
@@ -116,19 +120,19 @@
        // 目标站点状态检测
        BasDevp staNo = basDevpService.checkSiteStatus(param.getOutSite());
        // 获取库位明细
        List<LocDetl> locDetls = new ArrayList<>();
        List<LocDetlDto> locDetlDtos = new ArrayList<>();
        for (StockOutParam.LocDetl locDetl : param.getLocDetls()) {
            if (!Cools.isEmpty(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getCount())) {
                LocDetl sqlParam = new LocDetl();
                sqlParam.setLocNo(locDetl.getLocNo());
                sqlParam.setMatnr(locDetl.getMatnr());
                LocDetl one = locDetlService.selectOne(new EntityWrapper<>(sqlParam));
                if (null != one) locDetls.add(one);
                if (null != one) locDetlDtos.add(new LocDetlDto(one, locDetl.getCount()));
            }
        }
        if (!locDetls.isEmpty()) {
        if (!locDetlDtos.isEmpty()) {
            // 启动出库开始
            stockOut(staNo, locDetls, userId);
            stockOut(staNo, locDetlDtos, userId);
        } else {
            throw new CoolException("库位物料不存在");
        }
@@ -136,20 +140,20 @@
    @Override
    @Transactional
    public void stockOut(BasDevp staNo, List<LocDetl> locDetls, Long userId) {
    public void stockOut(BasDevp staNo, List<LocDetlDto> locDetlDtos, Long userId) {
        // 生成工作号
        int workNo = commonService.getWorkNo(DEFAULT_WORK_NO_TYPE);
        // 合并同类项
        Set<String> locNos = new HashSet<>();
        locDetls.forEach(locDetl -> locNos.add(locDetl.getLocNo()));
        locDetlDtos.forEach(dto -> locNos.add(dto.getLocDetl().getLocNo()));
        List<OutLocDto> dtos = new ArrayList<>();
        for (String locNo : locNos) {
            List<LocDetl> list = new ArrayList<>();
            Iterator<LocDetl> iterator = locDetls.iterator();
            List<LocDetlDto> list = new ArrayList<>();
            Iterator<LocDetlDto> iterator = locDetlDtos.iterator();
            while (iterator.hasNext()) {
                LocDetl locDetl = iterator.next();
                if (locNo.equals(locDetl.getLocNo())) {
                    list.add(locDetl);
                LocDetlDto dto = iterator.next();
                if (locNo.equals(dto.getLocDetl().getLocNo())) {
                    list.add(dto);
                    iterator.remove();
                }
            }
@@ -192,19 +196,20 @@
                throw new CoolException("保存工作档失败,出库库位号:"+dto.getLocNo());
            }
            // 生成工作档明细
            for (LocDetl locDetl : dto.getLocDetls()) {
            for (LocDetlDto detlDto : dto.getLocDetlDtos()) {
                if (detlDto.getCount() <= 0.0D) {continue;}
                WrkDetl wrkDetl = new WrkDetl();
                wrkDetl.setWrkNo(workNo);
                wrkDetl.setIoTime(new Date());
                wrkDetl.setMatnr(locDetl.getMatnr());
                wrkDetl.setAnfme(locDetl.getAnfme()); // 数量
                wrkDetl.setZmatid(locDetl.getZmatid());
                wrkDetl.setTbpos(locDetl.getTbpos());
                wrkDetl.setTbnum(locDetl.getTbnum());
                wrkDetl.setLgnum(locDetl.getLgnum());
                wrkDetl.setAltme(locDetl.getAltme());
                wrkDetl.setBname(locDetl.getBname());
                wrkDetl.setMaktx(locDetl.getMaktx());
                wrkDetl.setMatnr(detlDto.getLocDetl().getMatnr());
                wrkDetl.setAnfme(detlDto.getCount()); // 数量
                wrkDetl.setZmatid(detlDto.getLocDetl().getZmatid());
                wrkDetl.setTbpos(detlDto.getLocDetl().getTbpos());
                wrkDetl.setTbnum(detlDto.getLocDetl().getTbnum());
                wrkDetl.setLgnum(detlDto.getLocDetl().getLgnum());
                wrkDetl.setAltme(detlDto.getLocDetl().getAltme());
                wrkDetl.setBname(detlDto.getLocDetl().getBname());
                wrkDetl.setMaktx(detlDto.getLocDetl().getMaktx());
                wrkDetl.setAppeTime(new Date());
                wrkDetl.setAppeUser(userId);
                wrkDetl.setModiTime(new Date());
@@ -393,6 +398,13 @@
            wrkDetl.setIoTime(new Date());
            wrkDetl.setMatnr(locDetl.getMatnr());
            wrkDetl.setAnfme(locDetl.getAnfme());
            wrkDetl.setZmatid(locDetl.getZmatid());
            wrkDetl.setTbpos(locDetl.getTbpos());
            wrkDetl.setTbnum(locDetl.getTbnum());
            wrkDetl.setLgnum(locDetl.getLgnum());
            wrkDetl.setAltme(locDetl.getAltme());
            wrkDetl.setBname(locDetl.getBname());
            wrkDetl.setMaktx(locDetl.getMaktx());
            wrkDetl.setAppeTime(new Date());
            wrkDetl.setAppeUser(userId);
            wrkDetl.setModiTime(new Date());
@@ -421,7 +433,7 @@
                throw new CoolException("更新目标库位状态失败");
            }
        } else {
            throw new CoolException("预约目标库位入库失败,状态:"+loc.getLocType$());
            throw new CoolException("移转失败,目标库位状态:"+loc.getLocType$());
        }
    }
@@ -451,6 +463,58 @@
    @Override
    @Transactional
    public void adjustLocDetl(LocDetlAdjustParam param, Long userId) {
        LocMast locMast = locMastService.selectById(param.getLocNo());
        if (Cools.isEmpty(locMast)) {
            throw new CoolException("库位不存在");
        }
        for (LocDetlAdjustParam.LocDetlAdjust adjust : param.getList()) {
            LocDetl sqlParam = new LocDetl();
            sqlParam.setLocNo(locMast.getLocNo());
            sqlParam.setMatnr(adjust.getMatNo());
            LocDetl one = locDetlService.selectOne(new EntityWrapper<>(sqlParam));
            // 保存新库存明细
            if (Cools.isEmpty(one)) {
                MatCode matCode = matCodeService.selectById(adjust.getMatNo());
                LocDetl locDetl = new LocDetl();
                locDetl.setLocNo(locMast.getLocNo());
                locDetl.setMatnr(matCode.getMatNo());
                locDetl.setMaktx(matCode.getMatName()); // 物料描述
                locDetl.setAnfme(adjust.getCount()); // 数量
                locDetl.setAltme(matCode.getStr1()); // 单位
                // todo:luxiaoao
                locDetl.setModiUser(userId); // 操作人员信息
                locDetl.setModiTime(new Date());
                locDetl.setAppeUser(userId);
                locDetl.setAppeTime(new Date());
                if (!locDetlService.insert(locDetl)) {
                    throw new CoolException("保存库存明细失败");
                }
            // 修改原库存明细
            } else {
                // 如果数量修改,则更新库存明细
                if (!adjust.getCount().equals(one.getAnfme())) {
                    // 当数量被修改为 0 时,直接清除库存明细
                    if (adjust.getCount() == 0) {
                        if (!locDetlService.delete(new EntityWrapper<>(one))) {
                            throw new CoolException("清除库存明细失败");
                        }
                    } else {
                        one.setAnfme(adjust.getCount());
                        one.setModiTime(new Date());
                        one.setModiUser(userId);
                        if (!locDetlService.updateById(one)) {
                            throw new CoolException("修改库存明细失败");
                        }
                    }
                }
            }
        }
    }
    @Override
    @Transactional
    public void cancelWrkMast(String workNo, Long userId) {
        WrkMast wrkMast = wrkMastService.selectById(workNo);
        if (Cools.isEmpty(wrkMast)){