|
@@ -541,10 +541,11 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
List<Long> contractIds = list.stream().map(ContractBudgetVo::getContractId).collect(Collectors.toList());
|
|
|
List<Contract> contractList = recursionOldContract(contractIds);
|
|
|
List<Long> allContractIds = contractList.stream().map(Contract::getId).collect(Collectors.toList());
|
|
|
- Map<Long, Contract> contractMap = contractList.stream().collect(Collectors.toMap(Contract::getId, Function.identity()));
|
|
|
+ Map<Long, Contract> contractMap = contractList.stream().collect(Collectors.groupingBy(Contract::getId,
|
|
|
+ Collectors.collectingAndThen(Collectors.toList(), value -> value.get(0))));
|
|
|
|
|
|
List<EhsdPurchase> ehsdPurchaseList = ehsdPurchaseService.list(q -> q.in(EhsdPurchase::getDataResourceId, allContractIds)
|
|
|
- .in(EhsdPurchase::getStatus, 10, 30, 60, 70, 99));
|
|
|
+ .in(EhsdPurchase::getStatus, 10, 30, 60, 70));
|
|
|
|
|
|
for (ContractBudgetVo contractBudgetVo : list) {
|
|
|
Long contractId = contractBudgetVo.getContractId();
|
|
@@ -574,42 +575,94 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
grossProfitInfo.setContractCurrency(contract.getCurrency());
|
|
|
grossProfitInfo.setContractRmbAmount(contract.getAmount().multiply(contract.getRate()));
|
|
|
grossProfitInfo.setCreateTime(contract.getCreateTime());
|
|
|
+ grossProfitInfo.setId(contract.getId());
|
|
|
+ grossProfitInfo.setType(1);
|
|
|
grossProfitInfoList.add(grossProfitInfo);
|
|
|
}
|
|
|
for (EhsdPurchase ehsdPurchase : ehsdPurchaseList1) {
|
|
|
ContractBudgetVo.GrossProfitInfo grossProfitInfo = new ContractBudgetVo.GrossProfitInfo();
|
|
|
grossProfitInfo.setPurchaseAmount(ehsdPurchase.getAmount());
|
|
|
grossProfitInfo.setCreateTime(ehsdPurchase.getCreateTime());
|
|
|
+ grossProfitInfo.setId(ehsdPurchase.getId());
|
|
|
+ grossProfitInfo.setOldPurchaseId(ehsdPurchase.getOldPurchaseId());
|
|
|
+ grossProfitInfo.setType(2);
|
|
|
grossProfitInfoList.add(grossProfitInfo);
|
|
|
}
|
|
|
+ //按时间升序
|
|
|
grossProfitInfoList = grossProfitInfoList.stream()
|
|
|
.sorted(Comparator.comparing(ContractBudgetVo.GrossProfitInfo::getCreateTime)).collect(Collectors.toList());
|
|
|
|
|
|
- //赋值信息
|
|
|
+ //计数采购价格
|
|
|
BigDecimal lastContractAmount = BigDecimal.ZERO;
|
|
|
String lastContractCurrency = "";
|
|
|
BigDecimal lastContractRmbAmount = BigDecimal.ZERO;
|
|
|
BigDecimal lastPurchaseAmount = BigDecimal.ZERO;
|
|
|
for (ContractBudgetVo.GrossProfitInfo grossProfitInfo : grossProfitInfoList) {
|
|
|
- BigDecimal contractRmbAmount = grossProfitInfo.getContractRmbAmount();
|
|
|
- BigDecimal purchaseAmount = grossProfitInfo.getPurchaseAmount();
|
|
|
- if (ObjectUtil.isEmpty(contractRmbAmount)) {
|
|
|
+ if (grossProfitInfo.getType() == 2) {
|
|
|
+ //如果是采购节点
|
|
|
+ BigDecimal purchaseAmount = BigDecimal.ZERO;
|
|
|
+ //获取当前节点之前的节点,并过滤出有效的数据
|
|
|
+// List<EhsdPurchase> oldPurchase = ehsdPurchaseService.list(q -> q
|
|
|
+// .eq(EhsdPurchase::getDataResourceId,contractBudgetVo.getContractId())
|
|
|
+// .lt(EhsdPurchase::getCreateTime, grossProfitInfo.getCreateTime())
|
|
|
+// .in(EhsdPurchase::getStatus, 10, 30, 60, 70));
|
|
|
+
|
|
|
+ List<EhsdPurchase> oldPurchase = ehsdPurchaseList.stream()
|
|
|
+ .filter(item -> item.getCreateTime().before(grossProfitInfo.getCreateTime()))
|
|
|
+ .filter(item -> item.getDataResourceId().equals(contractBudgetVo.getContractId()))
|
|
|
+ .sorted(Comparator.comparing(EhsdPurchase::getCreateTime))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<Long> oldIds = oldPurchase.stream().map(EhsdPurchase::getOldPurchaseId).collect(Collectors.toList());
|
|
|
+ for (EhsdPurchase ehsdPurchase : oldPurchase) {
|
|
|
+ //过滤掉历史节点中非有效节点 和 非当前节点父节点的数据
|
|
|
+ if (!oldIds.contains(ehsdPurchase.getId()) && !Objects.equals(ehsdPurchase.getId(), grossProfitInfo.getOldPurchaseId())) {
|
|
|
+ purchaseAmount = purchaseAmount.add(ehsdPurchase.getAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //当前节点采购金额加上之前的有效采购金额
|
|
|
+ purchaseAmount = purchaseAmount.add(grossProfitInfo.getPurchaseAmount());
|
|
|
+
|
|
|
grossProfitInfo.setContractAmount(lastContractAmount);
|
|
|
grossProfitInfo.setContractCurrency(lastContractCurrency);
|
|
|
grossProfitInfo.setContractRmbAmount(lastContractRmbAmount);
|
|
|
- }
|
|
|
- if (ObjectUtil.isEmpty(purchaseAmount)) {
|
|
|
+
|
|
|
+ grossProfitInfo.setPurchaseAmount(purchaseAmount);
|
|
|
+ lastPurchaseAmount = purchaseAmount;
|
|
|
+ } else {
|
|
|
+ //销售合同节点
|
|
|
+ lastContractAmount = grossProfitInfo.getContractAmount();
|
|
|
+ lastContractRmbAmount = grossProfitInfo.getContractRmbAmount();
|
|
|
+ lastContractCurrency = grossProfitInfo.getContractCurrency();
|
|
|
grossProfitInfo.setPurchaseAmount(lastPurchaseAmount);
|
|
|
}
|
|
|
- //赋值上次金额
|
|
|
- lastContractRmbAmount = grossProfitInfo.getContractRmbAmount();
|
|
|
- lastContractAmount = grossProfitInfo.getContractAmount();
|
|
|
- lastContractCurrency = grossProfitInfo.getContractCurrency();
|
|
|
- lastPurchaseAmount = grossProfitInfo.getPurchaseAmount();
|
|
|
-
|
|
|
+// }
|
|
|
+//
|
|
|
+// //赋值信息
|
|
|
+// BigDecimal lastContractAmount = BigDecimal.ZERO;
|
|
|
+// String lastContractCurrency = "";
|
|
|
+// BigDecimal lastContractRmbAmount = BigDecimal.ZERO;
|
|
|
+// BigDecimal lastPurchaseAmount = BigDecimal.ZERO;
|
|
|
+// for (ContractBudgetVo.GrossProfitInfo grossProfitInfo : grossProfitInfoList) {
|
|
|
+// BigDecimal contractRmbAmount = grossProfitInfo.getContractRmbAmount();
|
|
|
+// BigDecimal purchaseAmount = grossProfitInfo.getPurchaseAmount();
|
|
|
+// if (ObjectUtil.isEmpty(contractRmbAmount)) {
|
|
|
+// grossProfitInfo.setContractAmount(lastContractAmount);
|
|
|
+// grossProfitInfo.setContractCurrency(lastContractCurrency);
|
|
|
+// grossProfitInfo.setContractRmbAmount(lastContractRmbAmount);
|
|
|
+// }
|
|
|
+// //赋值上次金额
|
|
|
+// lastContractRmbAmount = grossProfitInfo.getContractRmbAmount();
|
|
|
+// lastContractAmount = grossProfitInfo.getContractAmount();
|
|
|
+// lastContractCurrency = grossProfitInfo.getContractCurrency();
|
|
|
+// lastPurchaseAmount = grossProfitInfo.getPurchaseAmount();
|
|
|
+
|
|
|
+
|
|
|
+ //计数毛利
|
|
|
|
|
|
//退税金额
|
|
|
BigDecimal refundableAmount = contractBudgetVo.getRefundableAmount();
|
|
|
+ //总收入
|
|
|
BigDecimal incomeAmount = grossProfitInfo.getContractRmbAmount().add(refundableAmount);
|
|
|
|
|
|
//计算支出总计 除合同金额(转人民币)+应退税金额(转人民币) 其他金额相加
|
|
@@ -623,7 +676,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
expenditureAmount = expenditureAmount.add(grossProfitInfo.getPurchaseAmount() == null ? BigDecimal.ZERO : grossProfitInfo.getPurchaseAmount());
|
|
|
|
|
|
BigDecimal grossProfit = incomeAmount.subtract(expenditureAmount);
|
|
|
- grossProfitInfo.setGross(grossProfit);
|
|
|
+ grossProfitInfo.setGross(grossProfit.setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
|
|
|
}
|
|
|
contractBudgetVo.setGrossProfitInfoList(grossProfitInfoList);
|