|
|
@@ -305,7 +305,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public R outboundWorkOrder(String ids) {
|
|
|
- List<Long> shipIds = Func.toLongList(ids);
|
|
|
+ /*List<Long> shipIds = Func.toLongList(ids);
|
|
|
List<PjShip> pjShipList = baseMapper.selectList(new LambdaQueryWrapper<PjShip>()
|
|
|
.eq(PjShip::getTenantId, AuthUtil.getTenantId())
|
|
|
.eq(PjShip::getIsDeleted, 0)
|
|
|
@@ -511,27 +511,10 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- /*// 创建线程池
|
|
|
- ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
|
- // 启动任务并提交给线程池
|
|
|
- executor.submit(() -> {
|
|
|
- try {
|
|
|
- this.sendMessage(rwShip, item, goodsNames, 1);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("业务处理成功,发送消息异常,时间:" + new Date());
|
|
|
- System.out.println(e.getMessage());
|
|
|
- // 关闭线程池
|
|
|
- executor.shutdown();
|
|
|
- } finally {
|
|
|
- // 关闭线程池
|
|
|
- executor.shutdown();
|
|
|
- }
|
|
|
- });
|
|
|
- // 关闭线程池
|
|
|
- executor.shutdown();*/
|
|
|
}
|
|
|
this.saveOrUpdateBatch(rwShipList);
|
|
|
- shipItemsService.saveOrUpdateBatch(shipItemsList);
|
|
|
+ shipItemsService.saveOrUpdateBatch(shipItemsList);*/
|
|
|
+ this.outboundWorkOrderV1(ids);
|
|
|
return R.success("操作成功");
|
|
|
}
|
|
|
|
|
|
@@ -919,317 +902,45 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
} else {
|
|
|
throw new RuntimeException("出库明细不能为空");
|
|
|
}
|
|
|
-
|
|
|
- //数量和
|
|
|
- BigDecimal goodsNum = pjOrderItemsList.stream().map(PjOrderItems::getGoodsNum).filter(Objects::nonNull)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- //发货数量和
|
|
|
- BigDecimal sendNum = pjOrderItemsList.stream().map(PjOrderItems::getSendNum).filter(Objects::nonNull)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- BigDecimal goodsTotalShipAmount = pjOrderItemsList.stream().map(PjOrderItems::getGoodsTotalShipAmount)
|
|
|
- .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
PjOrder order = orderMapper.selectById(ship.getOrdId());
|
|
|
if (ObjectUtil.isNotEmpty(order)) {
|
|
|
- order.setGoodsTotalShipAmount(goodsTotalShipAmount);
|
|
|
- order.setGoodsTotalShipNum(sendNum);
|
|
|
- if ("已收货".equals(order.getStatus()) || "退款请核".equals(order.getStatus()) || "已取消".equals(order.getStatus())) {
|
|
|
- throw new RuntimeException("单据已收货或申请售后中,操作失败");
|
|
|
- }
|
|
|
- order.setGrossProfit(pjOrderItemsList.stream().map(PjOrderItems::getGrossProfit).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
- order.setCost(pjOrderItemsList.stream().map(PjOrderItems::getCostprie).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
- order.setShipType(ship.getShipType());
|
|
|
- order.setLogisticsCorpId(ship.getLogisticsCorpId());
|
|
|
- order.setLogisticsCorpName(ship.getLogisticsCorpName());
|
|
|
- order.setExpressNo(ship.getExpressNo());
|
|
|
- if (goodsNum.compareTo(sendNum) == 0) {//数量等于发货数量修改销售订单状态
|
|
|
- order.setStatus(OrderTypeEnum.SHIPED.getType());
|
|
|
- order.setXcxStatus(OrderTypeEnum.GOODSRECEIVED.getType());
|
|
|
- order.setDeliveryBusinesDate(new Date());
|
|
|
- orderMapper.updateById(order);
|
|
|
- } else {
|
|
|
- order.setStorageId(ship.getStorageId());
|
|
|
- order.setStorageName(ship.getStorageName());
|
|
|
- orderMapper.updateById(order);
|
|
|
- }
|
|
|
- }
|
|
|
- //融资流程
|
|
|
- /*if (ObjectUtils.isNotNull(status) && "1".equals(status)) {
|
|
|
- String firstProportion = sysClient.getParamService("first.month.proportion");
|
|
|
- String secondProportion = sysClient.getParamService("second.month.proportion");
|
|
|
- PjpfFunding pjpfFunding = pjpfFundingService.getOne(new LambdaQueryWrapper<PjpfFunding>()
|
|
|
- .eq(PjpfFunding::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjpfFunding::getIsDeleted, 0));
|
|
|
- if (pjpfFunding == null) {
|
|
|
- throw new RuntimeException("未找到融资总账");
|
|
|
- }
|
|
|
- Date date = new Date();
|
|
|
- Calendar calendarDate = Calendar.getInstance();
|
|
|
- calendarDate.setTime(date);
|
|
|
- calendarDate.add(Calendar.DAY_OF_MONTH, -90);
|
|
|
- Date dateTime = calendarDate.getTime();
|
|
|
- //获取融资采购单主表数据
|
|
|
- List<PjOrder> orderList = orderMapper.selectList(new LambdaQueryWrapper<PjOrder>()
|
|
|
- .eq(PjOrder::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjOrder::getIsDeleted, 0)
|
|
|
- .eq(PjOrder::getWhetherFinancing, "1")
|
|
|
- .eq(PjOrder::getBsType, "RZCG")
|
|
|
- .ge(PjOrder::getBusinesDate, dateTime)
|
|
|
- .apply("goods_total_ship_num > out_goods_total_ship_num")
|
|
|
- .orderByAsc(PjOrder::getBusinesDate)
|
|
|
- );
|
|
|
- List<Long> ordIds = orderList.stream().map(PjOrder::getId).collect(Collectors.toList());
|
|
|
- List<Long> goodsList = shipItemsList.stream().filter(e -> ObjectUtils.isNotNull(financingBrand) && financingBrand.contains(e.getBrandName()))
|
|
|
- .map(PjShipItems::getGoodsId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
- //获取融资采购单明细数据
|
|
|
List<PjOrderItems> orderItemsList = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
.eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
.eq(PjOrderItems::getIsDeleted, 0)
|
|
|
- .eq(PjOrderItems::getBizType, "RZCG")
|
|
|
- .in(PjOrderItems::getGoodsId, goodsList)
|
|
|
- .in(PjOrderItems::getPid, ordIds)
|
|
|
- .apply("send_num > out_goods_total_ship_num")
|
|
|
- .orderByAsc(PjOrderItems::getCreateTime)
|
|
|
- );
|
|
|
- BigDecimal amountSum = new BigDecimal("0.00");
|
|
|
- if (!orderItemsList.isEmpty()) {
|
|
|
- List<PjOrder> orders = orderList.stream().filter(e -> e.getWhetherRedeem().equals("0")).distinct().collect(Collectors.toList());
|
|
|
- if (!orders.isEmpty()) {
|
|
|
- if (pjpfFunding.getBondAmount().compareTo(pjpfFunding.getPaidAlreadyBondAmount()) > 0) {
|
|
|
- throw new RuntimeException("已缴保证金不足,出库失败");
|
|
|
- }
|
|
|
- BigDecimal amount = shipItemsList.stream().filter(e -> ObjectUtils.isNotNull(financingBrand) && financingBrand.contains(e.getBrandName()))
|
|
|
- .map(PjShipItems::getCostprie).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- if (pjpfFunding.getAvailableAmount().compareTo(amount) < 0) {
|
|
|
- throw new RuntimeException("剩余可用资金:" + pjpfFunding.getAvailableAmount() + "小于本次出库金额:" + amount + ",出库失败");
|
|
|
- }
|
|
|
- amountSum = amount;
|
|
|
- pjpfFunding.setAvailableAmount(pjpfFunding.getAvailableAmount().subtract(amount));
|
|
|
-// pjpfFunding.setFundingAmount(pjpfFunding.getFundingAmount().add(amount));
|
|
|
- }
|
|
|
- }
|
|
|
- List<FinancingShipItemDto> allList = new ArrayList<>();
|
|
|
- List<ShipItemsRecord> recordList = new ArrayList<>();
|
|
|
- List<PjOrderItems> orderItemList1 = new ArrayList<>();
|
|
|
- //出库明细循环
|
|
|
- for (PjShipItems shipItems : shipItemsList) {
|
|
|
- if (ObjectUtils.isNull(shipItems.getCostprie()) || shipItems.getCostprie().compareTo(new BigDecimal("0.00")) == 0) {
|
|
|
- throw new RuntimeException("获取数据失败,请重新生成出库工单");
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotNull(financingBrand) && financingBrand.contains(shipItems.getBrandName())) {
|
|
|
- BigDecimal number = shipItems.getSendNum();
|
|
|
- //获取出库明细商品对应融资采购商品明细
|
|
|
- List<PjOrderItems> orderItemList = orderItemsList.stream().filter(e -> e.getGoodsId().equals(shipItems.getGoodsId())).collect(Collectors.toList());
|
|
|
- List<FinancingShipItemDto> mapList = new ArrayList<>();
|
|
|
- if (number.compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
- //采购商品明细循环
|
|
|
- for (PjOrderItems orderItems1 : orderItemList) {
|
|
|
- if (orderItems1.getGoodsId().equals(shipItems.getGoodsId())) {
|
|
|
- //记录出库明细对应融资采购单据
|
|
|
- ShipItemsRecord shipItemsRecord = new ShipItemsRecord();
|
|
|
- shipItemsRecord.setBillNo(ship.getBillno());
|
|
|
- shipItemsRecord.setPid(shipItems.getPid());
|
|
|
- shipItemsRecord.setItemId(shipItems.getId());
|
|
|
- shipItemsRecord.setSrcId(orderItems1.getPid());
|
|
|
- shipItemsRecord.setSrcItemId(orderItems1.getId());
|
|
|
- shipItemsRecord.setSrcOrd(orderItems1.getBillNo());
|
|
|
- shipItemsRecord.setCreateUser(AuthUtil.getUserId());
|
|
|
- shipItemsRecord.setCreateUserName(AuthUtil.getUserName());
|
|
|
- shipItemsRecord.setCreateTime(new Date());
|
|
|
- //记录具体出库数量,来源融资采购明细
|
|
|
- FinancingShipItemDto financingShipItemDto = new FinancingShipItemDto();
|
|
|
- financingShipItemDto.setId(orderItems1.getId());
|
|
|
- financingShipItemDto.setPid(orderItems1.getPid());
|
|
|
- financingShipItemDto.setItemId(shipItems.getId());
|
|
|
- BigDecimal subNum = orderItems1.getSendNum().subtract(orderItems1.getOutGoodsTotalShipNum());
|
|
|
- //剩余数量 = 入库数量-已出数量
|
|
|
- //修改明细出库数量
|
|
|
- if (new BigDecimal("0.00").compareTo(subNum) != 0) {
|
|
|
- if (number.compareTo(subNum) > 0) {
|
|
|
- financingShipItemDto.setNum(subNum);
|
|
|
- financingShipItemDto.setAmount(subNum.multiply(orderItems1.getPrice()));
|
|
|
- shipItemsRecord.setNum(subNum);
|
|
|
- shipItemsRecord.setAmount(subNum.multiply(orderItems1.getPrice()));
|
|
|
- //本次出库数量大于剩余数量 融资采购明细出库数量=入库数量
|
|
|
- orderItems1.setOutGoodsTotalShipNum(orderItems1.getSendNum());
|
|
|
- orderItems1.setThisOutGoodsTotalShipNum(subNum);
|
|
|
- orderItems1.setOutGoodsTotalShipAmount(orderItems1.getOutGoodsTotalShipNum().multiply(orderItems1.getPrice()));
|
|
|
- orderItems1.setThisOutGoodsTotalShipAmount(subNum.multiply(orderItems1.getPrice()));
|
|
|
- number = number.subtract(subNum);
|
|
|
- } else if (number.compareTo(subNum) == 0) {
|
|
|
- financingShipItemDto.setNum(subNum);
|
|
|
- financingShipItemDto.setAmount(subNum.multiply(orderItems1.getPrice()));
|
|
|
- shipItemsRecord.setNum(subNum);
|
|
|
- shipItemsRecord.setAmount(subNum.multiply(orderItems1.getPrice()));
|
|
|
- //本次出库数量等于剩余数量 融资采购明细出库数量=入库数量
|
|
|
- orderItems1.setOutGoodsTotalShipNum(orderItems1.getSendNum());
|
|
|
- orderItems1.setThisOutGoodsTotalShipNum(subNum);
|
|
|
- orderItems1.setOutGoodsTotalShipAmount(orderItems1.getOutGoodsTotalShipNum().multiply(orderItems1.getPrice()));
|
|
|
- orderItems1.setThisOutGoodsTotalShipAmount(subNum.multiply(orderItems1.getPrice()));
|
|
|
- number = new BigDecimal("0.00");
|
|
|
- } else {
|
|
|
- financingShipItemDto.setNum(number);
|
|
|
- financingShipItemDto.setAmount(number.multiply(orderItems1.getPrice()));
|
|
|
- shipItemsRecord.setNum(number);
|
|
|
- shipItemsRecord.setAmount(number.multiply(orderItems1.getPrice()));
|
|
|
- //本次出库数量小于剩余数量 融资采购明细出库数量=入库数量-本次出库数量
|
|
|
- orderItems1.setOutGoodsTotalShipNum(orderItems1.getOutGoodsTotalShipNum().add(number));
|
|
|
- orderItems1.setThisOutGoodsTotalShipNum(number);
|
|
|
- orderItems1.setOutGoodsTotalShipAmount(orderItems1.getOutGoodsTotalShipNum().multiply(orderItems1.getPrice()));
|
|
|
- orderItems1.setThisOutGoodsTotalShipAmount(number.multiply(orderItems1.getPrice()));
|
|
|
- number = new BigDecimal("0.00");
|
|
|
- }
|
|
|
- mapList.add(financingShipItemDto);
|
|
|
- recordList.add(shipItemsRecord);
|
|
|
- }
|
|
|
- }
|
|
|
- orderItemList1.add(orderItems1);
|
|
|
- }
|
|
|
- }
|
|
|
- if (!mapList.isEmpty()) {
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- try {
|
|
|
- String jsonString = mapper.writeValueAsString(mapList);
|
|
|
- shipItems.setSrcFinancing(jsonString);
|
|
|
- } catch (Exception e) {
|
|
|
- System.err.println(e.getMessage());
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- allList.addAll(mapList);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (!recordList.isEmpty()) {
|
|
|
- shipItemsRecordService.saveBatch(recordList);
|
|
|
- }
|
|
|
- orderItemsService.updateBatchById(orderItemList1);
|
|
|
- if (!orderItemList1.isEmpty()) {
|
|
|
- //所有融资采购剩余金额的保证金
|
|
|
- BigDecimal bondAmountSum = new BigDecimal("0.00");
|
|
|
- //所有融资采购剩余金额的融资金额
|
|
|
- BigDecimal fundingAmountSum = new BigDecimal("0.00");
|
|
|
- //保证金释放金额
|
|
|
- BigDecimal availableAmountSum = new BigDecimal("0.00");
|
|
|
- for (PjOrder items : orderList) {
|
|
|
- List<PjOrderItems> pjOrderItems = orderItemList1.stream().filter(e -> items.getId().equals(e.getPid()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- //重新合计融资采购已出数量,金额
|
|
|
- if (!pjOrderItems.isEmpty()) {
|
|
|
- items.setOutGoodsTotalShipNum(items.getOutGoodsTotalShipNum().add(pjOrderItems.stream().map(PjOrderItems::getThisOutGoodsTotalShipNum)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add)));
|
|
|
- items.setOutGoodsTotalShipAmount(items.getOutGoodsTotalShipAmount().add(pjOrderItems.stream().map(PjOrderItems::getThisOutGoodsTotalShipAmount)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add)));
|
|
|
- }
|
|
|
- //重新计算所有未赎回融资采购,保证金,融资金额
|
|
|
- if (!"1".equals(items.getWhetherRedeem())) {
|
|
|
- Date currentDate = new Date();
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(currentDate);
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH, -60);
|
|
|
- Date thirtyDayAgo = calendar.getTime();
|
|
|
- //计算本融资采购剩余金额
|
|
|
- BigDecimal subAmount = items.getGoodsTotalShipAmount().subtract(items.getOutGoodsTotalShipAmount());
|
|
|
- List<Long> itemIdList = allList.stream().filter(e -> e.getPid().equals(items.getId())).map(FinancingShipItemDto::getItemId).collect(Collectors.toList());
|
|
|
- //判断本融资采购单据是否超过两个月 未超过按第一个比例计算,否则按第二个比例计算
|
|
|
- if (currentDate.compareTo(thirtyDayAgo) > 0) {
|
|
|
- if (!shipItemsList.isEmpty()) {
|
|
|
- for (PjShipItems shipItems1 : shipItemsList) {
|
|
|
- if (ObjectUtils.isNotNull(financingBrand) && financingBrand.contains(shipItems1.getBrandName())) {
|
|
|
- if (!itemIdList.isEmpty() && itemIdList.contains(shipItems1.getId())) {
|
|
|
- shipItems1.setProportion(firstProportion);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- String[] arr = firstProportion.split(":");
|
|
|
- //计算剩余金额的保证金
|
|
|
- BigDecimal bondAmount = subAmount.multiply(
|
|
|
- (new BigDecimal(arr[0]).divide(new BigDecimal("10"), MathContext.DECIMAL32)
|
|
|
- .setScale(2, RoundingMode.HALF_UP)));
|
|
|
- //计算剩余金额的融资金额
|
|
|
- BigDecimal fundingAmount = subAmount.multiply(
|
|
|
- (new BigDecimal(arr[1]).divide(new BigDecimal("10"), MathContext.DECIMAL32)
|
|
|
- .setScale(2, RoundingMode.HALF_UP)));
|
|
|
- //判断本次出库后保证金是否小于等于上次保证金
|
|
|
- if (bondAmount.compareTo(items.getBondAmount()) <= 0) {
|
|
|
- //本次出库后释放金额
|
|
|
- BigDecimal availableAmount = items.getBondAmount().subtract(bondAmount);
|
|
|
- items.setBondAmount(bondAmount);
|
|
|
- bondAmountSum = bondAmountSum.add(bondAmount);
|
|
|
- availableAmountSum = availableAmountSum.add(availableAmount);
|
|
|
- }
|
|
|
- //判断本次出库后融资金额是否小于等于上次融资金额
|
|
|
- if (fundingAmount.compareTo(items.getFundingAmount()) <= 0) {
|
|
|
- items.setFundingAmount(fundingAmount);
|
|
|
- fundingAmountSum = fundingAmountSum.add(fundingAmount);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (!shipItemsList.isEmpty()) {
|
|
|
- for (PjShipItems shipItems1 : shipItemsList) {
|
|
|
- if (!itemIdList.isEmpty() && itemIdList.contains(shipItems1.getId())) {
|
|
|
- shipItems1.setProportion(secondProportion);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- String[] arr = secondProportion.split(":");
|
|
|
- BigDecimal bondAmount = subAmount.multiply(
|
|
|
- (new BigDecimal(arr[0]).divide(new BigDecimal("10"), MathContext.DECIMAL32)
|
|
|
- .setScale(2, RoundingMode.HALF_UP)));
|
|
|
- BigDecimal fundingAmount = subAmount.multiply(
|
|
|
- (new BigDecimal(arr[1]).divide(new BigDecimal("10"), MathContext.DECIMAL32)
|
|
|
- .setScale(2, RoundingMode.HALF_UP)));
|
|
|
- if (bondAmount.compareTo(items.getBondAmount()) <= 0) {
|
|
|
- BigDecimal availableAmount = items.getBondAmount().subtract(bondAmount);
|
|
|
- items.setBondAmount(bondAmount);
|
|
|
- bondAmountSum = bondAmountSum.add(bondAmount);
|
|
|
- availableAmountSum = availableAmountSum.add(availableAmount);
|
|
|
- }
|
|
|
- if (fundingAmount.compareTo(items.getFundingAmount()) <= 0) {
|
|
|
- items.setFundingAmount(fundingAmount);
|
|
|
- fundingAmountSum = fundingAmountSum.add(fundingAmount);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- orderMapper.updateById(items);
|
|
|
- }
|
|
|
- //可用金额 = 原可用金额 + 本次释放金额
|
|
|
- pjpfFunding.setAvailableAmount(pjpfFunding.getAvailableAmount().add(availableAmountSum));
|
|
|
- pjpfFunding.setSurplusFundingAmount(fundingAmountSum);
|
|
|
- pjpfFunding.setPaidAlreadyBondAmount(bondAmountSum);
|
|
|
- pjpfFunding.setBondAmount(bondAmountSum);
|
|
|
- //总金额 = 保证金 + 在库融资金额
|
|
|
- pjpfFunding.setAmount(pjpfFunding.getSurplusFundingAmount().add(pjpfFunding.getBondAmount()));
|
|
|
- //融资金额 = 原融资金额 + (本次出库金额-本次释放金额)
|
|
|
- pjpfFunding.setFundingAmount(pjpfFunding.getFundingAmount().add(amountSum.subtract(availableAmountSum)));
|
|
|
- pjpfFunding.setProportion(pjpfFunding.getBondAmount().divide(pjpfFunding.getAmount(), MathContext.DECIMAL32)
|
|
|
- .setScale(2, RoundingMode.HALF_UP));
|
|
|
- pjpfFundingService.updateById(pjpfFunding);
|
|
|
- //融资管理明细记录
|
|
|
- PjpfFundingItem item = new PjpfFundingItem();
|
|
|
- item.setPid(pjpfFunding.getId());
|
|
|
- item.setTenantId(AuthUtil.getTenantId());
|
|
|
- item.setCreateTime(new Date());
|
|
|
- item.setCreateUser(AuthUtil.getUserId());
|
|
|
- item.setCreateUserName(AuthUtil.getUserName());
|
|
|
- item.setCreateDept(pjpfFunding.getCreateDept());
|
|
|
- item.setCreateDeptName(pjpfFunding.getCreateDeptName());
|
|
|
- item.setType("融资出库");
|
|
|
- item.setSrcId(ship.getId());
|
|
|
- item.setSrcNo(ship.getBillno());
|
|
|
- item.setAmount(amountSum);
|
|
|
- item.setFundingAmount(amountSum.subtract(availableAmountSum));
|
|
|
- item.setBondAmount(availableAmountSum);
|
|
|
- pjpfFundingItemService.save(item);
|
|
|
- for (PjShipItems shipItems : shipItemsList) {
|
|
|
- if (ObjectUtils.isNotNull(financingBrand) && financingBrand.contains(shipItems.getBrandName())) {
|
|
|
- List<PjOrderItems> orderItems = pjOrderItemsList.stream().filter(e -> e.getId().equals(shipItems.getSrcItemId())).collect(Collectors.toList());
|
|
|
- for (PjOrderItems items : orderItems) {
|
|
|
- items.setProportion(shipItems.getProportion());
|
|
|
- items.setSrcFinancing(shipItems.getSrcFinancing());
|
|
|
- }
|
|
|
- }
|
|
|
+ .eq(PjOrderItems::getPid, order.getId()));
|
|
|
+ if (!orderItemsList.isEmpty()){
|
|
|
+ if ("已收货".equals(order.getStatus()) || "退款请核".equals(order.getStatus()) || "已取消".equals(order.getStatus())) {
|
|
|
+ throw new RuntimeException("单据已收货或申请售后中,操作失败");
|
|
|
+ }
|
|
|
+ //数量和
|
|
|
+ BigDecimal goodsNum = orderItemsList.stream().map(PjOrderItems::getGoodsNum).filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ //发货数量和
|
|
|
+ BigDecimal sendNum = orderItemsList.stream().map(PjOrderItems::getSendNum).filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal goodsTotalShipAmount = orderItemsList.stream().map(PjOrderItems::getGoodsTotalShipAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ order.setGoodsTotalShipAmount(goodsTotalShipAmount);
|
|
|
+ order.setGoodsTotalShipNum(sendNum);
|
|
|
+ order.setGrossProfit(orderItemsList.stream().map(PjOrderItems::getGrossProfit).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ order.setCost(orderItemsList.stream().map(PjOrderItems::getCostprie).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ order.setShipType(ship.getShipType());
|
|
|
+ order.setLogisticsCorpId(ship.getLogisticsCorpId());
|
|
|
+ order.setLogisticsCorpName(ship.getLogisticsCorpName());
|
|
|
+ order.setExpressNo(ship.getExpressNo());
|
|
|
+ if (goodsNum.compareTo(sendNum) == 0) {//数量等于发货数量修改销售订单状态
|
|
|
+ order.setStatus(OrderTypeEnum.SHIPED.getType());
|
|
|
+ order.setXcxStatus(OrderTypeEnum.GOODSRECEIVED.getType());
|
|
|
+ order.setDeliveryBusinesDate(new Date());
|
|
|
+ orderMapper.updateById(order);
|
|
|
+ } else {
|
|
|
+ order.setStorageId(ship.getStorageId());
|
|
|
+ order.setStorageName(ship.getStorageName());
|
|
|
+ orderMapper.updateById(order);
|
|
|
}
|
|
|
}
|
|
|
- }*/
|
|
|
+ }
|
|
|
+ //融资流程
|
|
|
if (ObjectUtils.isNotNull(status) && "1".equals(status)) {
|
|
|
String firstProportion = sysClient.getParamService("first.month.proportion");
|
|
|
String secondProportion = sysClient.getParamService("second.month.proportion");
|
|
|
@@ -1674,8 +1385,19 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
if ("已收货".equals(order.getStatus()) || "退款请核".equals(order.getStatus()) || "已取消".equals(order.getStatus())) {
|
|
|
throw new RuntimeException("单据已收货或申请售后中,操作失败");
|
|
|
}
|
|
|
- order.setGrossProfit(pjOrderItemsList.stream().map(PjOrderItems::getGrossProfit).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
- order.setCost(pjOrderItemsList.stream().map(PjOrderItems::getCostprie).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ List<PjOrderItems> orderItemsList = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .eq(PjOrderItems::getPid, order.getId()));
|
|
|
+ if (!orderItemsList.isEmpty()){
|
|
|
+ //发货数量和
|
|
|
+ BigDecimal sendNum = orderItemsList.stream().map(PjOrderItems::getSendNum).filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal goodsTotalShipAmount = orderItemsList.stream().map(PjOrderItems::getGoodsTotalShipAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ order.setGoodsTotalShipAmount(goodsTotalShipAmount);
|
|
|
+ order.setGoodsTotalShipNum(sendNum);
|
|
|
+ }
|
|
|
order.setStatus(OrderTypeEnum.XSDFH.getType());
|
|
|
order.setXcxStatus(OrderTypeEnum.XSDFH.getType());
|
|
|
order.setDeliveryBusinesDate(null);
|
|
|
@@ -1961,7 +1683,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
);
|
|
|
List<Long> ordIds = orderList.stream().map(PjOrder::getId).collect(Collectors.toList());
|
|
|
List<PjOrderItems> orderItemsList = new ArrayList<>();
|
|
|
- if (!ordIds.isEmpty()){
|
|
|
+ if (!ordIds.isEmpty()) {
|
|
|
orderItemsList = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
.eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
.eq(PjOrderItems::getIsDeleted, 0)
|
|
|
@@ -2381,6 +2103,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
List<PjProductLaunch> pjProductLaunchList = new ArrayList<>();
|
|
|
List<PjOrderItems> pjOrderItemsList = new ArrayList<>();
|
|
|
if (CollectionUtils.isNotEmpty(ship.getShipItemsList())) {
|
|
|
+ ship.setSendTotalNum(ship.getShipItemsList().stream().map(PjShipItems::getSendNum).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
List<Long> goodIds = ship.getShipItemsList().stream().map(PjShipItems::getGoodsId).distinct().collect(Collectors.toList());
|
|
|
List<PjGoodsDesc> pjGoodsDescList = goodsDescMapper.selectList(new LambdaQueryWrapper<PjGoodsDesc>()
|
|
|
.eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
@@ -2622,15 +2345,19 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
baseMapper.updateById(rwShip);
|
|
|
}
|
|
|
PjOrder order = orderMapper.selectById(ship.getOrdId());
|
|
|
- if (!pjOrderItemsList.isEmpty()) {
|
|
|
+ List<PjOrderItems> orderItemsList = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .eq(PjOrderItems::getPid, order.getId()));
|
|
|
+ if (!orderItemsList.isEmpty()) {
|
|
|
//数量和
|
|
|
- BigDecimal goodsNum = pjOrderItemsList.stream().map(PjOrderItems::getGoodsNum).filter(Objects::nonNull)
|
|
|
+ BigDecimal goodsNum = orderItemsList.stream().map(PjOrderItems::getGoodsNum).filter(Objects::nonNull)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
//发货数量和
|
|
|
- BigDecimal sendNum = pjOrderItemsList.stream().map(PjOrderItems::getSendNum).filter(Objects::nonNull)
|
|
|
+ BigDecimal sendNum = orderItemsList.stream().map(PjOrderItems::getSendNum).filter(Objects::nonNull)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
//发货金额和
|
|
|
- BigDecimal goodsTotalShipAmount = pjOrderItemsList.stream().map(PjOrderItems::getGoodsTotalShipAmount).filter(Objects::nonNull)
|
|
|
+ BigDecimal goodsTotalShipAmount = orderItemsList.stream().map(PjOrderItems::getGoodsTotalShipAmount).filter(Objects::nonNull)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
if (ObjectUtil.isNotEmpty(order)) {
|
|
|
order.setGoodsTotalShipNum(sendNum);
|
|
|
@@ -3234,6 +2961,20 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
if (order1 != null && "待出库,已完成".contains(order1.getStatus())) {
|
|
|
throw new RuntimeException("已生成采购退货单据,撤销失败");
|
|
|
}
|
|
|
+ List<PjOrderItems> orderItemsList = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .eq(PjOrderItems::getPid, order.getId()));
|
|
|
+ if (!orderItemsList.isEmpty()) {
|
|
|
+ //发货数量和
|
|
|
+ BigDecimal sendNum = orderItemsList.stream().map(PjOrderItems::getSendNum).filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ //发货金额和
|
|
|
+ BigDecimal goodsTotalShipAmount = orderItemsList.stream().map(PjOrderItems::getGoodsTotalShipAmount).filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ order.setGoodsTotalShipNum(sendNum);
|
|
|
+ order.setGoodsTotalShipAmount(goodsTotalShipAmount);
|
|
|
+ }
|
|
|
order.setStatus(OrderTypeEnum.GOODSRECEIVED.getType());
|
|
|
order.setXcxStatus(OrderTypeEnum.GOODSRECEIVED.getType());
|
|
|
order.setDeliveryBusinesDate(null);
|
|
|
@@ -3618,6 +3359,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
String status = sysClient.getParamService("whether.financing");
|
|
|
List<PjStockDesc> pjStockDescArrayList = new ArrayList<>();
|
|
|
List<PjStockDesc> pjStockDescList = new ArrayList<>();
|
|
|
+ int count = 1;
|
|
|
for (PjShipItems orderItems : order.getShipItemsList()) {
|
|
|
//获得商品
|
|
|
PjGoodsDesc goodsDesc = goodsDescMapper.selectById(orderItems.getGoodsId());
|
|
|
@@ -3644,21 +3386,21 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
PjStockDesc stockOneC = iStockDescService.getOne(lambdaQueryWrapperC);
|
|
|
if (ObjectUtil.isNotEmpty(stockOneC)) {
|
|
|
if (orderItems.getGoodsNum().compareTo(stockOneC.getBalanceQuantity()) > 0) {
|
|
|
- throw new RuntimeException("库存不足,保存失败");
|
|
|
+ throw new RuntimeException("第" + count + "行,商品:" + goodsDesc.getCname() + "库存不足,保存失败");
|
|
|
}
|
|
|
stockOneC.setBalanceQuantity(stockOneC.getBalanceQuantity().subtract(orderItems.getGoodsNum()));
|
|
|
if (!"1".equals(status)) {
|
|
|
if (orderItems.getGoodsNum().compareTo(stockOneC.getBalanceQuantityHave()) > 0) {
|
|
|
- throw new RuntimeException("自有库存不足,保存失败");
|
|
|
+ throw new RuntimeException("第" + count + "行,商品:" + goodsDesc.getCname() + "自有库存不足,保存失败");
|
|
|
}
|
|
|
stockOneC.setBalanceQuantityHave(stockOneC.getBalanceQuantityHave().subtract(orderItems.getGoodsNum()));
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
if (orderItems.getSendNumFinancing().compareTo(stockOneC.getBalanceQuantityFinancing()) > 0) {
|
|
|
- throw new RuntimeException("融资库存不足,保存失败");
|
|
|
+ throw new RuntimeException("第" + count + "行,商品:" + goodsDesc.getCname() + "融资库存不足,保存失败");
|
|
|
}
|
|
|
stockOneC.setBalanceQuantityFinancing(stockOneC.getBalanceQuantityFinancing().subtract(orderItems.getSendNumFinancing()));
|
|
|
if (orderItems.getSendNumHave().compareTo(stockOneC.getBalanceQuantityHave()) > 0) {
|
|
|
- throw new RuntimeException("自有库存不足,保存失败");
|
|
|
+ throw new RuntimeException("第" + count + "行,商品:" + goodsDesc.getCname() + "自有库存不足,保存失败");
|
|
|
}
|
|
|
stockOneC.setBalanceQuantityHave(stockOneC.getBalanceQuantityHave().subtract(orderItems.getSendNumHave()));
|
|
|
}
|
|
|
@@ -3689,7 +3431,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
stockOneR.setBalanceQuantity(stockOneR.getBalanceQuantity().add(orderItems.getGoodsNum()));
|
|
|
if (!"1".equals(status)) {
|
|
|
stockOneR.setBalanceQuantityHave(stockOneR.getBalanceQuantityHave().add(orderItems.getGoodsNum()));
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
stockOneR.setBalanceQuantityFinancing(stockOneR.getBalanceQuantityFinancing().add(orderItems.getSendNumFinancing()));
|
|
|
stockOneR.setBalanceQuantityHave(stockOneR.getBalanceQuantityHave().add(orderItems.getSendNumHave()));
|
|
|
}
|
|
|
@@ -3716,7 +3458,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
stockDesc.setBalanceQuantity(orderItems.getGoodsNum());
|
|
|
if (!"1".equals(status)) {
|
|
|
stockDesc.setBalanceQuantityHave(orderItems.getGoodsNum());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
stockDesc.setBalanceQuantityFinancing(orderItems.getSendNumFinancing());
|
|
|
stockDesc.setBalanceQuantityHave(orderItems.getSendNumHave());
|
|
|
}
|
|
|
@@ -3732,6 +3474,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
stockDesc.setTenantId(AuthUtil.getTenantId());
|
|
|
pjStockDescList.add(stockDesc);
|
|
|
}
|
|
|
+ count++;
|
|
|
}
|
|
|
R res = iStockDescService.updateBatchByIdNew(pjStockDescArrayList);
|
|
|
if (!res.isSuccess()) {
|
|
|
@@ -3764,6 +3507,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
if (CollectionUtils.isNotEmpty(order.getShipItemsList())) {
|
|
|
String status = sysClient.getParamService("whether.financing");
|
|
|
List<PjStockDesc> pjStockDescArrayList = new ArrayList<>();
|
|
|
+ int count = 1;
|
|
|
for (PjShipItems orderItems : order.getShipItemsList()) {
|
|
|
//获得商品
|
|
|
PjGoodsDesc goodsDesc = goodsDescMapper.selectById(orderItems.getGoodsId());
|
|
|
@@ -3789,9 +3533,9 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
PjStockDesc stockOneC = iStockDescService.getOne(lambdaQueryWrapperC);
|
|
|
if (ObjectUtil.isNotEmpty(stockOneC)) {
|
|
|
stockOneC.setBalanceQuantity(stockOneC.getBalanceQuantity().add(orderItems.getGoodsNum()));
|
|
|
- if (!"1".equals(status)){
|
|
|
+ if (!"1".equals(status)) {
|
|
|
stockOneC.setBalanceQuantityHave(stockOneC.getBalanceQuantityHave().add(orderItems.getGoodsNum()));
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
stockOneC.setBalanceQuantityFinancing(stockOneC.getBalanceQuantityFinancing().add(orderItems.getSendNumFinancing()));
|
|
|
stockOneC.setBalanceQuantityHave(stockOneC.getBalanceQuantityHave().add(orderItems.getSendNumHave()));
|
|
|
}
|
|
|
@@ -3821,18 +3565,18 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
PjStockDesc stockOneR = iStockDescService.getOne(lambdaQueryWrapperR);
|
|
|
if (ObjectUtil.isNotEmpty(stockOneR)) {
|
|
|
stockOneR.setBalanceQuantity(stockOneR.getBalanceQuantity().subtract(orderItems.getGoodsNum()));
|
|
|
- if (!"1".equals(status)){
|
|
|
+ if (!"1".equals(status)) {
|
|
|
if (orderItems.getGoodsNum().compareTo(stockOneR.getBalanceQuantityHave()) > 0) {
|
|
|
- throw new RuntimeException("自有库存不足,保存失败");
|
|
|
+ throw new RuntimeException("第" + count + "行,商品:" + goodsDesc.getCname() + "自有库存不足,保存失败");
|
|
|
}
|
|
|
stockOneR.setBalanceQuantityHave(stockOneR.getBalanceQuantityHave().subtract(orderItems.getGoodsNum()));
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
if (orderItems.getSendNumFinancing().compareTo(stockOneR.getBalanceQuantityFinancing()) > 0) {
|
|
|
- throw new RuntimeException("融资库存不足,保存失败");
|
|
|
+ throw new RuntimeException("第" + count + "行,商品:" + goodsDesc.getCname() + "融资库存不足,保存失败");
|
|
|
}
|
|
|
stockOneR.setBalanceQuantityFinancing(stockOneR.getBalanceQuantityFinancing().subtract(orderItems.getSendNumFinancing()));
|
|
|
if (orderItems.getSendNumHave().compareTo(stockOneR.getBalanceQuantityHave()) > 0) {
|
|
|
- throw new RuntimeException("自有库存不足,保存失败");
|
|
|
+ throw new RuntimeException("第" + count + "行,商品:" + goodsDesc.getCname() + "自有库存不足,保存失败");
|
|
|
}
|
|
|
stockOneR.setBalanceQuantityHave(stockOneR.getBalanceQuantityHave().subtract(orderItems.getSendNumHave()));
|
|
|
}
|
|
|
@@ -3851,6 +3595,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
} else {
|
|
|
throw new RuntimeException("未查到库存账");
|
|
|
}
|
|
|
+ count++;
|
|
|
}
|
|
|
R res = iStockDescService.updateBatchByIdNew(pjStockDescArrayList);
|
|
|
if (!res.isSuccess()) {
|
|
|
@@ -6169,4 +5914,264 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R outboundWorkOrderV1(String ids) {
|
|
|
+ List<Long> shipIds = Func.toLongList(ids);
|
|
|
+ List<PjShip> pjShipList = baseMapper.selectList(new LambdaQueryWrapper<PjShip>()
|
|
|
+ .eq(PjShip::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjShip::getIsDeleted, 0)
|
|
|
+ .apply("find_in_set(id,'" + ids + "')"));
|
|
|
+ List<PjOrderItems> pjOrderItemsList = new ArrayList<>();
|
|
|
+ List<PjShip> pjShips = new ArrayList<>();
|
|
|
+ List<PjStockDesc> stockDescList = new ArrayList<>();
|
|
|
+ List<Long> storageId = new ArrayList<>();
|
|
|
+ if (!pjShipList.isEmpty()) {
|
|
|
+ List<Long> ordIds = pjShipList.stream().map(PjShip::getOrdId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ storageId = pjShipList.stream().map(PjShip::getStorageId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ pjOrderItemsList = orderItemsService.list(new QueryWrapper<PjOrderItems>()
|
|
|
+ .in("pid", ordIds)
|
|
|
+ .eq("is_deleted", 0)
|
|
|
+ .apply("goods_num != send_num")
|
|
|
+ .eq("tenant_id", AuthUtil.getTenantId()));
|
|
|
+ }
|
|
|
+ if (!pjOrderItemsList.isEmpty()) {
|
|
|
+ List<Long> goodsId = pjOrderItemsList.stream().map(PjOrderItems::getGoodsId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ if (!goodsId.isEmpty() && !storageId.isEmpty()) {
|
|
|
+ stockDescList = iStockDescService.list(new LambdaQueryWrapper<PjStockDesc>()
|
|
|
+ .eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .in(PjStockDesc::getGoodsId, goodsId)
|
|
|
+ .in(PjStockDesc::getStorageId, storageId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Long id : shipIds) {
|
|
|
+ //获得出库任务数据
|
|
|
+ PjShip rwShip = pjShipList.stream().filter(e -> e.getId().equals(id)).findFirst().orElse(null);
|
|
|
+ if (rwShip == null) {
|
|
|
+ throw new RuntimeException("数据异常 请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
+ //新建出库工单
|
|
|
+ PjShip gdShip = new PjShip();
|
|
|
+ // 获取系统编号
|
|
|
+ String billNo = serialService.getBillNo(OrderTypeEnum.FHGD.getType(), OrderTypeEnum.FHGD.getType(), OrderTypeEnum.FHGD.getType());
|
|
|
+ if (ObjectUtils.isNull(billNo)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.fail(500, "生成系统编号失败");
|
|
|
+ }
|
|
|
+ BeanUtil.copyProperties(rwShip, gdShip);
|
|
|
+
|
|
|
+ gdShip.setId(null);
|
|
|
+ gdShip.setBillno(billNo);
|
|
|
+ gdShip.setStatusName(OrderTypeEnum.TOBESHIPPEDOUT.getType());
|
|
|
+ gdShip.setTenantId(AuthUtil.getTenantId());
|
|
|
+ gdShip.setBizTypeName(OrderTypeEnum.FHGD.getType());
|
|
|
+ gdShip.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ gdShip.setCreateUser(AuthUtil.getUserId());
|
|
|
+ gdShip.setCreateTime(new Date());
|
|
|
+ gdShip.setTaskId(rwShip.getId());
|
|
|
+ gdShip.setSendTotalNum(new BigDecimal("0.00"));
|
|
|
+ pjShips.add(gdShip);
|
|
|
+ }
|
|
|
+ this.saveOrUpdateBatch(pjShips);
|
|
|
+ List<PjShipItems> shipItemsList = new ArrayList<>();
|
|
|
+ List<PjShip> rwShipList = new ArrayList<>();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String formatted = now.format(formatter);
|
|
|
+ for (PjShip item : pjShips) {
|
|
|
+ //获得出库任务数据
|
|
|
+ PjShip rwShip = pjShipList.stream().filter(e -> e.getId().equals(item.getTaskId())).findFirst().orElse(null);
|
|
|
+ if (rwShip == null) {
|
|
|
+ throw new RuntimeException("数据异常 请联系管理员");
|
|
|
+ }
|
|
|
+ StringBuilder goodsNames = new StringBuilder();
|
|
|
+
|
|
|
+ //根据销售id获得销售明细数据
|
|
|
+ List<PjOrderItems> list = pjOrderItemsList.stream().filter(e -> e.getPid().equals(item.getOrdId())).collect(Collectors.toList());
|
|
|
+ if (ObjectUtil.isNotEmpty(list)) {
|
|
|
+ for (PjOrderItems e : list) {
|
|
|
+ if (!stockDescList.isEmpty()) {
|
|
|
+ List<PjStockDesc> stockDescs = stockDescList.stream().filter(i -> i.getStorageId().equals(item.getStorageId())
|
|
|
+ && e.getGoodsId().equals(i.getGoodsId())).collect(Collectors.toList());
|
|
|
+ if (!stockDescs.isEmpty()) {
|
|
|
+ BigDecimal balanceQuantity = stockDescs.stream().map(PjStockDesc::getBalanceQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (new BigDecimal("0.00").compareTo(balanceQuantity) != 0) {
|
|
|
+ goodsNames.append(e.getGoodsName()).append(",");
|
|
|
+ //根据销售明细创建出库工单明细
|
|
|
+ PjShipItems shipItems = new PjShipItems();
|
|
|
+ BeanUtil.copyProperties(e, shipItems);
|
|
|
+ shipItems.setId(null);
|
|
|
+ shipItems.setPid(item.getId());
|
|
|
+ shipItems.setSrcItemId(e.getId());
|
|
|
+ shipItems.setCreateTime(new Date());
|
|
|
+ shipItems.setCreateUser(AuthUtil.getUserId());
|
|
|
+ shipItems.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ BigDecimal sendNum = e.getGoodsNum().subtract(e.getSendNum());
|
|
|
+ if (balanceQuantity.compareTo(sendNum) >= 0) {
|
|
|
+ shipItems.setSendNum(sendNum);
|
|
|
+ } else {
|
|
|
+ shipItems.setSendNum(balanceQuantity);
|
|
|
+ }
|
|
|
+ if (e.getGoodsNum().compareTo(e.getSendNum()) != 0) {
|
|
|
+ shipItemsList.add(shipItems);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.setNumberRows(list.size());
|
|
|
+ }
|
|
|
+ if (shipItemsList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到可用库存,请修改数据");
|
|
|
+ }
|
|
|
+ //修改出库任务状态
|
|
|
+ rwShip.setStatusName(OrderTypeEnum.DISPATCHED.getType());
|
|
|
+ rwShipList.add(rwShip);
|
|
|
+
|
|
|
+ //生成出库工单历史记录
|
|
|
+ saveHistory(item.getId(), OrderTypeEnum.TOBESHIPPEDOUT.getType());
|
|
|
+
|
|
|
+ //给角色为派工的人发送消息
|
|
|
+ if (ObjectUtils.isNotNull(rwShip.getStockClerkId())) {
|
|
|
+ Message sendMessage = new Message();
|
|
|
+ sendMessage.setParameter(item.getId() + "");
|
|
|
+ sendMessage.setUserName(AuthUtil.getUserName());
|
|
|
+ sendMessage.setUserId(null);
|
|
|
+ sendMessage.setToUserId(rwShip.getStockClerkId());
|
|
|
+ sendMessage.setToUserName(rwShip.getStockClerkName());
|
|
|
+ sendMessage.setMessageType(1);
|
|
|
+ sendMessage.setTenantId(AuthUtil.getTenantId());
|
|
|
+ sendMessage.setCreateUser(null);
|
|
|
+ sendMessage.setCreateTime(new Date());
|
|
|
+ sendMessage.setUrl("/tirePartsMall/salesManagement/outboundWorkOrder/index");
|
|
|
+ sendMessage.setPageLabel("出库工单");
|
|
|
+ sendMessage.setPageStatus("this.$store.getters.domSaleStatus");
|
|
|
+ sendMessage.setMessageBody("您有新的出库工单请及时处理!单号:" + item.getBillno() + "时间:" + formatted);
|
|
|
+ R save = messageClient.save(sendMessage);
|
|
|
+ System.out.println("发送结果:" + save);
|
|
|
+ if (!save.isSuccess()) {
|
|
|
+ throw new SecurityException("发送消息失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //给角色为派工的人发送消息
|
|
|
+ R<String> clientDeptIds = sysClient.getRoleIds(AuthUtil.getTenantId(), "库管");
|
|
|
+ if (clientDeptIds.isSuccess() && StringUtils.isNotBlank(clientDeptIds.getData())) {
|
|
|
+ R<List<User>> userList = userClient.listUserByRoleId(clientDeptIds.getData(), AuthUtil.getTenantId(), item.getSalesCompanyId() + "");
|
|
|
+ if (userList.isSuccess() && CollectionUtils.isNotEmpty(userList.getData())) {
|
|
|
+ for (User datum : userList.getData()) {
|
|
|
+ //循环发送消息
|
|
|
+ Message sendMessage = new Message();
|
|
|
+ sendMessage.setParameter(item.getId() + "");
|
|
|
+ sendMessage.setUserName(AuthUtil.getUserName());
|
|
|
+ sendMessage.setUserId(null);
|
|
|
+ sendMessage.setToUserId(datum.getId());
|
|
|
+ sendMessage.setToUserName(datum.getName());
|
|
|
+ sendMessage.setMessageType(1);
|
|
|
+ sendMessage.setTenantId(AuthUtil.getTenantId());
|
|
|
+ sendMessage.setCreateUser(null);
|
|
|
+ sendMessage.setCreateTime(new Date());
|
|
|
+ sendMessage.setUrl("/tirePartsMall/salesManagement/outboundWorkOrder/index");
|
|
|
+ sendMessage.setPageLabel("出库工单");
|
|
|
+ sendMessage.setPageStatus("this.$store.getters.domSaleStatus");
|
|
|
+ sendMessage.setMessageBody("您有新的出库工单请及时处理!单号:" + item.getBillno() + "时间:" + formatted);
|
|
|
+ R save = messageClient.save(sendMessage);
|
|
|
+ System.out.println("发送结果:" + save);
|
|
|
+ if (!save.isSuccess()) {
|
|
|
+ throw new SecurityException("发送消息失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //给角色为财务的人发送消息
|
|
|
+ StringBuilder openIds = new StringBuilder();
|
|
|
+ R<String> clientDeptIds = sysClient.getRoleIds(AuthUtil.getTenantId(), "客服");
|
|
|
+ if (clientDeptIds.isSuccess() && StringUtils.isNotBlank(clientDeptIds.getData())) {
|
|
|
+ R<List<User>> userList = userClient.listUserByRoleId(clientDeptIds.getData(), AuthUtil.getTenantId(), rwShip.getSalesCompanyId() + "");
|
|
|
+ if (userList.isSuccess() && CollectionUtils.isNotEmpty(userList.getData())) {
|
|
|
+ for (User datum : userList.getData()) {
|
|
|
+ if (ObjectUtils.isNotNull(datum.getOaOpenId())) {
|
|
|
+ openIds.append(datum.getOaOpenId()).append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(rwShip.getStockClerkId())) {
|
|
|
+ R<User> resUser = userClient.userInfoById(rwShip.getStockClerkId());
|
|
|
+ if (resUser.isSuccess() && ObjectUtils.isNotNull(resUser.getData())) {
|
|
|
+ if (ObjectUtils.isNotNull(resUser.getData().getOaOpenId())) {
|
|
|
+ openIds.append(resUser.getData().getOaOpenId()).append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
|
|
+ String date1 = format.format(new Date());
|
|
|
+ System.out.println("=========发送人openIds=========" + openIds);
|
|
|
+ if (ObjectUtils.isNotNull(openIds)) {
|
|
|
+ R<List<WechatMessageConfigurationItem>> res = wechatClient.getTemplateType("1", AuthUtil.getTenantId());
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
+ item.setDate(date1);
|
|
|
+ if (goodsNames.length() > 8) {
|
|
|
+ item.setGoodsNames(goodsNames.substring(0, 8));
|
|
|
+ } else {
|
|
|
+ item.setGoodsNames(goodsNames.toString());
|
|
|
+ }
|
|
|
+ if (item.getCustomerName().length() > 8) {
|
|
|
+ item.setCustomerName(item.getCustomerName().substring(0, 8));
|
|
|
+ }
|
|
|
+ List<WxMpTemplateData> data = new ArrayList<>();
|
|
|
+ for (WechatMessageConfigurationItem items : res.getData()) {
|
|
|
+ try {
|
|
|
+ // 根据方法名获取对应的Method对象
|
|
|
+ Method method = item.getClass().getMethod(items.getMethod());
|
|
|
+ // 调用get方法并打印结果
|
|
|
+ Object result = method.invoke(item);
|
|
|
+ System.out.println(result);
|
|
|
+ if (ObjectUtils.isNotNull(result)) {
|
|
|
+ data.add(new WxMpTemplateData(items.getDataValue(), result.toString()));
|
|
|
+ } else {
|
|
|
+ data.add(new WxMpTemplateData(items.getDataValue(), "无"));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!data.isEmpty()) {
|
|
|
+ WxMpTemplateDto wxMpTemplateDto = new WxMpTemplateDto();
|
|
|
+ wxMpTemplateDto.setOpenid(openIds.substring(0, openIds.length() - 1));
|
|
|
+ wxMpTemplateDto.setTenantId(AuthUtil.getTenantId());
|
|
|
+ wxMpTemplateDto.setType("1");
|
|
|
+ wxMpTemplateDto.setData(data);
|
|
|
+ String rest = wechatClient.sendMessageNew(wxMpTemplateDto);
|
|
|
+ System.out.println("=========发送返回值=========" + rest);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*// 创建线程池
|
|
|
+ ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
|
+ // 启动任务并提交给线程池
|
|
|
+ executor.submit(() -> {
|
|
|
+ try {
|
|
|
+ this.sendMessage(rwShip, item, goodsNames, 1);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("业务处理成功,发送消息异常,时间:" + new Date());
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ // 关闭线程池
|
|
|
+ executor.shutdown();
|
|
|
+ } finally {
|
|
|
+ // 关闭线程池
|
|
|
+ executor.shutdown();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 关闭线程池
|
|
|
+ executor.shutdown();*/
|
|
|
+ }
|
|
|
+ this.saveOrUpdateBatch(rwShipList);
|
|
|
+ shipItemsService.saveOrUpdateBatch(shipItemsList);
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
}
|