自动化立体仓库 - WMS系统
#
18516761980
2021-12-06 7203d67cfa3a2fc1cab9b8985dfd35c1797207b1
src/main/java/com/zy/asrs/service/impl/MatOutServiceImpl.java
@@ -9,13 +9,17 @@
import com.zy.asrs.service.*;
import com.zy.asrs.utils.VersionUtils;
import com.zy.common.model.LocDetlDto;
import com.zy.common.model.OutLocDto;
import com.zy.common.service.CommonService;
import com.zy.ints.entity.WaitMatout;
import com.zy.ints.mapper.WaitMatoutMapper;
import com.zy.ints.service.WaitMatoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class MatOutServiceImpl implements MatOutService {
@@ -38,58 +42,74 @@
    private WrkDetlService wrkDetlService;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private WaitMatoutMapper waitMatoutMapper;
    @Autowired
    private WaitMatoutService waitMatoutService;
    @Override
    @Transactional
    public void startupMatOut(StockOutParam param, Long userId){
        // 目标站点状态检测
        BasDevp staNo = basDevpService.checkSiteStatus(param.getOutSite());
        // 获取库位明细
        List<LocDetlDto> locDetlDtos = new ArrayList<>();
        for (StockOutParam.LocDetl paramLocDetl : param.getLocDetls()) {
            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatNo(), paramLocDetl.getCount())) {
                LocDetl sqlParam = new LocDetl();
                sqlParam.setLocNo(paramLocDetl.getLocNo());
                sqlParam.setMatNo(paramLocDetl.getMatNo());
                LocDetl one = locDetlService.selectOne(new EntityWrapper<>(sqlParam));
                if (null != one) locDetlDtos.add(new LocDetlDto(one, paramLocDetl.getCount()));
            if (!Cools.isEmpty(paramLocDetl.getMatNo())) {
                //查询所有库位状态为F的库位信息
                List<LocDetl> locDetls=locDetlService.getlocDetlList(paramLocDetl.getMatNo());
                if (locDetls.size()==0){
                    throw new CoolException("库位状态出错");
                }
                for (LocDetl locDetl : locDetls) {
                    WaitMatout waitMatout = waitMatoutService.selectOne(new EntityWrapper<WaitMatout>().eq("bill_no", paramLocDetl.getBillNo()).eq("seq_no",paramLocDetl.getSeqNo()));
                    Double outQty = paramLocDetl.getCount() - waitMatout.getOutQty();
                    if(waitMatout.getOutQty() >= waitMatout.getQty()){
                        break;
                    }
                    // 判断入出库类型:101.全板出库 or 103.拣料出库
                    Double sumCount=locDetlService.getLocDetlSumQty(locDetl.getLocNo());
                    int ioType=0;
                    ioType = sumCount-locDetl.getQty()>0 ? 103 : 101;
                    Double curOutQty = outQty >= locDetl.getQty() ? locDetl.getQty() : outQty;   //本次出库量
                    stockOut(waitMatout.getBillNo(),waitMatout.getSeqNo(),staNo,new LocDetlDto(locDetl,curOutQty),ioType,userId);
                    waitMatout.setOutQty(waitMatout.getOutQty() + curOutQty);
                    waitMatout.setIoStatus(1);
                    //修改记录
                    Integer update = waitMatoutMapper.update(waitMatout, new EntityWrapper<WaitMatout>().eq("bill_no", paramLocDetl.getBillNo())
                            .eq("seq_no",paramLocDetl.getSeqNo()));
//                    if (outQty >= locDetl.getQty()){
//                        //生成文档记录
//                        stockOut(waitMatout.getBillNo(),waitMatout.getSeqNo(),staNo,new LocDetlDto(locDetl,locDetl.getQty()),ioType,userId);
//                        waitMatout.setOutQty(waitMatout.getOutQty() + locDetl.getQty());
//                        waitMatout.setIoStatus(1);
//                        //修改记录
//                        Integer update = waitMatoutMapper.update(waitMatout, new EntityWrapper<WaitMatout>().eq("bill_no", paramLocDetl.getBillNo())
//                                                                .eq("seq_no",paramLocDetl.getSeqNo()));
//                    }else {
//                        //生成文档记录
//                        stockOut(waitMatout.getBillNo(),waitMatout.getSeqNo(),staNo,new LocDetlDto(locDetl,outQty),ioType,userId);
//                        waitMatout.setOutQty(waitMatout.getOutQty() + outQty);
//                        waitMatout.setIoStatus(1);
//                        //修改记录
//                        Integer update = waitMatoutMapper.update(waitMatout, new EntityWrapper<WaitMatout>().eq("bill_no", paramLocDetl.getBillNo())
//                                                                .eq("seq_no",paramLocDetl.getSeqNo()));
//                    }
                }
            }
        }
        if (!locDetlDtos.isEmpty()) {
            // 启动出库开始 101.出库
            stockOut(staNo, locDetlDtos, null, userId);
        } else {
            throw new CoolException("库位产品不存在");
        }
    }
    @Override
    @Transactional
    public void stockOut(BasDevp staNo, List<LocDetlDto> locDetlDtos, Integer ioType, Long userId) {
        // 合并同类项
        Set<String> locNos = new HashSet<>();
        locDetlDtos.forEach(dto -> locNos.add(dto.getLocDetl().getLocNo()));
        List<OutLocDto> dtos = new ArrayList<>();
        for (String locNo : locNos) {
            List<LocDetlDto> list = new ArrayList<>();
            Iterator<LocDetlDto> iterator = locDetlDtos.iterator();
            while (iterator.hasNext()) {
                LocDetlDto dto = iterator.next();
                if (locNo.equals(dto.getLocDetl().getLocNo())) {
                    list.add(dto);
                    iterator.remove();
                }
            }
            dtos.add(new OutLocDto(locNo, list));
        }
    public void stockOut(String billNo, Integer seqNo, BasDevp staNo, LocDetlDto locDetlDtos, Integer ioType, Long userId) {
        // 生成工作档
        for (OutLocDto dto : dtos) {
            // 判断入出库类型:101.全板出库 or 103.拣料出库
            if (ioType == null) {
                ioType = dto.isAll() ? 101 : 103;
            }
            LocDetl locDetl=locDetlDtos.getLocDetl();
            // 获取库位
            LocMast locMast = locMastService.selectById(dto.getLocNo());
            LocMast locMast = locMastService.selectById(locDetl.getLocNo());
            // 获取路径
            Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                    .eq("type_no", ioType)
@@ -99,8 +119,14 @@
            if (Cools.isEmpty(staDesc)) {
                throw new CoolException("出库路径不存在");
            }
            int rok;
            if(ioType==103){
                rok=2;
            }else{
                rok=1;
            }
            // 生成工作号
            int workNo = commonService.getWorkNo(DEFAULT_WORK_NO_TYPE);
            int workNo = commonService.getWorkNo(rok);
            // 生成工作档
            WrkMast wrkMast = new WrkMast();
            wrkMast.setWrkNo(workNo);
@@ -111,7 +137,7 @@
            wrkMast.setCrnNo(locMast.getCrnNo());
            wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站
            wrkMast.setStaNo(staDesc.getStnNo()); // 目标站
            wrkMast.setSourceLocNo(dto.getLocNo()); // 源库位
            wrkMast.setSourceLocNo(locDetl.getLocNo()); // 源库位
            wrkMast.setFullPlt("Y"); // 满板:Y
            wrkMast.setPicking("N"); // 拣料
            wrkMast.setExitMk("N"); // 退出
@@ -122,39 +148,36 @@
            wrkMast.setModiUser(userId);
            wrkMast.setModiTime(new Date());
            if (!wrkMastService.insert(wrkMast)) {
                throw new CoolException("保存工作档失败,出库库位号:"+dto.getLocNo());
                throw new CoolException("保存工作档失败,出库库位号:"+locDetl.getLocNo());
            }
            // 生成工作档明细
            for (LocDetlDto detlDto : dto.getLocDetlDtos()) {
                // 出库时,数量为0的直接忽略
                if (detlDto.getCount()==null || detlDto.getCount() <= 0.0D) {continue;}
                if (locDetlDtos.getCount()==null || locDetlDtos.getCount() <= 0.0D) {return;}
                WrkDetl wrkDetl = new WrkDetl();
                wrkDetl.setWrkNo(workNo);
                wrkDetl.setIoTime(new Date());
                Double qty = ioType==101?detlDto.getLocDetl().getQty():detlDto.getCount();
                wrkDetl.setQty(qty); // 数量
                VersionUtils.setWrkDetl(wrkDetl, detlDto.getLocDetl()); // 版本控制
                wrkDetl.setQty(locDetlDtos.getCount()); // 数量
                VersionUtils.setWrkDetl(wrkDetl, locDetlDtos.getLocDetl()); // 版本控制
                wrkDetl.setAppeTime(new Date());
                wrkDetl.setAppeUser(userId);
                wrkDetl.setModiTime(new Date());
                wrkDetl.setBillNo(billNo);
                wrkDetl.setSeqNo(seqNo);
                wrkDetl.setModiUser(userId);
                if (!wrkDetlService.insert(wrkDetl)) {
                    throw new CoolException("保存工作档明细失败");
                }
            }
            // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
            locMast = locMastService.selectById(dto.getLocNo());
            locMast = locMastService.selectById(locDetl.getLocNo());
            if (locMast.getLocSts().equals("F")) {
                locMast.setLocSts(ioType==101?"R":"P");
                locMast.setModiUser(userId);
                locMast.setModiTime(new Date());
                if (!locMastService.updateById(locMast)) {
                    throw new CoolException("预约库位状态失败,库位号:"+dto.getLocNo());
                    throw new CoolException("预约库位状态失败,库位号:"+locDetl.getLocNo());
                }
            } else {
                throw new CoolException(dto.getLocNo() + "库位不是在库状态");
                throw new CoolException(locDetl.getLocNo() + "库位不是在库状态");
            }
        }
    }
}