减免接口-重复数据过滤1.0版修改
This commit is contained in:
parent
cbc6e0fb39
commit
03ee9b7926
|
|
@ -114,7 +114,8 @@ public class SltAgreementReduce extends BaseEntity {
|
|||
@ApiModelProperty(value = "减免天数")
|
||||
private Long reduceDays;
|
||||
|
||||
private BmFileInfo file;
|
||||
@ApiModelProperty(value = "附件列表")
|
||||
private List<BmFileInfo> bmFileInfos;
|
||||
|
||||
private List<SltAgreementReduce> detailList;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.bonus.material.settlement.service.impl;
|
||||
|
||||
import com.bonus.common.core.utils.DateUtils;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.material.basic.mapper.BmFileInfoMapper;
|
||||
import com.bonus.material.settlement.domain.SltAgreementReduce;
|
||||
|
|
@ -16,6 +17,7 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -53,16 +55,40 @@ public class SltAgreementReduceServiceImpl implements ISltAgreementReduceService
|
|||
|
||||
List<SltAgreementReduce> applyReduction = applyReduction(sltAgreement);
|
||||
|
||||
Long rs = sltAgreementRecudceMapper.insertReduce(sltAgreement);
|
||||
Long id = sltAgreement.getId();
|
||||
if (rs > 0 && list != null) {
|
||||
// 批量插入明细
|
||||
List<SltAgreementReduce> detailList = list.stream()
|
||||
.peek(detail -> detail.setId(id))
|
||||
.collect(Collectors.toList());
|
||||
sltAgreementRecudceMapper.insertBatchReduceDetail(detailList);
|
||||
if (applyReduction.size() > 0 && applyReduction!= null) {
|
||||
list = applyReduction;
|
||||
}else{
|
||||
list = null;
|
||||
}
|
||||
|
||||
if(list != null){
|
||||
Long rs = sltAgreementRecudceMapper.insertReduce(sltAgreement);
|
||||
Long id = sltAgreement.getId();
|
||||
AtomicBoolean addFileInfoResult = new AtomicBoolean(false);
|
||||
|
||||
if(sltAgreement.getBmFileInfos()!=null){
|
||||
sltAgreement.getBmFileInfos().forEach(bmFileInfo -> {
|
||||
bmFileInfo.setModelId(id);
|
||||
bmFileInfo.setCreateTime(DateUtils.getNowDate());
|
||||
addFileInfoResult.set(bmFileInfoMapper.insertBmFileInfo(bmFileInfo) > 0);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (rs > 0 && list != null) {
|
||||
// 批量插入明细
|
||||
List<SltAgreementReduce> detailList = list.stream()
|
||||
.peek(detail -> detail.setId(id))
|
||||
.collect(Collectors.toList());
|
||||
sltAgreementRecudceMapper.insertBatchReduceDetail(detailList);
|
||||
}
|
||||
}else{
|
||||
AjaxResult.warn("检索历史申请减免区间数据,已申请减免,请勿在提交申请单!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return AjaxResult.success();
|
||||
} catch (DataAccessException e) {
|
||||
// 记录详细的数据库操作异常日志
|
||||
|
|
@ -83,66 +109,66 @@ public class SltAgreementReduceServiceImpl implements ISltAgreementReduceService
|
|||
|
||||
public List<SltAgreementReduce> applyReduction(SltAgreementReduce sltAgreement) {
|
||||
// 初始化结果列表
|
||||
List<SltAgreementReduce> newReductions = new ArrayList<>();
|
||||
|
||||
List<SltAgreementReduce> temp = new ArrayList<>();
|
||||
// 遍历申请减免的每个区间
|
||||
for (SltAgreementReduce detail : sltAgreement.getDetailList()) {
|
||||
if (detail.getReduceStartTime() != null && detail.getReduceEndTime() != null) {
|
||||
|
||||
for (SltAgreementReduce current : sltAgreement.getDetailList()) {
|
||||
if (current.getReduceStartTime() != null && current.getReduceEndTime() != null) {
|
||||
// 将当前区间添加到结果列表中
|
||||
|
||||
// 查询与当前区间有重叠的历史减免记录
|
||||
List<SltAgreementReduce> historyReductions = sltAgreementRecudceMapper.findOverlappingReductions(detail);
|
||||
List<SltAgreementReduce> historyReductions = sltAgreementRecudceMapper.findOverlappingReductions(current);
|
||||
|
||||
if(historyReductions !=null && historyReductions.size()>0){
|
||||
// 对比并去掉重叠部分
|
||||
for (SltAgreementReduce history : historyReductions) {
|
||||
|
||||
// 对比并去掉重叠部分
|
||||
for (SltAgreementReduce history : historyReductions) {
|
||||
List<SltAgreementReduce> temp = new ArrayList<>();
|
||||
for (SltAgreementReduce current : newReductions) {
|
||||
// 如果当前区间与历史区间没有重叠,直接保留
|
||||
if (current.getEndTime().before(history.getStartTime()) || current.getStartTime().after(history.getEndTime())) {
|
||||
if (current.getReduceEndTime().before(history.getReduceStartTime()) || current.getReduceStartTime().after(history.getReduceEndTime())) {
|
||||
temp.add(current);
|
||||
} else {
|
||||
// 如果有重叠,拆分当前区间
|
||||
if (current.getStartTime().before(history.getStartTime())) {
|
||||
if (current.getReduceStartTime().before(history.getReduceStartTime())) {
|
||||
// 生成新的区间:申请开始时间到历史开始时间的前一天
|
||||
SltAgreementReduce newReduction = new SltAgreementReduce();
|
||||
//计算新的租赁情况
|
||||
newReduction.setStartTime(current.getStartTime());
|
||||
newReduction.setEndTime(new Date(history.getStartTime().getTime() - 86400000));
|
||||
long days = (history.getStartTime().getTime() - current.getStartTime().getTime()) / (24 * 60 * 60 * 1000) +1;
|
||||
current.setReduceStartTime(current.getReduceStartTime());
|
||||
current.setReduceEndTime(new Date(history.getReduceStartTime().getTime() - 86400000));
|
||||
long days = (history.getReduceStartTime().getTime() - current.getReduceStartTime().getTime()) / (24 * 60 * 60 * 1000) +1;
|
||||
BigDecimal num = current.getNum();
|
||||
BigDecimal leasePrice = current.getLeasePrice();
|
||||
newReduction.setLeasePrice(leasePrice);
|
||||
current.setLeasePrice(leasePrice);
|
||||
BigDecimal leaseMoney = new BigDecimal(days).multiply(num).multiply(leasePrice);
|
||||
newReduction.setLeaseMoney(leaseMoney);
|
||||
current.setLeaseMoney(leaseMoney);
|
||||
temp.add(
|
||||
newReduction
|
||||
current
|
||||
);
|
||||
}
|
||||
if (current.getEndTime().after(history.getEndTime())) {
|
||||
if (current.getReduceEndTime().after(history.getReduceEndTime())) {
|
||||
// 生成新的区间:历史结束时间的后一天到申请结束时间
|
||||
SltAgreementReduce newReduction = new SltAgreementReduce();
|
||||
//计算新的租赁情况
|
||||
newReduction.setStartTime( new Date(history.getEndTime().getTime() + 86400000));
|
||||
newReduction.setEndTime( current.getEndTime());
|
||||
long days = (current.getEndTime().getTime() - history.getEndTime().getTime()) / (24 * 60 * 60 * 1000) +1;
|
||||
current.setStartTime( new Date(history.getReduceEndTime().getTime() + 86400000));
|
||||
current.setEndTime( current.getReduceEndTime());
|
||||
long days = (current.getReduceEndTime().getTime() - history.getReduceEndTime().getTime()) / (24 * 60 * 60 * 1000) +1;
|
||||
BigDecimal num = current.getNum();
|
||||
BigDecimal leasePrice = current.getLeasePrice();
|
||||
newReduction.setLeasePrice(leasePrice);
|
||||
current.setLeasePrice(leasePrice);
|
||||
BigDecimal leaseMoney = new BigDecimal(days).multiply(num).multiply(leasePrice);
|
||||
newReduction.setLeaseMoney(leaseMoney);
|
||||
current.setLeaseMoney(leaseMoney);
|
||||
temp.add(
|
||||
newReduction
|
||||
current
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
newReductions = temp;
|
||||
}else{
|
||||
temp.add(current);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return newReductions;
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="endTime" column="endTime" />
|
||||
<result property="days" column="days" />
|
||||
<result property="leaseMoney" column="leaseMoney" />
|
||||
<result property="reduceStartTime" column="reduceStartTime" />
|
||||
<result property="reduceEndTime" column="reduceEndTime" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSltAgreementReduceVo">
|
||||
|
|
@ -178,14 +180,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<select id="findOverlappingReductions" resultMap="SltAgreementReudceResult">
|
||||
|
||||
SELECT *
|
||||
SELECT
|
||||
sd.id,
|
||||
sd.r_start_time as reduceStartTime,
|
||||
sd.r_end_time as reduceEndTime
|
||||
FROM slt_reduce_details sd
|
||||
left join slt_reduce_apply sa on sd.apply_id = sa.id
|
||||
WHERE
|
||||
sa.agreement_id = #{agreementId}
|
||||
AND sd.type_id = #{typeId}
|
||||
AND start_time <= #{endTime}
|
||||
AND end_time >= #{startTime}
|
||||
AND sd.r_start_time <= #{reduceEndTime}
|
||||
AND sd.r_end_time >= #{reduceStartTime}
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue