| | |
| | | package org.springblade.modules.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.google.common.collect.Lists; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.common.cache.SysCache; |
| | | import org.springblade.common.node.TreeStringNode; |
| | | import org.springblade.common.utils.NodeTreeUtil; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | |
| | | import org.springblade.modules.system.mapper.RegionMapper; |
| | | import org.springblade.modules.system.service.IDeptService; |
| | | import org.springblade.modules.system.service.IRegionService; |
| | | import org.springblade.modules.system.vo.RegionParamVO; |
| | | import org.springblade.modules.system.vo.RegionVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static org.springblade.common.cache.RegionCache.*; |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<TreeStringNode> getTree(RegionVO region) { |
| | | Dept dept = deptService.getById(AuthUtil.getDeptId()); |
| | | if (null != dept) { |
| | | region.setRegionCode(dept.getRegionCode()); |
| | | public List<TreeStringNode> getTree(RegionParamVO region) { |
| | | List<String> regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId(),null); |
| | | Integer isAdministrator = AuthUtil.isAdministrator()==true?1:2; |
| | | if (null!=region.getDeptNature()){ |
| | | // 公安 |
| | | if (region.getDeptNature()==1){ |
| | | // 查询公安对应的辖区树 |
| | | return NodeTreeUtil.getStringNodeTree(baseMapper.getPoliceTreeList()); |
| | | } |
| | | // 综治的需要查到网格 |
| | | if (region.getDeptNature()==2){ |
| | | region.setCityCode("361100"); |
| | | } |
| | | } |
| | | return NodeTreeUtil.getStringNodeTree(baseMapper.getTreeList(region)); |
| | | // 非公安 |
| | | return NodeTreeUtil.getStringNodeTree(baseMapper.getTreeList(region,regionChildCodesList,isAdministrator)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public List<TreeStringNode> getTownTree(String code) { |
| | | Dept dept = deptService.getById(AuthUtil.getDeptId()); |
| | | String regionCode = null; |
| | | if (null != dept) { |
| | | regionCode = dept.getRegionCode(); |
| | | if (StringUtils.isNotBlank(regionCode) && regionCode.equals("361100000000")) { |
| | | regionCode = "361102000000"; |
| | | if (!AuthUtil.isAdministrator() && !AuthUtil.isAdmin()){ |
| | | Dept dept = deptService.getById(AuthUtil.getDeptId()); |
| | | if (null != dept) { |
| | | regionCode = dept.getRegionCode(); |
| | | if (StringUtils.isNotBlank(regionCode) && regionCode.equals("361100")) { |
| | | regionCode = "361102"; |
| | | } |
| | | } |
| | | } |
| | | return NodeTreeUtil.getStringNodeTree(baseMapper.getTownTree(regionCode)); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 查询下级区域 |
| | | * 查询下级区域(拼接网格) |
| | | * @param regionCode |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Region> getRegionChild(String regionCode) { |
| | | return baseMapper.selectList(Wrappers.<Region>query().lambda().like(Region::getAncestors, regionCode)); |
| | | public List<Region> getRegionChild(String regionCode,String communityCode) { |
| | | // 创建区域对象 |
| | | List<Region> list = new ArrayList<>(); |
| | | // 查询公安相关的区域数据 |
| | | List<Region> regionList = baseMapper.getPoliceList(communityCode); |
| | | if (regionList.size()>0) { |
| | | List<Region> policeList = treeRegionList(regionList,regionCode, list); |
| | | list.addAll(policeList); |
| | | } |
| | | // 查询综治区域集合 |
| | | List<Region> regionChildList = baseMapper.getRegionChildList(regionCode,null,null); |
| | | list.addAll(regionChildList); |
| | | // 返回 |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 获取民警下级区域 |
| | | * @param regionCode |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Region> getPoliceRegionChild(String regionCode,String communityCode) { |
| | | // 创建区域对象 |
| | | List<Region> list = new ArrayList<>(); |
| | | // 查询公安相关的区域数据 |
| | | List<Region> regionList = baseMapper.getPoliceList(communityCode); |
| | | if (regionList.size()>0) { |
| | | List<Region> policeList = treeRegionList(regionList,regionCode, list); |
| | | list.addAll(policeList); |
| | | } |
| | | // 返回 |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 获取综治下级区域 |
| | | * @param regionCode |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Region> getGridRegionChild(String regionCode, String communityCode, String roleName) { |
| | | // 创建区域对象 |
| | | List<Region> list = new ArrayList<>(); |
| | | if (!Strings.isBlank(roleName) && roleName.equals("wgy")){ |
| | | // 查询综治区域集合 |
| | | List<Region> regionChildList = baseMapper.getGridRegionChildList(regionCode); |
| | | list.addAll(regionChildList); |
| | | }else if (!Strings.isBlank(roleName) && roleName.equals("mj")){ |
| | | // 查询公安相关的区域数据 |
| | | List<Region> regionList = baseMapper.getPoliceList(communityCode); |
| | | if (regionList.size()>0) { |
| | | List<Region> policeList = treeRegionList(regionList,regionCode, list); |
| | | list.addAll(policeList); |
| | | } |
| | | }else { |
| | | // 查询综治区域集合 |
| | | List<Region> regionChildList = baseMapper.getRegionChildList(regionCode, communityCode, roleName); |
| | | list.addAll(regionChildList); |
| | | } |
| | | // 返回 |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 获取某个父节点下面的所有子节点 |
| | | * @param regionList |
| | | * @param parentCode |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public static List<Region> treeRegionList( List<Region> regionList, String parentCode,List<Region> list){ |
| | | for(Region region: regionList){ |
| | | //遍历出父id等于参数的id,add进子节点集合 |
| | | if(region.getParentCode().equals(parentCode)){ |
| | | list.add(region); |
| | | //递归遍历下一级 |
| | | treeRegionList(regionList,region.getCode(),list); |
| | | } |
| | | if(region.getCode().equals(parentCode)){ |
| | | // 本身也加入 |
| | | list.add(region); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | } |