| | |
| | | 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.entity.param.CombParam; |
| | | import com.zy.asrs.entity.param.MobileAdjustNewParam; |
| | | import com.zy.asrs.entity.param.MobileAdjustParam; |
| | | import com.zy.asrs.entity.param.OffSaleParam; |
| | | 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.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.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.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 移动端服务核心类 |
| | |
| | | |
| | | @Autowired |
| | | private OriginRuleService originRuleService; |
| | | |
| | | @Autowired |
| | | private LocInPrintMatService locInPrintMatService; |
| | | |
| | | @Autowired |
| | | private LocOutPrintMatService locOutPrintMatService; |
| | | |
| | | @Autowired |
| | | private LocOwnerService locOwnerService; |
| | | @Autowired |
| | | private PlaService plaService; |
| | | @Autowired |
| | | private PlaQtyService plaQtyService; |
| | | @Autowired |
| | | private SaasLogService saasLogService; |
| | | |
| | | |
| | | |
| | |
| | | |
| | | @Override |
| | | public R manDetlOrigin(JSONObject json, User user) { |
| | | Date now = new Date(); |
| | | String jsonLocNo = (String) json.get("locNo"); //获取库位码 |
| | | String ownerName = (String) json.get("owner"); //获取拥有者 |
| | | LocOwner locOwner = locOwnerService.selectOne(new EntityWrapper<LocOwner>().eq("owner", ownerName)); |
| | | Long ownerId = locOwner.getId(); |
| | | String jsonCode = (String) json.get("code"); //获取条码 |
| | | String jsonOrigin = (String) json.get("origin"); //获取来源地 |
| | | if (Cools.isEmpty(jsonLocNo)){ |
| | | return R.error("库位号参数为空!"); |
| | | }else if (Cools.isEmpty(ownerId)){ |
| | | return R.error("拥有者参数为空!"); |
| | | }else if (Cools.isEmpty(jsonCode)){ |
| | | return R.error("条码参数为空!"); |
| | | }else if (Cools.isEmpty(jsonOrigin)){ |
| | | return R.error("来源地参数为空!"); |
| | | } |
| | | Integer jsonOwner = ownerId.intValue(); //获取拥有者 |
| | | OriginRule originRule = originRuleService.selectOne(new EntityWrapper<OriginRule>() |
| | | .eq("origin_address", jsonOrigin)); |
| | | |
| | |
| | | if (Cools.isEmpty(mat)){ |
| | | return R.error("未查询到商品信息"); |
| | | } |
| | | //增加打印档案 |
| | | LocInPrintMat locInPrintMat = new LocInPrintMat(now,user.getId(), mat.getMatnr(),jsonOriginDetl.getBatch(),jsonOriginDetl.getAnfme(),jsonLocNo,mat.getMaktx()); |
| | | locInPrintMat.setOwnerId(ownerId); |
| | | locInPrintMatService.insert(locInPrintMat); |
| | | |
| | | Wrapper<ManLocDetl> manLocDetlWrapper = new EntityWrapper<ManLocDetl>().eq("loc_no", jsonLocNo).eq("matnr", jsonOriginDetl.getMatnr()).eq("batch",date); |
| | | Wrapper<ManLocDetl> manLocDetlWrapper = new EntityWrapper<ManLocDetl>().eq("loc_no", jsonLocNo) |
| | | .eq("matnr", jsonOriginDetl.getMatnr()).eq("batch",date).eq("owner",jsonOwner); |
| | | ManLocDetl manLocDetl1 = manLocDetlService.selectOne(manLocDetlWrapper); |
| | | if(!Cools.isEmpty(manLocDetl1)){ |
| | | BigDecimal inAnfme = BigDecimal.valueOf(jsonOriginDetl.getAnfme()); |
| | |
| | | } |
| | | |
| | | }else { |
| | | Date now = new Date(); |
| | | ManLocDetl manLocDetl = new ManLocDetl(); //初始化库存实体类 |
| | | manLocDetl.sync(mat); |
| | | manLocDetl.setLocNo(node.getUuid()); |
| | |
| | | manLocDetl.setModiTime(now); |
| | | // manLocDetl.setOrderNo(waitPakin.getOrderNo()); |
| | | manLocDetl.setStockFreeze(1); |
| | | manLocDetl.setOwner(jsonOwner); |
| | | try { |
| | | Date produceTime = DateUtils.convert(manLocDetl.getBatch(),DateUtils.yyyyMMdd); |
| | | manLocDetl.setProduceTime(produceTime); |
| | | } catch (Exception e) { |
| | | manLocDetl.setProduceTime(now); |
| | | } |
| | | |
| | | if (!manLocDetlService.insert(manLocDetl)){ //数据库插入实体类信息 |
| | | return R.error("物料信息入库失败"); |
| | |
| | | |
| | | @Override |
| | | public R manDetlOrigInNo(JSONObject json, User user) { |
| | | Date now = new Date(); |
| | | String jsonLocNo = (String) json.get("locNo"); //获取库位码 |
| | | |
| | | String ownerName = (String) json.get("owner"); //获取拥有者 |
| | | LocOwner locOwner = locOwnerService.selectOne(new EntityWrapper<LocOwner>().eq("owner", ownerName)); |
| | | Long ownerId = locOwner.getId(); |
| | | if (Cools.isEmpty(jsonLocNo)){ |
| | | return R.error("库位号参数为空!"); |
| | | }else if (Cools.isEmpty(ownerId)){ |
| | | return R.error("拥有者参数为空!"); |
| | | } |
| | | Integer jsonOwner = ownerId.intValue(); //获取拥有者 |
| | | Node node = nodeService.selectOne(new EntityWrapper<Node>().eq("name", jsonLocNo)); //获取对应库位信息 |
| | | if (Cools.isEmpty(node)){ |
| | | return R.error("未查询到库位信息"); |
| | |
| | | if (Cools.isEmpty(mat)){ |
| | | return R.error("未查询到商品信息"); |
| | | } |
| | | //增加打印档案 |
| | | LocInPrintMat locInPrintMat = new LocInPrintMat(now,user.getId(), mat.getMatnr(),jsonOriginDetl.getBatch(),jsonOriginDetl.getAnfme(),jsonLocNo,mat.getMaktx()); |
| | | locInPrintMat.setOwnerId(ownerId); |
| | | locInPrintMatService.insert(locInPrintMat); |
| | | |
| | | Wrapper<ManLocDetl> manLocDetlWrapper = new EntityWrapper<ManLocDetl>().eq("loc_no", jsonLocNo).eq("matnr", jsonOriginDetl.getMatnr()).eq("batch",jsonOriginDetl.getBatch()); |
| | | Wrapper<ManLocDetl> manLocDetlWrapper = new EntityWrapper<ManLocDetl>().eq("loc_no", jsonLocNo) |
| | | .eq("matnr", jsonOriginDetl.getMatnr()).eq("batch",jsonOriginDetl.getBatch()).eq("owner",jsonOwner); |
| | | ManLocDetl manLocDetl1 = manLocDetlService.selectOne(manLocDetlWrapper); |
| | | if(!Cools.isEmpty(manLocDetl1)){ |
| | | BigDecimal inAnfme = BigDecimal.valueOf(jsonOriginDetl.getAnfme()); |
| | |
| | | } |
| | | |
| | | }else { |
| | | Date now = new Date(); |
| | | ManLocDetl manLocDetl = new ManLocDetl(); //初始化库存实体类 |
| | | manLocDetl.sync(mat); |
| | | manLocDetl.setLocNo(node.getUuid()); |
| | |
| | | manLocDetl.setCreateTime(now); |
| | | manLocDetl.setUpdateBy(user.getId()); |
| | | manLocDetl.setModiTime(now); |
| | | manLocDetl.setOwner(jsonOwner); |
| | | // manLocDetl.setOrderNo(waitPakin.getOrderNo()); |
| | | manLocDetl.setStockFreeze(1); |
| | | |
| | | try { |
| | | Date produceTime = DateUtils.convert(jsonOriginDetl.getBatch(),DateUtils.yyyyMMdd); |
| | | manLocDetl.setProduceTime(produceTime); |
| | | } catch (Exception e) { |
| | | manLocDetl.setProduceTime(now); |
| | | } |
| | | if (!manLocDetlService.insert(manLocDetl)){ //数据库插入实体类信息 |
| | | return R.error("物料信息入库失败"); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public R manDetlOriginOut(JSONObject json, User user) { |
| | | String jsonLocNo = (String) json.get("locNo"); //获取库位码 |
| | | |
| | | Date now = new Date(); |
| | | JSONArray combMats = json.getJSONArray("combMats"); |
| | | List<MatPrint> matPrintList=new ArrayList<>(); |
| | | List<Long> ids=new ArrayList<>(); |
| | | for (int i = 0; i < combMats.size(); i++) { |
| | | OrderDetl jsonOriginDetl = combMats.getObject(i, OrderDetl.class); |
| | | Wrapper<ManLocDetl> manLocDetlWrapper = new EntityWrapper<ManLocDetl>().eq("loc_no", jsonLocNo).eq("matnr", jsonOriginDetl.getMatnr()).eq("batch", jsonOriginDetl.getBatch()); |
| | | MatPrint matPrintNow = combMats.getObject(i, MatPrint.class); |
| | | if (!ids.contains(matPrintNow.getIndex())){ |
| | | ids.add(matPrintNow.getIndex()); |
| | | matPrintList.add(matPrintNow); |
| | | } |
| | | } |
| | | for (MatPrint jsonOriginDetl:matPrintList) { |
| | | Double parseLong = jsonOriginDetl.getAnfme(); |
| | | Long ownerId = Long.parseLong(jsonOriginDetl.getOwner()); |
| | | jsonOriginDetl.setOwnerId(ownerId); |
| | | Wrapper<ManLocDetl> manLocDetlWrapper = new EntityWrapper<ManLocDetl>().eq("loc_no", jsonOriginDetl.getLocNo()) |
| | | .eq("matnr", jsonOriginDetl.getMatnr()).eq("batch", jsonOriginDetl.getBatch()).eq("owner",jsonOriginDetl.getOwnerId()); |
| | | ManLocDetl manLocDetl = manLocDetlService.selectOne(manLocDetlWrapper); |
| | | if (Cools.isEmpty(manLocDetl)){ |
| | | return R.error("未商品明细信息!库位号:"+jsonLocNo+";商品编号:"+jsonOriginDetl.getMatnr()+"批次:"+jsonOriginDetl.getBatch()); |
| | | return R.error("未查询到商品明细信息!库位号:"+jsonOriginDetl.getLocNo()+";商品编号:"+jsonOriginDetl.getMatnr()+"批次:"+jsonOriginDetl.getBatch()+"货主"+jsonOriginDetl.getOwnerId()); |
| | | } |
| | | BigDecimal outAnfme = BigDecimal.valueOf(jsonOriginDetl.getAnfme()); |
| | | BigDecimal outAnfme = BigDecimal.valueOf(parseLong); |
| | | BigDecimal anfme = BigDecimal.valueOf(manLocDetl.getAnfme()); |
| | | |
| | | if (manLocDetl.getAnfme() > jsonOriginDetl.getAnfme()){ |
| | | if (manLocDetl.getAnfme() > parseLong){ |
| | | BigDecimal num = anfme.subtract(outAnfme); |
| | | manLocDetl.setAnfme(num.doubleValue()); |
| | | |
| | | |
| | | manLocDetl.setUpdateBy(user.getId()); |
| | | manLocDetl.setModiTime(now); |
| | | if (!manLocDetlService.update(manLocDetl,manLocDetlWrapper)) { |
| | | return R.error("物料信息下架失败"); |
| | | } |
| | |
| | | return R.error("物料信息删除失败"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | for (MatPrint jsonOriginDetl:matPrintList) { |
| | | //增加打印档案 |
| | | LocOutPrintMat locOutPrintMat = new LocOutPrintMat(now, user.getId(), jsonOriginDetl.getMatnr(), jsonOriginDetl.getBatch(), jsonOriginDetl.getAnfme(), jsonOriginDetl.getLocNo(), jsonOriginDetl.getMaktx()); |
| | | locOutPrintMat.setOwnerId(jsonOriginDetl.getOwnerId()); |
| | | locOutPrintMatService.insert(locOutPrintMat); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public void plaPakin(String locNo, String batch, String packageNo) { |
| | | Pla pla = plaService.selectByBatchAndPackageNo(batch, packageNo); |
| | | if(!pla.getLocNo().equals(locNo)){ |
| | | throw new CoolException("该物料入库的库位错误"); |
| | | } |
| | | if("已入库".equals(pla.getStatus())){ |
| | | throw new CoolException("该物料已入库"); |
| | | } |
| | | pla.setStatus("已入库"); |
| | | pla.setModifyTime(new Date()); |
| | | plaService.updateById(pla); |
| | | SaasUtils.insertLog(0,locNo,batch+","+packageNo,pla.getWeightAnfme(),null); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void plaPakout(String locNo, String batch, String packageNo, String orderNo, String orderDetlId, String wrkNo, Double anfme) { |
| | | Pla pla = plaService.selectByBatchAndPackageNo(batch, packageNo); |
| | | |
| | | ManPakOut manPakOut = manPakOutService.selectById(wrkNo); |
| | | |
| | | PlaQty plaQty = plaQtyService.selectById(orderDetlId); |
| | | |
| | | //更新拣货单信息 |
| | | 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); |
| | | manPakOutService.updateById(manPakOut); |
| | | } |
| | | |
| | | //更新pla明细 |
| | | pla.setWeightAnfme(pla.getWeightAnfme() - anfme); |
| | | pla.setQtyAnfme(pla.getQtyAnfme() - anfme); |
| | | if(pla.getWeightAnfme() <= 0){ |
| | | pla.setStatus("全部出库"); |
| | | }else { |
| | | pla.setStatus("部分出库"); |
| | | } |
| | | plaService.updateById(pla); |
| | | SaasUtils.insertLog(1,locNo,batch+","+packageNo,anfme,null); |
| | | |
| | | } |
| | | } |