@Override @Transactional(rollbackFor = Exception.class) public void save(WaveOrderConfirm waveOrderConfirm) { //先从redis中查寻如果确实出现人为因素redis中的数据没有。再从数据库查询数据考虑到并发暂时删除 /* List<WaveOrderResult> waveOrderResults = redisTemplate.opsForList().range("wave" + waveOrderConfirm.getPkGoodsOwner(), 0, -1);*/ //进入波次单的发货单 List<Long> pkSendOrders= waveOrderConfirm.getPkSendOrder(); Map mapForCount=new HashMap(2); mapForCount.put("mlist", pkSendOrders); mapForCount.put("orderStatus", WaveStatusEnum.HAS_BEEN_CREATED.getName()); Integer unCreated= sendOrderMapper.searchCount(mapForCount); if(unCreated>0){ throw new RuntimeException("生成失败,存在不是“已创建”状态的发货单"); } Map<Long, Map<Long, String>> allOrder2Rs = redisTemplate.opsForHash().entries("waveAR" + waveOrderConfirm.getPkGoodsOwner()); if (CollectionUtils.isEmpty(allOrder2Rs)) { String ownerid = waveOrderConfirm.getPkGoodsOwner(); allOrder2Rs = selectArea(Long.valueOf(ownerid)); } //从数据库中查找 Map map = new HashMap(); map.put("mlist", pkSendOrders); List<WaveOrderResult> waveOrderResults = sendOrderMapper.selectAllInfo(map); //要保存的波次对象 WaveOrder waveOrder = new WaveOrder(); //前端选中进行波次保存的订单 List<Long> sendOrders = waveOrderConfirm.getPkSendOrder(); //库区简码名称集合 Set<String> Rs = new HashSet<>(); //库区主键集合 Set<Long> pkRs = new HashSet<>(); //所选订单与库区相关的信息 所选订单的所有库区 // for (Long pkSendOrder : sendOrders) { //订单所对应的库区和和名称 Map<Long, String> order2R = allOrder2Rs.get(pkSendOrder); if (order2R != null) { //一个发货单所对应的库区暂时无用 /* Set<Long> longs = order2R.keySet(); pkRs.addAll(longs); System.out.println(longs);*/ //一个发货单所对应的简码 Collection<String> values = order2R.values(); System.out.println(values); Rs.addAll(values); System.out.println(Rs); } } //所有区域 StringBuilder builder = new StringBuilder(); if (!CollectionUtils.isEmpty(Rs)) { for (String r : Rs) { builder.append(r + ","); } String substring = builder.toString().substring(0, builder.toString().length() - 1); waveOrder.setReservoirsName(substring); } builder.delete(0, builder.length()); //暂时不需要库区主键列表 后期需要的时候放开 if (!CollectionUtils.isEmpty(pkRs)) { for (Long r : pkRs) { builder.append(r + ","); } String subpkRs = builder.toString().substring(0, builder.toString().length() - 1); waveOrder.setPkReservoirs(subpkRs); } //sku 的数量 && 货品数量和金额 Set<Long> goodsInfo = new HashSet<>(); Map<Long, String> ORs = new HashMap<Long, String>(); BigDecimal goodsNum = new BigDecimal(0); BigDecimal waveAmount = new BigDecimal(0); //承运商集合拼接 StringBuilder carriers = new StringBuilder(); for (WaveOrderResult waveOrderResult : waveOrderResults) { //发货单号 Long sendOrder = waveOrderResult.getPkSendOrder(); //说明是被选中进入波次的发货订单 /*if (sendOrders.contains(sendOrder)) {}*/ //组装波次对象开始 waveOrder.setPkGoodsOwner(waveOrderResult.getPkGoodsOwner()); List<SendOrderGoods> sendOrderGoodsList = waveOrderResult.getGoods(); //与货品相关的 for (SendOrderGoods good : sendOrderGoodsList) { goodsInfo.add(good.getPkGoodsInfo()); BigDecimal goodNum = good.getSalesVolumes() == null ? new BigDecimal(0) : good.getSalesVolumes(); BigDecimal sellingPrice = good.getSellingPrice(); goodsNum = goodsNum.add(goodNum); if (sellingPrice != null && goodsNum.equals(0)) { waveAmount = waveAmount.add(good.getSalesVolumes().multiply(sellingPrice)); } } Long carrier = waveOrderResult.getPkCarrier(); String carrierName = waveOrderResult.getCarrierName(); if (carrierName != null) { carriers.append(carrierName + ","); } } //承运商列 if (!"".equals(carriers.toString())) { String subCarriers = carriers.toString().substring(0, carriers.toString().length() - 1); waveOrder.setCreaterName(subCarriers); } //所有波次发货单的共同参数 仓库 货主 WaveOrderResult result = waveOrderResults.get(0); waveOrder.setPkWarehouse(result.getPkWarehouse()); waveOrder.setWarehouseName(result.getWarehouseName()); waveOrder.setPkGoodsOwner(result.getPkGoodsOwner()); waveOrder.setGoodsOwner(result.getGoodsOwner()); //波次状态 waveOrder.setWaveStatusNum(1); waveOrder.setWaveStatusName(WaveStatusEnum.HAS_BEEN_CREATED.getName()); //拣货类型必填参数 waveOrder.setPickType(waveOrderConfirm.getPickType()); waveOrder.setPickTypeName(WavePickType.DISTRIBUTE_AFTER_PICK.getName()); waveOrder.setSendOrderNum(waveOrderConfirm.getPkSendOrder().size()); waveOrder.setPickOrderNum(1); if (waveOrderConfirm.getCreatorCode() != null && waveOrderConfirm.getCreaterName() != null) { waveOrder.setCreatorCode(waveOrderConfirm.getCreatorCode()); waveOrder.setCreaterName(waveOrderConfirm.getCreaterName()); } //将所选订单全部计算完毕 此时将订单的所需结果填写到波次对象中 //sku数量 waveOrder.setSkuNum(goodsInfo.size()); //货品数量 waveOrder.setGoodsNum(goodsNum); //货品总金额 waveOrder.setWaveAount(waveAmount); //主键 和波次号 try { waveOrder.setPkWave(uidService.getUId()); waveOrder.setWaveCode(unicodeService.incrementOne(codeType, systemId)); } catch (Exception e) { e.printStackTrace(); } //波次对象构筑完毕保存 waveOrderMapper.insert(waveOrder); //货品明细保存 同时保存到拣货单详情中一份 //此时的波次货品详情和拣货单的是一致的 Map<String, WaveGoodDetail> goodMap = new HashMap(); for (WaveOrderResult waveOrderResult : waveOrderResults) { //说明是被选中进入波次的发货订单 List<SendOrderGoods> goods = waveOrderResult.getGoods(); for (SendOrderGoods good : goods) { String code = good.getGoodsCode(); Object supplier = good.getSupplier() == null ? good.getSupplier() : ""; String mapCodeSupplier = code + "_" + supplier; if (goodMap.containsKey(mapCodeSupplier)) { WaveGoodDetail goodHasKey = goodMap.get(mapCodeSupplier); BigDecimal wavevol = goodHasKey.getGoodsNum() == null ? new BigDecimal(0) : goodHasKey.getGoodsNum(); BigDecimal goodvol = good.getSalesVolumes() == null ? new BigDecimal(0) : good.getSalesVolumes(); goodHasKey.setGoodsNum(wavevol.add(goodvol)); } else { try { WaveGoodDetail goodDetail = new WaveGoodDetail();
只要遇到Exception异常无论是否处理事物都会回滚
最新推荐文章于 2022-09-16 13:16:05 发布