@ -47,6 +47,8 @@ import com.qs.serve.modules.tbs.entity.dto.TbsCenterGoodBirDTO;
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetCostResult ;
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetCostResult ;
import com.qs.serve.modules.tbs.entity.dto.TbsContractCostSubItem ;
import com.qs.serve.modules.tbs.entity.dto.TbsContractCostSubItem ;
import com.qs.serve.modules.tbs.entity.dto.TbsCostSubItem ;
import com.qs.serve.modules.tbs.entity.dto.TbsCostSubItem ;
import com.qs.serve.modules.tbs.entity.vo.TbsBudgetTableResultVo ;
import com.qs.serve.modules.tbs.entity.vo.TbsBudgetTableVo ;
import com.qs.serve.modules.tbs.mapper.* ;
import com.qs.serve.modules.tbs.mapper.* ;
import com.qs.serve.modules.tbs.service.* ;
import com.qs.serve.modules.tbs.service.* ;
import com.qs.serve.modules.vtb.common.VtbVerificationState ;
import com.qs.serve.modules.vtb.common.VtbVerificationState ;
@ -109,6 +111,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
private VtbVerificationMapper verificationMapper ;
private VtbVerificationMapper verificationMapper ;
private SysAttachService sysAttachService ;
private SysAttachService sysAttachService ;
private BirCenterRateService centerRateService ;
private BirCenterRateService centerRateService ;
private TbsBudgetMatchApplication tbsBudgetMatchApplication ;
@ -257,18 +260,29 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
if ( supplier . getCostFlag ( ) . equals ( 0 ) ) {
if ( supplier . getCostFlag ( ) . equals ( 0 ) ) {
Assert . throwEx ( "[" + supplier . getName ( ) + "]无投放费用权限" ) ;
Assert . throwEx ( "[" + supplier . getName ( ) + "]无投放费用权限" ) ;
}
}
TbsBudgetCostResult result = budgetApplicationService . buildBudgetCostResult ( tbsCostApply . getId ( ) , true , false ) ;
SysUser sysUser = sysUserService . getById ( AuthContextUtils . getSysUserId ( ) ) ;
SysUser sysUser = sysUserService . getById ( AuthContextUtils . getSysUserId ( ) ) ;
sysUser . checkSyAccount ( ) ;
sysUser . checkSyAccount ( ) ;
Map < String , Object > data = new HashMap < > ( 10 ) ;
//匹配方式的result
TbsBudgetCostResult result0 = null ;
TbsBudgetTableResultVo result1 = null ;
//TODO 加载匹配方式
Integer matchType = tbsCostApply . getMatchType ( ) ;
if ( matchType . equals ( 0 ) ) {
result0 = budgetApplicationService . buildBudgetCostResult ( tbsCostApply . getId ( ) , true , false ) ;
} else if ( matchType . equals ( 1 ) ) {
//新的匹配方式
result1 = tbsBudgetMatchApplication . getMatchResult ( tbsCostApply . getId ( ) , false ) ;
}
//恢复绑定
//恢复绑定
this . releaseCost ( tbsCostApply . getId ( ) , 0 ) ;
this . releaseCost ( tbsCostApply . getId ( ) , 0 ) ;
Map < String , Object > data = new HashMap < > ( 10 ) ;
if ( tbsCostApply . getContractFlag ( ) ! = null & & tbsCostApply . getContractFlag ( ) . equals ( 1 ) ) {
if ( tbsCostApply . getContractFlag ( ) ! = null & & tbsCostApply . getContractFlag ( ) . equals ( 1 ) ) {
//创建协议的费用申请Data
//创建协议的费用申请Data
this . buildContractApplyData ( id , tbsCostApply , activityList , payConditions , supplier , sysUser , data ) ;
this . buildContractApplyData ( id , tbsCostApply , activityList , payConditions , supplier , sysUser , data ) ;
} else {
} else {
//创建通用的费用申请Data
//创建通用的费用申请Data
this . buildCommonApplyData ( id , tbsCostApply , activityList , supplier , result , sysUser , data ) ;
this . buildCommonApplyData ( id , tbsCostApply , activityList , supplier , sysUser , data ) ;
}
}
//修改申请编码
//修改申请编码
String templateCode = tbsCostApply . getContractFlag ( ) . equals ( 1 )
String templateCode = tbsCostApply . getContractFlag ( ) . equals ( 1 )
@ -301,19 +315,129 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
//移除历史记录
//移除历史记录
budgetCostItemService . removeByCostApplyId ( costApply . getId ( ) ) ;
budgetCostItemService . removeByCostApplyId ( costApply . getId ( ) ) ;
//保存无命中条件的预算
//保存无命中条件的预算
if ( CollectionUtil . isNotEmpty ( result . getBudgetUnMatchList ( ) ) ) {
List < TbsBudgetLog > budgetLogList = null ;
List < TbsCostUnItem > costUnItems = result . getBudgetUnMatchList ( ) . stream ( )
if ( matchType . equals ( 0 ) ) {
. map ( obj - > CopierUtil . copy ( obj , new TbsCostUnItem ( ) ) ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtil . isNotEmpty ( result0 . getBudgetUnMatchList ( ) ) ) {
tbsCostUnItemService . saveBatch ( costUnItems ) ;
List < TbsCostUnItem > costUnItems = result0 . getBudgetUnMatchList ( ) . stream ( )
. map ( obj - > CopierUtil . copy ( obj , new TbsCostUnItem ( ) ) ) . collect ( Collectors . toList ( ) ) ;
tbsCostUnItemService . saveBatch ( costUnItems ) ;
}
//重新保存
List < TbsBudgetCostItem > allBudgetItem = new ArrayList < > ( ) ;
allBudgetItem . addAll ( result0 . getBudgetMatchList ( ) ) ;
allBudgetItem . addAll ( result0 . getBudgetUnMatchList ( ) ) ;
budgetCostItemService . saveBatch ( allBudgetItem ) ;
//保存预算使用日志
budgetLogList = saveBudgetLog ( result0 . getBudgetList ( ) , sysUser , costApply , result0 . getBudgetMatchList ( ) , result0 . getActivityList ( ) ) ;
} else if ( matchType . equals ( 1 ) ) {
// 未命中预算
List < TbsCostUnItem > costUnItems = new ArrayList < > ( ) ;
// 所有记录情况
List < TbsBudgetCostItem > allBudgetItem = new ArrayList < > ( ) ;
// 命中的预算
budgetLogList = new ArrayList < > ( ) ;
Map < Long , TbsScheduleItemBudget > matchItemBudgetsMap = result1 . getMatchItemBudgetsMap ( ) ;
for ( TbsActivityCenterGoods centerGoods : result1 . getActivityCenterGoodsList ( ) ) {
TbsBudgetCostItem costItem = new TbsBudgetCostItem ( ) ;
costItem . setCenterGoodsCode ( centerGoods . getCenterGoodsCode ( ) ) ;
costItem . setCostApplyId ( centerGoods . getCostApplyId ( ) ) ;
costItem . setActivityId ( centerGoods . getActivityId ( ) ) ;
costItem . setActivityCode ( centerGoods . getActivityCode ( ) ) ;
costItem . setSupplierId ( centerGoods . getSupplierId ( ) ) ;
costItem . setSupplierCode ( centerGoods . getSupplierCode ( ) ) ;
costItem . setSupplierName ( centerGoods . getSupplierName ( ) ) ;
costItem . setSubjectId ( centerGoods . getSubjectId ( ) ) ;
costItem . setSubjectCode ( centerGoods . getSubjectCode ( ) ) ;
costItem . setSubjectName ( centerGoods . getSubjectName ( ) ) ;
costItem . setCenterType ( centerGoods . getCenterType ( ) ) ;
costItem . setCenterId ( centerGoods . getCenterId ( ) ) ;
costItem . setCenterCode ( centerGoods . getCenterCode ( ) ) ;
costItem . setCenterName ( centerGoods . getCenterName ( ) ) ;
costItem . setCenterAmount ( centerGoods . getCenterAmount ( ) ) ;
costItem . setCenterRate ( centerGoods . getCenterRate ( ) ) ;
costItem . setCenterGoodsAmount ( centerGoods . getCenterGoodsAmount ( ) ) ;
costItem . setCenterGoodsRate ( centerGoods . getCenterGoodsRate ( ) ) ;
costItem . setTargetType ( centerGoods . getTargetType ( ) ) ;
costItem . setTargetId ( centerGoods . getTargetId ( ) ) ;
costItem . setTargetCode ( centerGoods . getTargetCode ( ) ) ;
costItem . setTargetName ( centerGoods . getTargetName ( ) ) ;
costItem . setTargetLevelPathIds ( centerGoods . getTargetLevelPathIds ( ) ) ;
costItem . setTargetLevelPathNames ( centerGoods . getTargetLevelPathNames ( ) ) ;
costItem . setActStartDate ( centerGoods . getActStartDate ( ) ) ;
costItem . setActEndDate ( centerGoods . getActEndDate ( ) ) ;
costItem . setPreStartDate ( centerGoods . getPreStartDate ( ) ) ;
costItem . setPreEndDate ( centerGoods . getPreEndDate ( ) ) ;
costItem . setPreCheckDate ( centerGoods . getPreCheckDate ( ) ) ;
costItem . setCenterGoodItemId ( centerGoods . getId ( ) ) ;
if ( centerGoods . getScheduleItemBudgetId ( ) = = null ) {
TbsCostUnItem costUnItem = new TbsCostUnItem ( ) ;
costUnItem . setCostApplyId ( centerGoods . getCostApplyId ( ) ) ;
costUnItem . setActivityId ( centerGoods . getActivityId ( ) ) ;
costUnItem . setActivityCode ( centerGoods . getActivityCode ( ) ) ;
costUnItem . setSubjectId ( centerGoods . getSubjectId ( ) ) ;
costUnItem . setSubjectCode ( centerGoods . getSubjectCode ( ) ) ;
costUnItem . setSubjectName ( centerGoods . getSubjectName ( ) ) ;
costUnItem . setCenterType ( centerGoods . getCenterType ( ) ) ;
costUnItem . setCenterId ( centerGoods . getCenterId ( ) ) ;
costUnItem . setCenterCode ( centerGoods . getCenterCode ( ) ) ;
costUnItem . setCenterName ( centerGoods . getCenterName ( ) ) ;
costUnItem . setAmount ( centerGoods . getCenterGoodsAmount ( ) ) ;
costUnItem . setTargetType ( centerGoods . getTargetType ( ) ) ;
costUnItem . setTargetId ( centerGoods . getTargetId ( ) ) ;
costUnItem . setTargetCode ( centerGoods . getTargetCode ( ) ) ;
costUnItem . setTargetName ( centerGoods . getTargetName ( ) ) ;
costUnItem . setTargetLevelPathIds ( centerGoods . getTargetLevelPathIds ( ) ) ;
costUnItem . setTargetLevelPathNames ( centerGoods . getTargetLevelPathNames ( ) ) ;
costUnItem . setActStartDate ( centerGoods . getActStartDate ( ) ) ;
costUnItem . setActEndDate ( centerGoods . getActEndDate ( ) ) ;
costUnItem . setPreStartDate ( centerGoods . getPreStartDate ( ) ) ;
costUnItem . setPreEndDate ( centerGoods . getPreEndDate ( ) ) ;
costUnItem . setPreCheckDate ( centerGoods . getPreCheckDate ( ) ) ;
costUnItem . setSupplierId ( centerGoods . getSupplierId ( ) ) ;
costUnItem . setSupplierCode ( centerGoods . getSupplierCode ( ) ) ;
costUnItem . setSupplierName ( centerGoods . getSupplierName ( ) ) ;
costUnItems . add ( costUnItem ) ;
costItem . setBudgetId ( 0L ) ;
costItem . setScheduleId ( 0L ) ;
costItem . setScheduleItemId ( 0L ) ;
costItem . setScheduleItemAmount ( BigDecimal . ZERO ) ;
costItem . setScheduleItemAmountUsed ( BigDecimal . ZERO ) ;
costItem . setScheduleItemAmountApply ( BigDecimal . ZERO ) ;
costItem . setScheduleItemBudgetId ( 0L ) ;
} else {
TbsScheduleItemBudget itemBudget = matchItemBudgetsMap . get ( centerGoods . getScheduleItemBudgetId ( ) ) ;
TbsActivity currActivity = null ;
for ( TbsActivity activity : activityList ) {
if ( centerGoods . getActivityId ( ) . equals ( activity . getId ( ) ) ) {
currActivity = activity ;
}
}
TbsBudgetLog budgetLog = TbsBudgetLogBuildUtil . buildTbsBudgetLog ( BudgetLogOptFlag . State_1 , sysUser , costApply , itemBudget , centerGoods , centerGoods . getCenterGoodsAmount ( ) , currActivity ) ;
budgetLogList . add ( budgetLog ) ;
costItem . setBudgetId ( itemBudget . getBudgetId ( ) ) ;
costItem . setScheduleId ( itemBudget . getScheduleId ( ) ) ;
costItem . setScheduleItemId ( itemBudget . getScheduleItemId ( ) ) ;
costItem . setScheduleItemName ( itemBudget . getItemName ( ) ) ;
costItem . setScheduleItemAmount ( itemBudget . getFinalBudgetAmount ( ) ) ;
costItem . setScheduleItemAmountUsed ( itemBudget . getUsedBudgetAmount ( ) ) ;
costItem . setScheduleItemAmountApply ( itemBudget . getUnUsedBudgetAmount ( ) ) ;
costItem . setScheduleItemBudgetId ( itemBudget . getId ( ) ) ;
}
allBudgetItem . add ( costItem ) ;
//保存
if ( costUnItems . size ( ) > 0 ) {
tbsCostUnItemService . saveBatch ( costUnItems ) ;
}
budgetCostItemService . saveBatch ( allBudgetItem ) ;
}
}
}
//重新保存
List < TbsBudgetCostItem > allBudgetItem = new ArrayList < > ( ) ;
allBudgetItem . addAll ( result . getBudgetMatchList ( ) ) ;
allBudgetItem . addAll ( result . getBudgetUnMatchList ( ) ) ;
budgetCostItemService . saveBatch ( allBudgetItem ) ;
//TODO 无匹配的预算item保存到 TbsCostUnItem
//保存预算使用日志
List < TbsBudgetLog > budgetLogList = saveBudgetLog ( result , sysUser , costApply , result . getBudgetMatchList ( ) , result . getActivityList ( ) ) ;
if ( tbsCostApply . getChargeState ( ) . equals ( TbsCostApplyState . State_0_unPublish . getCode ( ) ) ) {
if ( tbsCostApply . getChargeState ( ) . equals ( TbsCostApplyState . State_0_unPublish . getCode ( ) ) ) {
if ( CollectionUtil . isNotEmpty ( budgetLogList ) ) {
if ( CollectionUtil . isNotEmpty ( budgetLogList ) ) {
budgetLogService . saveBatch ( budgetLogList ) ;
budgetLogService . saveBatch ( budgetLogList ) ;
@ -539,7 +663,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
data . put ( "sub" , subList ) ;
data . put ( "sub" , subList ) ;
}
}
private void buildCommonApplyData ( String id , TbsCostApply tbsCostApply , List < TbsActivity > activityList , BmsSupplier supplier , TbsBudgetCostResult result , SysUser sysUser , Map < String , Object > data ) {
private void buildCommonApplyData ( String id , TbsCostApply tbsCostApply , List < TbsActivity > activityList , BmsSupplier supplier , SysUser sysUser , Map < String , Object > data ) {
String actTitles = activityList . stream ( ) . map ( TbsActivity : : getActTitle ) . collect ( Collectors . joining ( "; " ) ) ;
String actTitles = activityList . stream ( ) . map ( TbsActivity : : getActTitle ) . collect ( Collectors . joining ( "; " ) ) ;
data . put ( "costApplyCode" , tbsCostApply . getCode ( ) ) ;
data . put ( "costApplyCode" , tbsCostApply . getCode ( ) ) ;
data . put ( "applyUserCode" , sysUser . getCode ( ) ) ;
data . put ( "applyUserCode" , sysUser . getCode ( ) ) ;
@ -589,7 +713,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
List < Object > subList = new ArrayList < > ( ) ;
List < Object > subList = new ArrayList < > ( ) ;
//创建子表数据
//创建子表数据
try {
try {
this . buildSubList ( result , tbsActivityCenters , subjectNames , subList ) ;
this . buildSubList ( tbsActivityCenters , subjectNames , subList ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
e . printStackTrace ( ) ;
e . printStackTrace ( ) ;
}
}
@ -654,12 +778,11 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
/ * *
/ * *
* 创建子表数据
* 创建子表数据
* @param result
* @param tbsActivityCenters
* @param tbsActivityCenters
* @param subjectNames
* @param subjectNames
* @param subList
* @param subList
* /
* /
private void buildSubList ( TbsBudgetCostResult result , List < TbsActivityCenter > tbsActivityCenters , List < String > subjectNames , List < Object > subList ) {
private void buildSubList ( List < TbsActivityCenter > tbsActivityCenters , List < String > subjectNames , List < Object > subList ) {
for ( String subjectName : subjectNames ) {
for ( String subjectName : subjectNames ) {
subList . add ( new TbsCostSubItem . Subject ( subjectName ) ) ;
subList . add ( new TbsCostSubItem . Subject ( subjectName ) ) ;
}
}
@ -676,14 +799,13 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
/ * *
/ * *
* 保存预算使用日志
* 保存预算使用日志
* @param resul t
* @param budgetLis t
* @param sysUser
* @param sysUser
* @param costApply
* @param costApply
* @param allBudgetItem
* @param allBudgetItem
* /
* /
private List < TbsBudgetLog > saveBudgetLog ( TbsBudgetCostResult resul t, SysUser sysUser , TbsCostApply costApply , List < TbsBudgetCostItem > allBudgetItem , List < TbsActivity > activityList ) {
private List < TbsBudgetLog > saveBudgetLog ( List < TbsBudget > budgetLis t, SysUser sysUser , TbsCostApply costApply , List < TbsBudgetCostItem > allBudgetItem , List < TbsActivity > activityList ) {
List < TbsBudgetLog > budgetLogList = new ArrayList < > ( ) ;
List < TbsBudgetLog > budgetLogList = new ArrayList < > ( ) ;
List < TbsBudget > budgetList = result . getBudgetList ( ) ;
for ( TbsBudgetCostItem item : allBudgetItem ) {
for ( TbsBudgetCostItem item : allBudgetItem ) {
//排除不匹配预算的项
//排除不匹配预算的项
if ( item . getBudgetId ( ) . equals ( 0L ) ) {
if ( item . getBudgetId ( ) . equals ( 0L ) ) {