diff --git a/itc-pcitc-mdm/itc-pcitc-mdm-service/src/main/java/com/xjrsoft/module/mdm/controller/CountryRegionController.java b/itc-pcitc-mdm/itc-pcitc-mdm-service/src/main/java/com/xjrsoft/module/mdm/controller/CountryRegionController.java index 21ffcc4..fe31c72 100644 --- a/itc-pcitc-mdm/itc-pcitc-mdm-service/src/main/java/com/xjrsoft/module/mdm/controller/CountryRegionController.java +++ b/itc-pcitc-mdm/itc-pcitc-mdm-service/src/main/java/com/xjrsoft/module/mdm/controller/CountryRegionController.java @@ -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 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 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 pidList = CollectionUtils.newArrayList(); - if(StrUtil.isNotBlank(excludeType) && (pid == null || pid ==0) ){ - List pList = countryRegionService.list(Wrappers.query() - .lambda().eq(LngBRegion::getRegionTypeCode, excludeType)); - if(pList != null && pList.size() > 0) { - for(LngBRegion p:pList) { - pidList.add(p.getId()); - } - } - } - List regionList = countryRegionService.list(Wrappers.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 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() - .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)); } diff --git a/itc-pcitc-mdm/itc-pcitc-mdm-service/src/main/java/com/xjrsoft/module/mdm/service/ICountryRegionService.java b/itc-pcitc-mdm/itc-pcitc-mdm-service/src/main/java/com/xjrsoft/module/mdm/service/ICountryRegionService.java index eedf9ed..fe86c8d 100644 --- a/itc-pcitc-mdm/itc-pcitc-mdm-service/src/main/java/com/xjrsoft/module/mdm/service/ICountryRegionService.java +++ b/itc-pcitc-mdm/itc-pcitc-mdm-service/src/main/java/com/xjrsoft/module/mdm/service/ICountryRegionService.java @@ -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 { - Map getRegionByParentId(String code, String excludeType); + Map getRegionByParentId(String code, String excludeType, String startPCode); + + List child(Long pid,String excludeType, String keyword,String startPCode); LngBRegion getByCode(String code); diff --git a/itc-pcitc-mdm/itc-pcitc-mdm-service/src/main/java/com/xjrsoft/module/mdm/service/impl/CountryRegionServiceImpl.java b/itc-pcitc-mdm/itc-pcitc-mdm-service/src/main/java/com/xjrsoft/module/mdm/service/impl/CountryRegionServiceImpl.java index 05f9aae..aa9b2ec 100644 --- a/itc-pcitc-mdm/itc-pcitc-mdm-service/src/main/java/com/xjrsoft/module/mdm/service/impl/CountryRegionServiceImpl.java +++ b/itc-pcitc-mdm/itc-pcitc-mdm-service/src/main/java/com/xjrsoft/module/mdm/service/impl/CountryRegionServiceImpl.java @@ -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 implements ICountryRegionService { @Override - public Map getRegionByParentId(String code,String excludeType) { + public Map getRegionByParentId(String code,String excludeType,String startPCode) { Map result = new HashMap<>(); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); queryWrapper.eq(LngBRegion::getCode,code); - LngBRegion temp = this.getOne(queryWrapper); - if(temp == null) { - return result; - } - List codeList = CollectionUtils.newArrayList(); - - List allList = this.list(Wrappers.query() - .lambda().ne(StringUtils.isNotBlank(excludeType),LngBRegion::getRegionTypeCode, excludeType)); - Map 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 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 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 codeList = CollectionUtils.newArrayList(); + List excludeTypeList = CollectionUtils.newArrayList(); + if(StringUtils.isNotBlank(startPCode)) { + LambdaQueryWrapper qw = new LambdaQueryWrapper(); + queryWrapper.eq(LngBRegion::getCode,startPCode); + LngBRegion tempPr = this.getOne(qw); + excludeTypeList.add(tempPr.getRegionTypeCode()); + } + if(StringUtils.isNotBlank(startPCode)) { + excludeTypeList.add(excludeType); + } + + LambdaQueryWrapper tempQw = Wrappers.query().lambda() + .ne(StringUtils.isNotBlank(excludeType),LngBRegion::getRegionTypeCode, excludeType) + .eq(StringUtils.isNotBlank(startPCode),LngBRegion::getCode, startPCode); + List allList = this.list(tempQw); + Map 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 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 treeVoList = TreeUtil.build(voList); + filterNode(treeVoList,codeList); + result.put("areaList", treeVoList); + Collections.reverse(codeList); + result.put("regionCode", codeList); + return result; } private void filterNode(List treeVoList,List codeList) { @@ -102,4 +116,55 @@ public class CountryRegionServiceImpl extends ServiceImpl child(Long pid, String excludeType, String keyword, String startPCode) { + List pidList = CollectionUtils.newArrayList(); + + if(StrUtil.isNotBlank(startPCode) && (pid == null || pid ==0) ){ + List pList = this.list(Wrappers.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 pList = this.list(Wrappers.query() + .lambda().eq(LngBRegion::getRegionTypeCode, excludeType)); + if(pList != null && pList.size() > 0) { + for(LngBRegion p:pList) { + pidList.add(p.getId()); + } + } + } + } + List regionList = this.list(Wrappers.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 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() + .eq(LngBRegion::getPid, parentId)); + if(codeCount > 0) { + vo.setHasChild(true); + } + voList.add(vo); + } + } + return voList; + } + }