|
@@ -3,7 +3,10 @@ package com.fjhx.sale.service.statement.impl;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fjhx.account.entity.account.po.AccountRunningWater;
|
|
|
+import com.fjhx.account.service.account.AccountRunningWaterService;
|
|
|
import com.fjhx.common.entity.currency.po.CurrencyRate;
|
|
|
import com.fjhx.common.service.currency.CurrencyRateService;
|
|
|
import com.fjhx.customer.service.customer.CustomerService;
|
|
@@ -21,6 +24,7 @@ import com.fjhx.sale.service.claim.ClaimContractService;
|
|
|
import com.fjhx.sale.service.claim.ClaimService;
|
|
|
import com.fjhx.sale.service.contract.ContractService;
|
|
|
import com.fjhx.sale.service.statement.SaleStatementService;
|
|
|
+import com.github.pagehelper.util.StringUtil;
|
|
|
import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.system.utils.UserUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -50,6 +54,9 @@ public class SaleStatementServiceImpl implements SaleStatementService {
|
|
|
private ClaimContractService claimContractService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private AccountRunningWaterService accountRunningWaterService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private ClaimService claimService;
|
|
|
|
|
|
@Autowired
|
|
@@ -66,26 +73,22 @@ public class SaleStatementServiceImpl implements SaleStatementService {
|
|
|
if (records.size() == 0) {
|
|
|
return new Page<>();
|
|
|
}
|
|
|
-
|
|
|
- // 获取默认税率
|
|
|
- Map<String, BigDecimal> defaultRateMap = getDefaultRateMap();
|
|
|
-
|
|
|
- // 获取税率明细
|
|
|
- Map<Long, Map<String, BigDecimal>> detailsRateMap = getDetailsRateMap(records, defaultRateMap);
|
|
|
-
|
|
|
// 转换为vo
|
|
|
List<ProfitSettlementVo> list = createResultList(records);
|
|
|
-
|
|
|
// 赋值业务员名称
|
|
|
UserUtil.assignmentNickName(list, ProfitSettlementVo::getUserId, ProfitSettlementVo::setUserName);
|
|
|
-
|
|
|
// 赋值客户名称
|
|
|
customerService.attributeAssign(list, ProfitSettlementVo::getCustomerId, (item, customer) -> {
|
|
|
item.setCustomerName(customer.getName());
|
|
|
});
|
|
|
+ // 获取默认税率
|
|
|
+ Map<String, BigDecimal> defaultRateMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 获取税率明细
|
|
|
+ Map<Long, Map<String, BigDecimal>> detailsRateMap = getDetailsRateMap(records, defaultRateMap);
|
|
|
|
|
|
// 赋值合同到账
|
|
|
- setContractArrival(list, detailsRateMap);
|
|
|
+ setContractArrival(list);
|
|
|
|
|
|
// 赋值采购合同金额和支付货款
|
|
|
setPurchaseAmountAndPayForGoods(list, detailsRateMap);
|
|
@@ -120,9 +123,9 @@ public class SaleStatementServiceImpl implements SaleStatementService {
|
|
|
defaultRateMap.forEach(map::putIfAbsent);
|
|
|
|
|
|
} else {
|
|
|
- map = new HashMap<>(defaultRateMap);
|
|
|
-// map = new HashMap<>();
|
|
|
-// map.put(record.getCurrency(),record.getRate());
|
|
|
+// map = new HashMap<>(defaultRateMap);
|
|
|
+ map = new HashMap<>();
|
|
|
+ map.put(record.getCurrency(),record.getRate());
|
|
|
}
|
|
|
|
|
|
result.put(record.getId(), map);
|
|
@@ -177,63 +180,109 @@ public class SaleStatementServiceImpl implements SaleStatementService {
|
|
|
/**
|
|
|
* 赋值合同到账金额
|
|
|
*/
|
|
|
- private void setContractArrival(List<ProfitSettlementVo> list, Map<Long, Map<String, BigDecimal>> detailsRateMap) {
|
|
|
-
|
|
|
+ private void setContractArrival(List<ProfitSettlementVo> list) {
|
|
|
+
|
|
|
+// // 合同id
|
|
|
+// List<Long> contractIdList = list.stream().map(ProfitSettlementVo::getContractId).collect(Collectors.toList());
|
|
|
+//
|
|
|
+// // 根据合同id获取到账认领明细列表
|
|
|
+// List<ClaimContract> claimContractList = claimContractService.list(q ->
|
|
|
+// q.in(ClaimContract::getContractId, contractIdList));
|
|
|
+//
|
|
|
+// if (claimContractList.size() == 0) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 到账认领明细id列表
|
|
|
+// List<Long> claimIdList = claimContractList.stream()
|
|
|
+// .map(ClaimContract::getClaimId).distinct().collect(Collectors.toList());
|
|
|
+//
|
|
|
+// // 到账认领列表
|
|
|
+// List<Claim> claimList = claimService.listByIds(claimIdList);
|
|
|
+//
|
|
|
+// // 到账认领id 币种 map
|
|
|
+// Map<Long, String> claimIdCurrencyMap = claimList.stream()
|
|
|
+// .collect(Collectors.toMap(BaseIdPo::getId, Claim::getCurrency));
|
|
|
+//
|
|
|
+// // 合同id 到账认领明细列表 map
|
|
|
+// Map<Long, List<ClaimContract>> contractIdClaimContractListMap =
|
|
|
+// claimContractList.stream().collect(Collectors.groupingBy(ClaimContract::getContractId));
|
|
|
+//
|
|
|
+// for (ProfitSettlementVo profitSettlementVo : list) {
|
|
|
+//
|
|
|
+// // 合同id
|
|
|
+// Long contractId = profitSettlementVo.getContractId();
|
|
|
+//
|
|
|
+// // 到账认领
|
|
|
+// List<ClaimContract> itemClaimContractList = contractIdClaimContractListMap.getOrDefault(contractId, new ArrayList<>());
|
|
|
+//
|
|
|
+// // 汇率币种map
|
|
|
+// Map<String, BigDecimal> map = detailsRateMap.get(contractId);
|
|
|
+//
|
|
|
+// BigDecimal contractArrival = itemClaimContractList.stream().map(claimContract -> {
|
|
|
+//
|
|
|
+// // 根据到账认领id获取币种
|
|
|
+// String currency = claimIdCurrencyMap.get(claimContract.getClaimId());
|
|
|
+//
|
|
|
+// // 根据币种获取汇率
|
|
|
+// BigDecimal rate = map.getOrDefault(currency, BigDecimal.ONE);
|
|
|
+//
|
|
|
+// // 获取认领金额
|
|
|
+// BigDecimal money = claimContract.getMoney();
|
|
|
+//
|
|
|
+// // 返回兑人民币后金额
|
|
|
+// return rate.multiply(money);
|
|
|
+//
|
|
|
+// }).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+//
|
|
|
+// profitSettlementVo.setContractArrival(contractArrival);
|
|
|
+//
|
|
|
+// }
|
|
|
// 合同id
|
|
|
List<Long> contractIdList = list.stream().map(ProfitSettlementVo::getContractId).collect(Collectors.toList());
|
|
|
-
|
|
|
- // 根据合同id获取到账认领明细列表
|
|
|
- List<ClaimContract> claimContractList = claimContractService.list(q ->
|
|
|
- q.in(ClaimContract::getContractId, contractIdList));
|
|
|
-
|
|
|
- if (claimContractList.size() == 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 到账认领明细id列表
|
|
|
- List<Long> claimIdList = claimContractList.stream()
|
|
|
- .map(ClaimContract::getClaimId).distinct().collect(Collectors.toList());
|
|
|
-
|
|
|
- // 到账认领列表
|
|
|
- List<Claim> claimList = claimService.listByIds(claimIdList);
|
|
|
-
|
|
|
- // 到账认领id 币种 map
|
|
|
- Map<Long, String> claimIdCurrencyMap = claimList.stream()
|
|
|
- .collect(Collectors.toMap(BaseIdPo::getId, Claim::getCurrency));
|
|
|
-
|
|
|
- // 合同id 到账认领明细列表 map
|
|
|
- Map<Long, List<ClaimContract>> contractIdClaimContractListMap =
|
|
|
- claimContractList.stream().collect(Collectors.groupingBy(ClaimContract::getContractId));
|
|
|
-
|
|
|
- for (ProfitSettlementVo profitSettlementVo : list) {
|
|
|
-
|
|
|
- // 合同id
|
|
|
- Long contractId = profitSettlementVo.getContractId();
|
|
|
-
|
|
|
- // 到账认领
|
|
|
- List<ClaimContract> itemClaimContractList = contractIdClaimContractListMap.getOrDefault(contractId, new ArrayList<>());
|
|
|
-
|
|
|
- // 汇率币种map
|
|
|
- Map<String, BigDecimal> map = detailsRateMap.get(contractId);
|
|
|
-
|
|
|
- BigDecimal contractArrival = itemClaimContractList.stream().map(claimContract -> {
|
|
|
-
|
|
|
- // 根据到账认领id获取币种
|
|
|
- String currency = claimIdCurrencyMap.get(claimContract.getClaimId());
|
|
|
-
|
|
|
- // 根据币种获取汇率
|
|
|
- BigDecimal rate = map.getOrDefault(currency, BigDecimal.ONE);
|
|
|
-
|
|
|
- // 获取认领金额
|
|
|
- BigDecimal money = claimContract.getMoney();
|
|
|
-
|
|
|
- // 返回兑人民币后金额
|
|
|
- return rate.multiply(money);
|
|
|
-
|
|
|
- }).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-
|
|
|
- profitSettlementVo.setContractArrival(contractArrival);
|
|
|
-
|
|
|
+ //通过合同ID查询到账认领合同的数据
|
|
|
+ List<ClaimContract> claimContractList = claimContractService.getListByContractIds(contractIdList);
|
|
|
+ Map<Long,List<ClaimContract>> claimContractMap = claimContractList.stream().collect(Collectors.groupingBy(ClaimContract::getContractId));
|
|
|
+ for(ProfitSettlementVo p:list){
|
|
|
+ if(StringUtil.isNotEmpty(p.getCurrencyRateJson())){//取设置的汇率
|
|
|
+ List<CurrencyRate> assignCurrencyRatesList = JSON.parseArray(p.getCurrencyRateJson(), CurrencyRate.class);
|
|
|
+ Map<String, BigDecimal> assignCurrencyRatesMap = assignCurrencyRatesList.stream().collect(Collectors.toMap(CurrencyRate::getType, CurrencyRate::getRate));
|
|
|
+ /**
|
|
|
+ * 处理到账金额
|
|
|
+ */
|
|
|
+ List<ClaimContract> cList = claimContractMap.getOrDefault(p.getContractId(),null);
|
|
|
+ List<BigDecimal> sumArrayMoney = new ArrayList<>();
|
|
|
+ BigDecimal contractArrival = cList.stream().map(claimContract -> {
|
|
|
+ //获取汇率
|
|
|
+ BigDecimal rate = assignCurrencyRatesMap.getOrDefault(claimContract.getCurrency(),BigDecimal.ONE);
|
|
|
+ // 获取认领金额
|
|
|
+ BigDecimal money = claimContract.getMoney();
|
|
|
+ // 返回兑人民币后金额
|
|
|
+ return rate.multiply(money);
|
|
|
+ }).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ p.setContractArrival(contractArrival);
|
|
|
+ /**
|
|
|
+ * 处理合同金额
|
|
|
+ */
|
|
|
+ }else{//取数据汇率
|
|
|
+ /**
|
|
|
+ * 处理到账金额
|
|
|
+ */
|
|
|
+ List<ClaimContract> cList = claimContractMap.getOrDefault(p.getContractId(),null);
|
|
|
+ List<Long> warterIds = cList.stream().distinct().map(ClaimContract::getBusinessId).collect(Collectors.toList());
|
|
|
+ //查出流水
|
|
|
+ List<AccountRunningWater> accountRunningWaterList = accountRunningWaterService.list(Wrappers.<AccountRunningWater>query().lambda().select(AccountRunningWater::getRate,AccountRunningWater::getId).in(AccountRunningWater::getId,warterIds));
|
|
|
+ Map<Long,BigDecimal> waterMap = accountRunningWaterList.stream().collect(Collectors.toMap(AccountRunningWater::getId, AccountRunningWater::getRate));
|
|
|
+ BigDecimal contractArrival = cList.stream().map(claimContract -> {
|
|
|
+ //获取汇率
|
|
|
+ BigDecimal rate = waterMap.getOrDefault(claimContract.getBusinessId(),BigDecimal.ONE);
|
|
|
+ // 获取认领金额
|
|
|
+ BigDecimal money = claimContract.getMoney();
|
|
|
+ // 返回兑人民币后金额
|
|
|
+ return rate.multiply(money);
|
|
|
+ }).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ p.setContractArrival(contractArrival);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|