|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.Wrapper; | 
|---|
|  |  |  | import com.core.common.*; | 
|---|
|  |  |  | import com.core.common.BaseRes; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.DateUtils; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.sun.org.apache.xpath.internal.operations.Or; | 
|---|
|  |  |  | import com.zy.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.*; | 
|---|
|  |  |  | import com.zy.asrs.mapper.ManLocDetlMapper; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.asrs.utils.MatUtils; | 
|---|
|  |  |  | import com.zy.asrs.utils.SaasUtils; | 
|---|
|  |  |  | import com.zy.common.CodeRes; | 
|---|
|  |  |  | import com.zy.common.constant.MesConstant; | 
|---|
|  |  |  | import com.zy.common.entity.Parameter; | 
|---|
|  |  |  | import com.zy.asrs.utils.Utils; | 
|---|
|  |  |  | import com.zy.common.model.DetlDto; | 
|---|
|  |  |  | import com.zy.common.model.MesCombParam; | 
|---|
|  |  |  | import com.zy.common.service.CommonService; | 
|---|
|  |  |  | import com.zy.common.utils.HttpHandler; | 
|---|
|  |  |  | import com.zy.common.utils.Synchro; | 
|---|
|  |  |  | import com.zy.system.entity.User; | 
|---|
|  |  |  | import com.zy.system.service.SaasLogService; | 
|---|
|  |  |  | import lombok.Synchronized; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.Iterator; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 移动端服务核心类 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocOwnerService locOwnerService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PlaService plaService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PlaQtyService plaQtyService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SaasLogService saasLogService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderService.checkComplete(order.getOrderNo()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SaasUtils.insertLog(0,jsonLocNo,jsonOrderDetl.getMatnr(), jsonOrderDetl.getAnfme(),user.getUsername()); | 
|---|
|  |  |  | SaasUtils.insertLog(0,jsonLocNo,jsonOrderDetl.getMatnr(), jsonOrderDetl.getAnfme(),user.getUsername(), | 
|---|
|  |  |  | null,null,null,null,null,null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.error("更新平库库存状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | SaasUtils.insertLog(1,jsonLocNo,jsonOrderDetl.getMatnr(), jsonOrderDetl.getAnfme(),user.getUsername()); | 
|---|
|  |  |  | SaasUtils.insertLog(1,jsonLocNo,jsonOrderDetl.getMatnr(), jsonOrderDetl.getAnfme(),user.getUsername(), | 
|---|
|  |  |  | null,null,null,null,null,null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("下架完成"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void plaPakin(String brand, String locNo, String batch, Integer packageNo, User user) { | 
|---|
|  |  |  | Pla pla = plaService.selectByBatchAndPackageNo(batch, packageNo,brand); | 
|---|
|  |  |  | if(Cools.isEmpty(pla)){ | 
|---|
|  |  |  | throw new CoolException("系统未检测到该包物料信息,请重新录入"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(!pla.getStatus().equals(GlobleParameter.PLA_STATUS_0) && !pla.getStatus().equals(GlobleParameter.PLA_STATUS_00)){ | 
|---|
|  |  |  | throw new CoolException("该物料状态不为待入库,无法入库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | pla.setStatus(GlobleParameter.PLA_STATUS_1); | 
|---|
|  |  |  | pla.setModifyTime(new Date()); | 
|---|
|  |  |  | pla.setPakinTime(new Date()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Node node = nodeService.selectByUuid(locNo); | 
|---|
|  |  |  | if(Cools.isEmpty(node)){ | 
|---|
|  |  |  | throw new CoolException("库位信息不正确"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | pla.setStash(node.getParentName()); | 
|---|
|  |  |  | pla.setLocNo(node.getUuid()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | plaService.updateById(pla); | 
|---|
|  |  |  | SaasUtils.insertLog(0,locNo,pla.getBrand(),pla.getWeightAnfme(),user.getUsername(), | 
|---|
|  |  |  | null,pla.getBatch(),pla.getPackageNo(),pla.getOwner(),pla.getWorkshop(),null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | @Synchronized | 
|---|
|  |  |  | public void plaPakout(String brand, String locNo, String batch, Integer packageNo, String orderNo, String plaQtyId, String wrkNo, Double anfme, boolean isReplace) { | 
|---|
|  |  |  | Pla pla = plaService.selectByBatchAndPackageNo(batch, packageNo,brand); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ManPakOut manPakOut = manPakOutService.selectById(wrkNo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PlaQty plaQty = plaQtyService.selectById(plaQtyId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //物料替换 | 
|---|
|  |  |  | if(isReplace){ | 
|---|
|  |  |  | replacePla(pla,manPakOut,plaQty); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | if((!Cools.eq(pla.getStatus(),GlobleParameter.PLA_STATUS_2) && !Cools.eq(pla.getStatus(),GlobleParameter.PLA_STATUS_3) && !Cools.eq(pla.getStatus(),GlobleParameter.PLA_STATUS_1)) || | 
|---|
|  |  |  | !Cools.eq(pla.getBatch(),manPakOut.getBatch()) || | 
|---|
|  |  |  | !Cools.eq(pla.getPackageNo()+"",manPakOut.getBarcode()) || | 
|---|
|  |  |  | !Cools.eq(pla.getBrand(),manPakOut.getMaktx()) ){ | 
|---|
|  |  |  | throw new CoolException("物料不一致,无法出库" + "批号:" + pla.getBatch() + ",包号:" + pla.getPackageNo() + ",牌号:" + pla.getBrand()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新拣货单信息 | 
|---|
|  |  |  | if(manPakOut.getCount() + anfme > manPakOut.getAnfme()){ | 
|---|
|  |  |  | throw new CoolException("拣货重量大于拣货单所需拣货重量,请重新分配拣货重量"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(manPakOut.getStatus() == 1){ | 
|---|
|  |  |  | throw new CoolException("该拣料单已出库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | manPakOut.setCount(manPakOut.getCount() + anfme); | 
|---|
|  |  |  | if (manPakOut.getAnfme().equals(manPakOut.getCount())){ | 
|---|
|  |  |  | manPakOut.setStatus(1); | 
|---|
|  |  |  | manPakOut.setUpdateTime(new Date()); | 
|---|
|  |  |  | manPakOutService.updateById(manPakOut); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新plaQty信息 | 
|---|
|  |  |  | plaQty.setPakoutTime(Utils.getDateStr(new Date())); | 
|---|
|  |  |  | plaQtyService.updateById(plaQty); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新pla明细 | 
|---|
|  |  |  | pla.setWeightAnfme(pla.getWeightAnfme() - anfme); | 
|---|
|  |  |  | pla.setQtyAnfme(pla.getQtyAnfme() - anfme); | 
|---|
|  |  |  | pla.setModifyTime(new Date()); | 
|---|
|  |  |  | if(pla.getWeightAnfme() <= 0){ | 
|---|
|  |  |  | pla.setStatus(GlobleParameter.PLA_STATUS_4); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | pla.setStatus(GlobleParameter.PLA_STATUS_3); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info("pla出库v1,订单出库,更新为待出库或则全部出库,pla:{},anfme:{},是否替换:{}",pla,anfme,isReplace); | 
|---|
|  |  |  | plaService.updateById(pla); | 
|---|
|  |  |  | SaasUtils.insertLog(1,locNo,pla.getBrand(),anfme,null,null, | 
|---|
|  |  |  | pla.getBatch(),pla.getPackageNo(),pla.getOwner(),pla.getWorkshop(),null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新订单明细 | 
|---|
|  |  |  | Order order = orderService.selectByNo(orderNo); | 
|---|
|  |  |  | OrderDetl orderDetl = orderDetlService.selectById(plaQty.getOrderDetlId()); | 
|---|
|  |  |  | if (orderDetl == null){ | 
|---|
|  |  |  | throw new CoolException("订单明细不存在或者不匹配"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderDetl.setQty(orderDetl.getQty() + anfme); | 
|---|
|  |  |  | orderDetlService.updateById(orderDetl); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderService.checkComplete(orderNo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void plaPackOutWithoutOrder(String brand, String batch, Integer packageNo, Double anfme) { | 
|---|
|  |  |  | Pla pla = plaService.selectByBatchAndPackageNo(batch, packageNo,brand); | 
|---|
|  |  |  | if(Cools.isEmpty(pla)){ | 
|---|
|  |  |  | throw new CoolException("当前物料明细不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!pla.getStatus().equals(GlobleParameter.PLA_STATUS_1) && !pla.getStatus().equals(GlobleParameter.PLA_STATUS_3)){ | 
|---|
|  |  |  | throw new CoolException("当前物料状态无法出库"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(anfme > pla.getWeightAnfme()){ | 
|---|
|  |  |  | throw new CoolException("当前物料剩余库存不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | log.info("无订单拣货出库,更新为待出库或则全部出库,pla:{},anfme:{}",pla,anfme); | 
|---|
|  |  |  | pla.setWeightAnfme(pla.getWeightAnfme() - anfme); | 
|---|
|  |  |  | if(pla.getWeightAnfme() > 0){ | 
|---|
|  |  |  | pla.setStatus(GlobleParameter.PLA_STATUS_3); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | pla.setStatus(GlobleParameter.PLA_STATUS_4); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | plaService.updateById(pla); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SaasUtils.insertLog(1,pla.getLocNo(),pla.getBrand(),anfme,null,null,pla.getBatch(),pla.getPackageNo(),pla.getOwner(),pla.getWorkshop(),null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<ManPakOut> getManPakoutByOrderNo(String orderNo) { | 
|---|
|  |  |  | return manPakOutService.selectList(new EntityWrapper<ManPakOut>().eq("doc_num",orderNo).eq("status",0)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void replacePla(Pla plaNew, ManPakOut manPakOut, PlaQty plaQty){ | 
|---|
|  |  |  | //还原旧物料状态 | 
|---|
|  |  |  | Pla plaOld = plaService.selectByBatchAndPackageNo(manPakOut.getBatch(), Integer.parseInt(manPakOut.getBarcode()), manPakOut.getMaktx()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新新物料信息 | 
|---|
|  |  |  | plaNew.setQtyAnfme(plaOld.getQtyAnfme()); | 
|---|
|  |  |  | plaNew.setStatus(plaOld.getStatus()); | 
|---|
|  |  |  | plaService.updateById(plaNew); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | plaOld.setStatus(GlobleParameter.PLA_STATUS_1); | 
|---|
|  |  |  | plaOld.setQtyAnfme(0.0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | plaService.updateById(plaOld); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新plaQty信息 | 
|---|
|  |  |  | plaQty.setBatch(plaNew.getBatch()); | 
|---|
|  |  |  | plaQty.setBrand(plaNew.getBrand()); | 
|---|
|  |  |  | plaQty.setPackageNo(plaNew.getPackageNo()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | plaQtyService.updateById(plaQty); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新拣货单信息 | 
|---|
|  |  |  | manPakOut.setMaktx(plaNew.getBrand()); | 
|---|
|  |  |  | manPakOut.setBatch(plaNew.getBatch()); | 
|---|
|  |  |  | manPakOut.setBarcode(plaNew.getPackageNo() + ""); | 
|---|
|  |  |  | manPakOut.setUpdateTime(new Date()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | manPakOutService.updateById(manPakOut); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Pla> pdaSelectInfmt(String barcode) { | 
|---|
|  |  |  | EntityWrapper<Pla> plaEntityWrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | String[] split = barcode.split(";"); | 
|---|
|  |  |  | if (split.length == 4){ | 
|---|
|  |  |  | plaEntityWrapper.eq("brand",split[0]); | 
|---|
|  |  |  | plaEntityWrapper.eq("batch",split[1]); | 
|---|
|  |  |  | plaEntityWrapper.eq("package_no",split[2]); | 
|---|
|  |  |  | plaEntityWrapper.eq("line",split[3]); | 
|---|
|  |  |  | }else if (split.length == 1){ | 
|---|
|  |  |  | Node node = nodeService.selectOne(new EntityWrapper<Node>().eq("name", barcode)); | 
|---|
|  |  |  | if (Cools.isEmpty(node)){ | 
|---|
|  |  |  | throw new CoolException("请检查输入的库位码"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | plaEntityWrapper.eq("loc_no",barcode); | 
|---|
|  |  |  | plaEntityWrapper.notLike("status","全部出库"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | throw new CoolException("条码信息有误!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Pla> plaList = plaService.selectList(plaEntityWrapper); | 
|---|
|  |  |  | if (Cools.isEmpty(plaList)){ | 
|---|
|  |  |  | throw new CoolException("未查询到库存物料信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return plaList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public boolean checkMaximum(String locNo, int packageNum){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Node node = nodeService.selectByUuid(locNo); | 
|---|
|  |  |  | Node nodeParent = nodeService.selectById(node.getParentId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(Cools.isEmpty(nodeParent.getMajor())){ | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //当前库存包数 | 
|---|
|  |  |  | int count = plaService.selectCount(new EntityWrapper<Pla>().eq("loc_no", locNo) | 
|---|
|  |  |  | .notIn("status", "全部出库")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(nodeParent.getMajor() < count + packageNum){ | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|