Browse Source

预算使用情况

v1.0
Yen 2 years ago
parent
commit
8a46d96777
  1. 29
      src/main/java/com/qs/serve/modules/bir/controller/BirBudgetScheduleController.java
  2. 67
      src/main/java/com/qs/serve/modules/tbs/entity/dto/TbsBudgetWithAmount.java
  3. 65
      src/main/java/com/qs/serve/modules/tbs/mapper/TbsBudgetLog2Mapper.java
  4. 9
      src/main/java/com/qs/serve/modules/tbs/service/TbsScheduleItemBudgetService.java
  5. 106
      src/main/java/com/qs/serve/modules/tbs/service/impl/TbsScheduleItemBudgetServiceImpl.java
  6. 118
      src/main/resources/mapper/tbs/TbsBudget2Mapper.xml

29
src/main/java/com/qs/serve/modules/bir/controller/BirBudgetScheduleController.java

@ -6,6 +6,7 @@ import com.qs.serve.common.model.dto.R;
import com.qs.serve.common.util.CollectionUtil;
import com.qs.serve.modules.tbs.entity.TbsSchedule;
import com.qs.serve.modules.tbs.entity.TbsScheduleItem;
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetWithAmount;
import com.qs.serve.modules.tbs.entity.dto.TbsScheduleItemBudgetIdDto;
import com.qs.serve.modules.tbs.entity.dto.TbsScheduleItemWithAmount;
import com.qs.serve.modules.tbs.entity.so.TbsScheduleItemSearch;
@ -36,6 +37,34 @@ public class BirBudgetScheduleController {
private final TbsScheduleMapper tbsScheduleMapper;
/**
* 查询预算使用情况
* @param query
* @return
*/
@PostMapping("/budgetUsedList")
public R<List<TbsBudgetWithAmount>> queryBudgetUsed(@RequestBody TbsScheduleItemSearch query){
query.initCenterCombo();
if(CollectionUtil.isNotEmpty(query.getScheduleIds())){
LambdaQueryWrapper<TbsScheduleItem> lqw = new LambdaQueryWrapper<>();
lqw.in(TbsScheduleItem::getScheduleId,query.getScheduleIds());
lqw.select(TbsScheduleItem::getId);
List<TbsScheduleItem> scheduleItemList = tbsScheduleItemMapper.selectList(lqw);
List<String> itemIds = scheduleItemList.stream().map(a->a.getId().toString()).collect(Collectors.toList());
query.setScheduleItemIds(itemIds);
}
List<TbsScheduleItemBudgetIdDto> scheduleItemBudgetIdDtoList = scheduleItemBudget2Mapper.listItemBudgetIds(query);
List<Long> scheduleItemIds = scheduleItemBudgetIdDtoList.stream().map(TbsScheduleItemBudgetIdDto::getScheduleItemId).collect(Collectors.toList());
if(CollectionUtil.isEmpty(scheduleItemIds)){
return R.ok();
}
List<TbsScheduleItem> scheduleItemList = tbsScheduleItemMapper.selectBatchIds(scheduleItemIds);
List<TbsSchedule> scheduleList = tbsScheduleMapper.selectList(new QueryWrapper<>());
List<TbsBudgetWithAmount> scheduleItemWithAmounts = scheduleItemBudgetService.listBudgetAmountByIds(scheduleItemBudgetIdDtoList);
return R.ok(scheduleItemWithAmounts);
}
/**
* 查询周期使用情况
* @param query

67
src/main/java/com/qs/serve/modules/tbs/entity/dto/TbsBudgetWithAmount.java

@ -0,0 +1,67 @@
package com.qs.serve.modules.tbs.entity.dto;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author YenHex
* @since 2023/6/29
*/
@Data
public class TbsBudgetWithAmount {
/**
* 周期项ID
*/
String budgetId;
String budgetName;
String centerId;
String centerName;
String centerType;
/**
* 预算总额
*/
BigDecimal finalAmt = BigDecimal.ZERO;
/**
* 当前占用中的预算
*/
BigDecimal allUsingAmt = BigDecimal.ZERO;
/**
* 申请中的预算占用
*/
BigDecimal allCheckingAmt = BigDecimal.ZERO;
/**
* 费用申请-申请中的预算
*/
BigDecimal costUsingAmt = BigDecimal.ZERO;
/**
* 费用申请-申请中的预算
*/
BigDecimal costCheckingAmt = BigDecimal.ZERO;
/**
* 政策-申请中的预算
*/
BigDecimal policyUsingAmt = BigDecimal.ZERO;
/**
* 政策-申请中的预算
*/
BigDecimal policyCheckingAmt = BigDecimal.ZERO;
/**
* 剩余预算(预算总额-当前占用的预算)
*/
BigDecimal surplusAmt = BigDecimal.ZERO;
}

65
src/main/java/com/qs/serve/modules/tbs/mapper/TbsBudgetLog2Mapper.java

@ -0,0 +1,65 @@
package com.qs.serve.modules.tbs.mapper;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qs.serve.modules.tbs.entity.TbsBudgetLog;
import com.qs.serve.modules.tbs.entity.TbsCostApply;
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetLogWithAmount;
import com.qs.serve.modules.tbs.entity.dto.TbsScheduleItemBudgetIdDto;
import com.qs.serve.modules.tbs.entity.so.TbsScheduleItemSearch;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.math.BigDecimal;
import java.util.List;
/**
* 预算日志 Mapper
* @author YenHex
* @date 2023-01-05
*/
public interface TbsBudgetLog2Mapper extends BaseMapper<TbsBudgetLog> {
/**
* 统计budget金额
* @param ids budgetId
* @param optNumbers 包含
* @return
*/
@InterceptorIgnore(tenantLine = "true")
List<TbsBudgetLogWithAmount> getSumAmtInList(@Param("selectIds") List<Long> ids, @Param("optNumbers")List<Integer> optNumbers);
/**
* 统计budget金额
* @param ids budget_id
* @param optNumbers 不包含
* @return
*/
@InterceptorIgnore(tenantLine = "true")
List<TbsBudgetLogWithAmount> getSumAmtNotInList(@Param("selectIds") List<Long> ids,@Param("optNumbers")List<Integer> optNumbers);
/**
* 统计审批中的政策占用多少的预算
* @param ids
* @param optNumbers
* @return
*/
@InterceptorIgnore(tenantLine = "true")
List<TbsBudgetLogWithAmount> getPolicyCheckingList(@Param("selectIds") List<Long> ids,@Param("optNumbers")List<Integer> optNumbers);
/**
* 统计审批中的费用占用多少的预算
* @param ids
* @param optNumbers
* @return
*/
@InterceptorIgnore(tenantLine = "true")
List<TbsBudgetLogWithAmount> getCostCheckingList(@Param("selectIds") List<Long> ids,@Param("optNumbers")List<Integer> optNumbers);
}

9
src/main/java/com/qs/serve/modules/tbs/service/TbsScheduleItemBudgetService.java

@ -1,12 +1,12 @@
package com.qs.serve.modules.tbs.service;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qs.serve.modules.tbs.entity.TbsScheduleItemBudget;
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetScheduleWithAmount;
import com.qs.serve.modules.tbs.entity.dto.TbsScheduleItemBudgetIdDto;
import com.qs.serve.modules.tbs.entity.dto.TbsScheduleItemWithAmount;
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetWithAmount;
import java.time.LocalDate;
import java.util.List;
@ -37,5 +37,12 @@ public interface TbsScheduleItemBudgetService extends IService<TbsScheduleItemBu
*/
List<TbsScheduleItemWithAmount> listScheduleItemAmountByIds(List<TbsScheduleItemBudgetIdDto> budgetIdDtoList);
/**
* 预算维度统计
* @param budgetIdDtoList
* @return
*/
List<TbsBudgetWithAmount> listBudgetAmountByIds(List<TbsScheduleItemBudgetIdDto> budgetIdDtoList);
}

106
src/main/java/com/qs/serve/modules/tbs/service/impl/TbsScheduleItemBudgetServiceImpl.java

@ -3,10 +3,10 @@ package com.qs.serve.modules.tbs.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qs.serve.common.model.enums.BudgetLogOptFlag;
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetLogWithAmount;
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetScheduleWithAmount;
import com.qs.serve.modules.tbs.entity.dto.TbsScheduleItemBudgetIdDto;
import com.qs.serve.modules.tbs.entity.dto.TbsScheduleItemWithAmount;
import com.qs.serve.modules.tbs.entity.TbsBudget;
import com.qs.serve.modules.tbs.entity.dto.*;
import com.qs.serve.modules.tbs.mapper.TbsBudgetLog2Mapper;
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper;
import com.qs.serve.modules.tbs.mapper.TbsScheduleItemBudget2Mapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -31,7 +31,9 @@ import java.util.stream.Collectors;
@AllArgsConstructor
public class TbsScheduleItemBudgetServiceImpl extends ServiceImpl<TbsScheduleItemBudgetMapper,TbsScheduleItemBudget> implements TbsScheduleItemBudgetService {
private final TbsBudgetMapper tbsBudgetMapper;
private final TbsScheduleItemBudget2Mapper scheduleItemBudget2Mapper;
private final TbsBudgetLog2Mapper tbsBudgetLog2Mapper;
@Override
public List<TbsScheduleItemBudget> betweenDateList(LocalDate startDate, LocalDate endDate) {
@ -206,5 +208,101 @@ public class TbsScheduleItemBudgetServiceImpl extends ServiceImpl<TbsScheduleIte
return result;
}
@Override
public List<TbsBudgetWithAmount> listBudgetAmountByIds(List<TbsScheduleItemBudgetIdDto> budgetIdDtoList) {
List<Long> scheduleItemBudgetIds = budgetIdDtoList.stream().map(TbsScheduleItemBudgetIdDto::getScheduleItemBudgetId).collect(Collectors.toList());
//加载
LambdaQueryWrapper<TbsScheduleItemBudget> sibLqw = new LambdaQueryWrapper<>();
sibLqw.in(TbsScheduleItemBudget::getId,scheduleItemBudgetIds);
sibLqw.select(TbsScheduleItemBudget::getBudgetId);
List<TbsScheduleItemBudget> tbsScheduleItemBudgetList = this.list(sibLqw);
List<Long> budgetIds = tbsScheduleItemBudgetList.stream().map(TbsScheduleItemBudget::getBudgetId).distinct().collect(Collectors.toList());
List<TbsBudget> budgetList = tbsBudgetMapper.selectBatchIds(budgetIds);
// 预算金额
List<TbsBudgetLogWithAmount> finalList = tbsBudgetLog2Mapper.getSumAmtInList(scheduleItemBudgetIds, BudgetLogOptFlag.getFinalBudgetOptFlag());
// 被占用金额
List<TbsBudgetLogWithAmount> usedList = tbsBudgetLog2Mapper.getSumAmtNotInList(scheduleItemBudgetIds, BudgetLogOptFlag.getFinalBudgetOptFlag());
// 费用使用金额
List<TbsBudgetLogWithAmount> costUsedList = tbsBudgetLog2Mapper.getSumAmtInList(scheduleItemBudgetIds, BudgetLogOptFlag.finalCostOptFlag);
// 政策使用金额
List<TbsBudgetLogWithAmount> policyUsedList = tbsBudgetLog2Mapper.getSumAmtInList(scheduleItemBudgetIds, BudgetLogOptFlag.finalPolicyOptFlag);
List<TbsBudgetLogWithAmount> policyCheckingList = tbsBudgetLog2Mapper.getPolicyCheckingList(scheduleItemBudgetIds, BudgetLogOptFlag.finalPolicyOptFlag);
List<TbsBudgetLogWithAmount> costCheckingList = tbsBudgetLog2Mapper.getCostCheckingList(scheduleItemBudgetIds, BudgetLogOptFlag.finalCostOptFlag);
List<TbsBudgetWithAmount> result = new ArrayList<>();
for (Long budgetId : budgetIds) {
TbsBudgetWithAmount withAmount = new TbsBudgetWithAmount();
withAmount.setBudgetId(budgetId+"");
for (TbsBudget budget : budgetList) {
if(budget.getId().equals(budgetId)){
withAmount.setBudgetName(budget.getBudgetCode());
withAmount.setCenterId(budget.getCenterId());
withAmount.setCenterName(budget.getCenterName());
withAmount.setCenterType(budget.getCenterType());
}
}
for (TbsBudgetLogWithAmount obj : finalList) {
if(budgetId.equals(obj.getId())){
withAmount.setFinalAmt(obj.getAmt());
break;
}
}
for (TbsBudgetLogWithAmount obj : usedList) {
if(budgetId.equals(obj.getId())){
withAmount.setAllUsingAmt(obj.getAmt());
break;
}
}
for (TbsBudgetLogWithAmount obj : costUsedList) {
if(budgetId.equals(obj.getId())){
withAmount.setCostUsingAmt(obj.getAmt());
break;
}
}
for (TbsBudgetLogWithAmount obj : policyUsedList) {
if(budgetId.equals(obj.getId())){
withAmount.setPolicyUsingAmt(obj.getAmt());
break;
}
}
for (TbsBudgetLogWithAmount obj : costCheckingList) {
if(budgetId.equals(obj.getId())){
withAmount.setCostCheckingAmt(obj.getAmt());
break;
}
}
for (TbsBudgetLogWithAmount obj : policyCheckingList) {
if(budgetId.equals(obj.getId())){
withAmount.setPolicyCheckingAmt(obj.getAmt());
break;
}
}
//因为log统计为负数,需要把数值取正
withAmount.setAllUsingAmt(withAmount.getAllUsingAmt().negate());
withAmount.setCostUsingAmt(withAmount.getCostUsingAmt().negate());
withAmount.setCostCheckingAmt(withAmount.getCostCheckingAmt().negate());
withAmount.setPolicyUsingAmt(withAmount.getPolicyUsingAmt().negate());
withAmount.setPolicyCheckingAmt(withAmount.getPolicyCheckingAmt().negate());
//计算剩余及审批合计
withAmount.setAllCheckingAmt(withAmount.getCostCheckingAmt().add(withAmount.getPolicyCheckingAmt()));
withAmount.setSurplusAmt(withAmount.getFinalAmt().subtract(withAmount.getAllUsingAmt()));
result.add(withAmount);
}
return result;
}
}

118
src/main/resources/mapper/tbs/TbsBudget2Mapper.xml

@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.qs.serve.modules.tbs.mapper.TbsBudgetLog2Mapper">
<select id="listItemBudgetIds" resultType="com.qs.serve.modules.tbs.entity.dto.TbsScheduleItemBudgetIdDto">
SELECT
tbs_schedule_item_budget.id as schedule_item_budget_id,
tbs_schedule_item_budget.schedule_item_id
FROM `tbs_schedule_item_budget`
LEFT JOIN tbs_budget on tbs_schedule_item_budget.budget_id = tbs_budget.id
LEFT JOIN tbs_budget_condition on tbs_budget_condition.budget_id = tbs_budget.id
where
tbs_schedule_item_budget.del_flag = 0
and tbs_budget.del_flag = 0
and tbs_budget.budget_state = 1
<if test="query.centerCombos != null and query.centerCombos.size > 0">
and tbs_budget.center_combo in
<foreach collection="query.centerCombos" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
</if>
<if test="query.brandIds != null and query.brandIds.size > 0">
and
(
tbs_budget.condition_flag = 0 or tbs_budget_condition.brand_id in
<foreach collection="query.brandIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
)
</if>
and tbs_schedule_item_budget.schedule_item_id in
<foreach collection="query.scheduleItemIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
group by tbs_schedule_item_budget.id
</select>
<select id="getSumAmtInList" resultType="com.qs.serve.modules.tbs.entity.dto.TbsBudgetLogWithAmount">
select
budget_id as id,
sum(amount) as amt
from tbs_budget_log
where
del_flag = 0 and opt_type not in
<foreach collection="optNumbers" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
AND schedule_item_budget_id in
<foreach collection="selectIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
group by budget_id
</select>
<select id="getSumAmtNotInList" resultType="com.qs.serve.modules.tbs.entity.dto.TbsBudgetLogWithAmount">
select
budget_id as id,
sum(amount) as amt
from tbs_budget_log
where
del_flag = 0 and opt_type not in
<foreach collection="optNumbers" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
AND schedule_item_budget_id in
<foreach collection="selectIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
group by budget_id
</select>
<select id="getPolicyCheckingList" resultType="com.qs.serve.modules.tbs.entity.dto.TbsBudgetLogWithAmount">
select
tbs_budget_log.budget_id as id,
sum(amount) as amt
from tbs_budget_log
left join tzc_policy on tbs_budget_log.policy_id = tzc_policy.id
where
tbs_budget_log.policy_id is not null
and tzc_policy.policy_status = 1
and tbs_budget_log.del_flag = 0
and tzc_policy.del_flag = 0
and opt_type in
<foreach collection="optNumbers" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
AND schedule_item_budget_id in
<foreach collection="selectIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
group by tbs_budget_log.budget_id
</select>
<select id="getCostCheckingList" resultType="com.qs.serve.modules.tbs.entity.dto.TbsBudgetLogWithAmount">
select
tbs_budget_log.budget_id as id,
sum(amount) as amt
from tbs_budget_log
left join tbs_cost_apply on tbs_budget_log.cost_apply_id = tbs_cost_apply.id
where
tbs_budget_log.cost_apply_id is not null
and tbs_cost_apply.charge_state = 1
and tbs_budget_log.del_flag = 0
and tbs_cost_apply.del_flag = 0
and opt_type in
<foreach collection="optNumbers" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
AND schedule_item_budget_id in
<foreach collection="selectIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
group by tbs_budget_log.budget_id
</select>
</mapper>
Loading…
Cancel
Save