|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.qs.serve.modules.vtb.service; |
|
|
|
|
|
|
|
import cn.hutool.core.date.StopWatch; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.qs.serve.common.exception.Assert; |
|
|
|
import com.qs.serve.common.utils.SpringUtils; |
|
|
@ -29,6 +30,7 @@ import com.qs.serve.modules.tbs.entity.vo.CtpAffairVo; |
|
|
|
import com.qs.serve.modules.tbs.service.TbsActivityPayConditionService; |
|
|
|
import com.qs.serve.modules.tbs.service.TbsActivityService; |
|
|
|
import com.qs.serve.modules.tbs.service.TbsCostApplyService; |
|
|
|
import com.qs.serve.modules.vtb.common.VerificationUtil; |
|
|
|
import com.qs.serve.modules.vtb.common.VtbVerificationState; |
|
|
|
import com.qs.serve.modules.vtb.entity.*; |
|
|
|
import com.qs.serve.modules.vtb.mapper.VtbVerificationMapper; |
|
|
@ -36,6 +38,7 @@ import com.qs.serve.modules.vtb.service.impl.VtbVerificationOperationServiceImpl |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
@ -48,6 +51,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -77,10 +81,11 @@ public class VtbVerificationApplication { |
|
|
|
private VtbVerificationOperationServiceImpl verificationOperationService; |
|
|
|
|
|
|
|
public R<?> commitAffair(@RequestBody @Valid TbsAffairCommitBo affairCommit){ |
|
|
|
//临时测试
|
|
|
|
boolean devFlag = false; |
|
|
|
StopWatch stopWatch = new StopWatch(); |
|
|
|
VtbVerification verification = vtbVerificationService.getById(affairCommit.getCostApplyId()); |
|
|
|
String verificationCode = verification.getVerificationCode(); |
|
|
|
//更新释放标识
|
|
|
|
VerificationUtil.startLog(stopWatch,"更新释放标识"); |
|
|
|
if(affairCommit.getReleaseFlag()!=null){ |
|
|
|
VtbVerification vtbVer = new VtbVerification(); |
|
|
|
vtbVer.setId(verification.getId()); |
|
|
@ -90,6 +95,9 @@ public class VtbVerificationApplication { |
|
|
|
//完成时会调用更新
|
|
|
|
verification.setRegReleaseFlag(affairCommit.getReleaseFlag()); |
|
|
|
} |
|
|
|
VerificationUtil.stop(stopWatch); |
|
|
|
|
|
|
|
VerificationUtil.startLog(stopWatch,"检验核销单据状态变更"); |
|
|
|
if(!verification.getVerificationState().equals(VtbVerificationState.Commiting.getCode())){ |
|
|
|
VtbVerificationOperationServiceImpl optSvc = SpringUtils.getBean(VtbVerificationOperationServiceImpl.class); |
|
|
|
optSvc.runCompensate(verification.getId()+""); |
|
|
@ -98,27 +106,27 @@ public class VtbVerificationApplication { |
|
|
|
Assert.throwEx("核销单据状态已变更,请刷新页面"); |
|
|
|
} |
|
|
|
} |
|
|
|
VerificationUtil.stop(stopWatch); |
|
|
|
|
|
|
|
List<VtbVerificationSubjectCenter> verificationSubjectCenterList = vtbVerificationSubjectCenterService.listByVerificationId(verification.getId()); |
|
|
|
List<VtbVerificationSubject> verificationSubjects = vtbVerificationSubjectService.listByVerificationId(verification.getId()); |
|
|
|
//检测参数的金额
|
|
|
|
log.debug("checkParamAmount 检测参数的核销金额"); |
|
|
|
this.checkParamAmount(affairCommit, verificationSubjectCenterList, verificationSubjects); |
|
|
|
boolean isBackCommit = affairCommit.getState()==2; |
|
|
|
R<String> result; |
|
|
|
if(!devFlag){ |
|
|
|
result = seeYonService.commonCommit(affairCommit, TbsSeeYonConst.CostCheckConf.Code(),verification.getSyFormId()); |
|
|
|
}else { |
|
|
|
result = R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
VerificationUtil.startLog(stopWatch,"提交到OA接口"); |
|
|
|
R<String> result = seeYonService.commonCommit(affairCommit, TbsSeeYonConst.CostCheckConf.Code(),verification.getSyFormId()); |
|
|
|
VerificationUtil.stop(stopWatch,true,verificationCode); |
|
|
|
|
|
|
|
//提交审批
|
|
|
|
log.warn("提交审批到致远,{}",JsonUtil.objectToJson(result)); |
|
|
|
|
|
|
|
|
|
|
|
if(result.getStatus()==200 ){ |
|
|
|
|
|
|
|
|
|
|
|
VerificationUtil.startLog(stopWatch,"二次校验审批状态"); |
|
|
|
String templateCode = verificationOperationService.getTemplateCode(); |
|
|
|
SyAffairStateResult stateResult = verificationOperationService.checkAffairState(verification.getId()+"",templateCode); |
|
|
|
VerificationUtil.stop(stopWatch); |
|
|
|
SyAffairState affairState = stateResult.getState(); |
|
|
|
String summeryResult = affairState.toString(); |
|
|
|
if(affairState.equals(SyAffairState.backed)||affairState.equals(SyAffairState.refuse)){ |
|
|
@ -126,30 +134,16 @@ public class VtbVerificationApplication { |
|
|
|
} |
|
|
|
//提交审批
|
|
|
|
log.warn("提交审批到致远,检查单据[{}]状态:{}",verification.getVerificationCode(),affairState); |
|
|
|
|
|
|
|
//要确保所有不为next才支持回调
|
|
|
|
if(result.getData().equals("next")){ |
|
|
|
summeryResult = "next"; |
|
|
|
} |
|
|
|
|
|
|
|
// 判断是否含有下个节点
|
|
|
|
try { |
|
|
|
Thread.sleep(500); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
VerificationUtil.startLog(stopWatch,"成功回调"); |
|
|
|
R r = commitAffairSuccess(affairCommit, verification, isBackCommit, summeryResult); |
|
|
|
|
|
|
|
//解决同步冻结时有过期的活动
|
|
|
|
tbsActivityService.initReopenState(); |
|
|
|
LambdaQueryWrapper<TbsCostApply> lqwApply = new LambdaQueryWrapper<>(); |
|
|
|
lqwApply.select(TbsCostApply::getId); |
|
|
|
lqwApply.eq(TbsCostApply::getChargeState, TbsCostApplyState.State_2_actioning.getCode()); |
|
|
|
List<TbsCostApply> costApplyList = tbsCostApplyService.list(lqwApply); |
|
|
|
List<Long> costApplyIds = costApplyList.stream().map(TbsCostApply::getId).collect(Collectors.toList()); |
|
|
|
// 更新费用申请的活动的冻结状态
|
|
|
|
tbsActivityService.flushBandingState(costApplyIds); |
|
|
|
VerificationUtil.stop(stopWatch); |
|
|
|
VerificationUtil.startLog(stopWatch,"异步更新冻结状态"); |
|
|
|
asyncFlushBandingState(); |
|
|
|
VerificationUtil.stop(stopWatch,true,verificationCode); |
|
|
|
return r; |
|
|
|
}else if (result.getStatus()==500){ |
|
|
|
return result; |
|
|
@ -157,6 +151,20 @@ public class VtbVerificationApplication { |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
@Async |
|
|
|
public void asyncFlushBandingState() { |
|
|
|
AuthContextUtils.setTenant("001"); |
|
|
|
//解决同步冻结时有过期的活动
|
|
|
|
tbsActivityService.initReopenState(); |
|
|
|
LambdaQueryWrapper<TbsCostApply> lqwApply = new LambdaQueryWrapper<>(); |
|
|
|
lqwApply.select(TbsCostApply::getId); |
|
|
|
lqwApply.eq(TbsCostApply::getChargeState, TbsCostApplyState.State_2_actioning.getCode()); |
|
|
|
List<TbsCostApply> costApplyList = tbsCostApplyService.list(lqwApply); |
|
|
|
List<Long> costApplyIds = costApplyList.stream().map(TbsCostApply::getId).collect(Collectors.toList()); |
|
|
|
// 更新费用申请的活动的冻结状态
|
|
|
|
tbsActivityService.flushBandingState(costApplyIds); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 检查参数的金额 |
|
|
|
* @param affairCommit |
|
|
@ -218,7 +226,6 @@ public class VtbVerificationApplication { |
|
|
|
|
|
|
|
try { |
|
|
|
//保存记录
|
|
|
|
// 判断是否含有下个节点
|
|
|
|
DataAffairCommit dataAffairCommit = new DataAffairCommit(); |
|
|
|
dataAffairCommit.setTargetCode(TbsSeeYonConst.CostCheckConf.Code()); |
|
|
|
dataAffairCommit.setTargetId(verification.getId()+""); |
|
|
@ -285,35 +292,22 @@ public class VtbVerificationApplication { |
|
|
|
Integer countSession = null; |
|
|
|
Integer countPerson = null; |
|
|
|
List<TbsAffairCommitBo.AffairSubjectCenterItemLine> centerItemLineList = null; |
|
|
|
// if(isCenterCommit){
|
|
|
|
if(CollectionUtil.isNotEmpty(affairCommit.getAffairSubjectCenterLines())){ |
|
|
|
for (TbsAffairCommitBo.AffairSubjectCenterLine centerLine : affairCommit.getAffairSubjectCenterLines()) { |
|
|
|
if(currVs.getSubjectId().equals(centerLine.getSubjectId())){ |
|
|
|
changeAmount = BigDecimal.ZERO; |
|
|
|
if(centerLine.getCenterItemLines()!=null){ |
|
|
|
for (TbsAffairCommitBo.AffairSubjectCenterItemLine itemLine : centerLine.getCenterItemLines()) { |
|
|
|
changeAmount = changeAmount.add(itemLine.getAmount()); |
|
|
|
} |
|
|
|
if(CollectionUtil.isNotEmpty(affairCommit.getAffairSubjectCenterLines())){ |
|
|
|
for (TbsAffairCommitBo.AffairSubjectCenterLine centerLine : affairCommit.getAffairSubjectCenterLines()) { |
|
|
|
if(currVs.getSubjectId().equals(centerLine.getSubjectId())){ |
|
|
|
changeAmount = BigDecimal.ZERO; |
|
|
|
if(centerLine.getCenterItemLines()!=null){ |
|
|
|
for (TbsAffairCommitBo.AffairSubjectCenterItemLine itemLine : centerLine.getCenterItemLines()) { |
|
|
|
changeAmount = changeAmount.add(itemLine.getAmount()); |
|
|
|
} |
|
|
|
centerItemLineList = centerLine.getCenterItemLines(); |
|
|
|
countSession = centerLine.getCountSession(); |
|
|
|
countPerson = centerLine.getCountPerson(); |
|
|
|
break; |
|
|
|
} |
|
|
|
centerItemLineList = centerLine.getCenterItemLines(); |
|
|
|
countSession = centerLine.getCountSession(); |
|
|
|
countPerson = centerLine.getCountPerson(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
// }else {
|
|
|
|
// if(CollectionUtil.isNotEmpty(affairCommit.getAffairSubjectLines())){
|
|
|
|
// for (TbsAffairCommitBo.AffairSubjectLine affairSubjectLine : affairCommit.getAffairSubjectLines()) {
|
|
|
|
// if(currVs.getSubjectId().equals(affairSubjectLine.getSubjectId())){
|
|
|
|
// changeAmount = affairSubjectLine.getAmount();
|
|
|
|
// countSession = affairSubjectLine.getCountSession();
|
|
|
|
// countPerson = affairSubjectLine.getCountPerson();
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
} |
|
|
|
//保存明细判断是否更变金额
|
|
|
|
VtbVerificationYardItem yardItem = CopierUtil.copy(currVs,new VtbVerificationYardItem()); |
|
|
|
yardItem.setYardId(yard.getId()); |
|
|
|