| 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.exception.CoolException; | 
| import com.sun.org.apache.xpath.internal.operations.Or; | 
| import com.zy.asrs.entity.*; | 
| import com.zy.asrs.entity.param.CombParam; | 
| import com.zy.asrs.entity.param.MobileAdjustParam; | 
| import com.zy.asrs.entity.param.OffSaleParam; | 
| import com.zy.asrs.entity.param.OpenOrderPakinParam; | 
| 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 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.*; | 
|   | 
| /** | 
|  * 移动端服务核心类 | 
|  * Created by vincent on 2020/6/28 | 
|  */ | 
| @Slf4j | 
| @Service | 
| public class MobileServiceImpl implements MobileService { | 
|   | 
|     @Autowired | 
|     private MatService matService; | 
|     @Autowired | 
|     private WaitPakinService waitPakinService; | 
|     @Autowired | 
|     private OrderService orderService; | 
|     @Autowired | 
|     private OrderDetlService orderDetlService; | 
|     @Autowired | 
|     private BasDevpService basDevpService; | 
|     @Autowired | 
|     private WrkMastService wrkMastService; | 
|     @Autowired | 
|     private WrkDetlService wrkDetlService; | 
|     @Autowired | 
|     private PackService packService; | 
|     @Autowired | 
|     private OpenService openService; | 
|     @Autowired | 
|     private DocTypeService docTypeService; | 
|     @Autowired | 
|     private ManPakOutService manPakOutService; | 
|     @Autowired | 
|     private BasCrnpService basCrnpService; | 
|     @Autowired | 
|     private LocMastService locMastService; | 
|     @Autowired | 
|     private LocDetlService locDetlService; | 
|     @Autowired | 
|     private StaDescService staDescService; | 
|     @Autowired | 
|     private CommonService commonService; | 
|     @Autowired | 
|     private NodeService nodeService; | 
|     @Autowired | 
|     private ManLocDetlService manLocDetlService; | 
|     @Autowired | 
|     private ManLocDetlMapper manLocDetlMapper; | 
|     @Autowired | 
|     private WaitPakinLogService waitPakinLogService; | 
|   | 
|   | 
|   | 
|     @Override | 
|     @Transactional | 
|     public void comb(CombParam param, Long userId) { | 
|         if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { | 
|             throw new CoolException(BaseRes.PARAM); | 
|         } | 
| //        if (Cools.isEmpty(param.getBarcode())){ | 
| //            throw new CoolException("请填写货主信息"); | 
| //        } | 
|         // 判断是否有相同条码的数据 | 
|         if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). | 
|                 eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { | 
|             throw new CoolException(param.getBarcode() + "数据正在进行入库"); | 
|         } | 
|         try{ | 
|             param.setOrderNo(param.getCombMats().get(0).getOrderNo()); | 
|         }catch (Exception e){ | 
|   | 
|         } | 
|   | 
|         int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode())); | 
|         int countLoc2 =  manLocDetlMapper.selectCount(new EntityWrapper<ManLocDetl>().eq("zpallet",param.getBarcode())); | 
|         WrkMast wrkMast = wrkMastService.selectByBarcode(param.getBarcode()); | 
|         if (wrkMast != null && wrkMast.getIoType() < 100){ | 
|             throw new CoolException("工作档/库存条码数据已存在===>>" + param.getBarcode()); | 
|   | 
|         } | 
|         if (countLoc > 0 ) { | 
|             throw new CoolException("工作档/库存条码数据已存在===>>" + param.getBarcode()); | 
|         } | 
|         if (countLoc2 > 0 ) { | 
|             throw new CoolException("工作档/库存条码数据已存在===>>" + param.getBarcode()); | 
|         } | 
|   | 
|   | 
|         //设置非null批号, | 
|         for (CombParam.CombMat combMat : param.getCombMats()) { | 
|             if (combMat.getBatch() == null){ | 
|                 combMat.setBatch(""); | 
|             } | 
|         } | 
|         Date now = new Date(); | 
|         // 无单组托 | 
|         if (Cools.isEmpty(param.getOrderNo())) { | 
|   | 
|             // 生成入库通知档 | 
|             List<DetlDto> detlDtos = new ArrayList<>(); | 
|             param.getCombMats().forEach(elem -> { | 
|                 DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme(),elem.getWeight()); | 
|                 if (DetlDto.has(detlDtos, detlDto)) { | 
|                     DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch()); | 
|                     assert one != null; | 
|                     one.setAnfme(one.getAnfme() + detlDto.getAnfme()); | 
|                     one.setOwner(detlDto.getOwner()); | 
|                 } else { | 
|                     detlDtos.add(detlDto); | 
|                 } | 
|             }); | 
|   | 
|   | 
|             for (DetlDto detlDto : detlDtos) { | 
|                 String uuid = String.valueOf(System.currentTimeMillis()); | 
|                 Mat mat = matService.selectByMatnr(detlDto.getMatnr()); | 
|                 if (Cools.isEmpty(mat)) { | 
|                     throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); | 
|                 } | 
|                 WaitPakin waitPakin = new WaitPakin(); | 
|                 waitPakin.sync(mat); | 
|                 waitPakin.setBatch(detlDto.getBatch()); | 
|                 waitPakin.setZpallet(param.getBarcode());   // 托盘码 | 
|                 waitPakin.setIoStatus("N");     // 入出状态 | 
|                 waitPakin.setAnfme(detlDto.getAnfme());  // 数量 | 
|                 waitPakin.setStatus("Y");    // 状态 | 
|                 waitPakin.setAppeUser(userId); | 
|                 waitPakin.setAppeTime(now); | 
|                 waitPakin.setModiUser(userId); | 
|                 waitPakin.setModiTime(now); | 
|                 waitPakin.setOwner(detlDto.getOwner()); | 
|                 waitPakin.setUuid(uuid); | 
|                 waitPakin.setWeight(detlDto.getWeight()); | 
|                 if (!waitPakinService.insert(waitPakin)) { | 
|                     throw new CoolException("保存入库通知档失败"); | 
|                 } | 
|             } | 
|         // 关联组托 | 
|         } else { | 
|             for (CombParam.CombMat combMat : param.getCombMats()) { | 
|                 OrderDetl orderDetl = orderDetlService.selectItem(combMat.getOrderNo(), combMat.getMatnr(), combMat.getBatch()); | 
|                 if (orderDetl == null) { | 
|                     throw new CoolException("找不到组托的单据明细"); | 
|   | 
|                 } | 
|                 Double anfme = orderDetl.getAnfme(); | 
|                 Double workQty = orderDetl.getWorkQty(); | 
|                 BigDecimal a1 = new BigDecimal(orderDetl.getAnfme()).setScale(2,BigDecimal.ROUND_HALF_UP); | 
|                 BigDecimal b1 = new BigDecimal(orderDetl.getWorkQty()).setScale(2,BigDecimal.ROUND_HALF_UP); | 
|                 BigDecimal c1 = new BigDecimal(combMat.getAnfme()).setScale(2,BigDecimal.ROUND_HALF_UP); | 
|                 double e1 = b1.add(c1).doubleValue(); | 
|                 BigDecimal f1 = new BigDecimal(e1).setScale(2,BigDecimal.ROUND_HALF_UP); | 
|                 Double d1 = a1.subtract(f1).doubleValue(); | 
|                 if ( d1 < 0.0) { | 
|                     throw new CoolException("组托数量已超出订单需求量,请检查是否有其他的组托已完成"); | 
|                 } | 
|             } | 
|   | 
|             // 生成入库通知档 | 
|             List<DetlDto> detlDtos = new ArrayList<>(); | 
|             for (CombParam.CombMat elem : param.getCombMats()) { | 
|                 Order order = orderService.selectByNo(elem.getOrderNo()); | 
|                 if (order.getSettle() > 2) { | 
|                     throw new CoolException("单据编号已过期"); | 
|                 } | 
|                 // 订单明细数量校验 | 
|                 OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch()); | 
|                 if(orderDetl == null){ | 
|                     throw new CoolException("该单据中不存在该物料明细:" + elem); | 
|                 } | 
|                 if (elem.getAnfme() > orderDetl.getEnableQty()) { | 
|                     throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); | 
|                 } | 
|                 // 修改订单作业数量 | 
|                 if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) { | 
|                     throw new CoolException("修改单据作业数量失败"); | 
|                 } | 
|   | 
|                 DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme(),orderDetl.getOwner(),elem.getWeight()); | 
|                 detlDto.setPayment(orderDetl.getPayment()); | 
|                 if (DetlDto.has(detlDtos, detlDto)) { | 
|                     DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch()); | 
|                     assert one != null; | 
|                     one.setAnfme(one.getAnfme() + detlDto.getAnfme()); | 
|                 } else { | 
|                     detlDtos.add(detlDto); | 
|                 } | 
|             } | 
|             int i=0; | 
|             for (DetlDto detlDto : detlDtos) { | 
|                 Order order = orderService.selectByNo(param.getCombMats().get(i).getOrderNo()); | 
|                 i++; | 
|                 String uuid = String.valueOf(System.currentTimeMillis()); | 
|                 Mat mat = matService.selectByMatnr(detlDto.getMatnr()); | 
|                 if (Cools.isEmpty(mat)) { | 
|                     throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); | 
|                 } | 
|                 WaitPakin waitPakin = new WaitPakin(); | 
|                 waitPakin.sync(mat); | 
|                 waitPakin.setOrderNo(order.getOrderNo()); // 单据编号 | 
|                 waitPakin.setBatch(detlDto.getBatch());     // 序列码 | 
|                 waitPakin.setZpallet(param.getBarcode());   // 托盘码 | 
|                 waitPakin.setIoStatus("N");     // 入出状态 | 
|                 waitPakin.setAnfme(detlDto.getAnfme());  // 数量 | 
|                 waitPakin.setStatus("Y");    // 状态 | 
|                 waitPakin.setAppeUser(userId); | 
|                 waitPakin.setAppeTime(now); | 
|                 waitPakin.setModiUser(userId); | 
|                 waitPakin.setModiTime(now); | 
|                 waitPakin.setOwner(detlDto.getOwner()); | 
|                 waitPakin.setPayment(detlDto.getPayment()); | 
|                 waitPakin.setUuid(uuid); | 
|                 waitPakin.setWeight(detlDto.getWeight()); | 
|                 if (!waitPakinService.insert(waitPakin)) { | 
|                     throw new CoolException("保存入库通知档失败"); | 
|                 } | 
|                 orderService.updateSettle(order.getId(), 2L, userId); | 
|             } | 
|   | 
|         } | 
|   | 
|     } | 
|   | 
|     // 商品上架 | 
|     @Override | 
|     public void onSale(CombParam param) { | 
|         Date now = new Date(); | 
|         // 获取库位号 | 
|         String locno = param.getLocno(); | 
|         Node node = nodeService.selectByUuid(locno); | 
|         if (Cools.isEmpty(node)) { | 
|             throw new CoolException(param.getLocno() + ":库位不存在"); | 
|         } | 
|   | 
|         // 获取商品列表 | 
|         for(CombParam.CombMat combMat : param.getCombMats()){ | 
|   | 
|             Mat mat = matService.selectByMatnr(combMat.getMatnr()); | 
|             if (Cools.isEmpty(mat)){ | 
|                 throw new CoolException(combMat.getMatnr() + ":商品档案不存在!"); | 
|             } | 
|             if (Cools.isEmpty(combMat.getAnfme()) || combMat.getAnfme()==0){ | 
|                 throw new CoolException(combMat.getMatnr() + ":商品数量有误!"); | 
|             } | 
|             if (Cools.isEmpty(combMat.getBatch())){ | 
| //                throw new CoolException(combMat.getMatnr() + ":商品批号有误!"); | 
|             } | 
|             ManLocDetl manLocDetl = new ManLocDetl(); | 
|             manLocDetl.setLocNo(locno); | 
|             manLocDetl.setNodeId(node.getId()); | 
|             manLocDetl.setMaktx(mat.getMaktx()); | 
|             manLocDetl.setMatnr(mat.getMatnr()); | 
|             manLocDetl.setBatch(Cools.isEmpty(combMat.getBatch()) ? "" : combMat.getBatch()); | 
|             manLocDetl.setAnfme(combMat.getAnfme()); | 
|             manLocDetl.setModiTime(now); | 
|             manLocDetl.setOwner(1); | 
|             if (!manLocDetlService.insert(manLocDetl)) { | 
|                 throw new CoolException("商品上架失败!"); | 
|             } | 
|         } | 
|     } | 
|   | 
|     // 商品下架 | 
|     @Override | 
|     public void offSale(OffSaleParam offSaleParam) { | 
|         ManLocDetl manLocDetl = manLocDetlMapper.selectLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr()); | 
|         if (Cools.isEmpty(manLocDetl)){ | 
|             throw new CoolException("无此商品!"); | 
|         } | 
|         double anfme = manLocDetl.getAnfme() - offSaleParam.getAnfme(); | 
|         if (anfme < 0) { | 
|             throw new CoolException("商品库存不足!"); | 
|         } else if (anfme == 0){ | 
|             manLocDetlMapper.deleteLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr()); | 
|         } | 
|         manLocDetlMapper.updateAnfme0(anfme,manLocDetl.getNodeId()); | 
|     } | 
|   | 
|     // 查找商品 | 
|   | 
|   | 
|     @Override | 
|     @Transactional | 
|     public void adjust(MobileAdjustParam param, Long userId) { | 
|         BasDevp basDevp = basDevpService.selectById(param.getStaNo()); | 
|         if (null == basDevp || basDevp.getWrkNo() == null) { | 
|             throw new CoolException(param.getStaNo() + "盘点站无效"); | 
|         } | 
|         if (!param.getWrkNo().equals(basDevp.getWrkNo())) { | 
|             throw new CoolException(param.getStaNo() + "盘点站更新,请重新检索"); | 
|         } | 
|         WrkMast wrkMast = wrkMastService.selectById(param.getWrkNo()); | 
|         if (wrkMast.getWrkSts() < 10) { | 
|             throw new CoolException("盘点无效,任务已盘点再入库"); | 
|         } | 
|         Date now = new Date(); | 
|         List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()); | 
|   | 
|         List<WrkDetl> list = param.getWrkDetls(); | 
|   | 
|         // 修改数量 | 
|         Iterator<WrkDetl> iterator = wrkDetls.iterator(); | 
|         while (iterator.hasNext()) { | 
|             WrkDetl wrkDetl = iterator.next(); | 
|             Iterator<WrkDetl> iterator1 = list.iterator(); | 
|             while (iterator1.hasNext()) { | 
|                 WrkDetl wrkDetl1 = iterator1.next(); | 
|                 if (wrkDetl1.getAnfme() == 0) { | 
|                     iterator1.remove(); | 
|                 } | 
|                 if (wrkDetl.getMatnr().equals(wrkDetl1.getMatnr()) && Cools.eq(wrkDetl.getBatch(), wrkDetl1.getBatch())) { | 
|                     if (!wrkDetl.getAnfme().equals(wrkDetl1.getAnfme())) { | 
|                         // todo 盘点记录、保存调整记录 | 
|                         // 修改明细 | 
|                         if (!wrkDetlService.updateAnfme(wrkDetl1.getAnfme(), wrkMast.getWrkNo(), wrkDetl.getMatnr(), wrkDetl.getBatch())) { | 
|                             throw new CoolException(wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," + wrkDetl.getBatch() + "批号修改数量失败"); | 
|                         } | 
|                     } | 
|                     iterator.remove(); | 
|                     iterator1.remove(); | 
|                 } | 
|             } | 
|         } | 
|   | 
|         // 删除明细 | 
|         for (WrkDetl wrkDetl : wrkDetls) { | 
|             // todo 盘点记录、保存调整记录 | 
|             if (!wrkDetlService.updateAnfme(-1.0D, wrkMast.getWrkNo(), wrkDetl.getMatnr(), wrkDetl.getBatch())) { | 
|                 throw new CoolException("删除" + wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," + wrkDetl.getBatch() + "批号任务明细失败"); | 
|             } | 
|         } | 
|   | 
|         // 添加明细 | 
|         for (WrkDetl wrkDetl : list) { | 
|             if (wrkDetl.getAnfme() == 0.0D) { continue; } | 
|             // todo 盘点记录、保存调整记录 | 
|             String orderNo = wrkDetl.getOrderNo(); | 
|             Mat mat = matService.selectByMatnr(wrkDetl.getMatnr()); | 
|             wrkDetl.sync(mat); | 
|             wrkDetl.setOrderNo(orderNo); | 
|             wrkDetl.setModiTime(now); | 
|             wrkDetl.setModiUser(userId); | 
|             wrkDetl.setAppeTime(now); | 
|             wrkDetl.setAppeUser(userId); | 
|             if (!wrkDetlService.insert(wrkDetl)) { | 
|                 throw new CoolException("添加" + wrkMast.getWrkNo() + "盘点任务," + wrkDetl.getMatnr() + "商品," + wrkDetl.getBatch() + "批号任务明细失败"); | 
|             } | 
|         } | 
|   | 
|         // 修改盘点任务主档状态 | 
|         wrkMast.setFullPlt(wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()).size() != 0?"Y":"N"); | 
|         wrkMast.setModiTime(now); | 
|         wrkMast.setModiUser(userId); | 
|         if (!wrkMastService.updateById(wrkMast)) { | 
|             throw new CoolException("修改盘点任务主档失败"); | 
|         } | 
|   | 
|     } | 
|   | 
|     @Override | 
|     @Transactional | 
|     public void pakoutByOrder(JSONObject param, Long userId) { | 
|         Integer staNo = param.containsKey("staNo") ? Integer.parseInt(param.get("staNo").toString()) : 0; | 
|         String orderNo = param.containsKey("orderNo") ? param.get("orderNo").toString() : ""; | 
|   | 
|         BasDevp sta = basDevpService.checkSiteStatus(staNo); | 
|         //根据订单号生成出库任务工作档 | 
|         Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderNo)); | 
|         if (order.getSettle() != 1 && order.getSettle() != 2){ | 
|             throw new CoolException("该订单已处理"); | 
|         } | 
|   | 
|         List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo)); | 
|         Date now = new Date(); | 
|         for(OrderDetl orderDetl : orderDetls){ | 
|             //查询所有库位状态为F的库位信息 | 
|             List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(),orderDetl.getBatch(),orderDetl.getOwner()); | 
|             if (locDetls.size() == 0) { | 
|                 throw new CoolException("库存中没有该物料"); | 
|             } | 
|             for(LocDetl locDetl : locDetls){ | 
|                 //如果该库位出库路线所用的堆垛机out_enable不为Y,跳过该循环 | 
|                 LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() | 
|                         .eq("loc_no", locDetl.getLocNo())); | 
|                 if (Cools.isEmpty(locMast)) { | 
|                     continue; | 
|                 } | 
|                 BasCrnp crn_no = basCrnpService.selectOne(new EntityWrapper<BasCrnp>() | 
|                         .eq("crn_no", locMast.getCrnNo())); | 
|                 if (Cools.isEmpty(crn_no) || !crn_no.getOutEnable().equals("Y")){ | 
|                     continue; | 
|                 } | 
|   | 
|                 //可出库数量 = 订单数量 - 作业中数量 | 
|                 Double outQty = orderDetl.getAnfme() - orderDetl.getWorkQty(); | 
|                 if(outQty <= 0){ | 
|                     break; | 
|                 } | 
|                 // 判断入出库类型:101.全板出库 or 103.拣料出库 | 
|                 Double sumCount = locDetlService.getLocDetlSumQty(locDetl.getLocNo()); | 
|                 Double curOutQty = outQty >= locDetl.getAnfme() ? locDetl.getAnfme() : outQty;   //本次出库量 | 
|                 int ioType = sumCount <= curOutQty ? 101 : 103; | 
|   | 
|                 stockOut(orderDetl, sta, locDetl, curOutQty, ioType, userId, now); | 
|                 order.setSettle(2L); | 
|                 order.setUpdateBy(userId); | 
|                 order.setUpdateTime(now); | 
|                 if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){ | 
|                     throw new CoolException("更新订单状态失败"); | 
|                 } | 
|                 orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty); | 
|                 orderDetl.setUpdateBy(userId); | 
|                 orderDetl.setUpdateTime(now); | 
|                 Wrapper wrapper = new EntityWrapper<OrderDetl>().eq("order_no", orderNo) | 
|                         .eq("matnr",orderDetl.getMatnr()); | 
|                 if(!Cools.isEmpty(orderDetl.getBatch())){ | 
|                     wrapper.eq("batch", orderDetl.getBatch()); | 
|                 } | 
|                 if(!orderDetlService.update(orderDetl, wrapper)){ | 
|                     throw new CoolException("更新订单明细失败"); | 
|                 } | 
|             } | 
|   | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     @Transactional | 
|     public void stockOut(OrderDetl orderDetl, BasDevp staNo, LocDetl locDetl, | 
|                          Double curOutQty, Integer ioType, Long userId, Date now) { | 
|         // 获取库位 | 
|         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(2); | 
|         // 生成工作档 | 
|         WrkMast wrkMast = new WrkMast(); | 
|         wrkMast.setWrkNo(workNo); | 
|         wrkMast.setIoTime(now); | 
|         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(now); | 
|         wrkMast.setModiUser(userId); | 
|         wrkMast.setModiTime(now); | 
|         wrkMast.setBarcode(locMast.getBarcode()); | 
|         if (!wrkMastService.insert(wrkMast)) { | 
|             throw new CoolException("保存工作档失败,出库库位号:" + locDetl.getLocNo()); | 
|         } | 
|   | 
|         WrkDetl wrkDetl = new WrkDetl(); | 
|         wrkDetl.sync(locDetl); | 
|         wrkDetl.setWrkNo(workNo); | 
|         wrkDetl.setIoTime(now); | 
|         wrkDetl.setAnfme(curOutQty); // 数量 | 
|         wrkDetl.setOrderNo(orderDetl.getOrderNo()); | 
|         wrkDetl.setAppeTime(now); | 
|         wrkDetl.setAppeUser(userId); | 
|         wrkDetl.setModiTime(now); | 
|         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() + "库位不是在库状态"); | 
|         } | 
|     } | 
|   | 
|     @Transactional | 
|     @Override | 
|     public R manDetlIn(JSONObject json, User user) { | 
|         Date date = new Date(); | 
|         String jsonLocNo = (String) json.get("locNo"); | 
|         Node node = nodeService.selectOne(new EntityWrapper<Node>() | 
|                 .eq("name", jsonLocNo)); | 
|         JSONArray combMats = json.getJSONArray("combMats"); | 
|         for (int i = 0; i < combMats.size(); i++) { | 
|             OrderDetl jsonOrderDetl = combMats.getObject(i, OrderDetl.class); | 
|   | 
|             //查订单 | 
|             Order order = orderService.selectOne(new EntityWrapper<Order>() | 
|                     .eq("order_no", jsonOrderDetl.getOrderNo())); | 
|             if (Cools.isEmpty(node, order)) { | 
|                 return R.error("参数为空"); | 
|             } | 
|   | 
|             //判断订单类型是否是入库 | 
|             DocType docType=docTypeService.selectById(order.getDocType()); | 
|             if(docType.getPakin()!=1 || docType.getStatus()!=1){ | 
|                 return R.error("该订单是出库订单,无法入库"); | 
|             } | 
|   | 
|             OrderDetl orderDetl = orderDetlService.selectItem(jsonOrderDetl.getOrderNo(),jsonOrderDetl.getMatnr(),jsonOrderDetl.getBatch()); | 
|             if (Cools.isEmpty(orderDetl)) { | 
|                 return R.error("单据明细有误,请检查"); | 
|             } | 
|             if (orderDetl.getAnfme() - (jsonOrderDetl.getAnfme() + orderDetl.getWorkQty()) < 0) { | 
|                 return R.error("入库数量大于可入数量"); | 
|             } | 
|   | 
|   | 
|             //查询平库中是否有一样的物料号,有的话直接增加数量 | 
|             ManLocDetl checkManLocDetl = manLocDetlService.selectInventory(jsonLocNo,orderDetl.getMatnr(),jsonOrderDetl.getBatch()); | 
|             if (checkManLocDetl == null) { | 
|                 ManLocDetl manLocDetl = new ManLocDetl(); | 
|                 Synchro.Copy(orderDetl, manLocDetl); | 
|   | 
|                 BigDecimal decimal = BigDecimal.valueOf(jsonOrderDetl.getAnfme()).subtract(BigDecimal.valueOf(jsonOrderDetl.getAnfme()).setScale(0,BigDecimal.ROUND_DOWN)); | 
|                 if (decimal.doubleValue() > 0){ | 
|                     manLocDetl.setPrice(1.0); | 
|                 }else { | 
|                     manLocDetl.setPrice(2.0); | 
|                 } | 
|   | 
|   | 
|   | 
|                 manLocDetl.setLocNo(node.getName()); | 
|                 manLocDetl.setNodeId(node.getId()); | 
|                 manLocDetl.setMatnr(orderDetl.getMatnr()); | 
|                 manLocDetl.setMaktx(jsonOrderDetl.getMaktx()); | 
|                 manLocDetl.setAnfme(jsonOrderDetl.getAnfme()); | 
|                 manLocDetl.setModiTime(date); | 
|                 manLocDetl.setCreateTime(date); | 
|                 manLocDetl.setBatch(jsonOrderDetl.getBatch()); | 
|                 manLocDetl.setOwner(orderDetl.getOwner()); | 
|                 manLocDetl.setWeight(jsonOrderDetl.getWeight()); | 
|                 manLocDetl.setOrderNo(jsonOrderDetl.getOrderNo()); | 
|                 if(!manLocDetlService.insert(manLocDetl)){ | 
|                     return R.error("插入平库物料失败!"); | 
|                 } | 
|             } else { | 
|                   if (checkManLocDetl.getWeight() == null){ | 
|                       checkManLocDetl.setWeight(0.0); | 
|                   } | 
|                   if (jsonOrderDetl.getWeight() == null){ | 
|                       jsonOrderDetl.setWeight(0.0); | 
|                   } | 
|                 if(manLocDetlService.increase(checkManLocDetl.getAnfme() + jsonOrderDetl.getAnfme(), | 
|                         node.getName(), | 
|                         jsonOrderDetl.getMatnr(), | 
|                         jsonOrderDetl.getBatch(),checkManLocDetl.getWeight()+jsonOrderDetl.getWeight() | 
|                         )<=0 | 
|                         ){ | 
|                     return R.error("修改平库物料失败!"); | 
|                 } | 
|   | 
|             } | 
|             orderDetl.setQty(orderDetl.getQty() + jsonOrderDetl.getAnfme()); | 
|             orderDetl.setWorkQty(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme()); | 
|             orderDetl.setUpdateTime(date); | 
|             orderDetlService.updateById(orderDetl); | 
|             //更新订单状态 | 
|             List<OrderDetl> orderDetls=orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no",order.getOrderNo())); | 
|             order.setSettle(2L); | 
|             boolean log=true; | 
|             for (OrderDetl orderDetl1: orderDetls) { | 
|                 //工作中的数量小于总订单数时,订单状态改为2,作业中 | 
|                 if(orderDetl1.getQty() < orderDetl.getAnfme()){ | 
|                     log=false; | 
|                 } | 
|             } | 
|             if(log){ | 
|                 order.setSettle(4L); | 
|             } | 
|             if(!orderService.updateById(order)){ | 
|                 return R.error("更新订单状态失败"); | 
|             } | 
|             orderService.checkComplete(order.getOrderNo()); | 
|   | 
|             SaasUtils.insertLog(0,jsonLocNo,jsonOrderDetl.getMatnr(), jsonOrderDetl.getAnfme(),user.getUsername()); | 
|         } | 
|   | 
|   | 
|         return R.ok("上架完成"); | 
|     } | 
|   | 
|     @Transactional | 
|     @Override | 
|     public R manDetlOut(JSONObject json,User user) { | 
|         Date date = new Date(); | 
|         String jsonLocNo = (String) json.get("locNo"); | 
|         Node node = nodeService.selectOne(new EntityWrapper<Node>() | 
|                 .eq("name", jsonLocNo)); | 
|         JSONArray combMats = json.getJSONArray("combMats"); | 
|         for (int i = 0; i < combMats.size(); i++) { | 
|             OrderDetl jsonOrderDetl = combMats.getObject(i, OrderDetl.class); | 
|             Order order = orderService.selectOne(new EntityWrapper<Order>() | 
|                     .eq("order_no", jsonOrderDetl.getOrderNo())); | 
|   | 
|             //判断订单类型是否是出库 | 
|             DocType docType=docTypeService.selectById(order.getDocType()); | 
|             if(docType.getPakout()!=1 || docType.getStatus()!=1){ | 
|                 return R.error("该订单是入库订单,无法出库"); | 
|             } | 
|             if (Cools.isEmpty(node, order)) { | 
|                 return R.error("参数为空"); | 
|             } | 
|             OrderDetl orderDetl = orderDetlService.selectItem(jsonOrderDetl.getOrderNo(),jsonOrderDetl.getMatnr(),""); | 
|             if (Cools.isEmpty(orderDetl)) { | 
|                 return R.error("单据明细有误,请检查"); | 
|             } | 
|             EntityWrapper<ManPakOut> manPakOutEntityWrapper = new EntityWrapper<>(); | 
|             manPakOutEntityWrapper.eq("loc_no",jsonLocNo); | 
|             manPakOutEntityWrapper.eq("matnr",jsonOrderDetl.getMatnr()); | 
|             manPakOutEntityWrapper.eq("doc_num",order.getOrderNo()); | 
|             ManPakOut manPakOut = manPakOutService.selectOne(manPakOutEntityWrapper); //获取拣货单中的对应的订单 | 
|             if(Cools.isEmpty(manPakOut)){ | 
|                 return R.error("没有找到对应的出库单"+jsonLocNo+"-------"+jsonOrderDetl.getMatnr()); | 
|             } | 
|             if(manPakOut.getCount() == null){ | 
|                 manPakOut.setCount(0.0); | 
|             } | 
| //            if (jsonOrderDetl.getAnfme() > manPakOut.getAnfme()) { //判断工作数量是否大于拣货单的数量 | 
| //                return R.error("出库数量大于拣货单总数量"); | 
| //            } | 
|             BigDecimal a1 = new BigDecimal(manPakOut.getAnfme()).setScale(2,BigDecimal.ROUND_HALF_UP); | 
|             BigDecimal b1 = new BigDecimal(manPakOut.getCount()).setScale(2,BigDecimal.ROUND_HALF_UP); | 
|             Double c1 = a1.subtract(b1).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue(); | 
|             if (jsonOrderDetl.getAnfme() > c1) { //判断工作数量是否大于拣货单剩余可出的数量 | 
|                 return R.error("出库数量大于拣货单剩余可出数量"); | 
|             } | 
|   | 
|             BigDecimal e1 = new BigDecimal(orderDetl.getWorkQty()).setScale(2,BigDecimal.ROUND_HALF_UP); | 
|             BigDecimal f1 = new BigDecimal(orderDetl.getQty()).setScale(2,BigDecimal.ROUND_HALF_UP); | 
|             Double g1 = e1.subtract(f1).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue(); | 
|             if ( g1  <jsonOrderDetl.getAnfme() ){ | 
|                 return R.error("出库数量大于单据剩余可出数量"); | 
|             } | 
|             //查询平库中是否有一样的物料号 | 
|             ManLocDetl checkManLocDetl = manLocDetlService.selectInventory(jsonLocNo,orderDetl.getMatnr(),orderDetl.getBatch()); | 
|             if (checkManLocDetl == null) { | 
|                 return R.error("该库位没有出库的物料信息"); | 
|             } | 
|             if (jsonOrderDetl.getAnfme() > checkManLocDetl.getAnfme()) { | 
|                 return R.error("出库数量大于可出数量"); | 
|             } | 
|             if(checkManLocDetl.getWeight() == null){ | 
|                 checkManLocDetl.setWeight(0.0); | 
|             } | 
|             if(jsonOrderDetl.getWeight() == null){ | 
|                 jsonOrderDetl.setWeight(0.0); | 
|             } | 
|             Double finalQty =  new BigDecimal(checkManLocDetl.getAnfme()).setScale(2,BigDecimal.ROUND_HALF_UP).subtract(new BigDecimal(jsonOrderDetl.getAnfme()).setScale(2,BigDecimal.ROUND_HALF_UP)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue() ; | 
|             Double weight =  new BigDecimal(checkManLocDetl.getWeight()).setScale(2,BigDecimal.ROUND_HALF_UP).subtract(new BigDecimal(jsonOrderDetl.getWeight()).setScale(2,BigDecimal.ROUND_HALF_UP)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue() ; | 
|             checkManLocDetl.setAnfme(finalQty); | 
|             checkManLocDetl.setWeight(weight); | 
|             if (weight < 0){ | 
|                 return R.error("出库重量有误!"); | 
|             } | 
|             if (finalQty < 0){ | 
|                 //  if(manLocDetlService.deleteDatailed(jsonLocNo, jsonOrderDetl.getMatnr(), jsonOrderDetl.getBatch())<=0) { | 
|                 return R.error("数量有误!"); | 
|                 //   } | 
|             }else { | 
|                 if(manLocDetlService.increase(finalQty, jsonLocNo, jsonOrderDetl.getMatnr(), jsonOrderDetl.getBatch(),weight)<=0){ | 
|                     return R.error("修改平库物料失败!"); | 
|                 } | 
|             } | 
|             orderDetl.setQty( new BigDecimal(orderDetl.getQty()).setScale(2,BigDecimal.ROUND_HALF_UP).add(new BigDecimal(jsonOrderDetl.getAnfme()).setScale(2,BigDecimal.ROUND_HALF_UP)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue() ); | 
|             orderDetl.setUpdateTime(date); | 
|             orderDetlService.updateById(orderDetl); | 
|             //更新订单状态 | 
|             List<OrderDetl> orderDetls=orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no",order.getOrderNo())); | 
|             order.setSettle(2L); | 
|             boolean log=true; | 
|             for (OrderDetl orderDetl1: orderDetls) { | 
|                 //工作中的数量小于总订单数时,订单状态改为2,作业中 | 
|                 if(orderDetl1.getQty() < orderDetl1.getAnfme()){ | 
|                     log=false; | 
|                 } | 
|             } | 
|             if(log){ | 
|                 order.setSettle(4L); | 
|             } | 
|             if(!orderService.updateById(order)){ | 
|                 return R.error("更新订单状态失败"); | 
|             } | 
|             if(manPakOut.getCount() == null){ | 
|                 manPakOut.setCount(0.0); | 
|             } | 
|   | 
|             manPakOut.setCount(new BigDecimal(manPakOut.getCount()).setScale(2,BigDecimal.ROUND_HALF_UP).add(new BigDecimal(jsonOrderDetl.getAnfme()).setScale(2,BigDecimal.ROUND_HALF_UP)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue()); | 
|             if (!manPakOutService.update(manPakOut,manPakOutEntityWrapper)){ | 
|                 return R.error("更新拣货单完成数目失败"); | 
|             } | 
|             if (manPakOut.getAnfme().equals(manPakOut.getCount())){ | 
|                 manPakOut.setStatus(1); | 
|                 if (!manPakOutService.update(manPakOut,manPakOutEntityWrapper)){ | 
|                     return R.error("更新拣货单状态失败"); | 
|                 } | 
|             } | 
|             EntityWrapper<ManLocDetl> manLocDetlEntityWrapper = new EntityWrapper<>(); | 
|             manLocDetlEntityWrapper.eq("loc_no",manPakOut.getLocNo()); | 
|             manLocDetlEntityWrapper.eq("matnr",manPakOut.getMatnr()); | 
|             if (checkManLocDetl.getAnfme() == 0 ){ | 
|                 if(!manLocDetlService.delete(manLocDetlEntityWrapper)){ | 
|                     return R.error("删除平库库存失败"); | 
|                 } | 
|             }else{ | 
|                 checkManLocDetl.setStatus(1); | 
|                 if(!manLocDetlService.update(checkManLocDetl,manLocDetlEntityWrapper)){ | 
|                     return R.error("更新平库库存状态失败"); | 
|                 } | 
|             } | 
|             SaasUtils.insertLog(1,jsonLocNo,jsonOrderDetl.getMatnr(), jsonOrderDetl.getAnfme(),user.getUsername()); | 
|   | 
|         } | 
|         return R.ok("下架完成"); | 
|     } | 
|   | 
|     @Override | 
|     public R manDetlInBarcode(JSONObject json, User user) { | 
|         String jsonLocNo = (String) json.get("locNo"); //获取库位码 | 
|         String jsonBarNo = (String) json.get("barcode"); //获取托盘码 | 
|   | 
|         List<WaitPakin> waitPakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", jsonBarNo)); //获取对应组托信息 | 
|         if (Cools.isEmpty(waitPakins)){ | 
|             return R.error("未查询到组托"); | 
|         } else if (waitPakins.get(0).getIoStatus().equals("Y")) { | 
|             return R.error("组托已经生成工作档"); | 
|         } | 
|   | 
|         for (WaitPakin waitPakin: waitPakins) { | 
|             List<ManLocDetl> manLocDetls = manLocDetlService.selectList(new EntityWrapper<ManLocDetl>().eq("zpallet", waitPakin.getZpallet())); | 
|             if (!Cools.isEmpty(manLocDetls) || manLocDetls.size()>0){ | 
|                 return R.error("所在库位已存在明细"); | 
|             } | 
|         } | 
|         //判断订单是否完成 | 
|         boolean log =true; | 
|   | 
|         for (WaitPakin waitPakin: waitPakins) { | 
|             Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", waitPakin.getOrderNo()));  //获取对应订单信息 | 
|             if (order.equals(null)){ | 
|                 return R.error("未查询到订单信息"); | 
|             } | 
|             OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("order_no", waitPakin. | 
|                     getOrderNo()).eq("matnr", waitPakin.getMatnr()));  //获取对应订单明细信息 | 
|             if (orderDetl.equals(null)){ | 
|                 return R.error("未查询到订单明细信息"); | 
|             } | 
|             Node node = nodeService.selectOne(new EntityWrapper<Node>().eq("name", jsonLocNo));  //获取对应库位信息 | 
|             if (node.equals(null)){ | 
|                 return R.error("未查询到库位信息"); | 
|             } | 
|             ManLocDetl manLocDetl = new ManLocDetl();  //初始化库存实体类 | 
|             //获取组托小数位 | 
|             BigDecimal decimal = BigDecimal.valueOf(waitPakin.getAnfme()).subtract(BigDecimal.valueOf(waitPakin.getAnfme()).setScale(0,BigDecimal.ROUND_DOWN)); | 
|             if (decimal.doubleValue() > 0){ | 
|                 manLocDetl.setPrice(1.0); | 
|             }else { | 
|                 manLocDetl.setPrice(2.0); | 
|             } | 
|   | 
|   | 
|   | 
|             Date date = new Date(); | 
|   | 
|             manLocDetl.setLocNo(node.getName()); | 
|             manLocDetl.setNodeId(node.getId()); | 
|             manLocDetl.setZpallet(waitPakin.getZpallet()); | 
|             manLocDetl.setAnfme(waitPakin.getAnfme()); | 
|             manLocDetl.setMatnr(waitPakin.getMatnr()); | 
|             manLocDetl.setMaktx(waitPakin.getMaktx()); | 
|             manLocDetl.setStatus(1); | 
|             manLocDetl.setCreateBy(user.getId()); | 
|             manLocDetl.setCreateTime(date); | 
|             manLocDetl.setUpdateBy(user.getId()); | 
|             manLocDetl.setModiTime(date); | 
|             manLocDetl.setOrderNo(waitPakin.getOrderNo()); | 
|             manLocDetl.setOwner(waitPakin.getOwner()); | 
|             manLocDetl.setPayment(waitPakin.getPayment()); | 
|   | 
|             if (!manLocDetlService.insert(manLocDetl)){  //数据库插入实体类信息 | 
|                 return R.error("物料信息入库失败"); | 
|             } | 
|             orderDetl.setQty(orderDetl.getQty()+ waitPakin.getAnfme());  //更新订单明细数量 | 
|             if (!orderDetlService.updateById(orderDetl)){ | 
|                 return R.error("更新订单明细失败"); | 
|             } | 
|   | 
|             WaitPakinLog waitPakinLog = new WaitPakinLog(); //初始化入库通知单日志实体类 | 
|             waitPakinLog.setZpallet(waitPakin.getZpallet()); | 
|             waitPakinLog.setAnfme(waitPakin.getAnfme()); | 
|             waitPakinLog.setMatnr(waitPakin.getMatnr()); | 
|             waitPakinLog.setLocNo(jsonLocNo); | 
|             waitPakinLog.setMaktx(waitPakin.getMaktx()); | 
|             waitPakinLog.setOrderNo(waitPakin.getOrderNo()); | 
|             waitPakinLog.setWeight(waitPakin.getWeight()); | 
|             waitPakinLog.setStatus("Y"); | 
|             waitPakinLog.setIoStatus("Y"); | 
|             waitPakinLog.setModiUser(user.getId()); | 
|             waitPakinLog.setModiTime(date); | 
|             waitPakinLog.setAppeUser(user.getId()); | 
|             waitPakinLog.setAppeTime(date); | 
|             waitPakinLog.setOwner(waitPakin.getOwner()); | 
|             waitPakinLog.setPayment(waitPakin.getPayment()); | 
|             waitPakinLog.setUuid(waitPakin.getUuid()); | 
|   | 
|             if (!waitPakinLogService.insert(waitPakinLog)){  //插入入库通知历史档数据库 | 
|                 return R.error("插入历史入库通知档失败"); | 
|             } | 
|             //订单是否完成 | 
|             List<OrderDetl> or = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", waitPakin.getOrderNo())); | 
|             for (OrderDetl o: or) { | 
|                 if(o.getAnfme()-o.getQty()>0){ | 
|                     log=false; | 
|                     break; | 
|                 } | 
|             } | 
|             if(log){ | 
|                 order.setSettle(4L); | 
|                 if(!orderService.update(order,new EntityWrapper<Order>().eq("order_no", waitPakin.getOrderNo()))){ | 
|                     return R.error("订单转完成状态失败!!!"); | 
|                 } | 
|             } | 
|         } | 
|   | 
|         if (!waitPakinService.delete(new EntityWrapper<WaitPakin>().eq("zpallet",jsonBarNo))){  //删除原入库通知档 | 
|             return R.error("删除入库通知档失败"); | 
|         } | 
|         return R.ok("上架成功"); | 
|     } | 
|   | 
|     @Override | 
|     @Transactional | 
|     public R barcodeDelete(JSONObject json, User user) { | 
|         String jsonBarcode = (String) json.get("barcode"); | 
|         String jsonOrderNo = (String) json.get("orderNo"); | 
|         JSONArray combMats = json.getJSONArray("combMats"); | 
|         for (int i = 0; i < combMats.size(); i++) { | 
|             ManLocDetl jsonManLocDetl = combMats.getObject(i, ManLocDetl.class); | 
|             Wrapper<OrderDetl> orderDetlWrapper = new EntityWrapper<OrderDetl>() | 
|                     .eq("order_no", jsonOrderNo) | 
|                     .eq("matnr", jsonManLocDetl.getMatnr()); | 
|             OrderDetl orderDetl = orderDetlService.selectOne(orderDetlWrapper); | 
|             if (Cools.isEmpty(orderDetl)){ | 
|                 return R.error("订单中未查询到下架数据"); | 
|   | 
|             } | 
|             EntityWrapper<ManLocDetl> manLocDetlWrapper = new EntityWrapper<>(); | 
|             manLocDetlWrapper.eq("zpallet",jsonBarcode); | 
|             manLocDetlWrapper.eq("matnr",jsonManLocDetl.getMatnr()); | 
|             ManLocDetl manLocDetl = manLocDetlService.selectOne(manLocDetlWrapper); | 
|             if (Cools.isEmpty(manLocDetl)){ | 
|                 return R.error("托盘码未查询到库存信息"); | 
|   | 
|             } | 
|             BigDecimal orderQty = new BigDecimal(orderDetl.getQty()); | 
|             BigDecimal orderWorkQty = new BigDecimal(orderDetl.getWorkQty()); | 
|             BigDecimal anfme = new BigDecimal(jsonManLocDetl.getAnfme()); | 
|             BigDecimal diffQty = orderQty.add(anfme); | 
|             BigDecimal diffWorkQty = orderWorkQty.add(anfme); | 
|             if (diffQty.doubleValue() > orderDetl.getAnfme()){ | 
|                 return R.error("完成数量大于订单数量"); | 
|             } | 
|             if (diffWorkQty.doubleValue() > orderDetl.getAnfme()){ | 
|                 return R.error("工作数量大于订单数量"); | 
|             } | 
|             BigDecimal locDetlAnfme = new BigDecimal(manLocDetl.getAnfme()); | 
|   | 
|             BigDecimal diffAnfme = locDetlAnfme.subtract(anfme); | 
|             if (diffAnfme.doubleValue() <0){ | 
|                 return R.error("出库数量大于库存数量"); | 
|             } | 
|             if (diffAnfme.doubleValue() == 0){ | 
|                 if (!manLocDetlService.delete(manLocDetlWrapper)){ | 
|                     throw new RuntimeException("删除库存明细失败"); | 
|                 } | 
|             } else if (diffAnfme.doubleValue() > 0) { | 
|                 manLocDetl.setAnfme(diffAnfme.doubleValue()); | 
|                 if (!manLocDetlService.update(manLocDetl,manLocDetlWrapper)){ | 
|                     throw new RuntimeException("更新库存明细失败"); | 
|                 } | 
|             } | 
|             orderDetl.setQty(diffQty.doubleValue()); | 
|             orderDetl.setWorkQty(diffWorkQty.doubleValue()); | 
|             if (!orderDetlService.updateById(orderDetl)){ | 
|                 return R.error("订单明细更新失败"); | 
|             } | 
|             Order order = orderService.selectByNo(jsonOrderNo); | 
|             if (IsOrderStatus(jsonOrderNo)){ | 
|                 order.setSettle(4L); | 
|             }else { | 
|                 order.setSettle(2L); | 
|             } | 
|             if(!orderService.update(order,new EntityWrapper<Order>().eq("order_no", jsonOrderNo))){ | 
|                 throw new RuntimeException("更新订单状态失败"); | 
|             } | 
|         } | 
|         return R.ok(); | 
|     } | 
|   | 
|     public Boolean IsOrderStatus(String order){ | 
|         //判断订单是否完成 | 
|         boolean log =true; | 
|         //订单是否完成 | 
|         List<OrderDetl> or = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", order)); | 
|         for (OrderDetl o: or) { | 
|             if(o.getAnfme()-o.getQty()>0){ | 
|                 log=false; | 
|                 break; | 
|             } | 
|         } | 
|         return log; | 
|     } | 
| } |