2021-11-02 07:51:52 +00:00
|
|
|
|
package cn.palmte.work.service;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.palmte.work.bean.BudgetBean;
|
|
|
|
|
|
import cn.palmte.work.model.*;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2021-11-04 02:32:16 +00:00
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2021-11-02 07:51:52 +00:00
|
|
|
|
import org.springframework.stereotype.Service;
|
2021-11-04 10:45:11 +00:00
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2021-11-02 07:51:52 +00:00
|
|
|
|
import top.jfunc.common.utils.CollectionUtil;
|
|
|
|
|
|
|
2021-11-04 02:32:16 +00:00
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
import java.util.ArrayList;
|
2021-11-02 07:51:52 +00:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 项目预算service
|
|
|
|
|
|
* @author xiongshiyan at 2021/10/29 , contact me with email yanshixiong@126.com or phone 15208384257
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class ProjectBudgetService {
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ProjectBudgetIncomeRepository projectBudgetIncomeRepository;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ProjectBudgetCostRepository projectBudgetCostRepository;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ProjectBudgetCostManageRepository projectBudgetCostManageRepository;
|
2021-11-02 09:33:34 +00:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private ProjectBudgetIncomeDetailRepository projectBudgetIncomeDetailRepository;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ProjectBudgetCostDetailRepository projectBudgetCostDetailRepository;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ProjectBudgetCostProjectManageDetailRepository projectBudgetCostProjectManageDetailRepository;
|
2021-11-04 05:17:03 +00:00
|
|
|
|
@Autowired
|
2021-11-04 08:05:36 +00:00
|
|
|
|
private ProjectBudgetPlanDetailRepository projectBudgetPlanDetailRepository;
|
2021-11-02 07:51:52 +00:00
|
|
|
|
|
2021-11-04 02:32:16 +00:00
|
|
|
|
@Value("#{'${fourcal.fixedprojectmanagedetails}'.split('\\|')}")
|
|
|
|
|
|
private String[] fixedProjectManageDetails;
|
2021-11-02 07:51:52 +00:00
|
|
|
|
|
|
|
|
|
|
public void clearBudget(Project project){
|
|
|
|
|
|
List<ProjectBudgetIncome> incomes = projectBudgetIncomeRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(incomes)){
|
|
|
|
|
|
projectBudgetIncomeRepository.deleteInBatch(incomes);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<ProjectBudgetCost> costs = projectBudgetCostRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(costs)){
|
|
|
|
|
|
projectBudgetCostRepository.deleteInBatch(costs);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<ProjectBudgetCostManage> costManages = projectBudgetCostManageRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(costManages)){
|
|
|
|
|
|
projectBudgetCostManageRepository.deleteInBatch(costManages);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void saveBudget(Project project, BudgetBean budgetBean){
|
|
|
|
|
|
//收入记录
|
|
|
|
|
|
income(project, budgetBean);
|
|
|
|
|
|
//成本记录
|
|
|
|
|
|
cost(project, budgetBean);
|
|
|
|
|
|
//管理记录
|
|
|
|
|
|
costManage(project, budgetBean);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void cost(Project project, BudgetBean budgetBean) {
|
|
|
|
|
|
ProjectBudgetCost projectBudgetCostDevice = new ProjectBudgetCost();
|
|
|
|
|
|
projectBudgetCostDevice.setProjectId(project.getId());
|
|
|
|
|
|
projectBudgetCostDevice.setFee(ProjectBudgetCost.FEE_PURCHASE);
|
|
|
|
|
|
projectBudgetCostDevice.setType(ProjectBudgetCost.TYPE_DEVICE);
|
|
|
|
|
|
projectBudgetCostDevice.setCostTaxInclude(budgetBean.getCostPurchaseDeviceTaxInclude());
|
|
|
|
|
|
projectBudgetCostDevice.setCostTaxExclude(budgetBean.getCostPurchaseDeviceTaxExclude());
|
|
|
|
|
|
projectBudgetCostRepository.saveAndFlush(projectBudgetCostDevice);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetCost projectBudgetCostBuild = new ProjectBudgetCost();
|
|
|
|
|
|
projectBudgetCostBuild.setProjectId(project.getId());
|
|
|
|
|
|
projectBudgetCostBuild.setFee(ProjectBudgetCost.FEE_PURCHASE);
|
|
|
|
|
|
projectBudgetCostBuild.setType(ProjectBudgetCost.TYPE_BUILDING);
|
|
|
|
|
|
projectBudgetCostBuild.setCostTaxInclude(budgetBean.getCostPurchaseBuildTaxInclude());
|
|
|
|
|
|
projectBudgetCostBuild.setCostTaxExclude(budgetBean.getCostPurchaseBuildTaxExclude());
|
|
|
|
|
|
projectBudgetCostRepository.saveAndFlush(projectBudgetCostBuild);
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetCost projectBudgetCostService = new ProjectBudgetCost();
|
|
|
|
|
|
projectBudgetCostService.setProjectId(project.getId());
|
|
|
|
|
|
projectBudgetCostService.setFee(ProjectBudgetCost.FEE_PURCHASE);
|
|
|
|
|
|
projectBudgetCostService.setType(ProjectBudgetCost.TYPE_SERVICE);
|
|
|
|
|
|
projectBudgetCostService.setCostTaxInclude(budgetBean.getCostPurchaseServiceTaxInclude());
|
|
|
|
|
|
projectBudgetCostService.setCostTaxExclude(budgetBean.getCostPurchaseServiceTaxExclude());
|
|
|
|
|
|
projectBudgetCostRepository.saveAndFlush(projectBudgetCostService);
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetCost projectBudgetCostOther = new ProjectBudgetCost();
|
|
|
|
|
|
projectBudgetCostOther.setProjectId(project.getId());
|
|
|
|
|
|
projectBudgetCostOther.setFee(ProjectBudgetCost.FEE_PURCHASE);
|
|
|
|
|
|
projectBudgetCostOther.setType(ProjectBudgetCost.TYPE_OTHER);
|
|
|
|
|
|
projectBudgetCostOther.setCostTaxInclude(budgetBean.getCostPurchaseOtherTaxInclude());
|
|
|
|
|
|
projectBudgetCostOther.setCostTaxExclude(budgetBean.getCostPurchaseOtherTaxExclude());
|
|
|
|
|
|
projectBudgetCostRepository.saveAndFlush(projectBudgetCostOther);
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetCost projectBudgetCostProject = new ProjectBudgetCost();
|
|
|
|
|
|
projectBudgetCostProject.setProjectId(project.getId());
|
|
|
|
|
|
projectBudgetCostProject.setFee(ProjectBudgetCost.FEE_PROJECT_MANAGE);
|
|
|
|
|
|
projectBudgetCostProject.setType(ProjectBudgetCost.TYPE_PROJECT_MANAGE);
|
2021-11-03 09:26:06 +00:00
|
|
|
|
/*projectBudgetCostProject.setCostTaxInclude(budgetBean.getCostProjectManageTaxInclude());*/
|
2021-11-02 07:51:52 +00:00
|
|
|
|
projectBudgetCostProject.setCostTaxExclude(budgetBean.getCostProjectManageTaxExclude());
|
|
|
|
|
|
projectBudgetCostRepository.saveAndFlush(projectBudgetCostProject);
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetCost projectBudgetCostOtherOther = new ProjectBudgetCost();
|
|
|
|
|
|
projectBudgetCostOtherOther.setProjectId(project.getId());
|
|
|
|
|
|
projectBudgetCostOtherOther.setFee(ProjectBudgetCost.FEE_OTHER);
|
|
|
|
|
|
projectBudgetCostOtherOther.setType(ProjectBudgetCost.TYPE_OTHER_OTHER);
|
|
|
|
|
|
projectBudgetCostOtherOther.setCostTaxInclude(budgetBean.getCostOtherOtherTaxInclude());
|
|
|
|
|
|
projectBudgetCostOtherOther.setCostTaxExclude(budgetBean.getCostOtherOtherTaxExclude());
|
|
|
|
|
|
projectBudgetCostRepository.saveAndFlush(projectBudgetCostOtherOther);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private void costManage(Project project, BudgetBean budgetBean) {
|
|
|
|
|
|
ProjectBudgetCostManage projectBudgetCostZijin = new ProjectBudgetCostManage();
|
|
|
|
|
|
projectBudgetCostZijin.setProjectId(project.getId());
|
|
|
|
|
|
projectBudgetCostZijin.setType(ProjectBudgetCostManage.TYPE_EXPROPRIATION);
|
|
|
|
|
|
projectBudgetCostZijin.setCostTaxExclude(budgetBean.getCostExpropriationTaxExclude());
|
|
|
|
|
|
projectBudgetCostManageRepository.saveAndFlush(projectBudgetCostZijin);
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetCostManage projectBudgetCostManage = new ProjectBudgetCostManage();
|
|
|
|
|
|
projectBudgetCostManage.setProjectId(project.getId());
|
|
|
|
|
|
projectBudgetCostManage.setType(ProjectBudgetCostManage.TYPE_COMPANY_MANAGE);
|
|
|
|
|
|
projectBudgetCostManage.setCostTaxExclude(budgetBean.getCostCompanyManageTaxExclude());
|
|
|
|
|
|
projectBudgetCostManageRepository.saveAndFlush(projectBudgetCostManage);
|
|
|
|
|
|
}
|
|
|
|
|
|
private void income(Project project, BudgetBean budgetBean) {
|
|
|
|
|
|
ProjectBudgetIncome projectBudgetIncomeDevice = new ProjectBudgetIncome();
|
|
|
|
|
|
projectBudgetIncomeDevice.setProjectId(project.getId());
|
|
|
|
|
|
projectBudgetIncomeDevice.setType(ProjectBudgetIncome.TYPE_DEVICE);
|
|
|
|
|
|
projectBudgetIncomeDevice.setIncomeTaxInclude(budgetBean.getIncomeDeviceTaxInclude());
|
|
|
|
|
|
projectBudgetIncomeDevice.setIncomeTaxExclude(budgetBean.getIncomeDeviceTaxExclude());
|
|
|
|
|
|
projectBudgetIncomeRepository.saveAndFlush(projectBudgetIncomeDevice);
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetIncome projectBudgetIncomeEngineer = new ProjectBudgetIncome();
|
|
|
|
|
|
projectBudgetIncomeEngineer.setProjectId(project.getId());
|
|
|
|
|
|
projectBudgetIncomeEngineer.setType(ProjectBudgetIncome.TYPE_ENGINEER);
|
|
|
|
|
|
projectBudgetIncomeEngineer.setIncomeTaxInclude(budgetBean.getIncomeEngineerTaxInclude());
|
|
|
|
|
|
projectBudgetIncomeEngineer.setIncomeTaxExclude(budgetBean.getIncomeEngineerTaxExclude());
|
|
|
|
|
|
projectBudgetIncomeRepository.saveAndFlush(projectBudgetIncomeEngineer);
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetIncome projectBudgetIncomeService = new ProjectBudgetIncome();
|
|
|
|
|
|
projectBudgetIncomeService.setProjectId(project.getId());
|
|
|
|
|
|
projectBudgetIncomeService.setType(ProjectBudgetIncome.TYPE_SERVICE);
|
|
|
|
|
|
projectBudgetIncomeService.setIncomeTaxInclude(budgetBean.getIncomeServiceTaxInclude());
|
|
|
|
|
|
projectBudgetIncomeService.setIncomeTaxExclude(budgetBean.getIncomeServiceTaxExclude());
|
|
|
|
|
|
projectBudgetIncomeRepository.saveAndFlush(projectBudgetIncomeService);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-03 11:06:31 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* 其实最好是通过明细表生成,不然可能有数据不一致的情况
|
|
|
|
|
|
*/
|
2021-11-02 07:51:52 +00:00
|
|
|
|
public BudgetBean getBudget(Project project) {
|
|
|
|
|
|
BudgetBean budgetBean = new BudgetBean();
|
|
|
|
|
|
|
|
|
|
|
|
List<ProjectBudgetIncome> incomes = projectBudgetIncomeRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
|
|
|
|
|
|
List<ProjectBudgetIncome> collect = incomes.stream().filter(d -> d.getType() == ProjectBudgetIncome.TYPE_DEVICE).collect(Collectors.toList());
|
|
|
|
|
|
if(CollectionUtil.isEmpty(collect)){
|
|
|
|
|
|
//要么全部,要么没有
|
|
|
|
|
|
return budgetBean;
|
|
|
|
|
|
}
|
|
|
|
|
|
ProjectBudgetIncome projectBudgetIncomeDevice = collect.get(0);
|
|
|
|
|
|
budgetBean.setIncomeDeviceTaxInclude(projectBudgetIncomeDevice.getIncomeTaxInclude());
|
|
|
|
|
|
budgetBean.setIncomeDeviceTaxExclude(projectBudgetIncomeDevice.getIncomeTaxExclude());
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetIncome projectBudgetIncomeEngineer = incomes.stream().filter(d -> d.getType() == ProjectBudgetIncome.TYPE_ENGINEER).collect(Collectors.toList()).get(0);
|
|
|
|
|
|
budgetBean.setIncomeEngineerTaxInclude(projectBudgetIncomeEngineer.getIncomeTaxInclude());
|
|
|
|
|
|
budgetBean.setIncomeEngineerTaxExclude(projectBudgetIncomeEngineer.getIncomeTaxExclude());
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetIncome projectBudgetIncomeService = incomes.stream().filter(d -> d.getType() == ProjectBudgetIncome.TYPE_SERVICE).collect(Collectors.toList()).get(0);
|
|
|
|
|
|
budgetBean.setIncomeServiceTaxInclude(projectBudgetIncomeService.getIncomeTaxInclude());
|
|
|
|
|
|
budgetBean.setIncomeServiceTaxExclude(projectBudgetIncomeService.getIncomeTaxExclude());
|
|
|
|
|
|
|
|
|
|
|
|
List<ProjectBudgetCost> costs = projectBudgetCostRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetCost projectBudgetCostDevice = costs.stream().filter(d -> d.getType() == ProjectBudgetCost.TYPE_DEVICE).collect(Collectors.toList()).get(0);
|
|
|
|
|
|
budgetBean.setCostPurchaseDeviceTaxInclude(projectBudgetCostDevice.getCostTaxInclude());
|
|
|
|
|
|
budgetBean.setCostPurchaseDeviceTaxExclude(projectBudgetCostDevice.getCostTaxExclude());
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetCost projectBudgetCostBuild = costs.stream().filter(d -> d.getType() == ProjectBudgetCost.TYPE_BUILDING).collect(Collectors.toList()).get(0);
|
|
|
|
|
|
budgetBean.setCostPurchaseBuildTaxInclude(projectBudgetCostBuild.getCostTaxInclude());
|
|
|
|
|
|
budgetBean.setCostPurchaseBuildTaxExclude(projectBudgetCostBuild.getCostTaxExclude());
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetCost projectBudgetCostService = costs.stream().filter(d -> d.getType() == ProjectBudgetCost.TYPE_SERVICE).collect(Collectors.toList()).get(0);
|
|
|
|
|
|
budgetBean.setCostPurchaseServiceTaxInclude(projectBudgetCostService.getCostTaxInclude());
|
|
|
|
|
|
budgetBean.setCostPurchaseServiceTaxExclude(projectBudgetCostService.getCostTaxExclude());
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetCost projectBudgetCostOther = costs.stream().filter(d -> d.getType() == ProjectBudgetCost.TYPE_OTHER).collect(Collectors.toList()).get(0);
|
|
|
|
|
|
budgetBean.setCostPurchaseOtherTaxInclude(projectBudgetCostOther.getCostTaxInclude());
|
|
|
|
|
|
budgetBean.setCostPurchaseOtherTaxExclude(projectBudgetCostOther.getCostTaxExclude());
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetCost projectBudgetCostProjectManage = costs.stream().filter(d -> d.getType() == ProjectBudgetCost.TYPE_PROJECT_MANAGE).collect(Collectors.toList()).get(0);
|
2021-11-03 09:26:06 +00:00
|
|
|
|
/*budgetBean.setCostProjectManageTaxInclude(projectBudgetCostProjectManage.getCostTaxInclude());*/
|
2021-11-02 07:51:52 +00:00
|
|
|
|
budgetBean.setCostProjectManageTaxExclude(projectBudgetCostProjectManage.getCostTaxExclude());
|
|
|
|
|
|
|
|
|
|
|
|
ProjectBudgetCost projectBudgetCostOtherOther = costs.stream().filter(d -> d.getType() == ProjectBudgetCost.TYPE_OTHER_OTHER).collect(Collectors.toList()).get(0);
|
|
|
|
|
|
budgetBean.setCostOtherOtherTaxInclude(projectBudgetCostOtherOther.getCostTaxInclude());
|
|
|
|
|
|
budgetBean.setCostOtherOtherTaxExclude(projectBudgetCostOtherOther.getCostTaxExclude());
|
|
|
|
|
|
|
|
|
|
|
|
List<ProjectBudgetCostManage> manages = projectBudgetCostManageRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
ProjectBudgetCostManage costManageExpropriation = manages.stream().filter(d -> d.getType() == ProjectBudgetCostManage.TYPE_EXPROPRIATION).collect(Collectors.toList()).get(0);
|
|
|
|
|
|
budgetBean.setCostExpropriationTaxExclude(costManageExpropriation.getCostTaxExclude());
|
|
|
|
|
|
ProjectBudgetCostManage costManageCompany = manages.stream().filter(d -> d.getType() == ProjectBudgetCostManage.TYPE_COMPANY_MANAGE).collect(Collectors.toList()).get(0);
|
|
|
|
|
|
budgetBean.setCostCompanyManageTaxExclude(costManageCompany.getCostTaxExclude());
|
|
|
|
|
|
|
|
|
|
|
|
return budgetBean;
|
|
|
|
|
|
}
|
2021-11-02 09:33:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 清空项目的收入明细
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void clearBudgetIncomeDetail(Project project){
|
|
|
|
|
|
List<ProjectBudgetIncomeDetail> incomeDetails = projectBudgetIncomeDetailRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(incomeDetails)){
|
|
|
|
|
|
projectBudgetIncomeDetailRepository.deleteInBatch(incomeDetails);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 保存项目的收入明细
|
|
|
|
|
|
*/
|
2021-11-04 10:45:11 +00:00
|
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
2021-11-02 09:33:34 +00:00
|
|
|
|
public void saveBudgetIncomeDetail(Project project, List<ProjectBudgetIncomeDetail> detailList){
|
2021-11-04 10:45:11 +00:00
|
|
|
|
clearBudgetIncomeDetail(project);
|
2021-11-02 09:33:34 +00:00
|
|
|
|
if(CollectionUtil.isNotEmpty(detailList)){
|
|
|
|
|
|
for (ProjectBudgetIncomeDetail projectBudgetIncomeDetail : detailList) {
|
|
|
|
|
|
projectBudgetIncomeDetail.setProjectId(project.getId());
|
|
|
|
|
|
}
|
|
|
|
|
|
projectBudgetIncomeDetailRepository.save(detailList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-11-03 02:49:11 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取项目的收入明细
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<ProjectBudgetIncomeDetail> getBudgetIncomeDetail(Project project){
|
|
|
|
|
|
return projectBudgetIncomeDetailRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
}
|
2021-11-02 09:33:34 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* 清空项目的成本明细
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void clearBudgetCostDetail(Project project){
|
|
|
|
|
|
List<ProjectBudgetCostDetail> costDetails = projectBudgetCostDetailRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(costDetails)){
|
|
|
|
|
|
projectBudgetCostDetailRepository.deleteInBatch(costDetails);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 保存项目的成本明细
|
|
|
|
|
|
*/
|
2021-11-04 10:45:11 +00:00
|
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
2021-11-02 09:33:34 +00:00
|
|
|
|
public void saveBudgetCostDetail(Project project, List<ProjectBudgetCostDetail> detailList){
|
2021-11-04 10:45:11 +00:00
|
|
|
|
clearBudgetCostDetail(project);
|
|
|
|
|
|
|
2021-11-02 09:33:34 +00:00
|
|
|
|
if(CollectionUtil.isNotEmpty(detailList)){
|
|
|
|
|
|
for (ProjectBudgetCostDetail projectBudgetCostDetail : detailList) {
|
|
|
|
|
|
projectBudgetCostDetail.setProjectId(project.getId());
|
|
|
|
|
|
}
|
|
|
|
|
|
projectBudgetCostDetailRepository.save(detailList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-11-03 02:49:11 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取项目的成本明细
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<ProjectBudgetCostDetail> getBudgetCostDetail(Project project){
|
|
|
|
|
|
return projectBudgetCostDetailRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
}
|
2021-11-02 09:33:34 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* 清空项目的项目管理成本明细
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void clearBudgetCostProjectManageDetail(Project project){
|
|
|
|
|
|
List<ProjectBudgetCostProjectManageDetail> costDetails = projectBudgetCostProjectManageDetailRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(costDetails)){
|
|
|
|
|
|
projectBudgetCostProjectManageDetailRepository.deleteInBatch(costDetails);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 保存项目的项目管理成本明细
|
|
|
|
|
|
*/
|
2021-11-04 10:45:11 +00:00
|
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
2021-11-02 09:33:34 +00:00
|
|
|
|
public void saveBudgetCostProjectManageDetail(Project project, List<ProjectBudgetCostProjectManageDetail> detailList){
|
2021-11-04 10:45:11 +00:00
|
|
|
|
clearBudgetCostProjectManageDetail(project);
|
2021-11-02 09:33:34 +00:00
|
|
|
|
if(CollectionUtil.isNotEmpty(detailList)){
|
|
|
|
|
|
for (ProjectBudgetCostProjectManageDetail projectBudgetCostProjectManageDetail : detailList) {
|
|
|
|
|
|
projectBudgetCostProjectManageDetail.setProjectId(project.getId());
|
|
|
|
|
|
}
|
|
|
|
|
|
projectBudgetCostProjectManageDetailRepository.save(detailList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-11-04 05:17:03 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取项目管理明细
|
|
|
|
|
|
*/
|
2021-11-03 02:49:11 +00:00
|
|
|
|
public List<ProjectBudgetCostProjectManageDetail> getBudgetCostProjectManageDetail(Project project){
|
2021-11-04 02:32:16 +00:00
|
|
|
|
List<ProjectBudgetCostProjectManageDetail> projectManageDetails = projectBudgetCostProjectManageDetailRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(projectManageDetails)){
|
|
|
|
|
|
return projectManageDetails;
|
|
|
|
|
|
}else {
|
|
|
|
|
|
//默认必填的明细
|
|
|
|
|
|
return getFixedNotDeletable();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<ProjectBudgetCostProjectManageDetail> getFixedNotDeletable() {
|
|
|
|
|
|
List<ProjectBudgetCostProjectManageDetail> projectManageDetails = new ArrayList<>(6);
|
|
|
|
|
|
for (String fixedProjectManageDetail : fixedProjectManageDetails) {
|
|
|
|
|
|
String[] split = fixedProjectManageDetail.split(",");
|
|
|
|
|
|
ProjectBudgetCostProjectManageDetail detail = new ProjectBudgetCostProjectManageDetail();
|
|
|
|
|
|
detail.setType(Integer.parseInt(split[0]));
|
|
|
|
|
|
detail.setName(split[1]);
|
|
|
|
|
|
detail.setPrice(new BigDecimal(0));
|
|
|
|
|
|
detail.setAmount(0);
|
|
|
|
|
|
detail.setDeletable(0);
|
|
|
|
|
|
projectManageDetails.add(detail);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return projectManageDetails;
|
2021-11-03 02:49:11 +00:00
|
|
|
|
}
|
2021-11-04 08:05:36 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* 清空项目的资金计划明细
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void clearBudgetPlanDetail(Project project){
|
|
|
|
|
|
List<ProjectBudgetPlanDetail> costDetails = projectBudgetPlanDetailRepository.findAllByProjectIdEquals(project.getId());
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(costDetails)){
|
|
|
|
|
|
projectBudgetPlanDetailRepository.deleteInBatch(costDetails);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-11-04 05:17:03 +00:00
|
|
|
|
|
2021-11-04 08:05:36 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* 保存项目的资金计划明细
|
|
|
|
|
|
*/
|
2021-11-04 10:45:11 +00:00
|
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
2021-11-04 08:05:36 +00:00
|
|
|
|
public void saveBudgetPlanDetail(Project project, List<ProjectBudgetPlanDetail> detailList){
|
2021-11-04 10:45:11 +00:00
|
|
|
|
clearBudgetPlanDetail(project);
|
2021-11-04 08:05:36 +00:00
|
|
|
|
if(CollectionUtil.isNotEmpty(detailList)){
|
|
|
|
|
|
for (ProjectBudgetPlanDetail projectBudgetPlanDetail : detailList) {
|
|
|
|
|
|
projectBudgetPlanDetail.setProjectId(project.getId());
|
|
|
|
|
|
}
|
|
|
|
|
|
projectBudgetPlanDetailRepository.save(detailList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-11-04 05:17:03 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取资金计划数据
|
|
|
|
|
|
*/
|
2021-11-04 08:05:36 +00:00
|
|
|
|
public List<ProjectBudgetPlanDetail> getProjectBudgetPlanDetails(Project project){
|
|
|
|
|
|
return projectBudgetPlanDetailRepository.findAllByProjectIdEquals(project.getId());
|
2021-11-04 05:17:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据每个月的计算资金计划的总
|
|
|
|
|
|
*/
|
2021-11-04 08:05:36 +00:00
|
|
|
|
public ProjectBudgetPlanDetail getProjectBudgetPlanDetailTotal(List<ProjectBudgetPlanDetail> projectBudgetPlanDetails) {
|
|
|
|
|
|
ProjectBudgetPlanDetail projectBudgetPlanDetail = new ProjectBudgetPlanDetail();
|
2021-11-04 05:17:03 +00:00
|
|
|
|
BigDecimal deviceCost = new BigDecimal(0);
|
|
|
|
|
|
BigDecimal engineerCost = new BigDecimal(0);
|
|
|
|
|
|
BigDecimal projectManageCost = new BigDecimal(0);
|
|
|
|
|
|
BigDecimal earnestMoneyCost = new BigDecimal(0);
|
|
|
|
|
|
BigDecimal totalCost = new BigDecimal(0);
|
|
|
|
|
|
BigDecimal saleIncome = new BigDecimal(0);
|
|
|
|
|
|
BigDecimal earnestMoneyIncome = new BigDecimal(0);
|
|
|
|
|
|
BigDecimal totalIncome = new BigDecimal(0);
|
|
|
|
|
|
BigDecimal fundBalance = new BigDecimal(0);
|
|
|
|
|
|
BigDecimal capitalInterest = new BigDecimal(0);
|
|
|
|
|
|
BigDecimal underwrittenPlan = new BigDecimal(0);
|
|
|
|
|
|
BigDecimal repaymentPlan = new BigDecimal(0);
|
|
|
|
|
|
|
2021-11-04 08:05:36 +00:00
|
|
|
|
if(CollectionUtil.isNotEmpty(projectBudgetPlanDetails)){
|
|
|
|
|
|
for (ProjectBudgetPlanDetail budgetPlan : projectBudgetPlanDetails) {
|
2021-11-04 05:17:03 +00:00
|
|
|
|
deviceCost = deviceCost.add(budgetPlan.getDeviceCost());
|
|
|
|
|
|
engineerCost = engineerCost.add(budgetPlan.getEngineerCost());
|
|
|
|
|
|
projectManageCost = projectManageCost.add(budgetPlan.getProjectManageCost());
|
|
|
|
|
|
earnestMoneyCost = earnestMoneyCost.add(budgetPlan.getEarnestMoneyCost());
|
|
|
|
|
|
totalCost = totalCost.add(budgetPlan.getTotalCost());
|
|
|
|
|
|
saleIncome = saleIncome.add(budgetPlan.getSaleIncome());
|
|
|
|
|
|
earnestMoneyIncome = earnestMoneyIncome.add(budgetPlan.getEarnestMoneyIncome());
|
|
|
|
|
|
totalIncome = totalIncome.add(budgetPlan.getTotalIncome());
|
2021-11-04 08:55:01 +00:00
|
|
|
|
/*fundBalance = fundBalance.add(budgetPlan.getFundBalance());*/
|
2021-11-04 05:17:03 +00:00
|
|
|
|
capitalInterest = capitalInterest.add(budgetPlan.getCapitalInterest());
|
|
|
|
|
|
underwrittenPlan = underwrittenPlan.add(budgetPlan.getUnderwrittenPlan());
|
|
|
|
|
|
repaymentPlan = repaymentPlan.add(budgetPlan.getRepaymentPlan());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-04 08:55:01 +00:00
|
|
|
|
//总余额等于总收入-总支出
|
2021-11-04 09:22:02 +00:00
|
|
|
|
fundBalance = totalIncome.subtract(totalCost);
|
2021-11-04 08:55:01 +00:00
|
|
|
|
|
2021-11-04 05:17:03 +00:00
|
|
|
|
|
2021-11-04 08:05:36 +00:00
|
|
|
|
projectBudgetPlanDetail.setMonth("合计");
|
|
|
|
|
|
projectBudgetPlanDetail.setDeviceCost(deviceCost);
|
|
|
|
|
|
projectBudgetPlanDetail.setEngineerCost(engineerCost);
|
|
|
|
|
|
projectBudgetPlanDetail.setProjectManageCost(projectManageCost);
|
|
|
|
|
|
projectBudgetPlanDetail.setEarnestMoneyCost(earnestMoneyCost);
|
|
|
|
|
|
projectBudgetPlanDetail.setTotalCost(totalCost);
|
|
|
|
|
|
projectBudgetPlanDetail.setSaleIncome(saleIncome);
|
|
|
|
|
|
projectBudgetPlanDetail.setEarnestMoneyIncome(earnestMoneyIncome);
|
|
|
|
|
|
projectBudgetPlanDetail.setTotalIncome(totalIncome);
|
|
|
|
|
|
projectBudgetPlanDetail.setFundBalance(fundBalance);
|
|
|
|
|
|
projectBudgetPlanDetail.setCapitalInterest(capitalInterest);
|
|
|
|
|
|
projectBudgetPlanDetail.setUnderwrittenPlan(underwrittenPlan);
|
|
|
|
|
|
projectBudgetPlanDetail.setRepaymentPlan(repaymentPlan);
|
|
|
|
|
|
return projectBudgetPlanDetail;
|
2021-11-04 05:17:03 +00:00
|
|
|
|
}
|
2021-11-02 07:51:52 +00:00
|
|
|
|
}
|