@ -20,6 +20,7 @@ import com.qs.serve.modules.seeyon.entity.CtpAffairQo;
import com.qs.serve.modules.seeyon.entity.bo.CtpAddNodeParam ;
import com.qs.serve.modules.seeyon.service.SeeYonRequestService ;
import com.qs.serve.modules.sys.entity.SysUser ;
import com.qs.serve.modules.sys.service.SysDeleteLogService ;
import com.qs.serve.modules.sys.service.SysPostUserService ;
import com.qs.serve.modules.sys.service.SysUserService ;
import com.qs.serve.modules.tbs.common.TbsCostApplyState ;
@ -28,12 +29,12 @@ import com.qs.serve.modules.tbs.common.dto.CompensateDTO;
import com.qs.serve.modules.tbs.common.util.TbsBudgetLogBuildUtil ;
import com.qs.serve.modules.tbs.entity.* ;
import com.qs.serve.modules.tbs.entity.bo.* ;
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetCostResult ;
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetScheduleWithAmount ;
import com.qs.serve.modules.tbs.entity.dto.TbsCostBudgetRelateInfo ;
import com.qs.serve.modules.tbs.entity.dto.* ;
import com.qs.serve.modules.tbs.entity.vo.CtpAffairVo ;
import com.qs.serve.modules.tbs.entity.vo.TbsBudgetTableVo ;
import com.qs.serve.modules.tbs.entity.vo.TbsCostApplyVo ;
import com.qs.serve.modules.tbs.mapper.TbsBudgetLogMapper ;
import com.qs.serve.modules.tbs.mapper.TbsCostApplyMapper ;
import com.qs.serve.modules.tbs.service.* ;
import com.qs.serve.modules.tbs.service.impl.TbsCostApplyOperationServiceImpl ;
import lombok.AllArgsConstructor ;
@ -64,6 +65,7 @@ public class TbsCostApplyController {
private TbsCostApplyService tbsCostApplyService ;
private TbsActivityService tbsActivityService ;
private TbsActivityTemplateService tbsActivityTemplateService ;
private TbsActivityCenterGoodsService tbsActivityCenterGoodsService ;
private final TbsActivityGoodsService activityGoodsService ;
private final TbsActivitySubjectService activitySubjectService ;
private final TbsActivityCenterService activityCenterService ;
@ -71,6 +73,7 @@ public class TbsCostApplyController {
private final TbsActivityChannelService activityChannelService ;
private final TbsActivityChannelPointService activityChannelPointService ;
private BmsSupplierService bmsSupplierService ;
private final TbsBudgetLogMapper tbsBudgetLogMapper ;
private BmsRegion2Service region2Service ;
private SysUserService sysUserService ;
private TbsBudgetApplicationService budgetApplicationService ;
@ -81,6 +84,8 @@ public class TbsCostApplyController {
private TbsBudgetCostItemService tbsBudgetCostItemService ;
private TbsBudgetLogService tbsBudgetLogService ;
private TbsScheduleItemBudgetService tbsScheduleItemBudgetService ;
private SysDeleteLogService deleteLogService ;
private TbsCostApplyMapper tbsCostApplyMapper ;
/ * *
@ -509,5 +514,209 @@ public class TbsCostApplyController {
return R . ok ( resultInfoList ) ;
}
/ * *
* 移除费用申请
* @param costApplyId
* @param remark
* @return
* /
@GetMapping ( "removeByAdmin" )
public R < ? > removeByAdmin ( Long costApplyId , String remark ) {
deleteLogService . deleteCostApply ( costApplyId , remark ) ;
return R . ok ( ) ;
}
@GetMapping ( "rebuildBudgetLog" )
public R dealCostBudget ( Long costApplyId ) {
if ( costApplyId ! = null ) {
rebuildBudgetLog ( costApplyId ) ;
return R . ok ( ) ;
}
List < TbsCostErrorBudgetDTO > costErrorBudgetDTOList = tbsCostApplyMapper . selectCostErrorBudgetDTO ( ) ;
for ( TbsCostErrorBudgetDTO budgetDTO : costErrorBudgetDTOList ) {
Long costApplyId2 = budgetDTO . getId ( ) ;
rebuildBudgetLog ( costApplyId2 ) ;
}
return R . ok ( ) ;
}
@GetMapping ( "rebuildBudgetLog3" )
public void dealCostBudget3 ( ) {
List < TbsCostErrorBudgetDTO > costErrorBudgetDTOList = tbsCostApplyMapper . selectCostErrorBudgetDTO ( ) ;
for ( TbsCostErrorBudgetDTO budgetDTO : costErrorBudgetDTOList ) {
Long costApplyId = budgetDTO . getId ( ) ;
centerGoodsAmtToBudgetLog ( costApplyId ) ;
}
}
@GetMapping ( "flushActivityCenterGoodsAmount" )
public void flushActivityCenterGoodsAmount ( ) {
//List<TbsCostErrorBudgetDTO> costErrorBudgetDTOList = tbsCostApplyMapper.selectCostErrorBudgetDTO();
//过滤大额错误订单
// costErrorBudgetDTOList = costErrorBudgetDTOList.stream().filter(a->a.getTotalActivityAmount()
// .subtract(a.getSumBudget())
// .abs()
// .compareTo(BigDecimal.ONE)<1).collect(Collectors.toList());
//List<Long> costApplyIds = costErrorBudgetDTOList.stream().map(TbsCostErrorBudgetDTO::getId).distinct().collect(Collectors.toList());
List < Long > costApplyIds = new ArrayList < > ( ) ;
costApplyIds . add ( 263925L ) ;
costApplyIds . add ( 263930L ) ;
costApplyIds . add ( 270102L ) ;
List < TbsActNotMatchAmtCenterGoods > notMatchAmtCenterGoodsList = activityCenterGoodsService . listNotMatchAmtCenterGoods ( costApplyIds ) ;
List < Long > activityIds = notMatchAmtCenterGoodsList . stream ( ) . map ( a - > a . getActivityId ( ) ) . collect ( Collectors . toList ( ) ) ;
for ( Long activityId : activityIds ) {
List < TbsActivityCenterGoods > activityCenterGoodsList = activityCenterGoodsService . listByActivityId ( activityId ) ;
Map < String , List < TbsActivityCenterGoods > > stringListMap = activityCenterGoodsList . stream ( )
. collect ( Collectors . groupingBy ( a - > a . getSubjectId ( ) + "_" + a . getCenterType ( ) + "_" + a . getCenterId ( ) ) ) ;
for ( String key : stringListMap . keySet ( ) ) {
List < TbsActivityCenterGoods > list = stringListMap . get ( key ) ;
BigDecimal totalAmountOfCenter = list . get ( 0 ) . getCenterAmount ( ) ;
BigDecimal totalCenterGoods = BigDecimal . ZERO ;
for ( TbsActivityCenterGoods centerGoods : list ) {
totalCenterGoods = totalCenterGoods . add ( centerGoods . getCenterGoodsAmount ( ) ) ;
}
BigDecimal diff = totalAmountOfCenter . subtract ( totalCenterGoods ) ;
if ( diff . compareTo ( BigDecimal . ZERO ) ! = 0 & & diff . compareTo ( BigDecimal . ONE ) < 0 ) {
TbsActivityCenterGoods centerGoods = list . get ( 0 ) ;
centerGoods . setCenterGoodsAmount ( centerGoods . getCenterGoodsAmount ( ) . add ( diff ) ) ;
activityCenterGoodsService . updateById ( centerGoods ) ;
}
}
}
}
private void centerGoodsAmtToBudgetLog ( Long costApplyId ) {
LambdaQueryWrapper < TbsBudgetLog > logLqw = new LambdaQueryWrapper < > ( ) ;
logLqw . eq ( TbsBudgetLog : : getCostApplyId , costApplyId ) ;
logLqw . lt ( TbsBudgetLog : : getOptType , 7 ) ;
List < TbsBudgetLog > budgetLogList = tbsBudgetLogMapper . selectList ( logLqw ) ;
List < TbsActivityCenterGoods > activityCenterGoodsList = activityCenterGoodsService . listByCostApplyId ( costApplyId ) ;
if ( budgetLogList . size ( ) = = activityCenterGoodsList . size ( ) ) {
List < TbsBudgetLog > updBudgetLogList = new ArrayList < > ( ) ;
for ( TbsBudgetLog budgetLog : budgetLogList ) {
TbsBudgetLog tmpObject = null ;
for ( TbsActivityCenterGoods centerGoods : activityCenterGoodsList ) {
if ( budgetLog . getActivityId ( ) . equals ( centerGoods . getActivityId ( ) )
& & budgetLog . getSubjectId ( ) . equals ( centerGoods . getSubjectId ( ) )
& & budgetLog . getCenterType ( ) . equals ( centerGoods . getCenterType ( ) )
& & budgetLog . getCenterId ( ) . equals ( centerGoods . getCenterId ( ) )
& & budgetLog . getTargetId ( ) . equals ( centerGoods . getTargetId ( ) )
//&&budgetLog.getScheduleItemBudgetId().equals(centerGoods.getScheduleItemBudgetId())
) {
budgetLog . setAmount ( centerGoods . getCenterGoodsAmount ( ) . negate ( ) ) ;
tmpObject = budgetLog ;
//tbsBudgetLogMapper.updateById(budgetLog);
}
}
if ( tmpObject = = null ) {
break ;
}
updBudgetLogList . add ( tmpObject ) ;
}
if ( updBudgetLogList . size ( ) = = budgetLogList . size ( ) ) {
for ( TbsBudgetLog budgetLog : updBudgetLogList ) {
tbsBudgetLogMapper . updateById ( budgetLog ) ;
}
}
}
}
/ * *
* 方法不可行
* /
@Deprecated
//@GetMapping("rebuildBudgetLog2")
public void dealCostBudget2 ( ) {
List < TbsCostErrorBudgetDTO > costErrorBudgetDTOList = new ArrayList < > ( ) ;
costErrorBudgetDTOList . add ( new TbsCostErrorBudgetDTO ( ) ) ;
//List<TbsCostErrorBudgetDTO> costErrorBudgetDTOList = tbsCostApplyMapper.selectCostErrorBudgetDTO();
for ( TbsCostErrorBudgetDTO budgetDTO : costErrorBudgetDTOList ) {
//Long costApplyId = budgetDTO.getId();
Long costApplyId = 115356L ;
//BigDecimal diff = budgetDTO.getTotalActivityAmount().subtract(budgetDTO.getSumBudget());
// if(diff.abs().compareTo(BigDecimal.ONE)<0){
LambdaQueryWrapper < TbsBudgetLog > logLqw = new LambdaQueryWrapper < > ( ) ;
logLqw . eq ( TbsBudgetLog : : getCostApplyId , costApplyId ) ;
logLqw . lt ( TbsBudgetLog : : getOptType , 7 ) ;
List < TbsBudgetLog > budgetLogList = tbsBudgetLogMapper . selectList ( logLqw ) ;
List < TbsBudgetCostItem > budgetCostItemList = tbsBudgetCostItemService . listByCostApplyId ( costApplyId ) ;
if ( budgetCostItemList . size ( ) = = budgetLogList . size ( ) ) {
for ( TbsBudgetLog budgetLog : budgetLogList ) {
for ( TbsBudgetCostItem costItem : budgetCostItemList ) {
if ( budgetLog . getActivityId ( ) . equals ( costItem . getActivityId ( ) )
& & budgetLog . getSubjectId ( ) . equals ( costItem . getSubjectId ( ) )
& & budgetLog . getCenterType ( ) . equals ( costItem . getCenterType ( ) )
& & budgetLog . getCenterId ( ) . equals ( costItem . getCenterId ( ) )
& & budgetLog . getTargetId ( ) . equals ( costItem . getTargetId ( ) )
& & budgetLog . getScheduleItemBudgetId ( ) . equals ( costItem . getScheduleItemBudgetId ( ) )
) {
budgetLog . setAmount ( costItem . getCenterGoodsAmount ( ) . negate ( ) ) ;
tbsBudgetLogMapper . updateById ( budgetLog ) ;
}
}
}
// }
}
return ;
}
}
public void rebuildBudgetLog ( Long costApplyId ) {
TbsCostApply costApply = tbsCostApplyMapper . selectById ( costApplyId ) ;
//调整center_goods和budget_log之间的占用
BigDecimal centerGoodsTotal = tbsCostApplyMapper . sumCostCenterGoodsAmount ( costApplyId ) ;
BigDecimal costAmt = costApply . getTotalActivityAmount ( ) ;
//判断合计金额与预算是否有差距过大
boolean diffCostCenterGoods = costAmt . subtract ( centerGoodsTotal ) . intValue ( ) ! = 0 ;
if ( diffCostCenterGoods ) {
log . error ( "{}金额错误" , costApply . getId ( ) ) ;
return ;
}
//BigDecimal costAmountBudget = tbsCostApplyMapper.sumCostAmountBudget(costApplyId);
//判断是否有释放,没有直接清理(后续可修改为全部清理)
LambdaQueryWrapper < TbsBudgetLog > budgetLogLqw = new LambdaQueryWrapper < > ( ) ;
budgetLogLqw . eq ( TbsBudgetLog : : getCostApplyId , costApply . getId ( ) ) ;
budgetLogLqw . eq ( TbsBudgetLog : : getOptType , 1 ) ;
List < TbsBudgetLog > budgetLogList = tbsBudgetLogMapper . selectList ( budgetLogLqw ) ;
List < TbsActivityCenterGoods > activityCenterGoodsList = tbsActivityCenterGoodsService . listByCostApplyId ( costApplyId ) ;
List < Long > updateLogIdsList = new ArrayList < > ( ) ;
updateLogIdsList . add ( 0L ) ;
if ( activityCenterGoodsList . size ( ) = = budgetLogList . size ( ) ) {
for ( TbsActivityCenterGoods centerGoods : activityCenterGoodsList ) {
for ( TbsBudgetLog budgetLog : budgetLogList ) {
if ( budgetLog . getActivityId ( ) . equals ( centerGoods . getActivityId ( ) )
& & budgetLog . getSubjectId ( ) . equals ( centerGoods . getSubjectId ( ) )
& & budgetLog . getCenterType ( ) . equals ( centerGoods . getCenterType ( ) )
& & budgetLog . getCenterId ( ) . equals ( centerGoods . getCenterId ( ) )
& & budgetLog . getTargetId ( ) . equals ( centerGoods . getTargetId ( ) )
) {
budgetLog . setAmount ( centerGoods . getCenterGoodsAmount ( ) . negate ( ) ) ;
tbsBudgetLogMapper . updateById ( budgetLog ) ;
updateLogIdsList . add ( budgetLog . getId ( ) ) ;
break ;
}
}
}
LambdaQueryWrapper < TbsBudgetLog > delBudgetLogLqw = new LambdaQueryWrapper < > ( ) ;
delBudgetLogLqw . eq ( TbsBudgetLog : : getCostApplyId , costApply . getId ( ) ) ;
delBudgetLogLqw . notIn ( TbsBudgetLog : : getId , updateLogIdsList ) ;
tbsBudgetLogMapper . delete ( delBudgetLogLqw ) ;
}
}
}