|
@ -14,14 +14,27 @@ import com.qs.serve.modules.bms.service.BmsRegion2Service; |
|
|
import com.qs.serve.modules.bms.service.BmsRegionService; |
|
|
import com.qs.serve.modules.bms.service.BmsRegionService; |
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
|
|
|
|
import com.qs.serve.modules.tbs.common.TbsCenterType; |
|
|
|
|
|
import com.qs.serve.modules.tbs.common.TbsGoodsType; |
|
|
|
|
|
import com.qs.serve.modules.tbs.entity.TbsBudget; |
|
|
|
|
|
import com.qs.serve.modules.tbs.entity.TbsBudgetCondition; |
|
|
|
|
|
import com.qs.serve.modules.tbs.entity.TbsBudgetLog; |
|
|
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetConditionMapper; |
|
|
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetLogMapper; |
|
|
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
import com.qs.serve.modules.bms.service.BmsSupplierService; |
|
|
import com.qs.serve.modules.bms.service.BmsSupplierService; |
|
|
import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|
|
import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 供应商 服务实现类 |
|
|
* 供应商 服务实现类 |
|
@ -36,6 +49,9 @@ public class BmsSupplierServiceImpl extends ServiceImpl<BmsSupplierMapper,BmsSup |
|
|
private BmsRegionService regionService; |
|
|
private BmsRegionService regionService; |
|
|
private BmsRegion2Service region2Service; |
|
|
private BmsRegion2Service region2Service; |
|
|
private SysUserService sysUserService; |
|
|
private SysUserService sysUserService; |
|
|
|
|
|
private TbsBudgetLogMapper budgetLogMapper; |
|
|
|
|
|
private TbsBudgetMapper budgetMapper; |
|
|
|
|
|
private TbsBudgetConditionMapper budgetConditionMapper; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public List<BmsSupplier> selectSupplierList(BmsSupplier bmsSupplier) { |
|
|
public List<BmsSupplier> selectSupplierList(BmsSupplier bmsSupplier) { |
|
@ -43,8 +59,17 @@ public class BmsSupplierServiceImpl extends ServiceImpl<BmsSupplierMapper,BmsSup |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public void edit(BmsSupplierBo param) { |
|
|
public void edit(BmsSupplierBo param) { |
|
|
BmsSupplier supplier = CopierUtil.copy(param,new BmsSupplier()); |
|
|
BmsSupplier supplier = CopierUtil.copy(param,new BmsSupplier()); |
|
|
|
|
|
String orgSaleRegionId = null; |
|
|
|
|
|
String orgBizRegionId = null; |
|
|
|
|
|
String editId = param.getId(); |
|
|
|
|
|
if(supplier.getId()!=null){ |
|
|
|
|
|
BmsSupplier dbSupplier = this.getById(param.getId()); |
|
|
|
|
|
orgSaleRegionId = dbSupplier.getRegionLast(); |
|
|
|
|
|
orgBizRegionId = dbSupplier.getRegion2Last(); |
|
|
|
|
|
} |
|
|
if(StringUtils.hasText(param.getMgrId())){ |
|
|
if(StringUtils.hasText(param.getMgrId())){ |
|
|
SysUser sysUser = sysUserService.getById(param.getMgrId()); |
|
|
SysUser sysUser = sysUserService.getById(param.getMgrId()); |
|
|
supplier.setUserId(sysUser.getId()); |
|
|
supplier.setUserId(sysUser.getId()); |
|
@ -69,14 +94,120 @@ public class BmsSupplierServiceImpl extends ServiceImpl<BmsSupplierMapper,BmsSup |
|
|
if(param.getRegionId()!=null){ |
|
|
if(param.getRegionId()!=null){ |
|
|
//绑定销售区域逻辑
|
|
|
//绑定销售区域逻辑
|
|
|
this.initRegion(supplier,param.getRegionId()); |
|
|
this.initRegion(supplier,param.getRegionId()); |
|
|
|
|
|
//判断是否需要迁移数据
|
|
|
|
|
|
if(editId!=null |
|
|
|
|
|
&& orgSaleRegionId!=null |
|
|
|
|
|
&&!orgSaleRegionId.equals(param.getRegionId())){ |
|
|
|
|
|
migrateRegion(editId,TbsCenterType.saleRegion.name(), orgSaleRegionId, orgBizRegionId); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
if(param.getRegionId2()!=null){ |
|
|
if(param.getRegionId2()!=null){ |
|
|
//绑定行政区域逻辑
|
|
|
//绑定行政区域逻辑
|
|
|
this.initRegion2(supplier,param.getRegionId2()); |
|
|
this.initRegion2(supplier,param.getRegionId2()); |
|
|
|
|
|
//判断是否需要迁移数据
|
|
|
|
|
|
if(!orgBizRegionId.equals(param.getRegionId2())){ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
this.saveOrUpdate(supplier); |
|
|
this.saveOrUpdate(supplier); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void migrateRegion(String supplierId, String regionType, String orgRegionId, String newRegionId) { |
|
|
|
|
|
//todo 开发中
|
|
|
|
|
|
if(1==1){return;} |
|
|
|
|
|
LambdaQueryWrapper<TbsBudgetLog> lqw4log = new LambdaQueryWrapper<>(); |
|
|
|
|
|
lqw4log.eq(TbsBudgetLog::getMigrateFlag,0); |
|
|
|
|
|
lqw4log.eq(TbsBudgetLog::getRollbackFlag,0); |
|
|
|
|
|
lqw4log.eq(TbsBudgetLog::getSupplierId, supplierId); |
|
|
|
|
|
lqw4log.eq(TbsBudgetLog::getCenterType, regionType); |
|
|
|
|
|
lqw4log.eq(TbsBudgetLog::getCenterId, orgRegionId); |
|
|
|
|
|
List<TbsBudgetLog> budgetLogList = budgetLogMapper.selectList(lqw4log); |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(budgetLogList)){ |
|
|
|
|
|
//查询符合条件的预算
|
|
|
|
|
|
final List<Long> subjectIds = budgetLogList.stream().map(TbsBudgetLog::getSubjectId).distinct().collect(Collectors.toList()); |
|
|
|
|
|
LambdaQueryWrapper<TbsBudget> lqwBudget = new LambdaQueryWrapper<>(); |
|
|
|
|
|
lqwBudget.eq(TbsBudget::getCenterType,regionType); |
|
|
|
|
|
lqwBudget.eq(TbsBudget::getCenterId, newRegionId); |
|
|
|
|
|
lqwBudget.and(wq->{ |
|
|
|
|
|
wq.eq(TbsBudget::getSubjectId,0).or().in(TbsBudget::getSubjectId,subjectIds); |
|
|
|
|
|
}); |
|
|
|
|
|
lqwBudget.orderByDesc(TbsBudget::getSubjectId); //将有科目条件的前置
|
|
|
|
|
|
List<TbsBudget> budgetList = budgetMapper.selectList(lqwBudget); |
|
|
|
|
|
//查询预算条件
|
|
|
|
|
|
List<Long> conditionBudgetIds = budgetList.stream() |
|
|
|
|
|
.filter(a->a.getConditionFlag().equals(1)) |
|
|
|
|
|
.map(TbsBudget::getId).distinct().collect(Collectors.toList()); |
|
|
|
|
|
Map<Long,List<TbsBudgetCondition>> budgetConditionsMap = null; |
|
|
|
|
|
if(conditionBudgetIds.size()>0){ |
|
|
|
|
|
LambdaQueryWrapper<TbsBudgetCondition> conditionLqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
conditionLqw.in(TbsBudgetCondition::getBudgetId,conditionBudgetIds); |
|
|
|
|
|
List<TbsBudgetCondition> budgetConditions = budgetConditionMapper.selectList(conditionLqw); |
|
|
|
|
|
budgetConditionsMap = budgetConditions.stream().collect(Collectors.groupingBy(TbsBudgetCondition::getBudgetId)); |
|
|
|
|
|
} |
|
|
|
|
|
//用于循环筛选条件
|
|
|
|
|
|
TbsGoodsType[] goodsTypes = new TbsGoodsType[]{ |
|
|
|
|
|
TbsGoodsType.sku, |
|
|
|
|
|
TbsGoodsType.spu, |
|
|
|
|
|
TbsGoodsType.series, |
|
|
|
|
|
TbsGoodsType.category, |
|
|
|
|
|
TbsGoodsType.brand |
|
|
|
|
|
}; |
|
|
|
|
|
//规则:品类条件比科目条件优先级更高
|
|
|
|
|
|
for (TbsBudgetLog budgetLog : budgetLogList) { |
|
|
|
|
|
//(数据结构:value=预算id列表,key=商品类型)
|
|
|
|
|
|
Map<String,List<Long>> matchConditionBudgetIdsMap = new HashMap<>(); |
|
|
|
|
|
if(budgetConditionsMap!=null){ |
|
|
|
|
|
for (Long budgetId : budgetConditionsMap.keySet()) { |
|
|
|
|
|
List<TbsBudgetCondition> budgetConditions = budgetConditionsMap.get(budgetId); |
|
|
|
|
|
String pathName = budgetLog.getTargetLevelPathNames(); |
|
|
|
|
|
for (TbsBudgetCondition condition : budgetConditions) { |
|
|
|
|
|
if(pathName.contains(condition.getTargetLevelPathNames())){ |
|
|
|
|
|
List<Long> tempList = matchConditionBudgetIdsMap.get(condition.getTargetType()); |
|
|
|
|
|
if(tempList==null){ |
|
|
|
|
|
tempList = new ArrayList<>(); |
|
|
|
|
|
} |
|
|
|
|
|
tempList.add(budgetId); |
|
|
|
|
|
matchConditionBudgetIdsMap.put(condition.getTargetType(),tempList); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//记录匹配到的预算
|
|
|
|
|
|
TbsBudget matchBudget = null; |
|
|
|
|
|
for (TbsBudget budget : budgetList) { |
|
|
|
|
|
if(matchBudget!=null){break;} |
|
|
|
|
|
if(budget.getConditionFlag().equals(1)){ |
|
|
|
|
|
for (TbsGoodsType goodsType : goodsTypes) { |
|
|
|
|
|
if(matchBudget!=null){break;} |
|
|
|
|
|
List<Long> tempList = matchConditionBudgetIdsMap.get(goodsType.name()); |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(tempList)){ |
|
|
|
|
|
for (Long budgetId01 : tempList) { |
|
|
|
|
|
if(budgetId01.equals(budget.getId())){ |
|
|
|
|
|
matchBudget = budget; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}else { |
|
|
|
|
|
matchBudget = budget; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//todo 设置已迁移记录
|
|
|
|
|
|
//todo 匹配条件
|
|
|
|
|
|
} |
|
|
|
|
|
//设置已迁移状态
|
|
|
|
|
|
List<Long> budgetLogIds = budgetLogList.stream().map(TbsBudgetLog::getId).collect(Collectors.toList()); |
|
|
|
|
|
TbsBudgetLog updLogParam = new TbsBudgetLog(); |
|
|
|
|
|
updLogParam.setMigrateFlag(1); |
|
|
|
|
|
LambdaQueryWrapper<TbsBudgetLog> updLogLqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
updLogLqw.in(TbsBudgetLog::getId,budgetLogIds); |
|
|
|
|
|
budgetLogMapper.update(updLogParam,updLogLqw); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public BmsSupplier getByCode(String code,String belong) { |
|
|
public BmsSupplier getByCode(String code,String belong) { |
|
|
LambdaQueryWrapper<BmsSupplier> lqw = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<BmsSupplier> lqw = new LambdaQueryWrapper<>(); |
|
|