Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
zhou-hongcheng
2026-03-18 19:09:28 +08:00
7 changed files with 231 additions and 7 deletions
@@ -22,7 +22,7 @@ public class BillingScheduler {
private ScheduledTaskService scheduledTaskService; private ScheduledTaskService scheduledTaskService;
// 每10秒扫描一次 // 每10秒扫描一次
//@Scheduled(fixedDelay = 10000) @Scheduled(fixedDelay = 10000)
@Transactional @Transactional
public void scanAndExecute() { public void scanAndExecute() {
// 查询当前时间前1分钟内待执行的任务 // 查询当前时间前1分钟内待执行的任务
@@ -109,6 +109,24 @@ public class CostCalculationApplicationService {
return result; return result;
} }
/**
* 费用计算器
*/
public BillingCostPo setComputationalCost(CostCalculationDTO costCalculationDTO) {
/* 1:根据合同编码查询合同并根据费用科目,获取计费策略,查询计费策略计算对应的字段,判断传来的计费参数必填项是否完整
2:根据计费策略公式进行替换,并根据配置的公式计算结果
*/
BillingCostPo result = new BillingCostPo();
BeanUtils.copyProperties(costCalculationDTO, result);
TaskFlowRecordsDO taskFlowRecordsDO = new TaskFlowRecordsDO();
//第一步 根据合同编码查询合同并根据费用科目,获取计费策略,查询计费策略计算对应的字段,判断传来的计费参数必填项是否完整
BillingRulesPO billingRulesPO = chooseBillingParams(costCalculationDTO,taskFlowRecordsDO);
//第二步 根据计费策略公式进行替换,并根据配置的公式计算结果
BigDecimal computationalCost = computational(billingRulesPO,costCalculationDTO,taskFlowRecordsDO);
result.setComputationalCost(computationalCost);
return result;
}
@Autowired @Autowired
private IDocumentTypeService documentTypeService; private IDocumentTypeService documentTypeService;
/** /**
@@ -370,4 +388,4 @@ public class CostCalculationApplicationService {
} }
} }
@@ -177,6 +177,43 @@ public class BusinessDocumentApplicationService {
return businessDocumentDomainService.insert(businessDocumentDO); return businessDocumentDomainService.insert(businessDocumentDO);
} }
/**
* 新增业务单据
*/
public BusinessDocumentDO getEstimatedCost(BusinessDocumentDO businessDocumentDO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (ObjectUtil.isNull(loginUser)) {
throw new DigitalLogisticsException(UserError.TIMEOUT);
}
//先设置组织信息,因为handleDate方法中需要使用topOrganizationId
businessDocumentDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
businessDocumentDO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
businessDocumentDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
UserPo userPo = loginUser.getUserPo();
businessDocumentDO.setCreateBy(userPo.getUserId());
businessDocumentDO.setCreateByName(userPo.getUserName());
//校验使用的表单是否必填校验
checkDoucumentType(businessDocumentDO);
//处理数据
handleDate(businessDocumentDO);
businessDocumentDO.setDataSources(2);
businessDocumentDO.setBusinessFlow(OrderSequence.getOrderCode("LS"));
//调用费用计算,计算费用金额进行保存
CostCalculationDTO costCalculationDTO = new CostCalculationDTO();
costCalculationDTO.setOriginalBusinessNum(businessDocumentDO.getOriginalBusinessNum());
costCalculationDTO.setContractNumber(businessDocumentDO.getContractNumber());
costCalculationDTO.setFormJson(businessDocumentDO.getDocumentFormJson());
costCalculationDTO.setSubjectCode(StringUtils.isEmpty(businessDocumentDO.getSecondSubjectCode()) ? businessDocumentDO.getFirstSubjectCode():businessDocumentDO.getSecondSubjectCode());
costCalculationDTO.setDocumentTypeCode(businessDocumentDO.getDocumentTypeCode());
costCalculationDTO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
costCalculationDTO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
costCalculationDTO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
BillingCostPo billingCostPo = costCalculationApplicationService.setComputationalCost(costCalculationDTO);
businessDocumentDO.setEstimatedCost(billingCostPo.getComputationalCost());
return businessDocumentDO;
}
@Autowired @Autowired
private IDocumentTypeService documentTypeService; private IDocumentTypeService documentTypeService;
/** /**
@@ -575,6 +612,34 @@ public class BusinessDocumentApplicationService {
} }
} }
/**
* 生效业务单据
*/
@Transactional
public void takeEffectByIdsBySystem(BusinessDocumentDTO businessDocumentDTO) {
//只有未生效状态的记录可以操作生效变更为已生效状态
if(!StringUtils.isNotEmpty(businessDocumentDTO.getBusinessDocumentIds())){
throw new ServiceException("所选数据不能为空");
}
List<Long> businessDocumentIdLongList = new ArrayList<>();
Set<String> businessDocumentIds = Stream.of(businessDocumentDTO.getBusinessDocumentIds().split(",")).collect(Collectors.toSet());
for (String businessDocumentId : businessDocumentIds) {
Long businessDocumentIdLong = Long.valueOf(businessDocumentId);
BusinessDocumentPO businessDocumentPO = businessDocumentDomainService.getInfo(businessDocumentIdLong);
if(null == businessDocumentPO){
throw new ServiceException("业务单据信息未找到");
}
if(businessDocumentPO.getBusinessState()!=1 && businessDocumentPO.getBusinessState()!=4){
throw new ServiceException("所选记录"+ businessDocumentPO.getBusinessFlow() +"已生效不可操作");
}
businessDocumentIdLongList.add(businessDocumentIdLong);
}
if(businessDocumentIdLongList.size()>0){
businessDocumentDomainService.takeEffectByIdsBySystem(businessDocumentIdLongList);
}
}
/** /**
* 审核业务单据 * 审核业务单据
*/ */
@@ -608,6 +673,39 @@ public class BusinessDocumentApplicationService {
} }
/**
* 审核业务单据
*/
@Transactional
public void auditByIdsBySystem(BusinessDocumentDTO businessDocumentDTO) {
//只有已生效状态的记录可以操作审核变更为已计费状态并生成计费流水
if(!StringUtils.isNotEmpty(businessDocumentDTO.getBusinessDocumentIds())){
throw new ServiceException("所选数据不能为空");
}
List<Long> businessDocumentIdLongList = new ArrayList<>();
Set<String> businessDocumentIds = Stream.of(businessDocumentDTO.getBusinessDocumentIds().split(",")).collect(Collectors.toSet());
for (String businessDocumentId : businessDocumentIds) {
Long businessDocumentIdLong = Long.valueOf(businessDocumentId);
BusinessDocumentPO businessDocumentPO = businessDocumentDomainService.getInfo(businessDocumentIdLong);
if(null == businessDocumentPO){
throw new ServiceException("业务单据信息未找到");
}
if(businessDocumentPO.getBusinessState()!=2){
throw new ServiceException("所选记录"+ businessDocumentPO.getBusinessFlow() +"不是已生效状态不可操作");
}
Integer auditOperation = businessDocumentDTO.getAuditOperation();
if(auditOperation != null && auditOperation == 1){
//生成计费流水
billingStatementDomainService.generateFlowBySystem(businessDocumentPO);
}
businessDocumentIdLongList.add(businessDocumentIdLong);
}
if(businessDocumentIdLongList.size()>0){
businessDocumentDomainService.auditByIdsBySystem(businessDocumentIdLongList,businessDocumentDTO);
}
}
/** /**
* 导入业务单据 * 导入业务单据
@@ -894,8 +992,9 @@ public class BusinessDocumentApplicationService {
BusinessDocument businessDocument = businessDocumentDomainService.insertRetrun(businessDocumentDO); BusinessDocument businessDocument = businessDocumentDomainService.insertRetrun(businessDocumentDO);
BusinessDocumentDTO businessDocumentDTO = new BusinessDocumentDTO(); BusinessDocumentDTO businessDocumentDTO = new BusinessDocumentDTO();
businessDocumentDTO.setBusinessDocumentIds(String.valueOf(businessDocument.getBusinessDocumentId())); businessDocumentDTO.setBusinessDocumentIds(String.valueOf(businessDocument.getBusinessDocumentId()));
this.takeEffectByIds(businessDocumentDTO); businessDocumentDTO.setAuditOperation(1);
this.auditByIds(businessDocumentDTO); this.takeEffectByIdsBySystem(businessDocumentDTO);
this.auditByIdsBySystem(businessDocumentDTO);
return true; return true;
} }
} }
@@ -430,6 +430,50 @@ public class BillingStatementDomainService {
return this.insert(billingStatementDO); return this.insert(billingStatementDO);
} }
/**
* 生成流水
*/
public Boolean generateFlowBySystem(BusinessDocumentPO businessDocumentPO) {
BillingStatementDO billingStatementDO = new BillingStatementDO();
String[] ignroreFields = new String[]{"billingStatementId","dataSources","createBy","createByName","createTime","updateBy","updateByName","updateTime"};
BeanUtils.copyProperties(businessDocumentPO,billingStatementDO,ignroreFields);
billingStatementDO.setBusinessDocumentId(businessDocumentPO.getBusinessDocumentId());
//设置业务日期:优先使用计费时间,如果没有则使用创建时间,如果还没有则使用当前日期
Date businessDate = businessDocumentPO.getBillingTime();
if (businessDate == null) {
businessDate = businessDocumentPO.getCreateTime();
}
if (businessDate == null) {
businessDate = new Date();
}
billingStatementDO.setBusinessDate(businessDate);
billingStatementDO.setBillingAmount(businessDocumentPO.getBillAmount());
billingStatementDO.setBillingState(1);
billingStatementDO.setDataSources(1);
//billingStatementDO.setCreateBy(loginUser.getUserPo().getUserId());
billingStatementDO.setCreateByName("system");
billingStatementDO.setCreateTime(new Date());
billingStatementDO.setBillingFlow(businessDocumentPO.getBusinessFlow());
billingStatementDO.setTopOrganizationId(businessDocumentPO.getTopOrganizationId());
billingStatementDO.setOrganizationId(businessDocumentPO.getOrganizationId());
billingStatementDO.setOrganizationName(businessDocumentPO.getOrganizationName());
//收款帐户信息
billingStatementDO.setPaymentAccountId(businessDocumentPO.getPaymentAccountId()); //收款帐户ID
billingStatementDO.setPaymentAccountName(businessDocumentPO.getPaymentAccountName()); //收款帐户名称
BigDecimal billingAmount = billingStatementDO.getBillingAmount();
Double taxRate = billingStatementDO.getTaxRate() != null ? billingStatementDO.getTaxRate() : 0.0;
BigDecimal taxAmount = billingAmount.divide(BigDecimal.ONE.add(new BigDecimal(taxRate).divide(BigDecimal.valueOf(100))),10, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(taxRate).divide(BigDecimal.valueOf(100))).setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal taxFreeFee = billingAmount.subtract(taxAmount);
billingStatementDO.setTaxAmount(taxAmount);
billingStatementDO.setTaxFreeFee(taxFreeFee);
//处理数据
handleData(billingStatementDO);
return this.insert(billingStatementDO);
}
/** /**
* 处理生成收支流水数据 * 处理生成收支流水数据
* @param billingStatementDO * @param billingStatementDO
@@ -136,6 +136,24 @@ public class BusinessDocumentDomainService {
} }
/**
* 根据id生效业务单据信息
*/
public Boolean takeEffectByIdsBySystem(List<Long> businessDocumentIdLongList) {
if(businessDocumentIdLongList != null && businessDocumentIdLongList.size() > 0){
LambdaUpdateWrapper<BusinessDocument> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.set(BusinessDocument::getBusinessState,2);
//updateWrapper.set(BusinessDocument::getUpdateBy,loginUser.getUserPo().getUserId());
updateWrapper.set(BusinessDocument::getUpdateTime,new Date());
//updateWrapper.set(BusinessDocument::getUpdateByName,loginUser.getUserPo().getUserName());
updateWrapper.in(BusinessDocument::getBusinessDocumentId,businessDocumentIdLongList);
return businessDocumentService.update(updateWrapper);
}
return false;
}
/** /**
* 审核业务单据 * 审核业务单据
*/ */
@@ -163,6 +181,30 @@ public class BusinessDocumentDomainService {
return false; return false;
} }
/**
* 审核业务单据
*/
public Boolean auditByIdsBySystem(List<Long> businessDocumentIdLongList, BusinessDocumentDTO businessDocumentDTO) {
if(businessDocumentIdLongList != null && businessDocumentIdLongList.size() > 0){
LambdaUpdateWrapper<BusinessDocument> updateWrapper = new LambdaUpdateWrapper<>();
if(businessDocumentDTO.getAuditOperation() == 1){
//同意
updateWrapper.set(BusinessDocument::getBusinessState,3);
}else {
//驳回
updateWrapper.set(BusinessDocument::getBusinessState,4);
}
updateWrapper.set(BusinessDocument::getReviewRemarks,businessDocumentDTO.getReviewRemarks());
//updateWrapper.set(BusinessDocument::getUpdateBy,loginUser.getUserPo().getUserId());
updateWrapper.set(BusinessDocument::getUpdateTime,new Date());
//updateWrapper.set(BusinessDocument::getUpdateByName,loginUser.getUserPo().getUserName());
updateWrapper.in(BusinessDocument::getBusinessDocumentId,businessDocumentIdLongList);
return businessDocumentService.update(updateWrapper);
}
return false;
}
public Boolean saveBatch(List<BusinessDocument> businessDocumentList) { public Boolean saveBatch(List<BusinessDocument> businessDocumentList) {
if(null != businessDocumentList && businessDocumentList.size() > 0){ if(null != businessDocumentList && businessDocumentList.size() > 0){
return businessDocumentService.saveBatch(businessDocumentList); return businessDocumentService.saveBatch(businessDocumentList);
@@ -76,7 +76,7 @@ public class SettlementCustomersDomainService {
public SettlementCustomers queryByCode(String settlementCustomersCode) { public SettlementCustomers queryByCode(String settlementCustomersCode) {
LambdaQueryWrapper<SettlementCustomers> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SettlementCustomers> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SettlementCustomers::getSettlementCustomersCode, settlementCustomersCode); queryWrapper.eq(SettlementCustomers::getSettlementCustomersCode, settlementCustomersCode);
queryWrapper.eq(SettlementCustomers::getTopOrganizationId, SecurityUtils.getLoginUser().getUserPo().getTopOrganizationId()); //queryWrapper.eq(SettlementCustomers::getTopOrganizationId, SecurityUtils.getLoginUser().getUserPo().getTopOrganizationId());
queryWrapper.eq(SettlementCustomers::getDelFlag, 1); queryWrapper.eq(SettlementCustomers::getDelFlag, 1);
return settlementCustomersService.getOne(queryWrapper); return settlementCustomersService.getOne(queryWrapper);
} }
@@ -84,4 +84,4 @@ public class SettlementCustomersDomainService {
} }
@@ -80,6 +80,27 @@ public class BusinessDocumentApi extends BaseController{
} }
/**
* 保存业务单据
*/
@ApiOperation("保存业务单据")
@PostMapping("/getEstimatedCost")
public AjaxResult getEstimatedCost(@RequestBody BusinessDocumentDTO businessDocumentDTO)
{
try {
//转换实体
BusinessDocumentDO businessDocumentDO = businessDocumentAssembler.toDO(businessDocumentDTO);
BusinessDocumentDO estimatedCost = businessDocumentApplicationService.getEstimatedCost(businessDocumentDO);
return AjaxResult.success(estimatedCost);
} catch (ServiceException e) {
return AjaxResult.error(e.getMessage());
} catch (Exception e){
return AjaxResult.error("查询估价失败:" + e.getMessage());
}
}
/** /**
* 整租推送 * 整租推送
*/ */
@@ -240,4 +261,4 @@ public class BusinessDocumentApi extends BaseController{
} }