|
|
@ -3,10 +3,13 @@ package com.qs.serve.modules.vtb.service.impl; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.qs.serve.common.util.Assert; |
|
|
|
import com.qs.serve.common.util.AuthContextUtils; |
|
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsSubject; |
|
|
|
import com.qs.serve.modules.bms.service.BmsSubjectService; |
|
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
|
import com.qs.serve.modules.tbs.service.*; |
|
|
|
import com.qs.serve.modules.vtb.common.VtbFundFlowType; |
|
|
@ -27,6 +30,8 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
@ -53,20 +58,41 @@ public class VtbVerificationServiceImpl extends ServiceImpl<VtbVerificationMappe |
|
|
|
private final VtbVerificationSubjectService verificationSubjectService; |
|
|
|
private final VtbFundFlowService fundFlowService; |
|
|
|
|
|
|
|
private final SysUserService sysUserService; |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void release(Long activityId) { |
|
|
|
SysUser sysUser = sysUserService.getById(AuthContextUtils.getSysUserId()); |
|
|
|
TbsActivity activity = activityService.getById(activityId); |
|
|
|
BigDecimal releaseAmount = validActivity(activity,false); |
|
|
|
TbsActivity param = new TbsActivity(); |
|
|
|
param.setId(activityId); |
|
|
|
param.setReleaseUserId(sysUser.getId()); |
|
|
|
param.setReleaseUserName(sysUser.getName()); |
|
|
|
param.setReleaseFlag(1); |
|
|
|
param.setReleaseTime(LocalDateTime.now()); |
|
|
|
param.setReleaseAmount(releaseAmount); |
|
|
|
param.setFinishedFlag(1); |
|
|
|
activityService.updateById(param); |
|
|
|
|
|
|
|
VtbFundFlow fundFlow = new VtbFundFlow(); |
|
|
|
fundFlow.setFundType(VtbFundFlowType.Release); |
|
|
|
fundFlow.setVerificationId(0L); |
|
|
|
fundFlow.setCenterGoodsCode(activity.getActivityCode()+"_0"); |
|
|
|
fundFlow.setCostApplyId(activity.getCostApplyId()); |
|
|
|
fundFlow.setActivityId(activity.getId()); |
|
|
|
fundFlow.setUsedAmount(releaseAmount); |
|
|
|
fundFlowService.save(fundFlow); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void commit(VtbVerificationBo verificationBo) { |
|
|
|
TbsActivity activity = activityService.getById(verificationBo.getActivityId()); |
|
|
|
TbsCostApply costApply = costApplyService.getById(activity.getCostApplyId()); |
|
|
|
//todo 结束的活动不支持核销
|
|
|
|
boolean hasRelease = fundFlowService.hasRelease(activity.getId()); |
|
|
|
if(hasRelease){ |
|
|
|
Assert.throwEx("费用已释放"); |
|
|
|
} |
|
|
|
boolean isCommitting = this.checkCommitting(activity.getId()); |
|
|
|
if(isCommitting){ |
|
|
|
Assert.throwEx("该活动核销中"); |
|
|
|
} |
|
|
|
validActivity(activity,true); |
|
|
|
VtbVerification verification = new VtbVerification(); |
|
|
|
verification.setId(verificationBo.getId()); |
|
|
|
verification.setActivityId(verificationBo.getActivityId()); |
|
|
@ -93,6 +119,42 @@ public class VtbVerificationServiceImpl extends ServiceImpl<VtbVerificationMappe |
|
|
|
verificationSubjectService.saveBatch(verificationSubjects); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 校验活动 |
|
|
|
* @param activity |
|
|
|
* @param filterActTime 释放拦截活动结束 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private BigDecimal validActivity(TbsActivity activity,boolean filterActTime){ |
|
|
|
LocalDate nowDate = LocalDate.now(); |
|
|
|
if(activity.getReopenFlag().equals(0) |
|
|
|
&& filterActTime |
|
|
|
&& nowDate.isAfter(activity.getActEndDate())){ |
|
|
|
Assert.throwEx("活动已结束"); |
|
|
|
} |
|
|
|
if(activity.getReleaseFlag().equals(1)){ |
|
|
|
Assert.throwEx("费用已释放"); |
|
|
|
} |
|
|
|
if(activity.getFinishedFlag().equals(1)){ |
|
|
|
Assert.throwEx("活动已完成"); |
|
|
|
} |
|
|
|
boolean isCommitting = this.checkCommitting(activity.getId()); |
|
|
|
if(isCommitting){ |
|
|
|
Assert.throwEx("该活动核销中,操作失败"); |
|
|
|
} |
|
|
|
List<VtbFundFlow> fundFlowList = fundFlowService.listByActivity(activity.getId(),VtbFundFlowType.Verification); |
|
|
|
BigDecimal totalFunFlow = BigDecimal.ZERO; |
|
|
|
for (VtbFundFlow fundFlow : fundFlowList) { |
|
|
|
totalFunFlow = totalFunFlow.add(fundFlow.getUsedAmount()); |
|
|
|
} |
|
|
|
BigDecimal allowAmount = activity.getTotalAmount().subtract(totalFunFlow); |
|
|
|
if(allowAmount.compareTo(BigDecimal.ZERO)<1){ |
|
|
|
Assert.throwEx("无可用费用"); |
|
|
|
} |
|
|
|
return allowAmount; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验和生成核销费用 |
|
|
|
* @param verificationBo |
|
|
@ -163,7 +225,6 @@ public class VtbVerificationServiceImpl extends ServiceImpl<VtbVerificationMappe |
|
|
|
List<VtbFundFlow> addFundFlowListOfSubject = new ArrayList<>(); |
|
|
|
Long subjectId = verificationSubject.getSubjectId(); |
|
|
|
BigDecimal usedAmount = verificationSubject.getUsedAmount(); |
|
|
|
BigDecimal subtractAmount = verificationSubject.getUsedAmount(); |
|
|
|
List<TbsActivityCenterGoods> activityCenterGoodsOfSubject = centerGoodsMapBySubject.get(subjectId); |
|
|
|
//统计前面项合计金额
|
|
|
|
BigDecimal totalPrefixAmount = BigDecimal.ZERO; |
|
|
|