自动化立体仓库 - WMS系统
#
luxiaotao1123
2022-03-30 e429033bedde0bf5f997411e688495c9518ec469
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -1,6 +1,5 @@
package com.zy.asrs.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.BaseRes;
@@ -20,7 +19,6 @@
import com.zy.common.service.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -76,12 +74,11 @@
        if (Cools.isEmpty(param.getDevpNo(), param.getList())) {
            throw new CoolException(BaseRes.PARAM);
        }
        Date now = new Date();
        // 源站点状态检测
        BasDevp sourceStaNo = basDevpService.checkSiteStatus(param.getDevpNo(), true);
        // 检索库位
        LocTypeDto locTypeDto = new LocTypeDto(sourceStaNo);
        log.info(JSON.toJSONString(locTypeDto));
        log.info("{}入库口尺寸检测:{}", param.getDevpNo(), locTypeDto.getLocType1()==1?"低规格库位":"高规格库位");
        List<String> matNos = param.getList().stream().map(FullStoreParam.MatCodeStore::getMatNo).distinct().collect(Collectors.toList());
        StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 1, param.getDevpNo(), matNos, locTypeDto, 0);
        // 生成工作号
@@ -92,7 +89,7 @@
        wrkMast.setIoTime(new Date());
        wrkMast.setWrkSts(1L); // 工作状态:生成入库ID
        wrkMast.setIoType(1); // 入出库状态:1.入库
        wrkMast.setIoPri(13D); // 优先级:10
        wrkMast.setIoPri(13D); // 优先级:13
        wrkMast.setCrnNo(dto.getCrnNo());
        wrkMast.setSourceStaNo(dto.getSourceStaNo());
        wrkMast.setStaNo(dto.getStaNo());
@@ -104,25 +101,30 @@
        wrkMast.setEmptyMk("N"); // 空板
        wrkMast.setLinkMis("N");
        wrkMast.setCtnType(sourceStaNo.getCtnType()); // 容器类型
        // 操作人员数据
        wrkMast.setAppeUser(userId);
        wrkMast.setAppeTime(new Date());
        wrkMast.setAppeTime(now);
        wrkMast.setModiUser(userId);
        wrkMast.setModiTime(new Date());
        boolean res = wrkMastService.insert(wrkMast);
        if (!res) {
        wrkMast.setModiTime(now);
        if (!wrkMastService.insert(wrkMast)) {
            throw new CoolException("保存工作档失败");
        }
        // 生成工作档明细
        List<DetlDto> detlDtos = new ArrayList<>();
        param.getList().forEach(elem -> {
            detlDtos.add(new DetlDto(elem.getMatNo(), elem.getCount()));
            DetlDto detlDto = new DetlDto(elem.getMatNo(), elem.getBatch(), elem.getAnfme());
            if (DetlDto.has(detlDtos, detlDto)) {
                DetlDto detlDto1 = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch());
                assert detlDto1 != null;
                detlDto1.setAnfme(detlDto1.getAnfme() + detlDto.getAnfme());
            } else {
                detlDtos.add(detlDto);
            }
        });
        wrkDetlService.createWorkDetail(workNo, detlDtos, param.getBarcode(), userId);
        // 更新源站点信息
        sourceStaNo.setWrkNo(workNo);
        sourceStaNo.setModiUser(userId);
        sourceStaNo.setModiTime(new Date());
        sourceStaNo.setModiTime(now);
        if (!basDevpService.updateById(sourceStaNo)){
            throw new CoolException("更新源站失败");
        }
@@ -131,7 +133,7 @@
        if (locMast.getLocSts().equals("O")){
            locMast.setLocSts("S"); // S.入库预约
            locMast.setModiUser(userId);
            locMast.setModiTime(new Date());
            locMast.setModiTime(now);
            if (!locMastService.updateById(locMast)){
                throw new CoolException("改变库位状态失败");
            }
@@ -150,10 +152,7 @@
        List<LocDetlDto> locDetlDtos = new ArrayList<>();
        for (StockOutParam.LocDetl paramLocDetl : param.getLocDetls()) {
            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getCount())) {
                LocDetl sqlParam = new LocDetl();
                sqlParam.setLocNo(paramLocDetl.getLocNo());
                sqlParam.setMatnr(paramLocDetl.getMatnr());
                LocDetl one = locDetlService.selectOne(new EntityWrapper<>(sqlParam));
                LocDetl one = locDetlService.selectItem(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getBatch());
                if (null != one) locDetlDtos.add(new LocDetlDto(one, paramLocDetl.getCount()));
            }
        }
@@ -161,7 +160,7 @@
            // 启动出库开始 101.出库
            stockOut(staNo, locDetlDtos, null, userId);
        } else {
            throw new CoolException("库位物料不存在");
            throw new CoolException("库存不存在");
        }
    }
@@ -825,56 +824,6 @@
        if (!locMastService.updateById(locMast)) {
            throw new CoolException("修改库位状态失败");
        }
    }
    @Autowired
    private JdbcTemplate jdbcTemplate;
    private boolean pickSite = false;
    private void stockOutRe(WrkMast wrkMast, List<WrkDetl> wrkDetls) {
        for (WrkDetl wrkDetl : wrkDetls) {
            List<LocDetl> locDetls = locDetlService.selectPakoutByRule(wrkDetl.getMatnr());
            double issued = wrkDetl.getAnfme();
            for (LocDetl locDetl : locDetls) {
                if (issued > 0) {
                    // 生成出库工作档
                    // 全板
                    if (issued>=locDetl.getAnfme()) {
                        BasDevp staNo = basDevpService.checkSiteStatus(103);
                        List<LocDetlDto> detlDtos = new ArrayList<>();
                        LocDetlDto dto = new LocDetlDto();
                        dto.setLocDetl(locDetl);
                        dto.setCount(issued>=locDetl.getAnfme()?locDetl.getAnfme():issued);
                        detlDtos.add(dto);
                        stockOut(staNo, detlDtos, 101, 9527L);
                        // 拣料
                    } else {
                        int priorCount = jdbcTemplate.queryForObject("select isnull(count(*),0) from man_prior where 1=1 and matnr = '" + wrkDetl.getMatnr() + "'", Integer.class);
                        if (priorCount > 0) {
                            BasDevp staNo = basDevpService.checkSiteStatus(103);
                            List<LocDetlDto> detlDtos = new ArrayList<>();
                            LocDetlDto dto = new LocDetlDto();
                            dto.setLocDetl(locDetl);
                            dto.setCount(locDetl.getAnfme());
                            detlDtos.add(dto);
                            stockOut(staNo, detlDtos, 101, 9527L);
                        } else {
                            BasDevp staNo = basDevpService.checkSiteStatus(pickSite?113:109);
                            List<LocDetlDto> detlDtos = new ArrayList<>();
                            LocDetlDto dto = new LocDetlDto();
                            dto.setLocDetl(locDetl);
                            dto.setCount(issued>=locDetl.getAnfme()?locDetl.getAnfme():issued);
                            detlDtos.add(dto);
                            stockOut(staNo, detlDtos, 103, 9527L);
                        }
                    }
                    // 剩余待出数量递减
                    issued = issued - locDetl.getAnfme();
                }
            }
        }
        pickSite = !pickSite;
    }
}