|
@ -15,6 +15,7 @@ import com.qs.serve.modules.bir.entity.so.BirMonthCusCenterSo; |
|
|
import com.qs.serve.modules.bir.entity.vo.BirActivityCenterGoodsMonthVo; |
|
|
import com.qs.serve.modules.bir.entity.vo.BirActivityCenterGoodsMonthVo; |
|
|
import com.qs.serve.modules.bir.mapper.BirBaseActivityMapper; |
|
|
import com.qs.serve.modules.bir.mapper.BirBaseActivityMapper; |
|
|
import com.qs.serve.modules.bir.mapper.BirRemoveIdMapper; |
|
|
import com.qs.serve.modules.bir.mapper.BirRemoveIdMapper; |
|
|
|
|
|
import com.qs.serve.modules.bir.service.BirBaseActivityService; |
|
|
import com.qs.serve.modules.bir.service.BirRemoveIdService; |
|
|
import com.qs.serve.modules.bir.service.BirRemoveIdService; |
|
|
import com.qs.serve.modules.bms.entity.BmsCostCenter; |
|
|
import com.qs.serve.modules.bms.entity.BmsCostCenter; |
|
|
import com.qs.serve.modules.bms.entity.BmsRegion; |
|
|
import com.qs.serve.modules.bms.entity.BmsRegion; |
|
@ -66,162 +67,30 @@ import java.util.stream.Collectors; |
|
|
@AllArgsConstructor |
|
|
@AllArgsConstructor |
|
|
public class BirActivityCenterGoodsServiceImpl extends ServiceImpl<BirActivityCenterGoodsMapper,BirActivityCenterGoods> implements BirActivityCenterGoodsService { |
|
|
public class BirActivityCenterGoodsServiceImpl extends ServiceImpl<BirActivityCenterGoodsMapper,BirActivityCenterGoods> implements BirActivityCenterGoodsService { |
|
|
|
|
|
|
|
|
private final TbsActivityCenterGoodsService centerGoodsService; |
|
|
|
|
|
|
|
|
|
|
|
private final BmsCostCenterMapper costCenterMapper; |
|
|
private final BmsCostCenterMapper costCenterMapper; |
|
|
|
|
|
|
|
|
private final BmsRegionMapper regionMapper; |
|
|
private final BmsRegionMapper regionMapper; |
|
|
|
|
|
|
|
|
private final BmsRegion2Mapper region2Mapper; |
|
|
private final BmsRegion2Mapper region2Mapper; |
|
|
|
|
|
|
|
|
private final VtbFundFlowMapper fundFlowMapper; |
|
|
|
|
|
|
|
|
|
|
|
private final TbsActivityMapper activityMapper; |
|
|
private final TbsActivityMapper activityMapper; |
|
|
|
|
|
|
|
|
private final TbsActivityCenterGoodsMapper tbsActivityCenterGoodsMapper; |
|
|
private final TbsActivityCenterGoodsMapper tbsActivityCenterGoodsMapper; |
|
|
|
|
|
|
|
|
private final BirBaseActivityMapper birBaseActivityMapper; |
|
|
|
|
|
|
|
|
|
|
|
private final BmsSupplierMapper bmsSupplierMapper; |
|
|
private final BmsSupplierMapper bmsSupplierMapper; |
|
|
//private final BirRemoveIdMapper birRemoveIdMapper;
|
|
|
|
|
|
|
|
|
|
|
|
private final BirRemoveIdService birRemoveIdService; |
|
|
|
|
|
|
|
|
|
|
|
private final TbsCostApplyMapper tbsCostApplyMapper; |
|
|
private final TbsCostApplyMapper tbsCostApplyMapper; |
|
|
|
|
|
|
|
|
@Override |
|
|
private final BirBaseActivityService birBaseActivityService; |
|
|
public void buildReport(int year, int month) { |
|
|
|
|
|
LocalDate startDate = LocalDate.of(year,month,1); |
|
|
|
|
|
int lastDayNum2 = startDate.lengthOfMonth(); |
|
|
|
|
|
LocalDate endDate = LocalDate.of(year,month,lastDayNum2); |
|
|
|
|
|
//加载所有异动的数据
|
|
|
|
|
|
List<TbsActivityCenterGoods> activityCenterGoodsAllList = this.baseMapper.selectChangeCenterGoods(startDate,endDate,null); |
|
|
|
|
|
|
|
|
|
|
|
//异常状态的费用申请,导致的Bir
|
|
|
|
|
|
birBaseActivityMapper.deleteErrorBir(); |
|
|
|
|
|
birBaseActivityMapper.removeActivityBirError(); |
|
|
|
|
|
|
|
|
|
|
|
List<BirActivityCenterGoods> removeErrorBirList = this.baseMapper.selectErrorBir(); |
|
|
|
|
|
List<Long> errorActIds = removeErrorBirList.stream().map(BirActivityCenterGoods::getActivityId).distinct().collect(Collectors.toList()); |
|
|
|
|
|
this.buildRemoveRecode(errorActIds); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(activityCenterGoodsAllList.size()<1){ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
//添加支持:活动明细删除了,在bir_activity_center_goods还存在
|
|
|
|
|
|
|
|
|
|
|
|
// 删除历史数据
|
|
|
|
|
|
List<Long> activityIds = activityCenterGoodsAllList.stream().filter(a->a.getId()!=null) |
|
|
|
|
|
.map(TbsActivityCenterGoods::getActivityId).collect(Collectors.toList()); |
|
|
|
|
|
this.buildRemoveRecode(activityIds); |
|
|
|
|
|
|
|
|
|
|
|
List<BirActivityCenterGoods> noExist = this.baseMapper.selectNoExistCenterGoods(); |
|
|
|
|
|
if(noExist.size()>0){ |
|
|
|
|
|
List<BirRemoveId> removeIds = noExist.stream().map(a-> { |
|
|
|
|
|
BirRemoveId birRemoveId = new BirRemoveId(); |
|
|
|
|
|
birRemoveId.setDeleteTime(LocalDateTime.now()); |
|
|
|
|
|
birRemoveId.setId(a.getId()); |
|
|
|
|
|
return birRemoveId; |
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
birRemoveIdService.saveBatch(removeIds); |
|
|
|
|
|
} |
|
|
|
|
|
this.removeBatchByIds(noExist); |
|
|
|
|
|
|
|
|
|
|
|
activityCenterGoodsAllList = this.baseMapper.selectChangeCenterGoods(startDate,endDate,null); |
|
|
|
|
|
// activityCenterGoodsAllList = this.baseMapper.selectChangeCenterGoods(null,null,15840L);
|
|
|
|
|
|
if(activityCenterGoodsAllList.size()<1){ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//加载所有自定义成本中心
|
|
|
|
|
|
List<BmsCostCenter> costCenterList = costCenterMapper.selectList(new QueryWrapper<>()); |
|
|
|
|
|
|
|
|
|
|
|
// 按活动id分组
|
|
|
|
|
|
Map<Long,List<TbsActivityCenterGoods>> collectMap = activityCenterGoodsAllList.stream() |
|
|
|
|
|
.collect(Collectors.groupingBy(TbsActivityCenterGoods::getActivityId)); |
|
|
|
|
|
|
|
|
|
|
|
List<Long> costApplyIds = activityCenterGoodsAllList.stream().map(a->a.getCostApplyId()).distinct().collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<BmsSupplier> supplierLqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
supplierLqw.in(BmsSupplier::getId,activityCenterGoodsAllList.stream().map(a->a.getSupplierId()).distinct().collect(Collectors.toList())); |
|
|
|
|
|
List<BmsSupplier> bmsSupplierList = bmsSupplierMapper.selectList(supplierLqw); |
|
|
|
|
|
Map<String,BmsSupplier> supplierMap = bmsSupplierList.stream().collect(Collectors.toMap(BmsSupplier::getId,a->a)); |
|
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<BmsRegion> regionLqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
regionLqw.in(BmsRegion::getId,bmsSupplierList.stream().map(a->a.getRegionLast()).collect(Collectors.toList())); |
|
|
|
|
|
List<BmsRegion> saleRegionList = regionMapper.selectList(regionLqw); |
|
|
|
|
|
Map<String,BmsRegion> saleRegionMap = saleRegionList.stream().collect(Collectors.toMap(BmsRegion::getId,a->a)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<BmsRegion2> region2Lqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
region2Lqw.in(BmsRegion2::getId,bmsSupplierList.stream().map(a->a.getRegion2Last()).collect(Collectors.toList())); |
|
|
|
|
|
List<BmsRegion2> bizRegionList = region2Mapper.selectList(region2Lqw); |
|
|
|
|
|
Map<String,BmsRegion2> bizRegionMap = bizRegionList.stream().collect(Collectors.toMap(BmsRegion2::getId,a->a)); |
|
|
|
|
|
|
|
|
|
|
|
// TODO查询费用释放
|
|
|
|
|
|
// VtbFundFlow flow = new VtbFundFlow();
|
|
|
|
|
|
// flow.setFundType(VtbFundFlowType.Release);
|
|
|
|
|
|
// flow.setSelectActivityIds(new ArrayList<>(collectMap.keySet()));
|
|
|
|
|
|
// List<VtbFundFlowSumAmtDTO> actReleaseList = fundFlowMapper.listSumAmount(flow);
|
|
|
|
|
|
// final Map<Long,BigDecimal> actReleaseMap = new HashMap<>();
|
|
|
|
|
|
// actReleaseList.forEach(actRelease -> actReleaseMap.put(actRelease.getActivityId(),actRelease.getTotalAmt()));
|
|
|
|
|
|
|
|
|
|
|
|
List<TbsCostApply> costApplyList = tbsCostApplyMapper.selectBatchIds(costApplyIds); |
|
|
|
|
|
|
|
|
|
|
|
Map<Long,List<TbsCostApply>> costApplyMap = costApplyList.stream().collect(Collectors.groupingBy(TbsCostApply::getId)); |
|
|
|
|
|
|
|
|
|
|
|
for (Long activityId : collectMap.keySet()) { |
|
|
|
|
|
|
|
|
|
|
|
TbsActivity activity = activityMapper.selectById(activityId); |
|
|
|
|
|
|
|
|
|
|
|
//用于保存的对象列表
|
|
|
|
|
|
List<BirActivityCenterGoods> bacgList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
//创建对象列表
|
|
|
|
|
|
List<TbsActivityCenterGoods> activityCenterGoodsList = collectMap.get(activityId); |
|
|
|
|
|
|
|
|
|
|
|
TbsActivityCenterGoods tempGoods = activityCenterGoodsList.get(0); |
|
|
|
|
|
TbsCostApply costApply = costApplyMap.get(tempGoods.getCostApplyId()).get(0); |
|
|
|
|
|
|
|
|
|
|
|
for (TbsActivityCenterGoods activityCenterGoods : activityCenterGoodsList) { |
|
|
|
|
|
LocalDate actStartDate = activityCenterGoods.getPreStartDate(); |
|
|
|
|
|
LocalDate actEndDate = activityCenterGoods.getPreEndDate(); |
|
|
|
|
|
int currentActDays = (int) (actEndDate.toEpochDay()-actStartDate.toEpochDay()+1); |
|
|
|
|
|
List<DateSplitDTO> dateSplitList = DateSplitUtil.getSplitDto(actStartDate,actEndDate); |
|
|
|
|
|
if(dateSplitList.size()>1){ |
|
|
|
|
|
for (DateSplitDTO currDateSplit : dateSplitList) { |
|
|
|
|
|
//获取该项分割金额对象
|
|
|
|
|
|
BirCenterGoodSplitDTO goodSplitDTO = this.buildSplitAmount(activity,activityCenterGoods, |
|
|
|
|
|
dateSplitList, currDateSplit,currentActDays); |
|
|
|
|
|
//创建底表对象
|
|
|
|
|
|
BirActivityCenterGoods entity = createBirActivityCenterGoodsEntity(costCenterList, |
|
|
|
|
|
activityCenterGoods, currentActDays, currDateSplit, goodSplitDTO,supplierMap,saleRegionMap,bizRegionMap,costApply); |
|
|
|
|
|
bacgList.add(entity); |
|
|
|
|
|
} |
|
|
|
|
|
}else if (dateSplitList.size()==1){ |
|
|
|
|
|
DateSplitDTO currDateSplit = dateSplitList.get(0); |
|
|
|
|
|
//获取该项分割金额对象
|
|
|
|
|
|
BirCenterGoodSplitDTO goodSplitDTO = this.buildSplitAmount(activity,activityCenterGoods, |
|
|
|
|
|
dateSplitList, currDateSplit,currentActDays); |
|
|
|
|
|
//创建底表对象
|
|
|
|
|
|
BirActivityCenterGoods entity = createBirActivityCenterGoodsEntity(costCenterList, |
|
|
|
|
|
activityCenterGoods, currentActDays, currDateSplit, goodSplitDTO,supplierMap,saleRegionMap,bizRegionMap,costApply); |
|
|
|
|
|
bacgList.add(entity); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if(bacgList.size()>0){ |
|
|
|
|
|
this.saveBatch(bacgList); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void rebuildBir(List<Long> costApplyIds) { |
|
|
public void rebuildBir(List<Long> costApplyIds) { |
|
|
|
|
|
|
|
|
|
|
|
//刷新BirBaseActivity
|
|
|
|
|
|
for (Long costApplyId : costApplyIds) { |
|
|
|
|
|
birBaseActivityService.flushByCostId(costApplyId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
LambdaQueryWrapper<TbsActivityCenterGoods> centerGoodsLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<TbsActivityCenterGoods> centerGoodsLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
centerGoodsLambdaQueryWrapper.in(TbsActivityCenterGoods::getCostApplyId,costApplyIds); |
|
|
centerGoodsLambdaQueryWrapper.in(TbsActivityCenterGoods::getCostApplyId,costApplyIds); |
|
|
List<TbsActivityCenterGoods> activityCenterGoodsAllList = tbsActivityCenterGoodsMapper.selectList(centerGoodsLambdaQueryWrapper); |
|
|
List<TbsActivityCenterGoods> activityCenterGoodsAllList = tbsActivityCenterGoodsMapper.selectList(centerGoodsLambdaQueryWrapper); |
|
@ -229,10 +98,6 @@ public class BirActivityCenterGoodsServiceImpl extends ServiceImpl<BirActivityCe |
|
|
if(activityCenterGoodsAllList.size()<1){ |
|
|
if(activityCenterGoodsAllList.size()<1){ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
// 删除历史数据
|
|
|
|
|
|
List<Long> activityIds = activityCenterGoodsAllList.stream().filter(a->a.getId()!=null) |
|
|
|
|
|
.map(TbsActivityCenterGoods::getActivityId).collect(Collectors.toList()); |
|
|
|
|
|
this.buildRemoveRecode(activityIds); |
|
|
|
|
|
|
|
|
|
|
|
//加载所有自定义成本中心
|
|
|
//加载所有自定义成本中心
|
|
|
List<BmsCostCenter> costCenterList = costCenterMapper.selectList(new QueryWrapper<>()); |
|
|
List<BmsCostCenter> costCenterList = costCenterMapper.selectList(new QueryWrapper<>()); |
|
@ -316,26 +181,6 @@ public class BirActivityCenterGoodsServiceImpl extends ServiceImpl<BirActivityCe |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void buildRemoveRecode(List<Long> activityIds) { |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(activityIds)) { |
|
|
|
|
|
LambdaQueryWrapper<BirActivityCenterGoods> birBaseActivityLqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
birBaseActivityLqw.in(BirActivityCenterGoods::getActivityId, activityIds); |
|
|
|
|
|
|
|
|
|
|
|
List<BirActivityCenterGoods> removeBirList = this.list(birBaseActivityLqw); |
|
|
|
|
|
if (removeBirList.size() > 0) { |
|
|
|
|
|
List<BirRemoveId> removeIds = removeBirList.stream().map(a -> { |
|
|
|
|
|
BirRemoveId birRemoveId = new BirRemoveId(); |
|
|
|
|
|
birRemoveId.setDeleteTime(LocalDateTime.now()); |
|
|
|
|
|
birRemoveId.setId(a.getId()); |
|
|
|
|
|
return birRemoveId; |
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
birRemoveIdService.saveBatch(removeIds); |
|
|
|
|
|
} |
|
|
|
|
|
this.remove(birBaseActivityLqw); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 创建底表对象 |
|
|
* 创建底表对象 |
|
|
* @param costCenterList |
|
|
* @param costCenterList |
|
@ -570,10 +415,6 @@ public class BirActivityCenterGoodsServiceImpl extends ServiceImpl<BirActivityCe |
|
|
return goodSplitDTO; |
|
|
return goodSplitDTO; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public List<BirActivityCenterGoodsMonthVo> listMonthCusCenterVo(BirMonthCusCenterSo param) { |
|
|
|
|
|
return baseMapper.listMonthCusCenterVo(param); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|