更新根据id获取下级地区接口

This commit is contained in:
2025-11-17 16:35:31 +08:00
parent a4132616ba
commit 5e68c82fcc
3 changed files with 119 additions and 94 deletions

View File

@ -5,8 +5,6 @@ import java.util.List;
import javax.validation.Valid;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
@ -17,12 +15,10 @@ import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pictc.datalog.DataOperationContent;
import com.pictc.datalog.DataOperationListener;
import com.pictc.enums.BusinessCode;
import com.pictc.enums.ExceptionCommonCode;
import com.pictc.enums.ValidEnum;
import com.pictc.utils.CollectionUtils;
import com.xjrsoft.common.advice.tran.RegionDataProvider;
import com.xjrsoft.common.constant.GlobalConstant;
@ -31,8 +27,6 @@ import com.xjrsoft.common.exception.BusinessException;
import com.xjrsoft.common.model.result.R;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.utils.RedisUtil;
import com.xjrsoft.common.utils.TenantUtil;
import com.xjrsoft.common.utils.TreeUtil;
import com.xjrsoft.common.utils.VoToColumnUtil;
import com.xjrsoft.module.common.db.utils.CommonCallUtils;
@ -183,12 +177,6 @@ public class CountryRegionController {
}));
}
@DeleteMapping
@ApiOperation(value = "删除")
@SaCheckPermission("countryRegion:delete")
public R delete(@Valid @RequestBody List<Long> ids){
return R.ok(dataService.deleteByIds(UpdateLngBRegionDto.class, ids));
}
@GetMapping(value = "/tree")
@ -222,7 +210,7 @@ public class CountryRegionController {
@ApiOperation(value = "启用")
@SaCheckPermission("countryRegion:enable")
public R enable(@Valid @RequestBody List<Long> ids){
return R.ok(dataService.enable(UpdateLngBRegionDto.class,ids));
return R.ok(dataService.enable(UpdateLngBRegionDto.class,ids));
}
@ -235,53 +223,19 @@ public class CountryRegionController {
@GetMapping("/child")
@ApiOperation(value = "根据id 查询下级区域")
public R getRegionByParentId(@RequestParam(required = false) Long pid,@RequestParam(required = false) String excludeType, @RequestParam(required = false) String keyword
public R child(@RequestParam(required = false) Long pid,@RequestParam(required = false) String excludeType,
@RequestParam(required = false) String keyword,@RequestParam(required = false) String startPCode
) {
List<Long> pidList = CollectionUtils.newArrayList();
if(StrUtil.isNotBlank(excludeType) && (pid == null || pid ==0) ){
List<LngBRegion> pList = countryRegionService.list(Wrappers.<LngBRegion>query()
.lambda().eq(LngBRegion::getRegionTypeCode, excludeType));
if(pList != null && pList.size() > 0) {
for(LngBRegion p:pList) {
pidList.add(p.getId());
}
}
}
List<LngBRegion> regionList = countryRegionService.list(Wrappers.<LngBRegion>query().lambda()
.eq(pid != null, LngBRegion::getPid, pid)
.eq(LngBRegion::getValid, ValidEnum.ENABLE.getCode())
.in(pid == null, LngBRegion::getPid, pidList)
.and(StrUtil.isNotBlank(keyword), x -> {
x.like(StrUtil.isNotBlank(keyword), LngBRegion::getFullName, keyword);
}));
List<LngBRegionVo> voList = CollectionUtils.newArrayList();
if(voList != null && regionList.size() > 0) {
for(LngBRegion br:regionList) {
LngBRegionVo vo = new LngBRegionVo();
BeanUtil.copyProperties(br, vo);
Long parentId = br.getId();
if(parentId == null) {
parentId = 0L;
}
Long codeCount = countryRegionService.count(new LambdaQueryWrapper<LngBRegion>()
.eq(LngBRegion::getPid, parentId));
if(codeCount > 0) {
vo.setHasChild(true);
}
voList.add(vo);
}
}
return R.ok(voList);
return R.ok(countryRegionService.child(pid, excludeType, keyword, startPCode));
}
@GetMapping("/getParentByCode")
@ApiOperation(value = "根据id 查询下级区域")
public R getRegionByParentId(@RequestParam(required = true) String code,@RequestParam(required = false) String excludeType
public R getRegionByParentId(@RequestParam(required = true) String code,@RequestParam(required = false) String excludeType,
@RequestParam(required = false) String startPCode
) {
return R.ok(countryRegionService.getRegionByParentId(code,excludeType));
return R.ok(countryRegionService.getRegionByParentId(code,excludeType,startPCode));
}

View File

@ -1,9 +1,13 @@
package com.xjrsoft.module.mdm.service;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xjrsoft.module.mdm.entity.LngBRegion;
import com.xjrsoft.module.mdm.vo.LngBRegionVo;
/**
* @title: service
@ -15,7 +19,9 @@ import com.xjrsoft.module.mdm.entity.LngBRegion;
public interface ICountryRegionService extends IService<LngBRegion> {
Map<String, Object> getRegionByParentId(String code, String excludeType);
Map<String, Object> getRegionByParentId(String code, String excludeType, String startPCode);
List<LngBRegionVo> child(Long pid,String excludeType, String keyword,String startPCode);
LngBRegion getByCode(String code);

View File

@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pictc.enums.ValidEnum;
import com.pictc.utils.CollectionUtils;
import com.xjrsoft.common.constant.GlobalConstant;
import com.xjrsoft.common.utils.TreeUtil;
@ -20,8 +21,10 @@ import com.xjrsoft.module.mdm.enums.CountryRegionEnum;
import com.xjrsoft.module.mdm.mapper.LngBRegionMapper;
import com.xjrsoft.module.mdm.service.ICountryRegionService;
import com.xjrsoft.module.mdm.vo.LngBRegionTreeVo;
import com.xjrsoft.module.mdm.vo.LngBRegionVo;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import shade.powerjob.com.google.common.collect.Lists;
@ -36,49 +39,60 @@ import shade.powerjob.com.google.common.collect.Lists;
public class CountryRegionServiceImpl extends ServiceImpl<LngBRegionMapper, LngBRegion> implements ICountryRegionService {
@Override
public Map<String, Object> getRegionByParentId(String code,String excludeType) {
public Map<String, Object> getRegionByParentId(String code,String excludeType,String startPCode) {
Map<String,Object> result = new HashMap<>();
LambdaQueryWrapper<LngBRegion> queryWrapper = new LambdaQueryWrapper<LngBRegion>();
queryWrapper.eq(LngBRegion::getCode,code);
LngBRegion temp = this.getOne(queryWrapper);
if(temp == null) {
return result;
}
List<String> codeList = CollectionUtils.newArrayList();
List<LngBRegion> allList = this.list(Wrappers.<LngBRegion>query()
.lambda().ne(StringUtils.isNotBlank(excludeType),LngBRegion::getRegionTypeCode, excludeType));
Map<Long,LngBRegion> map = allList.stream().collect(Collectors.toMap(LngBRegion::getId,
obj -> obj));
if(map != null) {
codeList.add(code);
while(temp != null && temp.getPid() != null && !CountryRegionEnum.CONTINENT.getCode().equals(temp.getRegionTypeCode())) {
temp = map.get(temp.getPid());
if(temp != null) {
codeList.add(temp.getCode());
}
}
}
List<LngBRegionTreeVo> voList = CollectionUtils.newArrayList();
if(allList != null && allList.size() > 0) {
for(LngBRegion br:allList) {
LngBRegionTreeVo vo = new LngBRegionTreeVo();
BeanUtil.copyProperties(br, vo);
if(br.getPid() != null) {
vo.setParentId(String.valueOf(br.getPid()) );
}else {
vo.setParentId(String.valueOf(GlobalConstant.FIRST_NODE_VALUE));
}
voList.add(vo);
}
}
List<LngBRegionTreeVo> treeVoList = TreeUtil.build(voList);
filterNode(treeVoList,codeList);
result.put("areaList", treeVoList);
Collections.reverse(codeList);
result.put("regionCode", codeList);
return result;
LngBRegion temp = this.getOne(queryWrapper);
if(temp == null) {
return result;
}
List<String> codeList = CollectionUtils.newArrayList();
List<String> excludeTypeList = CollectionUtils.newArrayList();
if(StringUtils.isNotBlank(startPCode)) {
LambdaQueryWrapper<LngBRegion> qw = new LambdaQueryWrapper<LngBRegion>();
queryWrapper.eq(LngBRegion::getCode,startPCode);
LngBRegion tempPr = this.getOne(qw);
excludeTypeList.add(tempPr.getRegionTypeCode());
}
if(StringUtils.isNotBlank(startPCode)) {
excludeTypeList.add(excludeType);
}
LambdaQueryWrapper<LngBRegion> tempQw = Wrappers.<LngBRegion>query().lambda()
.ne(StringUtils.isNotBlank(excludeType),LngBRegion::getRegionTypeCode, excludeType)
.eq(StringUtils.isNotBlank(startPCode),LngBRegion::getCode, startPCode);
List<LngBRegion> allList = this.list(tempQw);
Map<Long,LngBRegion> map = allList.stream().collect(Collectors.toMap(LngBRegion::getId,
obj -> obj));
if(map != null) {
codeList.add(code);
while(temp != null && temp.getPid() != null && !excludeTypeList.contains(temp.getRegionTypeCode())) {
temp = map.get(temp.getPid());
if(temp != null) {
codeList.add(temp.getCode());
}
}
}
List<LngBRegionTreeVo> voList = CollectionUtils.newArrayList();
if(allList != null && allList.size() > 0) {
for(LngBRegion br:allList) {
LngBRegionTreeVo vo = new LngBRegionTreeVo();
BeanUtil.copyProperties(br, vo);
if(br.getPid() != null) {
vo.setParentId(String.valueOf(br.getPid()) );
}else {
vo.setParentId(String.valueOf(GlobalConstant.FIRST_NODE_VALUE));
}
voList.add(vo);
}
}
List<LngBRegionTreeVo> treeVoList = TreeUtil.build(voList);
filterNode(treeVoList,codeList);
result.put("areaList", treeVoList);
Collections.reverse(codeList);
result.put("regionCode", codeList);
return result;
}
private void filterNode(List<LngBRegionTreeVo> treeVoList,List<String> codeList) {
@ -102,4 +116,55 @@ public class CountryRegionServiceImpl extends ServiceImpl<LngBRegionMapper, LngB
return baseMapper.selectOne(queryWrapper);
}
@Override
public List<LngBRegionVo> child(Long pid, String excludeType, String keyword, String startPCode) {
List<Long> pidList = CollectionUtils.newArrayList();
if(StrUtil.isNotBlank(startPCode) && (pid == null || pid ==0) ){
List<LngBRegion> pList = this.list(Wrappers.<LngBRegion>query()
.lambda().eq(LngBRegion::getCode, startPCode));
if(pList != null && pList.size() > 0) {
for(LngBRegion p:pList) {
pidList.add(p.getId());
}
}
}else {
if(StrUtil.isNotBlank(excludeType) && (pid == null || pid ==0) ){
List<LngBRegion> pList = this.list(Wrappers.<LngBRegion>query()
.lambda().eq(LngBRegion::getRegionTypeCode, excludeType));
if(pList != null && pList.size() > 0) {
for(LngBRegion p:pList) {
pidList.add(p.getId());
}
}
}
}
List<LngBRegion> regionList = this.list(Wrappers.<LngBRegion>query().lambda()
.eq(pid != null, LngBRegion::getPid, pid)
.eq(LngBRegion::getValid, ValidEnum.ENABLE.getCode())
.in(pid == null, LngBRegion::getPid, pidList)
.and(StrUtil.isNotBlank(keyword), x -> {
x.like(StrUtil.isNotBlank(keyword), LngBRegion::getFullName, keyword);
}));
List<LngBRegionVo> voList = CollectionUtils.newArrayList();
if(voList != null && regionList.size() > 0) {
for(LngBRegion br:regionList) {
LngBRegionVo vo = new LngBRegionVo();
BeanUtil.copyProperties(br, vo);
Long parentId = br.getId();
if(parentId == null) {
parentId = 0L;
}
Long codeCount = this.count(new LambdaQueryWrapper<LngBRegion>()
.eq(LngBRegion::getPid, parentId));
if(codeCount > 0) {
vo.setHasChild(true);
}
voList.add(vo);
}
}
return voList;
}
}