| | |
| | | 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.BasDevp; |
| | | import com.zy.asrs.entity.LocDetl; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.StockOutParam; |
| | | import com.zy.asrs.service.MatOutService; |
| | | 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.ArrayList; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | @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<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 (!locDetlDtos.isEmpty()) { |
| | | // // 启动出库开始 101.出库 |
| | | // stockOut(staNo, locDetlDtos, null, userId); |
| | | // } else { |
| | | // throw new CoolException("库位产品不存在"); |
| | | // } |
| | | |
| | | // 目标站点状态检测 |
| | | BasDevp staNo = basDevpService.checkSiteStatus(param.getOutSite()); |
| | | // 获取库位明细 |
| | | List<LocDetlDto> locDetlDtos = new ArrayList<>(); |
| | | for (StockOutParam.LocDetl paramLocDetl : param.getLocDetls()) { |
| | | if (!Cools.isEmpty(paramLocDetl.getMatNo())) { |
| | | //查询所有库位状态为F的库位信息 |
| | | List<LocDetl> locDetls=locDetlService.getlocDetlList(paramLocDetl.getMatNo()); |
| | | 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-outQty>0?103 : 101; |
| | | |
| | | if (outQty >= locDetl.getQty()){ |
| | | //生成文档记录 |
| | | stockOut(staNo,new LocDetlDto(locDetl,locDetl.getQty()),ioType,userId); |
| | | waitMatout.setOutQty(waitMatout.getOutQty() + locDetl.getQty()); |
| | | //修改记录 |
| | | Integer update = waitMatoutMapper.update(waitMatout, new EntityWrapper<WaitMatout>().eq("bill_no", paramLocDetl.getBillNo()) |
| | | .eq("seq_no",paramLocDetl.getSeqNo())); |
| | | }else { |
| | | //生成文档记录 |
| | | stockOut(staNo,new LocDetlDto(locDetl,outQty),ioType,userId); |
| | | waitMatout.setOutQty(waitMatout.getOutQty() + outQty); |
| | | //修改记录 |
| | | Integer update = waitMatoutMapper.update(waitMatout, new EntityWrapper<WaitMatout>().eq("bill_no", paramLocDetl.getBillNo()) |
| | | .eq("seq_no",paramLocDetl.getSeqNo())); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void stockOut(BasDevp staNo, LocDetlDto locDetlDtos, Integer ioType, Long userId) { |
| | | // 生成工作档 |
| | | LocDetl locDetl=locDetlDtos.getLocDetl(); |
| | | // 获取库位 |
| | | LocMast locMast = locMastService.selectById(locDetl.getLocNo()); |
| | | // 获取路径 |
| | | Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>() |
| | | .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.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() + "库位不是在库状态"); |
| | | } |
| | | } |
| | | } |