|
@@ -494,16 +494,120 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
|
|
|
Page<ContractBudgetVo> page = this.baseMapper.getProfitBudgetPage(dto.getPage(), wrapper);
|
|
Page<ContractBudgetVo> page = this.baseMapper.getProfitBudgetPage(dto.getPage(), wrapper);
|
|
List<ContractBudgetVo> list = page.getRecords();
|
|
List<ContractBudgetVo> list = page.getRecords();
|
|
- if (CollectionUtils.isNotEmpty(list)) {
|
|
|
|
- // 赋值客户名称
|
|
|
|
-// customerService.attributeAssign(list, Contract::getBuyCorporationId, (item, customer) -> {
|
|
|
|
-// item.setCustomerName(customer.getName());
|
|
|
|
-// });
|
|
|
|
- statisticCommon(list);
|
|
|
|
|
|
+ if (ObjectUtil.isEmpty(list)) {
|
|
|
|
+ return page;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //计数预算信息
|
|
|
|
+ statisticCommon(list);
|
|
|
|
+
|
|
|
|
+ //计数历史毛利率图
|
|
|
|
+ setGrossProfitInfoList(list);
|
|
|
|
+
|
|
return page;
|
|
return page;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取合同历史版本毛利信息
|
|
|
|
+ */
|
|
|
|
+ private void setGrossProfitInfoList(List<ContractBudgetVo> list) {
|
|
|
|
+ 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()));
|
|
|
|
+
|
|
|
|
+ List<EhsdPurchase> ehsdPurchaseList = ehsdPurchaseService.list(q -> q.in(EhsdPurchase::getDataResourceId, allContractIds));
|
|
|
|
+
|
|
|
|
+ for (ContractBudgetVo contractBudgetVo : list) {
|
|
|
|
+ Long contractId = contractBudgetVo.getContractId();
|
|
|
|
+
|
|
|
|
+ //递归出所有子合同
|
|
|
|
+ List<Contract> arr = new ArrayList<>();
|
|
|
|
+ Long oldContractId = contractId;
|
|
|
|
+ while (ObjectUtil.isNotEmpty(oldContractId)) {
|
|
|
|
+ Contract contract = contractMap.get(oldContractId);
|
|
|
|
+ if (ObjectUtil.isNotEmpty(contract)) {
|
|
|
|
+ oldContractId = contract.getOldContractId();
|
|
|
|
+ arr.add(contract);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Long> collect = arr.stream().map(Contract::getId).collect(Collectors.toList());
|
|
|
|
+ List<EhsdPurchase> ehsdPurchaseList1 = ehsdPurchaseList.stream()
|
|
|
|
+ .filter(item -> collect.contains(item.getDataResourceId())).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ //合并两个结果
|
|
|
|
+ List<ContractBudgetVo.GrossProfitInfo> grossProfitInfoList = new ArrayList<>();
|
|
|
|
+ for (Contract contract : arr) {
|
|
|
|
+ ContractBudgetVo.GrossProfitInfo grossProfitInfo = new ContractBudgetVo.GrossProfitInfo();
|
|
|
|
+ grossProfitInfo.setContractAmount(contract.getAmount());
|
|
|
|
+ grossProfitInfo.setCreateTime(contract.getCreateTime());
|
|
|
|
+ grossProfitInfoList.add(grossProfitInfo);
|
|
|
|
+ }
|
|
|
|
+ for (EhsdPurchase ehsdPurchase : ehsdPurchaseList1) {
|
|
|
|
+ ContractBudgetVo.GrossProfitInfo grossProfitInfo = new ContractBudgetVo.GrossProfitInfo();
|
|
|
|
+ grossProfitInfo.setPurchaseAmount(ehsdPurchase.getAmount());
|
|
|
|
+ grossProfitInfo.setCreateTime(ehsdPurchase.getCreateTime());
|
|
|
|
+ grossProfitInfoList.add(grossProfitInfo);
|
|
|
|
+ }
|
|
|
|
+ grossProfitInfoList = grossProfitInfoList.stream()
|
|
|
|
+ .sorted(Comparator.comparing(ContractBudgetVo.GrossProfitInfo::getCreateTime)).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ //赋值信息
|
|
|
|
+ BigDecimal lastContractAmount = BigDecimal.ZERO;
|
|
|
|
+ BigDecimal lastPurchaseAmount = BigDecimal.ZERO;
|
|
|
|
+ for (ContractBudgetVo.GrossProfitInfo grossProfitInfo : grossProfitInfoList) {
|
|
|
|
+ BigDecimal contractAmount = grossProfitInfo.getContractAmount();
|
|
|
|
+ BigDecimal purchaseAmount = grossProfitInfo.getPurchaseAmount();
|
|
|
|
+ if (ObjectUtil.isEmpty(contractAmount)) {
|
|
|
|
+ grossProfitInfo.setContractAmount(lastContractAmount);
|
|
|
|
+ }
|
|
|
|
+ if (ObjectUtil.isEmpty(purchaseAmount)) {
|
|
|
|
+ grossProfitInfo.setPurchaseAmount(lastPurchaseAmount);
|
|
|
|
+ }
|
|
|
|
+ //赋值上次金额
|
|
|
|
+ lastContractAmount = grossProfitInfo.getContractAmount();
|
|
|
|
+ lastPurchaseAmount = grossProfitInfo.getPurchaseAmount();
|
|
|
|
+
|
|
|
|
+ //退税金额
|
|
|
|
+ BigDecimal refundableAmount = contractBudgetVo.getRefundableAmount();
|
|
|
|
+ BigDecimal incomeAmount = grossProfitInfo.getContractAmount().add(refundableAmount);
|
|
|
|
+
|
|
|
|
+ //计算支出总计 除合同金额(转人民币)+应退税金额(转人民币) 其他金额相加
|
|
|
|
+ BigDecimal expenditureAmount = contractBudgetVo.getTrailerFee() == null ? BigDecimal.ZERO : contractBudgetVo.getTrailerFee().add
|
|
|
|
+ (contractBudgetVo.getCustomsFee() == null ? BigDecimal.ZERO : contractBudgetVo.getCustomsFee()).add
|
|
|
|
+ (contractBudgetVo.getAgencyFee() == null ? BigDecimal.ZERO : contractBudgetVo.getAgencyFee()).add
|
|
|
|
+ (contractBudgetVo.getPortMixedFee() == null ? BigDecimal.ZERO : contractBudgetVo.getPortMixedFee()).add
|
|
|
|
+ (contractBudgetVo.getInspectionRedPack() == null ? BigDecimal.ZERO : contractBudgetVo.getInspectionRedPack()).add
|
|
|
|
+ (contractBudgetVo.getCommission() == null ? BigDecimal.ZERO : contractBudgetVo.getCommission()).add
|
|
|
|
+ (contractBudgetVo.getOther() == null ? BigDecimal.ZERO : contractBudgetVo.getOther());
|
|
|
|
+ expenditureAmount = expenditureAmount.add(grossProfitInfo.getPurchaseAmount() == null ? BigDecimal.ZERO : grossProfitInfo.getPurchaseAmount());
|
|
|
|
+
|
|
|
|
+ BigDecimal grossProfit = incomeAmount.subtract(expenditureAmount);
|
|
|
|
+ grossProfitInfo.setGross(grossProfit);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ contractBudgetVo.setGrossProfitInfoList(grossProfitInfoList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 递归合同历史版本
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<Contract> recursionOldContract(List<Long> contractIds) {
|
|
|
|
+ List<Contract> contract = this.list(q -> q.in(Contract::getId, contractIds));
|
|
|
|
+ List<Long> contractIds1 = contract.stream().map(Contract::getOldContractId).distinct()
|
|
|
|
+ .filter(item -> ObjectUtil.isNotEmpty(item)).collect(Collectors.toList());
|
|
|
|
+ if (ObjectUtil.isNotEmpty(contractIds1)) {
|
|
|
|
+ List<Contract> contractList = recursionOldContract(contractIds1);
|
|
|
|
+ contract.addAll(contractList);
|
|
|
|
+ }
|
|
|
|
+ return contract;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 利润预算表头部统计
|
|
* 利润预算表头部统计
|
|
*
|
|
*
|