|
|
@ -9,23 +9,39 @@ import com.qs.serve.common.util.*; |
|
|
|
import com.qs.serve.modules.bir.consts.BirActivityCenterGoodsUtil; |
|
|
|
import com.qs.serve.modules.bir.service.BirCenterRateService; |
|
|
|
import com.qs.serve.modules.bir.service.BirRoiRateService; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsRegion; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsSubject; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsSubjectForm; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
|
import com.qs.serve.modules.bms.mapper.BmsRegion2Mapper; |
|
|
|
import com.qs.serve.modules.bms.mapper.BmsRegionMapper; |
|
|
|
import com.qs.serve.modules.bms.service.BmsSubjectService; |
|
|
|
import com.qs.serve.modules.bms.service.BmsSupplierService; |
|
|
|
import com.qs.serve.modules.bms.service.*; |
|
|
|
import com.qs.serve.modules.erp.mapper.ErpDispatchDataMapper; |
|
|
|
import com.qs.serve.modules.goods.entity.GoodsCategory; |
|
|
|
import com.qs.serve.modules.goods.entity.GoodsSku; |
|
|
|
import com.qs.serve.modules.goods.entity.GoodsSpu; |
|
|
|
import com.qs.serve.modules.goods.service.GoodsCategoryService; |
|
|
|
import com.qs.serve.modules.goods.service.GoodsSkuService; |
|
|
|
import com.qs.serve.modules.goods.service.GoodsSpuService; |
|
|
|
import com.qs.serve.modules.seeyon.service.SeeYonRequestService; |
|
|
|
import com.qs.serve.modules.sys.entity.SysAttach; |
|
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
|
import com.qs.serve.modules.sys.mapper.SysUserMapper; |
|
|
|
import com.qs.serve.modules.sys.service.SysAttachService; |
|
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsCenterType; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsCostApplyState; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsGoodsType; |
|
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsActivityDefaultCenterBo; |
|
|
|
import com.qs.serve.modules.tbs.entity.vo.TbsActivityDefaultCenterVo; |
|
|
|
import com.qs.serve.modules.tbs.mapper.*; |
|
|
|
import com.qs.serve.modules.tbs.service.*; |
|
|
|
import com.qs.serve.modules.vtb.common.VtbVerificationState; |
|
|
|
import com.qs.serve.modules.vtb.entity.VtbVerification; |
|
|
|
import com.qs.serve.modules.vtb.mapper.VtbVerificationMapper; |
|
|
|
import com.qs.serve.modules.vtb.service.VtbFundFlowService; |
|
|
|
import com.qs.serve.modules.vtb.service.VtbVerificationService; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -33,8 +49,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -62,6 +77,37 @@ public class TbsCostApplyPart1ServiceImpl implements TbsCostApplyPart1Service { |
|
|
|
private TbsBudgetLogMapper tbsBudgetLogMapper; |
|
|
|
private TbsBudgetCostItemMapper tbsBudgetCostItemMapper; |
|
|
|
private SysUserMapper sysUserMapper; |
|
|
|
private final SysUserService sysUserService; |
|
|
|
|
|
|
|
private final TbsCostApplyService costApplyService; |
|
|
|
private final TbsActivityService tbsActivityService; |
|
|
|
private final TbsActivityGoodsService activityGoodsService; |
|
|
|
private final TbsActivitySubjectService activitySubjectService; |
|
|
|
private final TbsActivityCenterService activityCenterService; |
|
|
|
private final TbsActivityCenterGoodsService activityCenterGoodsService; |
|
|
|
private final TbsActivityChannelService activityChannelService; |
|
|
|
private final TbsActivityChannelPointService activityChannelPointService; |
|
|
|
|
|
|
|
private final GoodsSkuService goodsSkuService; |
|
|
|
private final GoodsSpuService goodsSpuService; |
|
|
|
private final GoodsCategoryService goodsCategoryService; |
|
|
|
|
|
|
|
private final BmsSupplierService bmsSupplierService; |
|
|
|
private final BmsCostCenterService bmsCostCenterService; |
|
|
|
private final BmsRegion2Service bmsRegion2Service; |
|
|
|
private final BmsRegionService bmsRegionService; |
|
|
|
private final BmsSubjectService bmsSubjectService; |
|
|
|
private final BmsSubjectFormService bmsSubjectFormService; |
|
|
|
|
|
|
|
private final VtbVerificationService verificationService; |
|
|
|
private final VtbFundFlowService vtbFundFlowService; |
|
|
|
|
|
|
|
private final TbsActivityApplicationService tbsActivityApplicationService; |
|
|
|
private final TbsBudgetService tbsBudgetService; |
|
|
|
private final TbsBudgetConditionService tbsBudgetConditionService; |
|
|
|
private final TbsScheduleItemBudgetMapper tbsScheduleItemBudgetMapper; |
|
|
|
private final TbsCostApplyPart1Service tbsCostApplyPart1Service; |
|
|
|
private SysAttachService attachService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public TbsCostApply copyById(Long costId) { |
|
|
@ -419,4 +465,210 @@ public class TbsCostApplyPart1ServiceImpl implements TbsCostApplyPart1Service { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void buildDetailVo(TbsActivity activity) { |
|
|
|
LambdaQueryWrapper<TbsActivityGoods> actGoodsLqw = new LambdaQueryWrapper<>(); |
|
|
|
actGoodsLqw.eq(TbsActivityGoods::getActivityId,activity.getId()); |
|
|
|
actGoodsLqw.orderByDesc(TbsActivityGoods::getTargetName); |
|
|
|
List<TbsActivityGoods> goodsList = activityGoodsService.list(actGoodsLqw); |
|
|
|
if(goodsList.size()>0){ |
|
|
|
activity.setGoodsType(goodsList.get(0).getTargetType()); |
|
|
|
goodsList.forEach(TbsActivityGoods::initSpuSkuName); |
|
|
|
goodsList.forEach(TbsActivityGoods::initCategoryNameByPathsName); |
|
|
|
} |
|
|
|
activity.setGoodsList(goodsList); |
|
|
|
QueryWrapper qw = new QueryWrapper<>(); |
|
|
|
qw.eq("activity_id", activity.getId()); |
|
|
|
List<TbsActivityChannel> activityChannels = activityChannelService.list(qw); |
|
|
|
activity.setCustomChannelList(activityChannels); |
|
|
|
if(activityChannels.size()<1){ |
|
|
|
List<TbsActivityChannelPoint> channelPoints = activityChannelPointService.list(qw); |
|
|
|
activity.setCustomChannelPointList(channelPoints); |
|
|
|
if(channelPoints.size()<1 && activityChannels.size()<1){ |
|
|
|
activity.setCustomSupplier(bmsSupplierService.getById(activity.getSupplierId())); |
|
|
|
} |
|
|
|
} |
|
|
|
List<TbsActivitySubject> activitySubjects = activitySubjectService.list(qw); |
|
|
|
List<TbsActivityCenter> activityCenters = activityCenterService.list(qw); |
|
|
|
|
|
|
|
TbsCostApply costApply = costApplyService.getById(activity.getCostApplyId()); |
|
|
|
|
|
|
|
//成本中心关联出相关预算
|
|
|
|
for (TbsActivityCenter center : activityCenters) { |
|
|
|
//没通过加载可选的所有预算,已通过加载出选中的预算
|
|
|
|
String subjectId = center.getSubjectId()+""; |
|
|
|
String centerType = center.getCenterType(); |
|
|
|
String centerId = center.getCenterId(); |
|
|
|
if(costApply.getChargeState()>0||activity.getCostPassFlag().equals(1)){ |
|
|
|
//选中的预算
|
|
|
|
String activityId = activity.getId()+""; |
|
|
|
List<TbsScheduleItemBudget> list = tbsScheduleItemBudgetMapper.listByActivityAndSubjectAndCenter( |
|
|
|
activityId,subjectId,centerType,centerId); |
|
|
|
center.setMatchBudgetList(list); |
|
|
|
}else { |
|
|
|
//可选的所有预算
|
|
|
|
List<TbsScheduleItemBudget> list = |
|
|
|
tbsScheduleItemBudgetMapper.listBySubjectAndCenter(subjectId,centerType,centerId); |
|
|
|
center.setMatchBudgetList(list); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Map<Long,List<TbsActivityCenter>> centerListMap = activityCenters.stream().collect(Collectors.groupingBy(TbsActivityCenter::getSubjectId)); |
|
|
|
List<Long> subjectIds = activitySubjects.stream().map(TbsActivitySubject::getSubjectId).distinct().collect(Collectors.toList()); |
|
|
|
List<BmsSubject> subjectList = bmsSubjectService.listByIds(subjectIds); |
|
|
|
List<Long> formIds = subjectList.stream().map(BmsSubject::getFormId).distinct().collect(Collectors.toList()); |
|
|
|
List<BmsSubjectForm> subjectForms = null; |
|
|
|
if(CollectionUtil.isNotEmpty(formIds)){ |
|
|
|
subjectForms = bmsSubjectFormService.listByIds(formIds); |
|
|
|
} |
|
|
|
for (TbsActivitySubject activitySubject : activitySubjects) { |
|
|
|
if(CollectionUtil.isNotEmpty(subjectForms)){ |
|
|
|
for (BmsSubject subject : subjectList) { |
|
|
|
if(subject.getId().equals(activitySubject.getSubjectId())&&subject.getFormId()!=null){ |
|
|
|
for (BmsSubjectForm subjectForm : subjectForms) { |
|
|
|
if(subjectForm.getId().equals(subject.getFormId())){ |
|
|
|
activitySubject.setSubjectFormInfo(subjectForm); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
List<TbsActivityCenter> activityCenterList = centerListMap.get(activitySubject.getSubjectId()); |
|
|
|
activitySubject.setActivityCenterList(activityCenterList); |
|
|
|
} |
|
|
|
activity.setSubjectCenterList(activitySubjects); |
|
|
|
List<TbsActivityCenterGoods> activityCenterGoodsList = activityCenterGoodsService.list(qw); |
|
|
|
activityCenterGoodsList.forEach(TbsActivityCenterGoods::initSpuSkuName); |
|
|
|
activity.setCenterGoodsList(activityCenterGoodsList); |
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(activity.getAttachIds())){ |
|
|
|
List<String> attachIds = Arrays.asList(activity.getAttachIds()); |
|
|
|
List<SysAttach> attachList = attachService.listByIds(attachIds); |
|
|
|
activity.setAttachList(attachList); |
|
|
|
} |
|
|
|
|
|
|
|
LambdaQueryWrapper<VtbVerification> vtbLqw = new LambdaQueryWrapper<>(); |
|
|
|
vtbLqw.eq(VtbVerification::getActivityId,activity.getId()); |
|
|
|
activity.setVerificationNum(verificationService.count(vtbLqw)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public R<TbsActivityDefaultCenterVo> getDefaultCenter(TbsActivityDefaultCenterBo defaultCenterBo) { |
|
|
|
String goodsType = defaultCenterBo.getActivityGoodsType(); |
|
|
|
List<Long> goodsIds = defaultCenterBo.getGoodsIds(); |
|
|
|
goodsIds = goodsIds.stream().filter(Objects::nonNull).collect(Collectors.toList()); |
|
|
|
Long subjectId = defaultCenterBo.getSubjectId(); |
|
|
|
Long supplierId = defaultCenterBo.getSupplierId(); |
|
|
|
BmsSupplier supplier = bmsSupplierService.getById(supplierId); |
|
|
|
List<TbsBudget> centerBudgetList = new ArrayList<>(); |
|
|
|
//[产品List空] 或[科目ID空] ,返回[客户]
|
|
|
|
if(CollectionUtil.isNotEmpty(goodsIds)&&subjectId!=null){ |
|
|
|
LambdaQueryWrapper<TbsBudget> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(TbsBudget::getBudgetState,1); |
|
|
|
//排除随货编码
|
|
|
|
lqw.ne(TbsBudget::getSubjectCode,"FYMC05"); |
|
|
|
List<TbsBudget> budgetList = tbsBudgetService.list(lqw); |
|
|
|
List<String> idPaths = new ArrayList<>(); |
|
|
|
if(budgetList.size()>0){ |
|
|
|
if(TbsGoodsType.spu.name().equals(goodsType)){ |
|
|
|
for (Long goodsId : goodsIds) { |
|
|
|
GoodsSpu goodsSpu = goodsSpuService.getById(goodsId); |
|
|
|
String idPath = goodsSpu.getCategoryFirst()+"_"+goodsSpu.getCategorySecond()+"_" |
|
|
|
+goodsSpu.getCategoryThird()+"_"+goodsSpu.getId(); |
|
|
|
idPaths.add(idPath); |
|
|
|
} |
|
|
|
}else if(TbsGoodsType.sku.name().equals(goodsType)){ |
|
|
|
for (Long goodsId : goodsIds) { |
|
|
|
GoodsSku sku = goodsSkuService.getById(goodsId); |
|
|
|
GoodsSpu goodsSpu = goodsSpuService.getById(sku.getSpuId()); |
|
|
|
String idPath = goodsSpu.getCategoryFirst()+"_"+goodsSpu.getCategorySecond()+"_" |
|
|
|
+goodsSpu.getCategoryThird()+"_"+goodsSpu.getId()+"_"+sku.getId(); |
|
|
|
idPaths.add(idPath); |
|
|
|
} |
|
|
|
}else { |
|
|
|
for (Long goodsId : goodsIds) { |
|
|
|
GoodsCategory category = goodsCategoryService.getById(goodsId); |
|
|
|
if(category!=null){ |
|
|
|
idPaths.add(category.getLevelPath()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
List<Long> budgetIds = budgetList.stream().map(TbsBudget::getId).collect(Collectors.toList()); |
|
|
|
LambdaQueryWrapper<TbsBudgetCondition> lqwCon = new LambdaQueryWrapper<>(); |
|
|
|
lqwCon.in(TbsBudgetCondition::getBudgetId,budgetIds); |
|
|
|
List<TbsBudgetCondition> budgetConditionsAll = tbsBudgetConditionService.list(lqwCon); |
|
|
|
Map<Long, List<TbsBudgetCondition>> groupedConditions = budgetConditionsAll.stream() |
|
|
|
.collect(Collectors.groupingBy(TbsBudgetCondition::getBudgetId)); |
|
|
|
for (TbsBudget budget : budgetList) { |
|
|
|
if(budget.getConditionFlag().equals(1)){ |
|
|
|
List<TbsBudgetCondition> budgetConditions = groupedConditions.get(budget.getId()); |
|
|
|
for (int i = 0; i < idPaths.size(); i++) { |
|
|
|
String idPath = idPaths.get(i); |
|
|
|
boolean isMatch = false; |
|
|
|
if(budgetConditions!=null){ |
|
|
|
for (TbsBudgetCondition budgetCondition : budgetConditions) { |
|
|
|
if(idPath.contains(budgetCondition.getTargetLevelPathIds())){ |
|
|
|
isMatch = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(!isMatch){ |
|
|
|
break; |
|
|
|
} |
|
|
|
//满足条件
|
|
|
|
if(i+1==idPaths.size()){ |
|
|
|
centerBudgetList.add(budget); |
|
|
|
} |
|
|
|
} |
|
|
|
}else { |
|
|
|
centerBudgetList.add(budget); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//匹配有预算并且成本中心为客户的
|
|
|
|
for (TbsBudget budget : centerBudgetList) { |
|
|
|
if (budget.getCenterType().equals(TbsCenterType.customer.name())){ |
|
|
|
if(budget.getCenterId().equals(supplier.getId())){ |
|
|
|
TbsActivityDefaultCenterVo defaultCenterVo = new TbsActivityDefaultCenterVo(); |
|
|
|
defaultCenterVo.setSupplier(supplier); |
|
|
|
return R.ok(defaultCenterVo); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//匹配有预算并且成本中心为销售区域的,按最按近的销售区域优先级返回
|
|
|
|
Optional<TbsBudget> regionThirdCenter = centerBudgetList.stream().filter(a -> a.getCenterType().equals(TbsCenterType.saleRegion.name()) |
|
|
|
&& a.getCenterId().equals(supplier.getRegionThird())).findFirst(); |
|
|
|
if(regionThirdCenter.isPresent()){ |
|
|
|
TbsActivityDefaultCenterVo defaultCenterVo = new TbsActivityDefaultCenterVo(); |
|
|
|
BmsRegion saleRegionTemp = bmsRegionService.getById(regionThirdCenter.get().getCenterId()); |
|
|
|
defaultCenterVo.setSaleRegion(saleRegionTemp); |
|
|
|
return R.ok(defaultCenterVo); |
|
|
|
} |
|
|
|
Optional<TbsBudget> regionSecondCenter = centerBudgetList.stream().filter(a -> a.getCenterType().equals(TbsCenterType.saleRegion.name()) |
|
|
|
&& a.getCenterId().equals(supplier.getRegionSecond())).findFirst(); |
|
|
|
if(regionSecondCenter.isPresent()){ |
|
|
|
TbsActivityDefaultCenterVo defaultCenterVo = new TbsActivityDefaultCenterVo(); |
|
|
|
BmsRegion saleRegionTemp = bmsRegionService.getById(regionSecondCenter.get().getCenterId()); |
|
|
|
defaultCenterVo.setSaleRegion(saleRegionTemp); |
|
|
|
return R.ok(defaultCenterVo); |
|
|
|
} |
|
|
|
Optional<TbsBudget> regionFirstCenter = centerBudgetList.stream().filter(a -> a.getCenterType().equals(TbsCenterType.saleRegion.name()) |
|
|
|
&& a.getCenterId().equals(supplier.getRegionFirst())).findFirst(); |
|
|
|
if(regionFirstCenter.isPresent()){ |
|
|
|
TbsActivityDefaultCenterVo defaultCenterVo = new TbsActivityDefaultCenterVo(); |
|
|
|
BmsRegion saleRegionTemp = bmsRegionService.getById(regionFirstCenter.get().getCenterId()); |
|
|
|
defaultCenterVo.setSaleRegion(saleRegionTemp); |
|
|
|
return R.ok(defaultCenterVo); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TbsActivityDefaultCenterVo defaultCenterVo = new TbsActivityDefaultCenterVo(); |
|
|
|
defaultCenterVo.setSupplier(supplier); |
|
|
|
return R.ok(defaultCenterVo); |
|
|
|
} |
|
|
|
} |
|
|
|