|
|
@@ -252,6 +252,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
if (CollectionUtils.isNotEmpty(ship.getShipItemsList())) {
|
|
|
List<PjShipItems> shipItemsList = new ArrayList<>();
|
|
|
ship.getShipItemsList().forEach(item -> {
|
|
|
+ item.setCostprie(item.getSendNum().multiply(item.getCostpriePrice()));
|
|
|
if (item.getId() == null) {
|
|
|
item.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
item.setCreateTime(new Date());
|
|
|
@@ -499,6 +500,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
if (!data.isEmpty()) {
|
|
|
@@ -678,6 +680,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
if (!data.isEmpty()) {
|
|
|
@@ -791,6 +794,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
);
|
|
|
StringBuilder msg1 = new StringBuilder();
|
|
|
for (PjShipItems item : ship.getShipItemsList()) {
|
|
|
+ item.setCostprie(item.getSendNum().multiply(item.getCostpriePrice()));
|
|
|
number = number.add(item.getSendNum());
|
|
|
if (item.getId() == null) {
|
|
|
item.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
@@ -849,11 +853,11 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
if (orderItems != null) {
|
|
|
if (ObjectUtils.isNull(orderItems.getCostprie()) || new BigDecimal("0.00").compareTo(orderItems.getCostprie()) == 0) {
|
|
|
orderItems.setCostprie(stockOne.getInventoryCostPrice().multiply(orderItems.getGoodsNum()));
|
|
|
- orderItems.setGrossProfit(item.getSubTotalMoney().subtract(orderItems.getCostprie()));
|
|
|
+ orderItems.setGrossProfit(orderItems.getSubTotalMoney().subtract(orderItems.getCostprie()));
|
|
|
}
|
|
|
if (ObjectUtils.isNull(orderItems.getRebateCostprie()) || new BigDecimal("0.00").compareTo(orderItems.getRebateCostprie()) == 0) {
|
|
|
orderItems.setRebateCostprie(stockOne.getRebatePrice().multiply(orderItems.getGoodsNum()));
|
|
|
- orderItems.setRebateProfit(item.getSubTotalMoney().subtract(orderItems.getRebateCostprie()));
|
|
|
+ orderItems.setRebateProfit(orderItems.getSubTotalMoney().subtract(orderItems.getRebateCostprie()));
|
|
|
}
|
|
|
if (orderItems.getGoodsNum().compareTo(orderItems.getSendNum().add(item.getSendNum())) < 0) {
|
|
|
throw new RuntimeException(orderItems.getGoodsName() + "剩余应发货数量" + orderItems.getGoodsNum().subtract(orderItems.getSendNum()));
|
|
|
@@ -931,6 +935,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
orderMapper.updateById(order);
|
|
|
}
|
|
|
}
|
|
|
+ //融资流程
|
|
|
if (ObjectUtils.isNotNull(status) && "1".equals(status)) {
|
|
|
String firstProportion = sysClient.getParamService("first.month.proportion");
|
|
|
String secondProportion = sysClient.getParamService("second.month.proportion");
|
|
|
@@ -945,6 +950,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
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)
|
|
|
@@ -957,6 +963,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
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)
|
|
|
@@ -986,13 +993,17 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
List<FinancingShipItemDto> allList = new ArrayList<>();
|
|
|
List<ShipItemsRecord> recordList = new ArrayList<>();
|
|
|
List<PjOrderItems> orderItemList1 = new ArrayList<>();
|
|
|
+ //出库明细循环
|
|
|
for (PjShipItems shipItems : shipItemsList) {
|
|
|
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<>();
|
|
|
+ //采购商品明细循环
|
|
|
for (PjOrderItems orderItems1 : orderItemList) {
|
|
|
if (number.compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ //记录出库明细对应融资采购单据
|
|
|
ShipItemsRecord shipItemsRecord = new ShipItemsRecord();
|
|
|
shipItemsRecord.setBillNo(ship.getBillno());
|
|
|
shipItemsRecord.setPid(shipItems.getPid());
|
|
|
@@ -1003,16 +1014,20 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
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 (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.setOutGoodsTotalShipAmount(orderItems1.getOutGoodsTotalShipNum().multiply(orderItems1.getPrice()));
|
|
|
number = number.subtract(subNum);
|
|
|
@@ -1021,6 +1036,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
financingShipItemDto.setAmount(subNum.multiply(orderItems1.getPrice()));
|
|
|
shipItemsRecord.setNum(subNum);
|
|
|
shipItemsRecord.setAmount(subNum.multiply(orderItems1.getPrice()));
|
|
|
+ //本次出库数量等于剩余数量 融资采购明细出库数量=入库数量
|
|
|
orderItems1.setOutGoodsTotalShipNum(orderItems1.getSendNum());
|
|
|
orderItems1.setOutGoodsTotalShipAmount(orderItems1.getOutGoodsTotalShipNum().multiply(orderItems1.getPrice()));
|
|
|
number = new BigDecimal("0.00");
|
|
|
@@ -1029,6 +1045,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
financingShipItemDto.setAmount(number.multiply(orderItems1.getPrice()));
|
|
|
shipItemsRecord.setNum(number);
|
|
|
shipItemsRecord.setAmount(number.multiply(orderItems1.getPrice()));
|
|
|
+ //本次出库数量小于剩余数量 融资采购明细出库数量=入库数量-本次出库数量
|
|
|
orderItems1.setOutGoodsTotalShipNum(orderItems1.getOutGoodsTotalShipNum().add(number));
|
|
|
orderItems1.setOutGoodsTotalShipAmount(orderItems1.getOutGoodsTotalShipNum().multiply(orderItems1.getPrice()));
|
|
|
number = new BigDecimal("0.00");
|
|
|
@@ -1044,7 +1061,8 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
String jsonString = mapper.writeValueAsString(mapList);
|
|
|
shipItems.setSrcFinancing(jsonString);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ System.err.println(e.getMessage());
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
allList.addAll(mapList);
|
|
|
}
|
|
|
@@ -1055,26 +1073,33 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
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::getOutGoodsTotalShipNum)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add)));
|
|
|
items.setOutGoodsTotalShipAmount(items.getOutGoodsTotalShipAmount().add(pjOrderItems.stream().map(PjOrderItems::getOutGoodsTotalShipAmount)
|
|
|
.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) {
|
|
|
@@ -1086,18 +1111,23 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
}
|
|
|
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);
|
|
|
@@ -1131,15 +1161,19 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
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());
|
|
|
@@ -2795,6 +2829,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
shipItems.setSrcFinancing(jsonString);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
allList.addAll(mapList);
|
|
|
}
|
|
|
@@ -3808,6 +3843,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
shipItems.setSrcFinancing(jsonString);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
allList.addAll(mapList);
|
|
|
}
|
|
|
@@ -5105,6 +5141,7 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
} else {
|
|
|
throw new RuntimeException("access_token获取失败");
|
|
|
@@ -5114,8 +5151,8 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
- return R.data("操作成功");
|
|
|
}
|
|
|
|
|
|
}
|