package com.zy.asrs.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; import com.core.common.Cools; import com.core.exception.CoolException; import com.zy.asrs.entity.*; import com.zy.asrs.entity.param.StockOutParam; import com.zy.asrs.service.*; import com.zy.asrs.utils.VersionUtils; import com.zy.common.model.LocDetlDto; 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.ArrayList; import java.util.Date; import java.util.List; @Service public class MatOutServiceImpl implements MatOutService { // 工作号生成规则默认类型 private static final int DEFAULT_WORK_NO_TYPE = 0; // 库位排号分配默认类别 private static final int DEFAULT_ROW_NO_TYPE = 1; @Autowired BasDevpService basDevpService; @Autowired LocDetlService locDetlService; @Autowired LocMastService locMastService; @Autowired StaDescService staDescService; @Autowired private CommonService commonService; @Autowired 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 locDetlDtos = new ArrayList<>(); for (StockOutParam.LocDetl paramLocDetl : param.getLocDetls()) { if (!Cools.isEmpty(paramLocDetl.getMatNo())) { //查询所有库位状态为F的库位信息 List locDetls=locDetlService.getlocDetlList(paramLocDetl.getMatNo()); if (locDetls.size()==0){ throw new CoolException("库位状态出错"); } for (LocDetl locDetl : locDetls) { WaitMatout waitMatout = waitMatoutService.selectOne(new EntityWrapper().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-outQty>0?103 : 101; 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().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().eq("bill_no", paramLocDetl.getBillNo()) .eq("seq_no",paramLocDetl.getSeqNo())); } } } } } @Override @Transactional public void stockOut(String billNo, Integer seqNo, BasDevp staNo, LocDetlDto locDetlDtos, Integer ioType, Long userId) { // 生成工作档 LocDetl locDetl=locDetlDtos.getLocDetl(); // 获取库位 LocMast locMast = locMastService.selectById(locDetl.getLocNo()); // 获取路径 Wrapper wrapper = new EntityWrapper() .eq("type_no", ioType) .eq("stn_no", staNo.getDevNo()) .eq("crn_no", locMast.getCrnNo()); StaDesc staDesc = staDescService.selectOne(wrapper); if (Cools.isEmpty(staDesc)) { throw new CoolException("出库路径不存在"); } // 生成工作号 int workNo = commonService.getWorkNo(DEFAULT_WORK_NO_TYPE); // 生成工作档 WrkMast wrkMast = new WrkMast(); wrkMast.setWrkNo(workNo); wrkMast.setIoTime(new Date()); wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID wrkMast.setIoType(ioType); // 入出库状态 wrkMast.setIoPri(13D); // 优先级:13 wrkMast.setCrnNo(locMast.getCrnNo()); wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站 wrkMast.setStaNo(staDesc.getStnNo()); // 目标站 wrkMast.setSourceLocNo(locDetl.getLocNo()); // 源库位 wrkMast.setFullPlt("Y"); // 满板:Y wrkMast.setPicking("N"); // 拣料 wrkMast.setExitMk("N"); // 退出 wrkMast.setEmptyMk("N"); // 空板 wrkMast.setLinkMis("N"); wrkMast.setAppeUser(userId); // 操作人员数据 wrkMast.setAppeTime(new Date()); wrkMast.setModiUser(userId); wrkMast.setModiTime(new Date()); if (!wrkMastService.insert(wrkMast)) { throw new CoolException("保存工作档失败,出库库位号:"+locDetl.getLocNo()); } // 出库时,数量为0的直接忽略 if (locDetlDtos.getCount()==null || locDetlDtos.getCount() <= 0.0D) {return;} WrkDetl wrkDetl = new WrkDetl(); wrkDetl.setWrkNo(workNo); wrkDetl.setIoTime(new Date()); 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(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("预约库位状态失败,库位号:"+locDetl.getLocNo()); } } else { throw new CoolException(locDetl.getLocNo() + "库位不是在库状态"); } } }