更新根据id获取下级地区接口
This commit is contained in:
@ -5,8 +5,6 @@ import java.util.List;
|
|||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
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.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
||||||
import com.pictc.datalog.DataOperationContent;
|
import com.pictc.datalog.DataOperationContent;
|
||||||
import com.pictc.datalog.DataOperationListener;
|
import com.pictc.datalog.DataOperationListener;
|
||||||
import com.pictc.enums.BusinessCode;
|
import com.pictc.enums.BusinessCode;
|
||||||
import com.pictc.enums.ExceptionCommonCode;
|
import com.pictc.enums.ExceptionCommonCode;
|
||||||
import com.pictc.enums.ValidEnum;
|
|
||||||
import com.pictc.utils.CollectionUtils;
|
import com.pictc.utils.CollectionUtils;
|
||||||
import com.xjrsoft.common.advice.tran.RegionDataProvider;
|
import com.xjrsoft.common.advice.tran.RegionDataProvider;
|
||||||
import com.xjrsoft.common.constant.GlobalConstant;
|
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.model.result.R;
|
||||||
import com.xjrsoft.common.page.ConventPage;
|
import com.xjrsoft.common.page.ConventPage;
|
||||||
import com.xjrsoft.common.page.PageOutput;
|
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.TreeUtil;
|
||||||
import com.xjrsoft.common.utils.VoToColumnUtil;
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
||||||
import com.xjrsoft.module.common.db.utils.CommonCallUtils;
|
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")
|
@GetMapping(value = "/tree")
|
||||||
@ -222,7 +210,7 @@ public class CountryRegionController {
|
|||||||
@ApiOperation(value = "启用")
|
@ApiOperation(value = "启用")
|
||||||
@SaCheckPermission("countryRegion:enable")
|
@SaCheckPermission("countryRegion:enable")
|
||||||
public R enable(@Valid @RequestBody List<Long> ids){
|
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")
|
@GetMapping("/child")
|
||||||
@ApiOperation(value = "根据id 查询下级区域")
|
@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();
|
return R.ok(countryRegionService.child(pid, excludeType, keyword, startPCode));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getParentByCode")
|
@GetMapping("/getParentByCode")
|
||||||
@ApiOperation(value = "根据id 查询下级区域")
|
@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));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,13 @@
|
|||||||
package com.xjrsoft.module.mdm.service;
|
package com.xjrsoft.module.mdm.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.xjrsoft.module.mdm.entity.LngBRegion;
|
import com.xjrsoft.module.mdm.entity.LngBRegion;
|
||||||
|
import com.xjrsoft.module.mdm.vo.LngBRegionVo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @title: service
|
* @title: service
|
||||||
@ -15,7 +19,9 @@ import com.xjrsoft.module.mdm.entity.LngBRegion;
|
|||||||
public interface ICountryRegionService extends IService<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);
|
LngBRegion getByCode(String code);
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.pictc.enums.ValidEnum;
|
||||||
import com.pictc.utils.CollectionUtils;
|
import com.pictc.utils.CollectionUtils;
|
||||||
import com.xjrsoft.common.constant.GlobalConstant;
|
import com.xjrsoft.common.constant.GlobalConstant;
|
||||||
import com.xjrsoft.common.utils.TreeUtil;
|
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.mapper.LngBRegionMapper;
|
||||||
import com.xjrsoft.module.mdm.service.ICountryRegionService;
|
import com.xjrsoft.module.mdm.service.ICountryRegionService;
|
||||||
import com.xjrsoft.module.mdm.vo.LngBRegionTreeVo;
|
import com.xjrsoft.module.mdm.vo.LngBRegionTreeVo;
|
||||||
|
import com.xjrsoft.module.mdm.vo.LngBRegionVo;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import shade.powerjob.com.google.common.collect.Lists;
|
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 {
|
public class CountryRegionServiceImpl extends ServiceImpl<LngBRegionMapper, LngBRegion> implements ICountryRegionService {
|
||||||
|
|
||||||
@Override
|
@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<>();
|
Map<String,Object> result = new HashMap<>();
|
||||||
LambdaQueryWrapper<LngBRegion> queryWrapper = new LambdaQueryWrapper<LngBRegion>();
|
LambdaQueryWrapper<LngBRegion> queryWrapper = new LambdaQueryWrapper<LngBRegion>();
|
||||||
queryWrapper.eq(LngBRegion::getCode,code);
|
queryWrapper.eq(LngBRegion::getCode,code);
|
||||||
LngBRegion temp = this.getOne(queryWrapper);
|
LngBRegion temp = this.getOne(queryWrapper);
|
||||||
if(temp == null) {
|
if(temp == null) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
List<String> codeList = CollectionUtils.newArrayList();
|
List<String> codeList = CollectionUtils.newArrayList();
|
||||||
|
List<String> excludeTypeList = CollectionUtils.newArrayList();
|
||||||
List<LngBRegion> allList = this.list(Wrappers.<LngBRegion>query()
|
if(StringUtils.isNotBlank(startPCode)) {
|
||||||
.lambda().ne(StringUtils.isNotBlank(excludeType),LngBRegion::getRegionTypeCode, excludeType));
|
LambdaQueryWrapper<LngBRegion> qw = new LambdaQueryWrapper<LngBRegion>();
|
||||||
Map<Long,LngBRegion> map = allList.stream().collect(Collectors.toMap(LngBRegion::getId,
|
queryWrapper.eq(LngBRegion::getCode,startPCode);
|
||||||
obj -> obj));
|
LngBRegion tempPr = this.getOne(qw);
|
||||||
if(map != null) {
|
excludeTypeList.add(tempPr.getRegionTypeCode());
|
||||||
codeList.add(code);
|
}
|
||||||
while(temp != null && temp.getPid() != null && !CountryRegionEnum.CONTINENT.getCode().equals(temp.getRegionTypeCode())) {
|
if(StringUtils.isNotBlank(startPCode)) {
|
||||||
temp = map.get(temp.getPid());
|
excludeTypeList.add(excludeType);
|
||||||
if(temp != null) {
|
}
|
||||||
codeList.add(temp.getCode());
|
|
||||||
}
|
LambdaQueryWrapper<LngBRegion> tempQw = Wrappers.<LngBRegion>query().lambda()
|
||||||
}
|
.ne(StringUtils.isNotBlank(excludeType),LngBRegion::getRegionTypeCode, excludeType)
|
||||||
}
|
.eq(StringUtils.isNotBlank(startPCode),LngBRegion::getCode, startPCode);
|
||||||
List<LngBRegionTreeVo> voList = CollectionUtils.newArrayList();
|
List<LngBRegion> allList = this.list(tempQw);
|
||||||
if(allList != null && allList.size() > 0) {
|
Map<Long,LngBRegion> map = allList.stream().collect(Collectors.toMap(LngBRegion::getId,
|
||||||
for(LngBRegion br:allList) {
|
obj -> obj));
|
||||||
LngBRegionTreeVo vo = new LngBRegionTreeVo();
|
if(map != null) {
|
||||||
BeanUtil.copyProperties(br, vo);
|
codeList.add(code);
|
||||||
|
while(temp != null && temp.getPid() != null && !excludeTypeList.contains(temp.getRegionTypeCode())) {
|
||||||
if(br.getPid() != null) {
|
temp = map.get(temp.getPid());
|
||||||
vo.setParentId(String.valueOf(br.getPid()) );
|
if(temp != null) {
|
||||||
}else {
|
codeList.add(temp.getCode());
|
||||||
vo.setParentId(String.valueOf(GlobalConstant.FIRST_NODE_VALUE));
|
}
|
||||||
}
|
}
|
||||||
voList.add(vo);
|
}
|
||||||
}
|
List<LngBRegionTreeVo> voList = CollectionUtils.newArrayList();
|
||||||
}
|
if(allList != null && allList.size() > 0) {
|
||||||
List<LngBRegionTreeVo> treeVoList = TreeUtil.build(voList);
|
for(LngBRegion br:allList) {
|
||||||
filterNode(treeVoList,codeList);
|
LngBRegionTreeVo vo = new LngBRegionTreeVo();
|
||||||
result.put("areaList", treeVoList);
|
BeanUtil.copyProperties(br, vo);
|
||||||
Collections.reverse(codeList);
|
if(br.getPid() != null) {
|
||||||
result.put("regionCode", codeList);
|
vo.setParentId(String.valueOf(br.getPid()) );
|
||||||
return result;
|
}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) {
|
private void filterNode(List<LngBRegionTreeVo> treeVoList,List<String> codeList) {
|
||||||
@ -102,4 +116,55 @@ public class CountryRegionServiceImpl extends ServiceImpl<LngBRegionMapper, LngB
|
|||||||
return baseMapper.selectOne(queryWrapper);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user