费用计算;

This commit is contained in:
王奎兴
2026-04-03 09:11:16 +08:00
parent 571c41f6fe
commit 4fe5febdb0
6 changed files with 168 additions and 8 deletions
+7 -2
View File
@@ -104,7 +104,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<!-- JEP 动态计算 -->
<dependency>
<groupId>jep</groupId>
<artifactId>jep</artifactId>
<version>2.24</version>
</dependency>
<!-- JPush推送 -->
<!-- jpush极光推送导入start -->
@@ -163,4 +168,4 @@
</profile>
</profiles>
</project>
</project>
@@ -19,8 +19,7 @@ import com.mhd.basic.domain.contractManageDetail.repository.todo.ContractManageD
import com.mhd.basic.domain.contractManageDetail.service.ContractManageDetailDomainService;
import com.mhd.basic.domain.expenseAccount.repository.po.ExpenseAccountPO;
import com.mhd.basic.domain.expenseAccount.service.ExpenseAccountDomainService;
import com.mhd.basic.interfaces.dto.contractManage.ContractManageDTO;
import com.mhd.basic.interfaces.dto.contractManage.SubjectAndPriceDTO;
import com.mhd.basic.interfaces.dto.contractManage.*;
import com.mhd.basic.interfaces.dto.contractManageDetail.ContractManageDetailDTO;
import com.mhd.common.core.domain.po.*;
import com.mhd.common.core.enums.DictCode;
@@ -44,6 +43,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -129,6 +129,54 @@ public class ContractManageApplicationService {
return contractManageDomainService.queryList(contractManageDO);
}
public BigDecimal getAmount(List<SubjectAndPriceReturn> subjectAndPriceReturnList) {
if (subjectAndPriceReturnList == null || subjectAndPriceReturnList.size() == 1) {
SubjectAndPriceReturn subjectAndPriceReturn = subjectAndPriceReturnList.get(0);
Long billingRulesId = subjectAndPriceReturn.getBillingRulesId();
String name = subjectAndPriceReturn.getName();
BillingRulesPO billingRule = contractManageDetailMapper.getBillingRules(billingRulesId);
List<BillingParamsPO> billingParams = contractManageDetailMapper.getBillingParams(billingRulesId);
if (billingParams != null && billingParams.size() > 0) {
BillingParamsPO billingParam = billingParams.get(0);
String billingParamsJson = billingParam.getBillingParamsJson();
String preSetRules = billingParam.getPreSetRules();
List<Map<String, Object>> preSetRulesList = JSON.parseObject(preSetRules, new TypeReference<List<Map<String, Object>>>() {
});
List<Map<String, Object>> billingParamsList = JSON.parseObject(billingParamsJson, new TypeReference<List<Map<String, Object>>>() {
});
if (billingParamsList != null && billingParamsList.size() ==2) {
Map<String, Object> targetMap = billingParamsList.stream()
.filter(map -> name.equals(map.get("fieldsName"))) // 关键匹配条件
.findFirst() // 取第一个
.orElse(null); // 没找到返回null
String chargingId = (String) targetMap.get("chargingId");
Integer sort = (Integer) targetMap.get("sort");
Map<String, Object> reles = preSetRulesList.get(0);
String price = (String) reles.get("fields"+sort);
String billingFormula = billingRule.getBillingFormula();
billingFormula.replace(chargingId, price);
//需要判断阶梯类型进行获取各计费标志的取值,拼接公式
List<BillingParamsDetailDTO> billingParamsEntityList = JSON.parseArray(billingParamsJson, BillingParamsDetailDTO.class);
//将计费参数实体分成两组,即:固定参数和条件参数
List<BillingParamsDetailDTO> fixedParamsEntityList = billingParamsEntityList.stream().filter(item -> ObjectUtil.equal(item.getLadderType(),1)).collect(Collectors.toList());
List<BillingParamsDetailDTO> ladderParamsEntityList = billingParamsEntityList.stream().filter(item -> !ObjectUtil.equal(item.getLadderType(),1)).collect(Collectors.toList());
if (ladderParamsEntityList != null && ladderParamsEntityList.size() > 0) {
if (subjectAndPriceReturn.getNum() != null) {
for (BillingParamsDetailDTO ladderParamsEntity : ladderParamsEntityList) {
Integer sort1 = ladderParamsEntity.getSort();
billingFormula.replace("fields"+sort1, subjectAndPriceReturn.getNum().toEngineeringString());
}
}
}
return DynamicCalculationUtil.calculate(billingFormula);
} else {
}
}
}
return null;
}
public List<Map<String, Object>> getSubjectAndPrice(SubjectAndPriceDTO contractManageDTO) {
List<Map<String, Object>> result = new ArrayList<>();
Long settlementCustomersId = contractManageDTO.getSettlementCustomersId();
@@ -178,11 +226,14 @@ public class ContractManageApplicationService {
Map<String, Object> subjectAndPrice = new HashMap<>();
Integer sort = (Integer) stringObjectMap.get("sort");
String chargingId = (String) stringObjectMap.get("chargingId");
String fields = (String) stringObjectMap.get("fields");
String price = (String) stringObjectMap1.get("fields" + sort);
subjectAndPrice.put("name", fieldsName);
subjectAndPrice.put("price", price);
subjectAndPrice.put("chargingId", chargingId);
subjectAndPrice.put("billingRulesId", billingRulesId);
SubjectAndPriceReturn subjectAndPriceReturn = new SubjectAndPriceReturn();
subjectAndPriceReturn.setName(fieldsName);
subjectAndPriceReturn.setPrice(new BigDecimal(price));
subjectAndPriceReturn.setChargingId(chargingId);
subjectAndPriceReturn.setFields(fields);
subjectAndPriceReturn.setBillingRulesId(billingRulesId);
result.add(subjectAndPrice);
}
}
@@ -0,0 +1,36 @@
package com.mhd.basic.interfaces.dto.contractManage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 计费参数json实体
*/
@Data
public class BillingParamsDetailDTO {
private static final long serialVersionUID = 1L;
@ApiModelProperty("字段名称")
private String fields;
@ApiModelProperty("计费标识P1、P2")
private String chargingId;
@ApiModelProperty("阶梯类型(1-固定参数,2-无阶梯,3-到达阶梯,4-累进阶梯)")
private Integer ladderType;
@ApiModelProperty("1-左开右闭,2-左闭右开")
private Integer ladderRule;
@ApiModelProperty("阶梯值")
private String ladderNum;
@ApiModelProperty("标志值")
private String flagValue;
@ApiModelProperty("排序")
private Integer sort;
}
@@ -0,0 +1,41 @@
package com.mhd.basic.interfaces.dto.contractManage;
import lombok.extern.slf4j.Slf4j;
import org.nfunk.jep.JEP;
import java.math.BigDecimal;
/**
* JEP动态计算
**/
@Slf4j
public class DynamicCalculationUtil {
/**
* 动态计算
* @param formula 计算公式
* @return 计算结果
*/
public static BigDecimal calculate(String formula) {
try {
// 创建 JEP 实例
JEP jep = new JEP();
// 设置要计算的表达式
jep.parseExpression(formula);
// 计算表达式的结果
double result = jep.getValue();
// 将结果转换为 BigDecimal
return new BigDecimal(result);
} catch (Exception e) {
// 处理可能的异常
log.error("动态计算失败:"+e.getMessage());
}
return BigDecimal.ZERO;
}
}
@@ -0,0 +1,15 @@
package com.mhd.basic.interfaces.dto.contractManage;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class SubjectAndPriceReturn {
private String name;
private BigDecimal price;
private String chargingId;
private Long billingRulesId;
private String fields;
private BigDecimal num;
}
@@ -4,6 +4,7 @@ import java.util.List;
import com.mhd.basic.interfaces.assember.contractManage.ContractManageAssembler;
import com.mhd.basic.interfaces.dto.contractManage.SubjectAndPriceDTO;
import com.mhd.basic.interfaces.dto.contractManage.SubjectAndPriceReturn;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -58,6 +59,17 @@ public class ContractManageApi extends BaseController{
return AjaxResult.success(contractManageApplicationService.getSubjectAndPrice(subjectAndPriceDTO));
}
/**
* 获取科目和单价
*/
@ApiOperation("获取科目和单价")
@PostMapping("/getAmount")
public AjaxResult getAmount(@RequestBody List<SubjectAndPriceReturn> subjectAndPriceReturnList)
{
//转换实体
return AjaxResult.success(contractManageApplicationService.getAmount(subjectAndPriceReturnList));
}
/**
* 保存合同管理
*/