Commit d15e5f24 authored by wangqiang's avatar wangqiang

ExtSpendingContractController:业务代码迁入(2.x版本->4.1版本)

parent 9dfa2af4
......@@ -29,7 +29,17 @@ import org.springframework.stereotype.Controller;
@BasePermission("inet-plan:ExtSpendingContract")
public class ExtSpendingContractController<V extends ExtSpendingContractVO, S extends ExtSpendingContractService<V>> extends ExtSpendingContractControllerShadow<V, S> {
@Autowired
private ExtSpendingContractService extSpendingContractService;
@ApiOperation(value = "支出合同金额计算", notes = "支出合同金额计算", httpMethod = "GET")
@GetMapping("/calculateSpending/{id}")
public ApiResult calculateSpending(@PathVariable Long id) {
//通过收入基本属性id获取付款明细
ExtSpendingContractVO extSpendingContractVO = extSpendingContractService.calculateSpending(id);
return ApiResult.ok(extSpendingContractVO);
}
}
......@@ -10,4 +10,11 @@ import com.yonde.dcs.plan.core.service.shadow.ExtSpendingContractServiceShadow;
**/
public interface ExtSpendingContractService<V extends ExtSpendingContractVO> extends ExtSpendingContractServiceShadow<V> {
/**
* 支出合同金额计算
*
* @param id
* @return
*/
ExtSpendingContractVO calculateSpending(Long id);
}
package com.yonde.dcs.plan.core.service.impl;
import com.yonde.dcs.plan.common.utils.BigDecimalUtil;
import com.yonde.dcs.plan.common.vo.ExtSpendingDetailVO;
import com.yonde.dex.basedata.data.search.SearchItem;
import com.yonde.dex.basedata.data.search.SearchItems;
import com.yonde.dex.basedata.data.search.SearchQueryCondition;
import com.yonde.dex.basedata.entity.data.DxPageImpl;
import com.yonde.dex.basedata.entity.data.OperatorType;
import com.yonde.dex.dao.service.util.DxPageUtils;
import org.springframework.stereotype.Service;
import io.swagger.annotations.ApiOperation;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import com.yonde.dcs.plan.common.vo.ExtSpendingContractVO;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import com.yonde.dcs.plan.core.service.ExtSpendingContractService;
import com.yonde.dcs.plan.core.repository.ExtSpendingContractRepository;
......@@ -29,6 +42,66 @@ public class ExtSpendingContractServiceImpl<V extends ExtSpendingContractVO> imp
@Autowired
ExtSpendingContractRepository<ExtSpendingContract> extSpendingContractRepository;
@Override
public ExtSpendingContractVO calculateSpending(Long id) {
ExtSpendingContractVO recursionSpendingDetail = this.findRecursionSpendingDetail(id);
List<ExtSpendingDetailVO> extSpendingDetails = recursionSpendingDetail.getExtSpendingDetails();
//金额List累加
BigDecimal bigss = BigDecimal.ZERO;
//所有付款明细金额
List<BigDecimal> payAmoutList = new ArrayList<>();
if (!CollectionUtils.isEmpty(extSpendingDetails)) {
//已付金额=付款明细之和
extSpendingDetails.stream().forEach(item -> {
payAmoutList.add(item.getAmount());
});
}
//计算已付金额
if (!CollectionUtils.isEmpty(payAmoutList)) {
for (BigDecimal bigDecimal : payAmoutList) {
bigss = bigss.add(bigDecimal);
}
}
// 如果支出明细为空,已付金额为零
recursionSpendingDetail.setPaidAmount(bigss);
DecimalFormat df = new DecimalFormat("0.00%");
//计算未付金额 = 合同金额- 已付金额
BigDecimal contractAmount = recursionSpendingDetail.getContractAmount();
if (contractAmount != null) {
BigDecimal subtract = BigDecimalUtil.subtract(contractAmount, bigss);
recursionSpendingDetail.setUnpaidAmount(subtract);
//计算付款比例 = 已付金额/合同额
BigDecimal paymentRatio = BigDecimalUtil.divide(bigss, contractAmount);
String percent = df.format(paymentRatio);
recursionSpendingDetail.setPaymentRatio(percent);
}
recursionSpendingDetail.setOperator(OperatorType.MODIFY);
ExtSpendingContractVO extSpendingContractVO = this.saveRecursion((V) recursionSpendingDetail);
return extSpendingContractVO;
}
/**
* 深度查询支出合同
*
* @param
* @return
*/
public ExtSpendingContractVO findRecursionSpendingDetail(Long id) {
SearchQueryCondition query = SearchQueryCondition.builder()
.openProp(SearchQueryCondition.builder().name("extSpendingDetails").build())
.searchItems(SearchItems.builder().item(new SearchItem("id", SearchItem.Operator.EQ,
id, null)).build()).build();
;
DxPageImpl<V> dexPage = this.findRecursion(query);
if (!CollectionUtils.isEmpty(dexPage.getContent())) {
ExtSpendingContractVO spendingContractVO = DxPageUtils.getFirst(dexPage);
return spendingContractVO;
}
return new ExtSpendingContractVO();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment