|
@ -26,21 +26,16 @@ import com.qs.serve.modules.tbs.entity.*; |
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsAffairCommitBo; |
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsAffairCommitBo; |
|
|
import com.qs.serve.modules.tbs.entity.vo.CtpAffairVo; |
|
|
import com.qs.serve.modules.tbs.entity.vo.CtpAffairVo; |
|
|
import com.qs.serve.modules.tbs.mapper.*; |
|
|
import com.qs.serve.modules.tbs.mapper.*; |
|
|
import com.qs.serve.modules.tbs.service.TbsActivityCenterGoodsService; |
|
|
import com.qs.serve.modules.tbs.service.*; |
|
|
import com.qs.serve.modules.tbs.service.TbsBudgetLogService; |
|
|
|
|
|
import com.qs.serve.modules.tbs.service.TbsCostApplyPart1Service; |
|
|
|
|
|
import com.qs.serve.modules.tbs.service.TbsCostApplyService; |
|
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.RoundingMode; |
|
|
import java.math.RoundingMode; |
|
|
import java.time.LocalDateTime; |
|
|
import java.time.LocalDateTime; |
|
|
import java.util.ArrayList; |
|
|
import java.util.*; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Locale; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -53,6 +48,7 @@ import java.util.stream.Collectors; |
|
|
public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService { |
|
|
public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService { |
|
|
|
|
|
|
|
|
private final TbsBudgetLogService tbsBudgetLogService; |
|
|
private final TbsBudgetLogService tbsBudgetLogService; |
|
|
|
|
|
private final TbsBudgetCostItemService tbsBudgetCostItemService; |
|
|
private final SeeYonRequestService requestService; |
|
|
private final SeeYonRequestService requestService; |
|
|
private final SysUserService sysUserService; |
|
|
private final SysUserService sysUserService; |
|
|
|
|
|
|
|
@ -61,6 +57,7 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService |
|
|
private final SysUserMapper userMapper; |
|
|
private final SysUserMapper userMapper; |
|
|
private final TbsActivitySlottingFeeMapper activitySlottingFeeMapper; |
|
|
private final TbsActivitySlottingFeeMapper activitySlottingFeeMapper; |
|
|
private final TbsBudgetLogMapper tbsBudgetLogMapper; |
|
|
private final TbsBudgetLogMapper tbsBudgetLogMapper; |
|
|
|
|
|
private final TbsBudgetMapper tbsBudgetMapper; |
|
|
|
|
|
|
|
|
private final TbsCostApplyPart1Service costApplyPart1Service; |
|
|
private final TbsCostApplyPart1Service costApplyPart1Service; |
|
|
private final TbsActivitySubjectMapper activitySubjectMapper; |
|
|
private final TbsActivitySubjectMapper activitySubjectMapper; |
|
@ -194,6 +191,17 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Object doNext(TbsAffairCommitBo param) { |
|
|
public Object doNext(TbsAffairCommitBo param) { |
|
|
|
|
|
Long targetId = Long.parseLong(this.getTargetId(param)); |
|
|
|
|
|
// 更新金额
|
|
|
|
|
|
TbsCostApply apply = new TbsCostApply(); |
|
|
|
|
|
// TODO 1.有修改金额为0的异常;2.需要调整预算占用
|
|
|
|
|
|
BigDecimal totalApply = checkToChangeAmount(param); |
|
|
|
|
|
apply.setId(targetId); |
|
|
|
|
|
if(totalApply!=null){ |
|
|
|
|
|
apply.setTotalActivityAmount(totalApply); |
|
|
|
|
|
apply.setEditAmountFlag(1); |
|
|
|
|
|
} |
|
|
|
|
|
costApplyService.updateById(apply); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -219,20 +227,55 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService |
|
|
Long targetId = Long.parseLong(this.getTargetId(param)); |
|
|
Long targetId = Long.parseLong(this.getTargetId(param)); |
|
|
// 更新金额
|
|
|
// 更新金额
|
|
|
TbsCostApply apply = new TbsCostApply(); |
|
|
TbsCostApply apply = new TbsCostApply(); |
|
|
// TODO 1.有修改金额为0的异常;2.需要调整预算占用
|
|
|
|
|
|
BigDecimal totalApply = checkToChangeAmount(param); |
|
|
BigDecimal totalApply = checkToChangeAmount(param); |
|
|
apply.setId(targetId); |
|
|
apply.setId(targetId); |
|
|
// if(totalApply!=null){
|
|
|
if(totalApply!=null){ |
|
|
// apply.setTotalActivityAmount(totalApply);
|
|
|
apply.setTotalActivityAmount(totalApply); |
|
|
// apply.setEditAmountFlag(1);
|
|
|
apply.setEditAmountFlag(1); |
|
|
// }
|
|
|
} |
|
|
apply.setChargeState(TbsCostApplyState.State_2_actioning.getCode()); |
|
|
apply.setChargeState(TbsCostApplyState.State_2_actioning.getCode()); |
|
|
costApplyService.updateById(apply); |
|
|
costApplyService.updateById(apply); |
|
|
TbsCostApply costApply = costApplyService.getById(targetId); |
|
|
TbsCostApply costApply = costApplyService.getById(targetId); |
|
|
|
|
|
//判断异动
|
|
|
if(costApply.getChangeSourceId()!=null){ |
|
|
if(costApply.getChangeSourceId()!=null){ |
|
|
//移除
|
|
|
//移除
|
|
|
tbsBudgetLogMapper.updateLogDelFlagByCostApply(costApply.getChangeSourceId(),1); |
|
|
tbsBudgetLogMapper.updateLogDelFlagByCostApply(costApply.getChangeSourceId(),1); |
|
|
} |
|
|
} |
|
|
|
|
|
//判断审批过程,是否修改了金额
|
|
|
|
|
|
if(costApply.getEditAmountFlag().equals(1)){ |
|
|
|
|
|
//修改预算占用
|
|
|
|
|
|
TbsActivityCenterGoodsService tbsActivityCenterGoodsService = SpringUtils.getBean(TbsActivityCenterGoodsService.class); |
|
|
|
|
|
List<TbsActivityCenterGoods> activityCenterGoodsList = tbsActivityCenterGoodsService.listByCostApplyId(costApply.getId()); |
|
|
|
|
|
//查询当前预算占用
|
|
|
|
|
|
LambdaQueryWrapper<TbsBudgetLog> logLqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
logLqw.eq(TbsBudgetLog::getRollbackFlag,BudgetLogRollbackFlag.State_0); |
|
|
|
|
|
logLqw.eq(TbsBudgetLog::getCostApplyId,costApply.getId()); |
|
|
|
|
|
logLqw.and(qw->{ |
|
|
|
|
|
qw.eq(TbsBudgetLog::getOptType,BudgetLogOptFlag.State_1.getCode()).or() |
|
|
|
|
|
.eq(TbsBudgetLog::getOptType,BudgetLogOptFlag.State_6.getCode()); |
|
|
|
|
|
}); |
|
|
|
|
|
List<TbsBudgetLog> budgetLogList = tbsBudgetLogService.list(logLqw); |
|
|
|
|
|
//移除旧预算占用,即添预算
|
|
|
|
|
|
budgetLogList.forEach(bl->{ |
|
|
|
|
|
bl.setId(null); |
|
|
|
|
|
bl.setOptType(BudgetLogOptFlag.State_5.getCode()); |
|
|
|
|
|
bl.setAmount(bl.getAmount().negate()); |
|
|
|
|
|
//标记已完成
|
|
|
|
|
|
bl.setRollbackFlag(BudgetLogRollbackFlag.State_2); |
|
|
|
|
|
bl.setCreateBy(null); |
|
|
|
|
|
bl.setCreateTime(null); |
|
|
|
|
|
bl.setUpdateTime(null); |
|
|
|
|
|
bl.setUpdateBy(null); |
|
|
|
|
|
}); |
|
|
|
|
|
tbsBudgetLogService.saveBatch(budgetLogList); |
|
|
|
|
|
//保存新的预算占用
|
|
|
|
|
|
SysUser sysUser = sysUserService.getById(costApply.getUserId()); |
|
|
|
|
|
List<TbsBudgetCostItem> budgetCostItemList = tbsBudgetCostItemService.listByCostApplyId(costApply.getId()); |
|
|
|
|
|
List<Long> budgetIds = budgetCostItemList.stream().map(TbsBudgetCostItem::getBudgetId).collect(Collectors.toList()); |
|
|
|
|
|
List<TbsBudget> budgetList = tbsBudgetMapper.selectBatchIds(budgetIds); |
|
|
|
|
|
List<TbsBudgetLog> newBudgetLogList = this.createNewBudgetLogs(costApply, activityCenterGoodsList, sysUser, budgetCostItemList, budgetList); |
|
|
|
|
|
tbsBudgetLogService.saveBatch(newBudgetLogList); |
|
|
|
|
|
} |
|
|
//更新活动通过时间
|
|
|
//更新活动通过时间
|
|
|
TbsActivity tbsActivity = new TbsActivity(); |
|
|
TbsActivity tbsActivity = new TbsActivity(); |
|
|
tbsActivity.setCostPassTime(LocalDateTime.now()); |
|
|
tbsActivity.setCostPassTime(LocalDateTime.now()); |
|
@ -244,14 +287,69 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 创建新的预算占用记录 |
|
|
|
|
|
* @param costApply |
|
|
|
|
|
* @param activityCenterGoodsList |
|
|
|
|
|
* @param sysUser |
|
|
|
|
|
* @param budgetCostItemList |
|
|
|
|
|
* @param budgetList |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@NotNull |
|
|
|
|
|
private List<TbsBudgetLog> createNewBudgetLogs(TbsCostApply costApply, List<TbsActivityCenterGoods> activityCenterGoodsList, SysUser sysUser, List<TbsBudgetCostItem> budgetCostItemList, List<TbsBudget> budgetList) { |
|
|
|
|
|
List<TbsBudgetLog> newBudgetLogList = new ArrayList<>(); |
|
|
|
|
|
for (TbsBudgetCostItem budgetCostItem : budgetCostItemList) { |
|
|
|
|
|
TbsActivityCenterGoods currentCenterGoods = null; |
|
|
|
|
|
for (TbsActivityCenterGoods centerGoods : activityCenterGoodsList) { |
|
|
|
|
|
if(centerGoods.getId().equals(budgetCostItem.getCenterGoodItemId())){ |
|
|
|
|
|
currentCenterGoods = centerGoods; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if(currentCenterGoods==null){ |
|
|
|
|
|
log.error("费用申请单据异常,审批时费用调整后,数据不匹配。ID: {} ; 编码:{}", |
|
|
|
|
|
costApply.getId(), costApply.getCode()); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
String budgetCode = ""; |
|
|
|
|
|
for (TbsBudget budget : budgetList) { |
|
|
|
|
|
if(budget.getId().equals(currentCenterGoods.getBudgetId())){ |
|
|
|
|
|
budgetCode = budget.getBudgetNumber(); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
TbsBudgetLog budgetLog = budgetCostItem.toBudgetLog( |
|
|
|
|
|
costApply, |
|
|
|
|
|
BudgetLogOptFlag.State_6, |
|
|
|
|
|
currentCenterGoods.getCenterGoodsAmount(), |
|
|
|
|
|
sysUser, |
|
|
|
|
|
budgetCode |
|
|
|
|
|
,currentCenterGoods.getActivityCode()); |
|
|
|
|
|
newBudgetLogList.add(budgetLog); |
|
|
|
|
|
} |
|
|
|
|
|
return newBudgetLogList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public BigDecimal checkToChangeAmount(TbsAffairCommitBo param) { |
|
|
public BigDecimal checkToChangeAmount(TbsAffairCommitBo param) { |
|
|
Long targetId = Long.parseLong(this.getTargetId(param)); |
|
|
Long targetId = Long.parseLong(this.getTargetId(param)); |
|
|
|
|
|
TbsCostApply costApply = costApplyService.getById(targetId); |
|
|
|
|
|
boolean noChanged = costApply.getEditAmountFlag().equals(0); |
|
|
if(CollectionUtil.isNotEmpty(param.getAffairSubjectLines())){ |
|
|
if(CollectionUtil.isNotEmpty(param.getAffairSubjectLines())){ |
|
|
BigDecimal n100 = new BigDecimal("100"); |
|
|
BigDecimal n100 = new BigDecimal("100"); |
|
|
QueryWrapper comm_qw = new QueryWrapper(); |
|
|
QueryWrapper comm_qw = new QueryWrapper(); |
|
|
comm_qw.eq("cost_apply_id", targetId); |
|
|
comm_qw.eq("cost_apply_id", targetId); |
|
|
List<TbsActivity> activityList = tbsActivityMapper.selectList(comm_qw); |
|
|
List<TbsActivity> activityList = tbsActivityMapper.selectList(comm_qw); |
|
|
List<TbsActivitySubject> activitySubjectList = activitySubjectMapper.selectList(comm_qw); |
|
|
List<TbsActivitySubject> activitySubjectList = activitySubjectMapper.selectList(comm_qw); |
|
|
|
|
|
//判断subjectId是否匹配
|
|
|
|
|
|
Set<Long> subjectIds = new HashSet<>(param.getAffairSubjectLines().stream() |
|
|
|
|
|
.map(TbsAffairCommitBo.AffairSubjectLine::getSubjectId).collect(Collectors.toList())); |
|
|
|
|
|
for (TbsActivitySubject activitySubject : activitySubjectList) { |
|
|
|
|
|
subjectIds.add(activitySubject.getId()); |
|
|
|
|
|
} |
|
|
|
|
|
if(subjectIds.size()>activitySubjectList.size()){ |
|
|
|
|
|
Assert.throwEx("请求有错误的参数"); |
|
|
|
|
|
} |
|
|
List<TbsActivityCenter> activityCenterList = activityCenterMapper.selectList(comm_qw); |
|
|
List<TbsActivityCenter> activityCenterList = activityCenterMapper.selectList(comm_qw); |
|
|
TbsActivityCenterGoodsService tbsActivityCenterGoodsService = SpringUtils.getBean(TbsActivityCenterGoodsService.class); |
|
|
TbsActivityCenterGoodsService tbsActivityCenterGoodsService = SpringUtils.getBean(TbsActivityCenterGoodsService.class); |
|
|
List<TbsActivityCenterGoods> activityCenterGoodsList = tbsActivityCenterGoodsService.listByCostApplyId(targetId); |
|
|
List<TbsActivityCenterGoods> activityCenterGoodsList = tbsActivityCenterGoodsService.listByCostApplyId(targetId); |
|
@ -271,10 +369,11 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService |
|
|
activity.setTotalAmount(activity.getTotalAmount().add(subjectAmount)); |
|
|
activity.setTotalAmount(activity.getTotalAmount().add(subjectAmount)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if(subject.getOrgAmount()==null){ |
|
|
if(noChanged){ |
|
|
//只对第一次赋值
|
|
|
//只对第一次赋值
|
|
|
subject.setOrgAmount(subject.getAmount()); |
|
|
subject.setOrgAmount(subject.getAmount()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
subject.setAmount(subjectAmount); |
|
|
subject.setAmount(subjectAmount); |
|
|
subject.setCountPerson(subjectLine.getCountPerson()); |
|
|
subject.setCountPerson(subjectLine.getCountPerson()); |
|
|
subject.setCountSession(subjectLine.getCountSession()); |
|
|
subject.setCountSession(subjectLine.getCountSession()); |
|
@ -287,7 +386,7 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService |
|
|
if(eqActivity&&eqSubject){ |
|
|
if(eqActivity&&eqSubject){ |
|
|
BigDecimal centerAmt = activityCenter.getCenterRate() |
|
|
BigDecimal centerAmt = activityCenter.getCenterRate() |
|
|
.multiply(subjectAmount).divide(n100,2, RoundingMode.HALF_UP); |
|
|
.multiply(subjectAmount).divide(n100,2, RoundingMode.HALF_UP); |
|
|
if (activityCenter.getOrgCenterAmount()==null){ |
|
|
if (noChanged){ |
|
|
//只对第一次赋值
|
|
|
//只对第一次赋值
|
|
|
activityCenter.setOrgCenterAmount(activityCenter.getCenterAmount()); |
|
|
activityCenter.setOrgCenterAmount(activityCenter.getCenterAmount()); |
|
|
} |
|
|
} |
|
@ -302,9 +401,9 @@ public class TbsCostApplyOperationServiceImpl implements SeeYonOperationService |
|
|
&¢erGoods.getCenterId().equals(activityCenter.getCenterId()); |
|
|
&¢erGoods.getCenterId().equals(activityCenter.getCenterId()); |
|
|
boolean eqSubject4Goods = centerGoods.getSubjectId().equals(activityCenter.getSubjectId()); |
|
|
boolean eqSubject4Goods = centerGoods.getSubjectId().equals(activityCenter.getSubjectId()); |
|
|
if(eqActivity4Goods&&eqCenter4Goods&&eqSubject4Goods){ |
|
|
if(eqActivity4Goods&&eqCenter4Goods&&eqSubject4Goods){ |
|
|
if(centerGoods.getOrgCenterGoodsAmount()==null){ |
|
|
if(noChanged){ |
|
|
//只对第一次赋值
|
|
|
//只对第一次赋值
|
|
|
centerGoods.setOrgCenterAmount(activityCenter.getOrgCenterAmount()); |
|
|
centerGoods.setOrgCenterAmount(activityCenter.getCenterAmount()); |
|
|
centerGoods.setOrgCenterGoodsAmount(centerGoods.getCenterGoodsAmount()); |
|
|
centerGoods.setOrgCenterGoodsAmount(centerGoods.getCenterGoodsAmount()); |
|
|
} |
|
|
} |
|
|
centerGoods.setCenterAmount(centerAmt); |
|
|
centerGoods.setCenterAmount(centerAmt); |
|
|