12 changed files with 389 additions and 67 deletions
@ -0,0 +1,126 @@ |
|||||
|
package com.qs.serve.modules.bir.entity; |
||||
|
|
||||
|
import java.time.LocalDate; |
||||
|
import java.io.Serializable; |
||||
|
import java.math.BigDecimal; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.*; |
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import lombok.Data; |
||||
|
import org.hibernate.validator.constraints.Length; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
|
||||
|
/** |
||||
|
* 预算考核期项 实体类 |
||||
|
* @author YenHex |
||||
|
* @since 2023-07-07 |
||||
|
*/ |
||||
|
@Data |
||||
|
@TableName("bir_schedule_item_budget") |
||||
|
public class BirScheduleItemBudget implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** id */ |
||||
|
@TableId(type = IdType.AUTO) |
||||
|
private Long id; |
||||
|
|
||||
|
/** 考核id */ |
||||
|
@NotNull(message = "考核id不能为空") |
||||
|
private Long scheduleId; |
||||
|
|
||||
|
/** 考核期项id */ |
||||
|
@NotNull(message = "考核期项id不能为空") |
||||
|
private Long scheduleItemId; |
||||
|
|
||||
|
/** 考核编码 */ |
||||
|
@NotBlank(message = "考核编码不能为空") |
||||
|
@Length(max = 30,message = "考核编码长度不能超过30字") |
||||
|
private String itemName; |
||||
|
|
||||
|
/** 开始时间 */ |
||||
|
@NotNull(message = "开始时间不能为空") |
||||
|
@Length(max = 0,message = "开始时间长度不能超过0字") |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
private LocalDateTime budgetStartDate; |
||||
|
|
||||
|
/** 结束时间 */ |
||||
|
@NotNull(message = "结束时间不能为空") |
||||
|
@Length(max = 0,message = "结束时间长度不能超过0字") |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
private LocalDateTime budgetEndDate; |
||||
|
|
||||
|
/** 预算id */ |
||||
|
@NotNull(message = "预算id不能为空") |
||||
|
private Long budgetId; |
||||
|
|
||||
|
/** 预算金额 */ |
||||
|
@NotNull(message = "预算金额不能为空") |
||||
|
private BigDecimal budgetAmount; |
||||
|
|
||||
|
/** */ |
||||
|
private BigDecimal preDispatchAmount; |
||||
|
|
||||
|
private BigDecimal splitBudgetAmount; |
||||
|
private BigDecimal splitPreDispatchAmount; |
||||
|
|
||||
|
/** 备注 */ |
||||
|
@Length(max = 255,message = "备注长度不能超过255字") |
||||
|
private String remark; |
||||
|
|
||||
|
/** 创建时间 */ |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private LocalDateTime createTime; |
||||
|
|
||||
|
/** 最后更新时间 */ |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
@TableField(fill = FieldFill.UPDATE) |
||||
|
private LocalDateTime updateTime; |
||||
|
|
||||
|
/** 所属租户 */ |
||||
|
@JsonIgnore |
||||
|
@JsonProperty |
||||
|
private String tenantId; |
||||
|
|
||||
|
/** 创建人 */ |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private String createBy; |
||||
|
|
||||
|
/** 更新人 */ |
||||
|
@TableField(fill = FieldFill.UPDATE) |
||||
|
private String updateBy; |
||||
|
|
||||
|
/** 键值(日期数) */ |
||||
|
@NotNull(message = "键值(日期数)不能为空") |
||||
|
private Integer keyNum; |
||||
|
|
||||
|
/** 当月有多少天 */ |
||||
|
private Integer monthDays; |
||||
|
|
||||
|
/** 活动总天数 */ |
||||
|
private Integer totalDays; |
||||
|
|
||||
|
/** 当月分割开始 */ |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") |
||||
|
private LocalDate startDate; |
||||
|
|
||||
|
/** 当月分割结束 */ |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") |
||||
|
private LocalDate endDate; |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,14 @@ |
|||||
|
package com.qs.serve.modules.bir.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.qs.serve.modules.bir.entity.BirScheduleItemBudget; |
||||
|
|
||||
|
/** |
||||
|
* 预算考核期项 Mapper |
||||
|
* @author YenHex |
||||
|
* @date 2023-07-07 |
||||
|
*/ |
||||
|
public interface BirScheduleItemBudgetMapper extends BaseMapper<BirScheduleItemBudget> { |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,19 @@ |
|||||
|
package com.qs.serve.modules.bir.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.qs.serve.modules.bir.entity.BirScheduleItemBudget; |
||||
|
|
||||
|
/** |
||||
|
* 预算考核期项 服务接口 |
||||
|
* @author YenHex |
||||
|
* @date 2023-07-07 |
||||
|
*/ |
||||
|
public interface BirScheduleItemBudgetService extends IService<BirScheduleItemBudget> { |
||||
|
|
||||
|
/** |
||||
|
* 创建数据 |
||||
|
*/ |
||||
|
void buildScheduleItemBudget(); |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,172 @@ |
|||||
|
package com.qs.serve.modules.bir.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.qs.serve.common.model.dto.DateSplitDTO; |
||||
|
import com.qs.serve.common.model.enums.BudgetLogOptFlag; |
||||
|
import com.qs.serve.common.util.Assert; |
||||
|
import com.qs.serve.common.util.DateSplitUtil; |
||||
|
import com.qs.serve.modules.tbs.entity.TbsBudget; |
||||
|
import com.qs.serve.modules.tbs.entity.TbsBudgetLog; |
||||
|
import com.qs.serve.modules.tbs.entity.TbsScheduleItemBudget; |
||||
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetLogMapper; |
||||
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
||||
|
import com.qs.serve.modules.tbs.mapper.TbsScheduleItemBudgetMapper; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.jetbrains.annotations.NotNull; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import com.qs.serve.modules.bir.entity.BirScheduleItemBudget; |
||||
|
import com.qs.serve.modules.bir.service.BirScheduleItemBudgetService; |
||||
|
import com.qs.serve.modules.bir.mapper.BirScheduleItemBudgetMapper; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.time.LocalDate; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* 预算考核期项 服务实现类 |
||||
|
* @author YenHex |
||||
|
* @since 2023-07-07 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@AllArgsConstructor |
||||
|
public class BirScheduleItemBudgetServiceImpl extends ServiceImpl<BirScheduleItemBudgetMapper,BirScheduleItemBudget> implements BirScheduleItemBudgetService { |
||||
|
|
||||
|
private final TbsBudgetMapper budgetMapper; |
||||
|
private final TbsBudgetLogMapper budgetLogMapper; |
||||
|
private final TbsScheduleItemBudgetMapper scheduleItemBudgetMapper; |
||||
|
|
||||
|
@Override |
||||
|
public void buildScheduleItemBudget() { |
||||
|
//加载所有启用的预算
|
||||
|
LambdaQueryWrapper<TbsBudget> lqw = new LambdaQueryWrapper<>(); |
||||
|
lqw.select(TbsBudget::getId); |
||||
|
lqw.eq(TbsBudget::getBudgetState,1); |
||||
|
lqw.eq(TbsBudget::getBirFlag,0); |
||||
|
List<TbsBudget> budgetList = budgetMapper.selectList(lqw); |
||||
|
List<Long> budgetIds = budgetList.stream().map(TbsBudget::getId).collect(Collectors.toList()); |
||||
|
//清空异动数据
|
||||
|
LambdaQueryWrapper<BirScheduleItemBudget> rmLqw = new LambdaQueryWrapper<>(); |
||||
|
rmLqw.in(BirScheduleItemBudget::getBudgetId,budgetIds); |
||||
|
this.remove(rmLqw); |
||||
|
//加载所有的调增调减预算
|
||||
|
Map<Long, BigDecimal> budgetLogAmtMap = buildAdjustBudgetAmount(budgetIds); |
||||
|
//加载预算的周期金额
|
||||
|
LambdaQueryWrapper<TbsScheduleItemBudget> sibLqw = new LambdaQueryWrapper<>(); |
||||
|
sibLqw.in(TbsScheduleItemBudget::getBudgetId,budgetIds); |
||||
|
List<TbsScheduleItemBudget> scheduleItemBudgetList = scheduleItemBudgetMapper.selectList(sibLqw); |
||||
|
List<BirScheduleItemBudget> maintenanceList = new ArrayList<>(); |
||||
|
for (TbsScheduleItemBudget scheduleItemBudget : scheduleItemBudgetList) { |
||||
|
LocalDate actStartDate = scheduleItemBudget.getStartDate().toLocalDate(); |
||||
|
LocalDate actEndDate = scheduleItemBudget.getEndDate().toLocalDate(); |
||||
|
int currentActDays = (int) (actEndDate.toEpochDay()-actStartDate.toEpochDay()+1); |
||||
|
List<DateSplitDTO> dateSplitList = DateSplitUtil.getSplitDto(actStartDate,actEndDate); |
||||
|
if(dateSplitList.size()>1){ |
||||
|
for (DateSplitDTO splitDTO : dateSplitList) { |
||||
|
//日期占比
|
||||
|
/*BigDecimal dayRate = new BigDecimal(currDateSplit.getDays() + "") |
||||
|
.divide(new BigDecimal(currentActDays + ""), 2, BigDecimal.ROUND_HALF_DOWN); |
||||
|
maintenanceList.add( |
||||
|
this.buildMainEntity( |
||||
|
scheduleItemBudget, |
||||
|
dateSplitList.get(0), |
||||
|
currentActDays, |
||||
|
scheduleItemBudget.getBudgetAmount(), |
||||
|
scheduleItemBudget.getPreDispatchAmount()) |
||||
|
);*/ |
||||
|
} |
||||
|
|
||||
|
}else if (dateSplitList.size()==1){ |
||||
|
maintenanceList.add( |
||||
|
this.buildMainEntity( |
||||
|
scheduleItemBudget, |
||||
|
dateSplitList.get(0), |
||||
|
currentActDays, |
||||
|
scheduleItemBudget.getBudgetAmount(), |
||||
|
scheduleItemBudget.getPreDispatchAmount()) |
||||
|
); |
||||
|
}else { |
||||
|
Assert.throwEx("Invalid date"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Builds the main entity |
||||
|
* @param source |
||||
|
* @param dateSplit |
||||
|
* @param totalDays |
||||
|
* @param splitBudgetAmount |
||||
|
* @param splitPreDispatchAmount |
||||
|
* @return |
||||
|
*/ |
||||
|
public BirScheduleItemBudget buildMainEntity(TbsScheduleItemBudget source,DateSplitDTO dateSplit, |
||||
|
Integer totalDays, |
||||
|
BigDecimal splitBudgetAmount, |
||||
|
BigDecimal splitPreDispatchAmount){ |
||||
|
BirScheduleItemBudget scheduleItemBudget = new BirScheduleItemBudget(); |
||||
|
scheduleItemBudget.setId(source.getId()); |
||||
|
scheduleItemBudget.setScheduleId(source.getScheduleId()); |
||||
|
scheduleItemBudget.setScheduleItemId(source.getScheduleItemId()); |
||||
|
scheduleItemBudget.setItemName(source.getItemName()); |
||||
|
scheduleItemBudget.setBudgetStartDate(source.getStartDate()); |
||||
|
scheduleItemBudget.setBudgetEndDate(source.getEndDate()); |
||||
|
scheduleItemBudget.setBudgetId(source.getBudgetId()); |
||||
|
scheduleItemBudget.setBudgetAmount(source.getBudgetAmount()); |
||||
|
scheduleItemBudget.setPreDispatchAmount(source.getPreDispatchAmount()); |
||||
|
scheduleItemBudget.setSplitBudgetAmount(splitBudgetAmount); |
||||
|
scheduleItemBudget.setSplitPreDispatchAmount(splitPreDispatchAmount); |
||||
|
scheduleItemBudget.setRemark(source.getRemark()); |
||||
|
scheduleItemBudget.setCreateTime(source.getCreateTime()); |
||||
|
scheduleItemBudget.setUpdateTime(source.getUpdateTime()); |
||||
|
scheduleItemBudget.setTenantId(source.getTenantId()); |
||||
|
scheduleItemBudget.setCreateBy(source.getCreateBy()); |
||||
|
scheduleItemBudget.setUpdateBy(source.getUpdateBy()); |
||||
|
|
||||
|
scheduleItemBudget.setKeyNum(dateSplit.getYearMonth()); |
||||
|
scheduleItemBudget.setMonthDays(dateSplit.getDays()); |
||||
|
scheduleItemBudget.setTotalDays(totalDays); |
||||
|
scheduleItemBudget.setStartDate(dateSplit.getStartDate()); |
||||
|
scheduleItemBudget.setEndDate(dateSplit.getEndDate()); |
||||
|
|
||||
|
return scheduleItemBudget; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 加载所有的调增调减预算 |
||||
|
* @param budgetIds |
||||
|
* @return key -> scheduleItemBudgetId ; value -> 调整金额 |
||||
|
*/ |
||||
|
@NotNull |
||||
|
private Map<Long, BigDecimal> buildAdjustBudgetAmount(List<Long> budgetIds) { |
||||
|
LambdaQueryWrapper<TbsBudgetLog> budgetLogLqw = new LambdaQueryWrapper<>(); |
||||
|
budgetLogLqw.select(TbsBudgetLog::getBudgetId,TbsBudgetLog::getAmount); |
||||
|
budgetLogLqw.in(TbsBudgetLog::getBudgetId,budgetIds); |
||||
|
budgetLogLqw.in(TbsBudgetLog::getOptType, |
||||
|
BudgetLogOptFlag.State_2.getCode(), |
||||
|
BudgetLogOptFlag.State_3.getCode()); |
||||
|
List<TbsBudgetLog> budgetLogs = budgetLogMapper.selectList(budgetLogLqw); |
||||
|
Map<Long, BigDecimal> budgetLogAmtMap = new HashMap<>(); |
||||
|
Map<Long,List<TbsBudgetLog>> budgetLogsGroup = budgetLogs.stream().collect(Collectors.groupingBy(TbsBudgetLog::getScheduleItemBudgetId)); |
||||
|
for (Long budgetId : budgetLogsGroup.keySet()) { |
||||
|
BigDecimal adjustedAmount = BigDecimal.ZERO; |
||||
|
for (TbsBudgetLog budgetLog : budgetLogsGroup.get(budgetId)) { |
||||
|
if(budgetLog.getAmount() != null) { |
||||
|
adjustedAmount = adjustedAmount.add(budgetLog.getAmount()); |
||||
|
} |
||||
|
} |
||||
|
budgetLogAmtMap.put(budgetId, adjustedAmount); |
||||
|
} |
||||
|
return budgetLogAmtMap; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
Loading…
Reference in new issue