|
@ -21,6 +21,7 @@ import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import com.qs.serve.modules.bms.service.BmsRegionService; |
|
|
import com.qs.serve.modules.bms.service.BmsRegionService; |
|
|
import com.qs.serve.modules.bms.mapper.BmsRegionMapper; |
|
|
import com.qs.serve.modules.bms.mapper.BmsRegionMapper; |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Arrays; |
|
|
import java.util.Arrays; |
|
@ -44,6 +45,7 @@ public class BmsRegionServiceImpl extends ServiceImpl<BmsRegionMapper,BmsRegion> |
|
|
private BmsSupplierApplicationService bmsSupplierApplicationService; |
|
|
private BmsSupplierApplicationService bmsSupplierApplicationService; |
|
|
private BmsSupplierMapper bmsSupplierMapper; |
|
|
private BmsSupplierMapper bmsSupplierMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean saveBmsRegion(BmsRegion param){ |
|
|
public boolean saveBmsRegion(BmsRegion param){ |
|
|
this.checkSysCodes(param); |
|
|
this.checkSysCodes(param); |
|
@ -55,6 +57,92 @@ public class BmsRegionServiceImpl extends ServiceImpl<BmsRegionMapper,BmsRegion> |
|
|
return this.save(param); |
|
|
return this.save(param); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean updateSaleRegionById(BmsRegion newRegion) { |
|
|
|
|
|
String regionId = newRegion.getId(); |
|
|
|
|
|
this.checkSysCodes(newRegion); |
|
|
|
|
|
this.toSetLevel(newRegion); |
|
|
|
|
|
BmsRegion orgRegion = this.getById(regionId); |
|
|
|
|
|
boolean changePid = !orgRegion.getPid().equals(newRegion.getPid()); |
|
|
|
|
|
if(changePid){ |
|
|
|
|
|
//更变子级,拦截递归的错误设置
|
|
|
|
|
|
List<BmsRegion> childTree = this.listTreeChildByDeep(regionId,newRegion.getLevel()); |
|
|
|
|
|
|
|
|
|
|
|
//罗列相关的客户进行更新
|
|
|
|
|
|
List<BmsSupplier> supplierList = bmsSupplierMapper.selectList(new LambdaQueryWrapper<BmsSupplier>() |
|
|
|
|
|
.select(BmsSupplier::getId,BmsSupplier::getRegionFirst,BmsSupplier::getRegionSecond,BmsSupplier::getRegionThird) |
|
|
|
|
|
.eq(BmsSupplier::getRegionFirst,regionId) |
|
|
|
|
|
.or() |
|
|
|
|
|
.eq(BmsSupplier::getRegionSecond,regionId) |
|
|
|
|
|
.or() |
|
|
|
|
|
.eq(BmsSupplier::getRegionThird,regionId) |
|
|
|
|
|
.or() |
|
|
|
|
|
.eq(BmsSupplier::getRegionFourthly,regionId) |
|
|
|
|
|
); |
|
|
|
|
|
//利用有序
|
|
|
|
|
|
List<String> sortList = new ArrayList<>(); |
|
|
|
|
|
sortList.add(newRegion.getId()); |
|
|
|
|
|
if (!newRegion.getPid().equals("0")){ |
|
|
|
|
|
BmsRegion p1 = this.getById(newRegion.getPid()); |
|
|
|
|
|
sortList.add(p1.getId()); |
|
|
|
|
|
if(!p1.getPid().equals("0")){ |
|
|
|
|
|
BmsRegion p2 = this.getById(p1.getPid()); |
|
|
|
|
|
sortList.add(p2.getId()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// size对应层级数
|
|
|
|
|
|
int size = sortList.size(); |
|
|
|
|
|
for (BmsSupplier supplier : supplierList) { |
|
|
|
|
|
if(size==3){ |
|
|
|
|
|
//3级
|
|
|
|
|
|
supplier.setRegionFirst(sortList.get(2)); |
|
|
|
|
|
supplier.setRegionSecond(sortList.get(1)); |
|
|
|
|
|
supplier.setRegionThird(sortList.get(0)); |
|
|
|
|
|
supplier.setRegionLast(sortList.get(0)); |
|
|
|
|
|
log.debug("3级变动"); |
|
|
|
|
|
}else if (size==2){ |
|
|
|
|
|
//二级
|
|
|
|
|
|
supplier.setRegionFirst(sortList.get(1)); |
|
|
|
|
|
if (orgRegion.getLevel() > (newRegion.getLevel())){ |
|
|
|
|
|
supplier.setRegionSecond(sortList.get(0)); |
|
|
|
|
|
log.debug("层级变小,由三级变二级"); |
|
|
|
|
|
supplier.setRegion2Third("0"); |
|
|
|
|
|
}if (orgRegion.getLevel() < (newRegion.getLevel())){ |
|
|
|
|
|
log.debug("层级变大,由一级变二级"); |
|
|
|
|
|
supplier.setRegionThird(supplier.getRegion2Second()); |
|
|
|
|
|
supplier.setRegionSecond(sortList.get(0)); |
|
|
|
|
|
}else { |
|
|
|
|
|
log.debug("二级,平级更新"); |
|
|
|
|
|
supplier.setRegionSecond(sortList.get(0)); |
|
|
|
|
|
if(!StringUtils.hasText(supplier.getRegion2Third())){ |
|
|
|
|
|
supplier.setRegionLast(supplier.getRegion2Second()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}else { |
|
|
|
|
|
//一级
|
|
|
|
|
|
log.debug("更换变一级"); |
|
|
|
|
|
supplier.setRegionFirst(sortList.get(0)); |
|
|
|
|
|
supplier.setRegionLast(sortList.get(0)); |
|
|
|
|
|
if (orgRegion.getLevel() > (newRegion.getLevel())){ |
|
|
|
|
|
log.debug("层级变小,由二级变一级"); |
|
|
|
|
|
Assert.throwEx("二级变一级不支持"); |
|
|
|
|
|
supplier.setRegionSecond(supplier.getRegion2Third()); |
|
|
|
|
|
supplier.setRegionThird("0"); |
|
|
|
|
|
}else { |
|
|
|
|
|
supplier.setRegionSecond("0"); |
|
|
|
|
|
supplier.setRegionThird("0"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
bmsSupplierMapper.updateById(supplier); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
this.updateById(newRegion); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void checkSysCodes(BmsRegion param) { |
|
|
private void checkSysCodes(BmsRegion param) { |
|
|
if(StringUtils.hasText(param.getSysCode1())){ |
|
|
if(StringUtils.hasText(param.getSysCode1())){ |
|
|
long count1 = baseMapper.countSysCode1(param.getSysCode1(), param.getId());if(count1>0){ |
|
|
long count1 = baseMapper.countSysCode1(param.getSysCode1(), param.getId());if(count1>0){ |
|
@ -368,5 +456,40 @@ public class BmsRegionServiceImpl extends ServiceImpl<BmsRegionMapper,BmsRegion> |
|
|
region.setFactoryIds(newIds.stream().toArray(String[]::new)); |
|
|
region.setFactoryIds(newIds.stream().toArray(String[]::new)); |
|
|
return region; |
|
|
return region; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public BmsRegion toSetLevel(BmsRegion param) { |
|
|
|
|
|
if(StringUtils.hasText(param.getPid()) && !param.getPid().equals("0")){ |
|
|
|
|
|
BmsRegion parent = this.getById(param.getPid()); |
|
|
|
|
|
if(parent!=null){ |
|
|
|
|
|
if(parent.getLevel()>2){ |
|
|
|
|
|
Assert.throwEx("最高支持3层级"); |
|
|
|
|
|
} |
|
|
|
|
|
param.setLevel(parent.getLevel()+1); |
|
|
|
|
|
param.setPathIds(parent.getPathIds()+"_"+param.getId()); |
|
|
|
|
|
param.setPathNames(parent.getPathNames()+"_"+param.getName()); |
|
|
|
|
|
}else { |
|
|
|
|
|
Assert.throwEx("无相关父级数据"); |
|
|
|
|
|
} |
|
|
|
|
|
}else { |
|
|
|
|
|
param.setPid("0"); |
|
|
|
|
|
param.setLevel(1); |
|
|
|
|
|
param.setPathIds(param.getId()); |
|
|
|
|
|
param.setPathNames(param.getName()); |
|
|
|
|
|
} |
|
|
|
|
|
return param; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<BmsRegion> listTreeChildByDeep(String pid,Integer parentLevel){ |
|
|
|
|
|
List<BmsRegion> list = this.listChild(pid); |
|
|
|
|
|
if(parentLevel > 2 && CollectionUtil.isNotEmpty(list)){ |
|
|
|
|
|
Assert.throwEx("最高只能设置3层级"); |
|
|
|
|
|
} |
|
|
|
|
|
for (BmsRegion region2 : list) { |
|
|
|
|
|
List<BmsRegion> childList = listTreeChildByDeep(region2.getId(),parentLevel++); |
|
|
|
|
|
region2.setChildNodes(childList); |
|
|
|
|
|
} |
|
|
|
|
|
return list; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|