| | |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.core.exception.CoolException; |
| | | 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.*; |
| | | import com.zy.asrs.mapper.ManLocDetlMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.MatCompareUtils; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.model.LocDto; |
| | | import com.zy.common.service.CommonService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 移动端服务核心类 |
| | |
| | | private ManLocDetlService manLocDetlService; |
| | | @Autowired |
| | | private ManLocDetlMapper manLocDetlMapper; |
| | | @Autowired |
| | | private AdjDetlService adjDetlService; |
| | | |
| | | |
| | | @Override |
| | |
| | | throw new CoolException(locDetl.getLocNo() + "库位不是在库状态"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 拣料途中并板直接加到库存中 |
| | | * @param param |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public R WarehouseOutPickMergeV1(WarehouseOutPickMergeParam param, Long userId) { |
| | | //判断库位状态 |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", param.getLocNo())); |
| | | if (Cools.isEmpty(locMast)){ |
| | | return R.error("该库位不存在"); |
| | | } |
| | | if (!locMast.getLocSts().equals("P")){ |
| | | return R.error("该库位状态为:"+locMast.getLocSts()+",不满足拣料途中并板条件!!!"); |
| | | } |
| | | |
| | | HashMap<String, OrderDetl> mapData = new HashMap<>(); |
| | | for (OrderDetl orderDetl : param.getCombMats()) { |
| | | String key = orderDetl.getMatnr(); |
| | | // private static final String[] sameFields = {"matnr", "batch", "outOrderNo", "luHao", "packing", "sPgNO", "proType","color"}; |
| | | if (!Cools.isEmpty(orderDetl.getBatch())) { |
| | | key += "_" + orderDetl.getBatch(); |
| | | } |
| | | if (!Cools.isEmpty(orderDetl.getOutOrderNo())) { |
| | | key += "_" + orderDetl.getOutOrderNo(); |
| | | } |
| | | if (!Cools.isEmpty(orderDetl.getLuHao())) { |
| | | key += "_" + orderDetl.getLuHao(); |
| | | } |
| | | if (!Cools.isEmpty(orderDetl.getPacking())) { |
| | | key += "_" + orderDetl.getPacking(); |
| | | } |
| | | if (!Cools.isEmpty(orderDetl.getSPgNO())) { |
| | | key += "_" + orderDetl.getSPgNO(); |
| | | } |
| | | if (!Cools.isEmpty(orderDetl.getProType())) { |
| | | key += "_" + orderDetl.getProType(); |
| | | } |
| | | if (!Cools.isEmpty(orderDetl.getColor())) { |
| | | key += "_" + orderDetl.getColor(); |
| | | } |
| | | |
| | | OrderDetl value = mapData.get(key); |
| | | if(value == null){ |
| | | mapData.put(key, orderDetl); |
| | | }else { |
| | | value.setAnfme(value.getAnfme() + orderDetl.getAnfme()); |
| | | mapData.put(key, value); |
| | | } |
| | | } |
| | | |
| | | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo())); |
| | | |
| | | HashMap<String, PickMergeDto> locData = new HashMap<>(); |
| | | for (LocDetl locDetl : locDetls) { |
| | | String matKey = locDetl.getMatnr(); |
| | | if (!Cools.isEmpty(locDetl.getBatch())) { |
| | | matKey += "_" + locDetl.getBatch(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getOutOrderNo())) { |
| | | matKey += "_" + locDetl.getOutOrderNo(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getLuHao())) { |
| | | matKey += "_" + locDetl.getLuHao(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getPacking())) { |
| | | matKey += "_" + locDetl.getPacking(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getSPgNO())) { |
| | | matKey += "_" + locDetl.getSPgNO(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getProType())) { |
| | | matKey += "_" + locDetl.getProType(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getColor())) { |
| | | matKey += "_" + locDetl.getColor(); |
| | | } |
| | | |
| | | PickMergeDto dto = new PickMergeDto(); |
| | | dto.setOriginAnfme(locDetl.getAnfme()); |
| | | dto.setLocDetl(locDetl); |
| | | dto.setOrders(new ArrayList<>()); |
| | | locData.put(matKey, dto); |
| | | } |
| | | |
| | | for (Map.Entry<String, OrderDetl> entry : mapData.entrySet()) { |
| | | OrderDetl orderDetl = entry.getValue(); |
| | | LocDetl locDetl = new LocDetl(); |
| | | locDetl.sync(orderDetl); |
| | | locDetl.setLocNo(param.getLocNo()); |
| | | locDetl.setBarcode(locMast.getBarcode()); |
| | | Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("matnr",locDetl.getMatnr())); |
| | | locDetl.setMaktx(mat.getMaktx()); |
| | | |
| | | String matKey = locDetl.getMatnr(); |
| | | if (!Cools.isEmpty(locDetl.getBatch())) { |
| | | matKey += "_" + locDetl.getBatch(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getOutOrderNo())) { |
| | | matKey += "_" + locDetl.getOutOrderNo(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getLuHao())) { |
| | | matKey += "_" + locDetl.getLuHao(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getPacking())) { |
| | | matKey += "_" + locDetl.getPacking(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getSPgNO())) { |
| | | matKey += "_" + locDetl.getSPgNO(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getProType())) { |
| | | matKey += "_" + locDetl.getProType(); |
| | | } |
| | | if (!Cools.isEmpty(locDetl.getColor())) { |
| | | matKey += "_" + locDetl.getColor(); |
| | | } |
| | | |
| | | |
| | | PickMergeDto dto = locData.get(matKey); |
| | | if (dto == null) { |
| | | ArrayList<PickMergeOrderDto> orders = new ArrayList<>(); |
| | | orders.add(new PickMergeOrderDto(locDetl.getOrderNo(), locDetl.getAnfme())); |
| | | |
| | | dto = new PickMergeDto(); |
| | | dto.setOriginAnfme(0.0); |
| | | dto.setLocDetl(locDetl); |
| | | dto.setOrders(orders); |
| | | |
| | | locData.put(matKey, dto); |
| | | }else { |
| | | LocDetl detl = dto.getLocDetl(); |
| | | List<PickMergeOrderDto> orders = dto.getOrders(); |
| | | |
| | | detl.setAnfme(detl.getAnfme() + locDetl.getAnfme()); |
| | | orders.add(new PickMergeOrderDto(locDetl.getOrderNo(), locDetl.getAnfme())); |
| | | |
| | | dto.setLocDetl(detl); |
| | | dto.setOrders(orders); |
| | | |
| | | locData.put(matKey, dto); |
| | | } |
| | | } |
| | | |
| | | |
| | | for (Map.Entry<String, PickMergeDto> entry : locData.entrySet()) { |
| | | PickMergeDto dto = entry.getValue(); |
| | | |
| | | Double originAnfme = dto.getOriginAnfme(); |
| | | LocDetl locDetl = dto.getLocDetl(); |
| | | List<PickMergeOrderDto> orders = dto.getOrders(); |
| | | |
| | | Boolean b=false; |
| | | for (LocDetl detl : locDetls) { |
| | | b= MatCompareUtils.compare(detl, locDetl); |
| | | if (b) break; |
| | | } |
| | | |
| | | if (b){ |
| | | if (!locDetlService.updateAnfmeAdd(locDetl.getAnfme(),locDetl.getLocNo(),locDetl)) { |
| | | throw new CoolException("并板库存更新失败"); |
| | | } |
| | | }else { |
| | | locDetl.setZpallet(locDetl.getBarcode()); |
| | | if (!locDetlService.insert(locDetl)) { |
| | | throw new CoolException("并板库存插入失败"); |
| | | } |
| | | } |
| | | |
| | | if (!orders.isEmpty()){ |
| | | for (PickMergeOrderDto orderDto : orders) { |
| | | Order order = orderService.selectByNo(orderDto.getOrderNo()); |
| | | if (Cools.isEmpty(order)){ |
| | | continue; |
| | | } |
| | | if (order.getSettle() == 1){ |
| | | orderService.updateSettle(order.getId(), 2L, 9527L); |
| | | } |
| | | |
| | | |
| | | LocDto locDto = new LocDto(locDetl.getOrderNo(),locDetl.getMatnr(),locDetl.getBatch(),locDetl.getOutOrderNo(),locDetl.getLuHao(),locDetl.getPacking(),locDetl.getSPgNO(),locDetl.getProType(),locDetl.getColor()); |
| | | OrderDetl orderDetl = orderDetlService.selectItem(locDto); |
| | | if (Cools.isEmpty(orderDetl)){ |
| | | continue; |
| | | } |
| | | if (orderDetl.getAnfme() < (orderDetl.getWorkQty() + orderDto.getAnfme())) { |
| | | throw new CoolException("并板数量出错,订单剩余出库数量小于已出库数量与将并板数量之和!!!"); |
| | | } |
| | | // 修改订单明细作业数量 |
| | | if (!orderDetlService.increaseWorkQtyByOrderNo(orderDto.getOrderNo(), orderDetl, orderDto.getAnfme())) { |
| | | throw new CoolException("修改单据明细工作数量失败"); |
| | | } |
| | | // 修改订单明细完成数量 |
| | | if (!orderDetlService.increaseQtyByOrderNo1(orderDto.getOrderNo(), orderDetl, orderDto.getAnfme())) { |
| | | throw new CoolException("修改单据明细完成数量失败"); |
| | | } |
| | | // 修改订单状态 作业中 ===>> 已完成 |
| | | orderService.checkComplete(orderDto.getOrderNo()); |
| | | |
| | | try { |
| | | //处理库存信息 |
| | | AdjDetl adjDetl = new AdjDetl(); |
| | | adjDetl.setLocNo(locDetl.getLocNo()); |
| | | adjDetl.setMatnr(locDetl.getMatnr()); |
| | | adjDetl.setBatch(locDetl.getBatch()); |
| | | adjDetl.setOriQty(originAnfme); |
| | | adjDetl.setAdjQty(locDetl.getAnfme()); |
| | | adjDetl.setMemo("拣料途中并板"); |
| | | adjDetl.setModiUser(userId); |
| | | adjDetl.setAppeUser(userId); |
| | | adjDetl.setAppeTime(new Date()); |
| | | adjDetl.setModiTime(new Date()); |
| | | adjDetl.setExpand(locDetl);//对扩充进行拼接 |
| | | adjDetl.setOrderNo(order.getOrderNo()); |
| | | |
| | | if (!adjDetlService.save(adjDetl,userId)) { |
| | | throw new CoolException("保存库存调整记录失败"); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | throw new CoolException("更新库存数据出错" + e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |