|
@@ -2,21 +2,22 @@ package org.springblade.control.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
-import org.springblade.control.entity.AnnualBudget;
|
|
|
|
-import org.springblade.control.entity.DepartmentMonthPlan;
|
|
|
|
-import org.springblade.control.entity.DictInfo;
|
|
|
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
|
+import org.springblade.control.dto.AnnualBudgetDTO;
|
|
|
|
+import org.springblade.control.entity.*;
|
|
import org.springblade.control.mapper.AnnualBudgetMapper;
|
|
import org.springblade.control.mapper.AnnualBudgetMapper;
|
|
import org.springblade.control.mapper.DepartmentMonthPlanMapper;
|
|
import org.springblade.control.mapper.DepartmentMonthPlanMapper;
|
|
-import org.springblade.control.service.IAnnualBudgetService;
|
|
|
|
-import org.springblade.control.service.IDepartmentMonthPlanService;
|
|
|
|
-import org.springblade.control.service.IProjectCostBudgetService;
|
|
|
|
-import org.springblade.control.vo.ProjectCostBudgetVO;
|
|
|
|
|
|
+import org.springblade.control.service.*;
|
|
|
|
+import org.springblade.control.vo.*;
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Param
|
|
* @Param
|
|
@@ -27,5 +28,352 @@ import java.util.List;
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
public class AnnualBudgetServiceImpl extends BaseServiceImpl<AnnualBudgetMapper, AnnualBudget> implements IAnnualBudgetService {
|
|
public class AnnualBudgetServiceImpl extends BaseServiceImpl<AnnualBudgetMapper, AnnualBudget> implements IAnnualBudgetService {
|
|
|
|
|
|
|
|
+ private final IAnnualBudgetIncomeService incomeService;
|
|
|
|
|
|
|
|
+ private final IAnnualBudgetDisburseService disburseService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 新增年度经营预算
|
|
|
|
+ * @param dto
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public void addAnnualBudget(AnnualBudgetDTO dto) {
|
|
|
|
+ Long id = SnowFlakeUtil.getId();
|
|
|
|
+ dto.setId(id);
|
|
|
|
+ //统计支出
|
|
|
|
+ Map<String, BigDecimal> map = statisticDisburse(dto);
|
|
|
|
+ BigDecimal disburseTotal = map.get("1");
|
|
|
|
+ BigDecimal staffTotal = map.get("2");
|
|
|
|
+ //统计收入
|
|
|
|
+ Map<String, BigDecimal> map2 = statisticIncome(dto);
|
|
|
|
+ BigDecimal contractTotal = map2.get("1");
|
|
|
|
+ BigDecimal planReturnedTotal = map2.get("2");
|
|
|
|
+
|
|
|
|
+ //总经营预算
|
|
|
|
+ dto.setTotalBudget(disburseTotal);
|
|
|
|
+ //年度合同指标
|
|
|
|
+ dto.setAnnualContractTarget(contractTotal);
|
|
|
|
+ //年度利润指标
|
|
|
|
+ dto.setAnnualProfitTarget(planReturnedTotal.subtract(disburseTotal));
|
|
|
|
+ //人工成本
|
|
|
|
+ dto.setStaffCost(staffTotal);
|
|
|
|
+ //管理支出
|
|
|
|
+ dto.setManageDisburse(disburseTotal.subtract(staffTotal));
|
|
|
|
+
|
|
|
|
+ //保存年度预算
|
|
|
|
+ AnnualBudget annualBudget = new AnnualBudget();
|
|
|
|
+ BeanUtils.copyProperties(dto,annualBudget);
|
|
|
|
+ this.save(annualBudget);
|
|
|
|
+ //保存年度收入
|
|
|
|
+ incomeService.saveBatch(dto.getIncomeList());
|
|
|
|
+ //保存年度支出
|
|
|
|
+ disburseService.saveBatch(dto.getDisburseList());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改年度经营预算
|
|
|
|
+ * @param dto
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public void updateAnnualBudget(AnnualBudgetDTO dto) {
|
|
|
|
+ //统计支出
|
|
|
|
+ Map<String, BigDecimal> map = statisticDisburse(dto);
|
|
|
|
+ BigDecimal disburseTotal = map.get("1");
|
|
|
|
+ BigDecimal staffTotal = map.get("2");
|
|
|
|
+ //统计收入
|
|
|
|
+ Map<String, BigDecimal> map2 = statisticIncome(dto);
|
|
|
|
+ BigDecimal contractTotal = map2.get("1");
|
|
|
|
+ BigDecimal planReturnedTotal = map2.get("2");
|
|
|
|
+
|
|
|
|
+ //总经营预算
|
|
|
|
+ dto.setTotalBudget(disburseTotal);
|
|
|
|
+ //年度合同指标
|
|
|
|
+ dto.setAnnualContractTarget(contractTotal);
|
|
|
|
+ //年度利润指标
|
|
|
|
+ dto.setAnnualProfitTarget(planReturnedTotal.subtract(disburseTotal));
|
|
|
|
+ //人工成本
|
|
|
|
+ dto.setStaffCost(staffTotal);
|
|
|
|
+ //管理支出
|
|
|
|
+ dto.setManageDisburse(disburseTotal.subtract(staffTotal));
|
|
|
|
+
|
|
|
|
+ //保存年度预算
|
|
|
|
+ AnnualBudget annualBudget = new AnnualBudget();
|
|
|
|
+ BeanUtils.copyProperties(dto,annualBudget);
|
|
|
|
+ this.updateById(annualBudget);
|
|
|
|
+ //保存年度收入
|
|
|
|
+ incomeService.deleteByAnnualId(dto.getId());
|
|
|
|
+ incomeService.saveBatch(dto.getIncomeList());
|
|
|
|
+ //保存年度支出
|
|
|
|
+ disburseService.deleteByAnnualId(dto.getId());
|
|
|
|
+ disburseService.saveBatch(dto.getDisburseList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取单个年度经营预算
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public AnnualBudgetVO getAnnualBudget(Long id) {
|
|
|
|
+ //获取总预算
|
|
|
|
+ AnnualBudgetVO vo = baseMapper.getAnnualBudget(id);
|
|
|
|
+ //获取收入列表
|
|
|
|
+ List<AnnualBudgetIncome> incomeList = incomeService.list(new LambdaQueryWrapper<AnnualBudgetIncome>().eq(AnnualBudgetIncome::getAnnualBudgetId, id));
|
|
|
|
+ vo.setIncomeList(incomeList);
|
|
|
|
+ //获取支出列表
|
|
|
|
+ List<AnnualBudgetDisburse> disburseList = disburseService.list(new LambdaQueryWrapper<AnnualBudgetDisburse>().eq(AnnualBudgetDisburse::getAnnualBudgetId, id));
|
|
|
|
+ vo.setDisburseList(disburseList);
|
|
|
|
+ return vo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除单个年度经营预算
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public void deleteAnnualBudget(Long id) {
|
|
|
|
+ baseMapper.removeById(id);
|
|
|
|
+ incomeService.deleteByAnnualId(id);
|
|
|
|
+ disburseService.deleteByAnnualId(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取项目列表及相关信息
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<ControlProjectInfoVO> getProjectList() {
|
|
|
|
+ return baseMapper.getProjectList();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询预览
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public AnnualBudgetVO2 preview(Long id) {
|
|
|
|
+ AnnualBudgetVO2 vo2 = new AnnualBudgetVO2();
|
|
|
|
+ List<AnnualBudgetVO2.IncomeDetail> incomeDetails = new ArrayList<>();
|
|
|
|
+ List<AnnualBudgetVO2.disburseDetail> disburseDetails = new ArrayList<>();
|
|
|
|
+ List<BigDecimal> bigDecimals = new ArrayList<>();
|
|
|
|
+ //获取预算收入集合
|
|
|
|
+ List<AnnualBudgetIncomeVO> incomeList = baseMapper.getReturnedByAnnualBudgetId(id);
|
|
|
|
+ //获取预算支出集合
|
|
|
|
+ List<AnnualBudgetDisburseVO> disburseList = baseMapper.getDisburseByAnnualBudgetId(id);
|
|
|
|
+ //分别计算12个月
|
|
|
|
+ for (int i = 1; i <= 12; i++) {
|
|
|
|
+ //统计单月收入
|
|
|
|
+ AnnualBudgetVO2.IncomeDetail incomeDetail = new AnnualBudgetVO2.IncomeDetail();
|
|
|
|
+ BigDecimal incomeTotal = new BigDecimal("0");
|
|
|
|
+ List<AnnualBudgetIncomeVO> list1 = new ArrayList<>();
|
|
|
|
+ if (incomeList != null && incomeList.size() >0){
|
|
|
|
+ for (AnnualBudgetIncomeVO vo : incomeList) {
|
|
|
|
+ if (vo.getReturnTime().getMonthValue() == i) {
|
|
|
|
+ incomeTotal = incomeTotal.add(vo.getReturnMoney());
|
|
|
|
+ list1.add(vo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //移除集中和已经通过的月
|
|
|
|
+ incomeDetail.setIncome(incomeTotal);
|
|
|
|
+ incomeDetail.setIncomeList(list1);
|
|
|
|
+ incomeDetails.add(incomeDetail);
|
|
|
|
+ //统计单月支出
|
|
|
|
+ AnnualBudgetVO2.disburseDetail disburseDetail = new AnnualBudgetVO2.disburseDetail();
|
|
|
|
+ BigDecimal disburseTotal = new BigDecimal("0");
|
|
|
|
+ List<AnnualBudgetDisburseVO> list2 = new ArrayList<>();
|
|
|
|
+ if (disburseList != null && disburseList.size() >0){
|
|
|
|
+ for (AnnualBudgetDisburseVO vo : disburseList) {
|
|
|
|
+ if (i == 1){
|
|
|
|
+ if (vo.getJanuary().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
+ disburseTotal = disburseTotal.add(vo.getJanuary());
|
|
|
|
+ list2.add(vo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (i == 2){
|
|
|
|
+ if (vo.getFebruary().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
+ disburseTotal = disburseTotal.add(vo.getFebruary());
|
|
|
|
+ list2.add(vo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (i == 3){
|
|
|
|
+ if (vo.getMarch().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
+ disburseTotal = disburseTotal.add(vo.getMarch());
|
|
|
|
+ list2.add(vo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (i == 4){
|
|
|
|
+ if (vo.getApril().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
+ disburseTotal = disburseTotal.add(vo.getApril());
|
|
|
|
+ list2.add(vo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (i == 5){
|
|
|
|
+ if (vo.getMay().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
+ disburseTotal = disburseTotal.add(vo.getMay());
|
|
|
|
+ list2.add(vo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (i == 6){
|
|
|
|
+ if (vo.getJune().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
+ disburseTotal = disburseTotal.add(vo.getJune());
|
|
|
|
+ list2.add(vo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (i == 7){
|
|
|
|
+ if (vo.getJuly().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
+ disburseTotal = disburseTotal.add(vo.getJuly());
|
|
|
|
+ list2.add(vo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (i == 8){
|
|
|
|
+ if (vo.getAugust().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
+ disburseTotal = disburseTotal.add(vo.getAugust());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (i == 9){
|
|
|
|
+ if (vo.getSeptember().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
+ disburseTotal = disburseTotal.add(vo.getSeptember());
|
|
|
|
+ list2.add(vo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (i == 10){
|
|
|
|
+ if (vo.getOctober().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
+ disburseTotal = disburseTotal.add(vo.getOctober());
|
|
|
|
+ list2.add(vo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (i == 11){
|
|
|
|
+ if (vo.getNovember().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
+ disburseTotal = disburseTotal.add(vo.getNovember());
|
|
|
|
+ list2.add(vo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (i == 12){
|
|
|
|
+ if (vo.getDecember().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
+ disburseTotal = disburseTotal.add(vo.getDecember());
|
|
|
|
+ list2.add(vo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ disburseDetail.setDisburse(disburseTotal);
|
|
|
|
+ disburseDetail.setDisburseList(list2);
|
|
|
|
+ disburseDetails.add(disburseDetail);
|
|
|
|
+ //统计单月盈利,月收入-月支出
|
|
|
|
+ bigDecimals.add(incomeTotal.subtract(disburseTotal));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ vo2.setMonthIncome(incomeDetails);
|
|
|
|
+ vo2.setMonthDisburse(disburseDetails);
|
|
|
|
+ vo2.setMonthTotal(bigDecimals);
|
|
|
|
+ return vo2;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取二级科目
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<DictInfoVO> getSecondSubject() {
|
|
|
|
+ List<DictInfoVO> allBudgetSubject = baseMapper.getAllBudgetSubject();
|
|
|
|
+ List<DictInfoVO> allSecondSubject =baseMapper.getAllSecondSubject();
|
|
|
|
+ for (DictInfoVO vo : allBudgetSubject) {
|
|
|
|
+ List<DictInfoVO> list = new ArrayList<>();
|
|
|
|
+ for (DictInfoVO v02 : allSecondSubject) {
|
|
|
|
+ if (vo.getId().equals(v02.getParentId())){
|
|
|
|
+ list.add(v02);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ list = list.stream().sorted(Comparator.comparing(DictInfo::getSort)).collect(Collectors.toList());
|
|
|
|
+ vo.setChildren(list);
|
|
|
|
+ }
|
|
|
|
+ return allBudgetSubject;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 统计支出 1支出总和2工资总和
|
|
|
|
+ */
|
|
|
|
+ public static Map<String,BigDecimal> statisticDisburse(AnnualBudgetDTO dto){
|
|
|
|
+ BigDecimal disburseTotal = new BigDecimal("0");
|
|
|
|
+ BigDecimal staffTotal = new BigDecimal("0");
|
|
|
|
+ List<AnnualBudgetDisburse> disburseList = dto.getDisburseList();
|
|
|
|
+ if (disburseList != null && disburseList.size() > 0){
|
|
|
|
+ for (AnnualBudgetDisburse disburse : disburseList) {
|
|
|
|
+ disburse.setAnnualBudgetId(dto.getId());
|
|
|
|
+ //统计支出总和
|
|
|
|
+ BigDecimal temp = new BigDecimal("0");
|
|
|
|
+ if (disburse.getJanuary() != null){
|
|
|
|
+ temp = temp.add(disburse.getJanuary());
|
|
|
|
+ }
|
|
|
|
+ if (disburse.getFebruary() != null){
|
|
|
|
+ temp = temp.add(disburse.getFebruary());
|
|
|
|
+ }
|
|
|
|
+ if (disburse.getMarch() != null){
|
|
|
|
+ temp = temp.add(disburse.getMarch());
|
|
|
|
+ }
|
|
|
|
+ if (disburse.getApril() != null){
|
|
|
|
+ temp = temp.add(disburse.getApril());
|
|
|
|
+ }
|
|
|
|
+ if (disburse.getMay() != null){
|
|
|
|
+ temp = temp.add(disburse.getMay());
|
|
|
|
+ }
|
|
|
|
+ if (disburse.getJune() != null){
|
|
|
|
+ temp = temp.add(disburse.getJune());
|
|
|
|
+ }
|
|
|
|
+ if (disburse.getJuly() != null){
|
|
|
|
+ temp = temp.add(disburse.getJuly());
|
|
|
|
+ }
|
|
|
|
+ if (disburse.getAugust() != null){
|
|
|
|
+ temp = temp.add(disburse.getAugust());
|
|
|
|
+ }
|
|
|
|
+ if (disburse.getSeptember() != null){
|
|
|
|
+ temp = temp.add(disburse.getSeptember());
|
|
|
|
+ }
|
|
|
|
+ if (disburse.getOctober() != null){
|
|
|
|
+ temp = temp.add(disburse.getOctober());
|
|
|
|
+ }
|
|
|
|
+ if (disburse.getNovember() != null){
|
|
|
|
+ temp = temp.add(disburse.getNovember());
|
|
|
|
+ }
|
|
|
|
+ if (disburse.getDecember() != null){
|
|
|
|
+ temp = temp.add(disburse.getDecember());
|
|
|
|
+ }
|
|
|
|
+ disburseTotal = disburseTotal.add(temp);
|
|
|
|
+ //单独统计支出中的人工成本总和
|
|
|
|
+ if (disburse.getBudgetSubject() == 3){
|
|
|
|
+ staffTotal = staffTotal.add(temp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Map<String,BigDecimal> map = new HashMap<>();
|
|
|
|
+ map.put("1",disburseTotal);
|
|
|
|
+ map.put("2",staffTotal);
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 统计收入,1合同收入2计划回款
|
|
|
|
+ */
|
|
|
|
+ public static Map<String,BigDecimal> statisticIncome(AnnualBudgetDTO dto){
|
|
|
|
+ List<AnnualBudgetIncome> incomeList = dto.getIncomeList();
|
|
|
|
+ BigDecimal contractTotal = new BigDecimal("0");
|
|
|
|
+ BigDecimal planReturnedTotal = new BigDecimal("0");
|
|
|
|
+ if (incomeList != null && incomeList.size() > 0){
|
|
|
|
+ for (AnnualBudgetIncome income : incomeList) {
|
|
|
|
+ income.setAnnualBudgetId(dto.getId());
|
|
|
|
+ //合同额总和
|
|
|
|
+ if (income.getPredictContractMoney() != null) {
|
|
|
|
+ contractTotal = contractTotal.add(income.getPredictContractMoney());
|
|
|
|
+ }
|
|
|
|
+ //计划回款总和
|
|
|
|
+ if (income.getPredictAnnualReturned() != null){
|
|
|
|
+ planReturnedTotal = planReturnedTotal.add(income.getPredictAnnualReturned());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Map<String,BigDecimal> map = new HashMap<>();
|
|
|
|
+ map.put("1",contractTotal);
|
|
|
|
+ map.put("2",planReturnedTotal);
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
}
|
|
}
|