From 0b16d57f05a8fbde98e68ddc46504c7c35a5eff2 Mon Sep 17 00:00:00 2001 From: "java_cuibaocheng@163.com" Date: Fri, 17 Nov 2023 19:04:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=8F=A3=E5=9F=BA=E6=9C=AC=E4=BF=A1?= =?UTF-8?q?=E6=81=AF-=20=E4=BF=AE=E6=94=B9=E5=85=A8=E5=9B=BD=E5=9C=B0?= =?UTF-8?q?=E5=8C=BA=E4=B8=8B=E6=8B=89=E5=8A=A0=E8=BD=BD=E6=85=A2=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=E8=A7=A3=E5=86=B3=E6=96=B9=E6=B3=95,=20?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E5=B0=86=E5=85=A8=E5=9B=BD=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=9A=84=E5=9C=B0=E5=8C=BA=E4=BF=A1=E6=81=AF=E5=88=86=E7=BA=A7?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=88=B0Java=E9=9D=99=E6=80=81=E5=8C=BA?= =?UTF-8?q?=E4=B8=AD,=20=E5=A2=9E=E5=8A=A0=E5=90=8E=E5=8F=B0=E7=9A=84?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=80=9F=E5=BA=A6(=E6=9C=80=E7=BB=88?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E9=80=9F=E5=BA=A6=E5=8F=96=E5=86=B3=E4=BA=8E?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=BD=91=E9=80=9F=E4=B8=8E=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=BD=91=E9=80=9F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/areatree/AreaTreeController.java | 87 ++++------ .../api/areatree/AreaTreeAppController.java | 31 ++-- .../population/dao/areatree/IAreatreeDao.java | 4 + .../pojo/dtos/areatree/AreaZtreeDTO.java | 22 ++- .../IPopulationInfoService.java | 9 + .../impl/PopulationInfoServiceImpl.java | 20 +++ .../java/com/cm/population/utils/AreaDTO.java | 54 ++++++ .../com/cm/population/utils/AreaUtils.java | 158 ++++++++++++++++++ .../utils/SystemPopulationUtil.java | 40 +++++ .../mapper/areatree/areatree-mapper.xml | 49 +++++- src/main/resources/templates/cult/save.html | 4 +- src/main/resources/templates/cult/update.html | 4 +- .../resources/templates/dispute/save.html | 6 +- .../resources/templates/dispute/update.html | 4 +- .../templates/populationinfo/importexcel.html | 4 +- .../templates/populationinfo/save.html | 8 +- .../templates/populationinfo/update.html | 8 +- .../resources/templates/security/save.html | 4 +- .../resources/templates/security/update.html | 4 +- 19 files changed, 424 insertions(+), 96 deletions(-) create mode 100644 src/main/java/com/cm/population/utils/AreaDTO.java create mode 100644 src/main/java/com/cm/population/utils/AreaUtils.java create mode 100644 src/main/java/com/cm/population/utils/SystemPopulationUtil.java diff --git a/src/main/java/com/cm/population/controller/api/areatree/AreaTreeController.java b/src/main/java/com/cm/population/controller/api/areatree/AreaTreeController.java index 8108bc0..a5ac720 100644 --- a/src/main/java/com/cm/population/controller/api/areatree/AreaTreeController.java +++ b/src/main/java/com/cm/population/controller/api/areatree/AreaTreeController.java @@ -18,6 +18,7 @@ import com.cm.population.pojo.dtos.populationinfo.PopulationInfoBaseDTO; import com.cm.population.pojo.vos.correct.CorrectVO; import com.cm.population.service.correct.ICorrectService; import com.cm.population.service.populationinfo.IPopulationInfoService; +import com.cm.population.utils.AreaUtils; import io.swagger.annotations.*; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -39,6 +40,8 @@ public class AreaTreeController extends AbstractController { @Autowired private IPopulationInfoService iPopulationInfoService; + @Autowired + private AreaUtils areaUtils; @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("get/{areaCode}") public Map get(@PathVariable("areaCode") String areaCode) { @@ -51,38 +54,38 @@ public class AreaTreeController extends AbstractController { return objectMap; } - /** - * 全国地区属 - * @return - */ - @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @GetMapping("list2") - public List list2() { - List list = iPopulationInfoService.getAreaList(); - for(DataAreaDTO dto : list) { - ArrayList names = new ArrayList<>(); - names.add(dto.getAreaName()); - getParent(names, dto.getAreaParentId()); - dto.setAreaMergerMame(StringUtils.join(names, "/")); - } - return list; - } +// /** +// * 全国地区属 +// * @return +// */ +// @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) +// @GetMapping("list2") +// public List list2() { +// List list = iPopulationInfoService.getAreaList(); +// for(DataAreaDTO dto : list) { +// ArrayList names = new ArrayList<>(); +// names.add(dto.getAreaName()); +// getParent(names, dto.getAreaParentId()); +// dto.setAreaMergerMame(StringUtils.join(names, "/")); +// } +// return list; +// } - @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @GetMapping("newtree") - public List> tree1(String id) { - String parentId = id == null ? "0" : id; - List list = iPopulationInfoService.listAreaTree(parentId); - List> result = new ArrayList<>(); - for(AreaZtreeDTO dto : list) { - Map objectMap = new HashMap<>(); - objectMap.put("label", dto.getName()); - objectMap.put("code", dto.getAreaCode()); - objectMap.put("value", dto.getId()); - result.add(objectMap); - } - return result; - } +// @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) +// @GetMapping("newtree") +// public List> tree1(String id) { +// String parentId = id == null ? "0" : id; +// List list = iPopulationInfoService.listAreaTree(parentId); +// List> result = new ArrayList<>(); +// for(AreaZtreeDTO dto : list) { +// Map objectMap = new HashMap<>(); +// objectMap.put("label", dto.getName()); +// objectMap.put("code", dto.getAreaCode()); +// objectMap.put("value", dto.getId()); +// result.add(objectMap); +// } +// return result; +// } @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @PostMapping("huji") @@ -147,14 +150,7 @@ public class AreaTreeController extends AbstractController { if (StringUtils.isEmpty(id)) { parentId = "752234"; } - List list = iPopulationInfoService.listAreaTree(parentId); - for(AreaZtreeDTO dto : list) { - ArrayList names = new ArrayList<>(); - names.add(dto.getName()); - getParent(names, dto.getpId()); - dto.setTitle(StringUtils.join(names, "/")); - } - return list; + return areaUtils.getList(parentId); } /** @@ -165,18 +161,7 @@ public class AreaTreeController extends AbstractController { @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @PostMapping("list") public List list(String id) { - String parentId = id; - if (StringUtils.isEmpty(id)) { - parentId = "0"; // 默认查找全国 - } - List list = iPopulationInfoService.listAreaTree(parentId); - for(AreaZtreeDTO dto : list) { - ArrayList names = new ArrayList<>(); - names.add(dto.getName()); - getParent(names, dto.getpId()); - dto.setTitle(StringUtils.join(names, "/")); - } - return list; + return areaUtils.getList(id); } public void getParent(ArrayList names, String pId) { diff --git a/src/main/java/com/cm/population/controller/app/api/areatree/AreaTreeAppController.java b/src/main/java/com/cm/population/controller/app/api/areatree/AreaTreeAppController.java index fae5242..9ff1d80 100644 --- a/src/main/java/com/cm/population/controller/app/api/areatree/AreaTreeAppController.java +++ b/src/main/java/com/cm/population/controller/app/api/areatree/AreaTreeAppController.java @@ -7,6 +7,7 @@ import com.cm.common.pojo.dtos.ZTreeDTO; import com.cm.common.result.ErrorResult; import com.cm.population.pojo.dtos.areatree.AreaZtreeDTO; import com.cm.population.service.populationinfo.IPopulationInfoService; +import com.cm.population.utils.AreaUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; @@ -33,6 +34,14 @@ public class AreaTreeAppController extends AbstractController { @Autowired private IPopulationInfoService iPopulationInfoService; + @Autowired + private AreaUtils areaUtils; + + @ApiResponses({@ApiResponse(code = 400, message = "用来测试地区的-不参与业务", response = ErrorResult.class)}) + @GetMapping("hu") + public List huji1(String id) { + return areaUtils.getList(id); + } @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("huji") @@ -97,14 +106,7 @@ public class AreaTreeAppController extends AbstractController { if (StringUtils.isEmpty(id)) { parentId = "752234"; } - List list = iPopulationInfoService.listAreaTree(parentId); - for(AreaZtreeDTO dto : list) { - ArrayList names = new ArrayList<>(); - names.add(dto.getName()); - getParent(names, dto.getpId()); - dto.setTitle(StringUtils.join(names, "/")); - } - return list; + return areaUtils.getList(parentId); } /** @@ -115,18 +117,7 @@ public class AreaTreeAppController extends AbstractController { @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("list") public List list(String id) { - String parentId = id; - if (StringUtils.isEmpty(id)) { - parentId = "0"; // 默认查找全国 - } - List list = iPopulationInfoService.listAreaTree(parentId); - for(AreaZtreeDTO dto : list) { - ArrayList names = new ArrayList<>(); - names.add(dto.getName()); - getParent(names, dto.getpId()); - dto.setTitle(StringUtils.join(names, "/")); - } - return list; + return areaUtils.getList(id); } public void getParent(ArrayList names, String pId) { diff --git a/src/main/java/com/cm/population/dao/areatree/IAreatreeDao.java b/src/main/java/com/cm/population/dao/areatree/IAreatreeDao.java index bab37ea..77820ce 100644 --- a/src/main/java/com/cm/population/dao/areatree/IAreatreeDao.java +++ b/src/main/java/com/cm/population/dao/areatree/IAreatreeDao.java @@ -18,4 +18,8 @@ public interface IAreatreeDao { Integer countByParentId(String parentId); List list(Map params); + + List listCache(Map params); + + AreaZtreeDTO getAreaByAreaId(Map params); } diff --git a/src/main/java/com/cm/population/pojo/dtos/areatree/AreaZtreeDTO.java b/src/main/java/com/cm/population/pojo/dtos/areatree/AreaZtreeDTO.java index 871016c..65d66f1 100644 --- a/src/main/java/com/cm/population/pojo/dtos/areatree/AreaZtreeDTO.java +++ b/src/main/java/com/cm/population/pojo/dtos/areatree/AreaZtreeDTO.java @@ -2,9 +2,29 @@ package com.cm.population.pojo.dtos.areatree; import com.cm.common.pojo.dtos.ZTreeDTO; -public class AreaZtreeDTO extends ZTreeDTO { +import java.io.Serializable; + +public class AreaZtreeDTO extends ZTreeDTO implements Serializable { private String areaCode; + private String areaLevel; + private Integer subCount; + + public String getAreaLevel() { + return areaLevel; + } + + public void setAreaLevel(String areaLevel) { + this.areaLevel = areaLevel; + } + + public Integer getSubCount() { + return subCount; + } + + public void setSubCount(Integer subCount) { + this.subCount = subCount; + } public AreaZtreeDTO(){ super(); diff --git a/src/main/java/com/cm/population/service/populationinfo/IPopulationInfoService.java b/src/main/java/com/cm/population/service/populationinfo/IPopulationInfoService.java index 6b338d6..02662f4 100644 --- a/src/main/java/com/cm/population/service/populationinfo/IPopulationInfoService.java +++ b/src/main/java/com/cm/population/service/populationinfo/IPopulationInfoService.java @@ -27,8 +27,17 @@ public interface IPopulationInfoService { void getTuoMin(PopulationInfoDTO dto); void getTuoMin(PopulationInfoBaseDTO dto); + /** + * 按照level查询地区 + * @param level 地区级别 + * @param page 0为不分页 , 每次默认10000条 + * @return + */ + List getAreaListByLevel(String level, Integer page); + DataAreaDTO getAreaByCode(String code); DataAreaDTO getAreaById(String id); + AreaZtreeDTO getAreaByAreaId(String id); List listAreaTree(String parentId); PopulationInfoBaseDTO getBase(String populationInfoId); diff --git a/src/main/java/com/cm/population/service/populationinfo/impl/PopulationInfoServiceImpl.java b/src/main/java/com/cm/population/service/populationinfo/impl/PopulationInfoServiceImpl.java index f014874..082c98c 100644 --- a/src/main/java/com/cm/population/service/populationinfo/impl/PopulationInfoServiceImpl.java +++ b/src/main/java/com/cm/population/service/populationinfo/impl/PopulationInfoServiceImpl.java @@ -42,6 +42,7 @@ import com.cm.population.service.populationinfo.IPopulationInfoService; import com.cm.population.service.populationlog.IPopulationLogService; import com.cm.population.service.release.IReleaseService; import com.cm.population.service.security.ISecurityService; +import com.cm.population.utils.AreaDTO; import com.cm.population.utils.IdCardVerifyUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; @@ -84,6 +85,13 @@ public class PopulationInfoServiceImpl extends AbstractService implements IPopul return iAreatreeDao.getArea(params); } + @Override + public AreaZtreeDTO getAreaByAreaId(String id) { + Map params = new HashMap<>(); + params.put("areaId", id); + return iAreatreeDao.getAreaByAreaId(params); + } + @Override public List getAreaList() { Map params = new HashMap<>(); @@ -91,6 +99,18 @@ public class PopulationInfoServiceImpl extends AbstractService implements IPopul return list; } + @Override + public List getAreaListByLevel(String level, Integer page) { + Map params = new HashMap<>(); + params.put("level", StringUtils.isEmpty(level) ? "-1" : level); + if (-1 != page) { + params.put("startPage", page * 10000); + System.err.println(level + "正在缓存:" + (page * 10000) + "-" + ((page * 10000) + 10000) ) ; + } + List list = iAreatreeDao.listCache(params); + return list; + } + @Override public void getTuoMin(PopulationInfoDTO dto) { String idcard = dto.getIdcard(); diff --git a/src/main/java/com/cm/population/utils/AreaDTO.java b/src/main/java/com/cm/population/utils/AreaDTO.java new file mode 100644 index 0000000..8690658 --- /dev/null +++ b/src/main/java/com/cm/population/utils/AreaDTO.java @@ -0,0 +1,54 @@ +package com.cm.population.utils; + +public class AreaDTO{ + + private String name; + + private String id; + + private String code; + + private String pId; + + private String names; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getpId() { + return pId; + } + + public void setpId(String pId) { + this.pId = pId; + } + + public String getNames() { + return names; + } + + public void setNames(String names) { + this.names = names; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/com/cm/population/utils/AreaUtils.java b/src/main/java/com/cm/population/utils/AreaUtils.java new file mode 100644 index 0000000..130db51 --- /dev/null +++ b/src/main/java/com/cm/population/utils/AreaUtils.java @@ -0,0 +1,158 @@ +package com.cm.population.utils; + +import com.cm.common.plugin.pojo.dtos.dataarea.DataAreaDTO; +import com.cm.population.pojo.dtos.areatree.AreaZtreeDTO; +import com.cm.population.service.populationinfo.IPopulationInfoService; +import com.cm.population.service.populationinfo.impl.PopulationInfoServiceImpl; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentSkipListMap; + +@Component +public class AreaUtils { + + @Autowired + private IPopulationInfoService PopulationInfoService; + private static IPopulationInfoService PopulationInfoStaticService; + private static final Map> aree = new ConcurrentSkipListMap>(); + private static final Map area0 = new ConcurrentSkipListMap();//省 + private static final Map area1 = new ConcurrentSkipListMap();//市 + private static final Map area2 = new ConcurrentSkipListMap();//线 + private static final Map area3 = new ConcurrentSkipListMap();//街道 + private static final Map area4 = new ConcurrentSkipListMap();//社区 + + @PostConstruct + public void init() { + PopulationInfoStaticService = PopulationInfoService; + initArea0(); + initArea1(); + initArea2(); + initArea3(); + initArea4(); + aree.put(0, area0); + aree.put(1, area1); + aree.put(2, area2); + aree.put(3, area3); + aree.put(4, area4); + } + + public List getList(String id) { + id = "0".equals(id) ? "" : id; + List list = new ArrayList(); + Integer level = -1; + Integer subCount = 0; + // 确定级别 + if (!StringUtils.isEmpty(id) ) { + AreaZtreeDTO areaDTO = PopulationInfoStaticService.getAreaByAreaId(id); + level = Integer.valueOf(areaDTO.getAreaLevel()); + subCount = areaDTO.getSubCount(); + } + Map dataMap = aree.get(level + 1); + if (dataMap != null) { + // 找出所有的子类 + for(Map.Entry m : dataMap.entrySet()) { + AreaZtreeDTO ztreeDTO = m.getValue(); + String pId = ztreeDTO.getpId(); + String title = ztreeDTO.getTitle(); + if(!StringUtils.isEmpty(id) && pId.equals(id)) { + if (StringUtils.isEmpty(title)) { + ArrayList names = new ArrayList<>(); + getParent(level, names, id); + String newName = StringUtils.join(names, "/") + "/" + ztreeDTO.getName(); + ztreeDTO.setTitle(newName); + } + list.add(ztreeDTO); + if (list.size() == subCount) { + break; + } + } + if(StringUtils.isEmpty(id)) { + ztreeDTO.setTitle(ztreeDTO.getName()); + list.add(ztreeDTO); + } + + } + } + return list; + } + + // 递归拼接全名称 + public void getParent(Integer level, ArrayList names, String pId) { + Map dataMap = aree.get(level); + if (level > -1 && dataMap != null) { + level--; + for(Map.Entry m : dataMap.entrySet()) { + String id = m.getValue().getId(); + if(pId.equals(id)) { + names.add(0, m.getValue().getName()); + getParent(level, names, m.getValue().getpId()); + break; + } + } + + } + } + + private static void initArea0() { + List dto = PopulationInfoStaticService.getAreaListByLevel("0", -1); + for(AreaZtreeDTO areaDTO : dto) { + if (areaDTO.getSubCount() > 0 ) { + areaDTO.setIsParent(true); + } + area0.put(areaDTO.getId(), areaDTO); + } + } + + private static void initArea1() { + List dto = PopulationInfoStaticService.getAreaListByLevel("1", -1); + for(AreaZtreeDTO areaDTO : dto) { + if (areaDTO.getSubCount() > 0 ) { + areaDTO.setIsParent(true); + } + area1.put(areaDTO.getId(), areaDTO); + } + } + + private static void initArea2() { + List dto = PopulationInfoStaticService.getAreaListByLevel("2", -1); + for(AreaZtreeDTO areaDTO : dto) { + if (areaDTO.getSubCount() > 0 ) { + areaDTO.setIsParent(true); + } + area2.put(areaDTO.getId(), areaDTO); + } + } + + private static void initArea3() { + for(int i = 0 ; i < 9 ; i++ ) { + List dto = PopulationInfoStaticService.getAreaListByLevel("3", i); + for(AreaZtreeDTO areaDTO : dto) { + if (areaDTO.getSubCount() > 0 ) { + areaDTO.setIsParent(true); + } + area3.put(areaDTO.getId(), areaDTO); + } + } + } + + private static void initArea4() { + for(int i = 0 ; i < 67 ; i++ ) { + List dto = PopulationInfoStaticService.getAreaListByLevel("4", i); + for(AreaZtreeDTO areaDTO : dto) { + if (areaDTO.getSubCount() > 0 ) { + areaDTO.setIsParent(true); + } + area4.put(areaDTO.getId(), areaDTO); + } + } + } + +} diff --git a/src/main/java/com/cm/population/utils/SystemPopulationUtil.java b/src/main/java/com/cm/population/utils/SystemPopulationUtil.java new file mode 100644 index 0000000..4c694a8 --- /dev/null +++ b/src/main/java/com/cm/population/utils/SystemPopulationUtil.java @@ -0,0 +1,40 @@ +package com.cm.population.utils; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +@Component +public class SystemPopulationUtil implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + if(SystemPopulationUtil.applicationContext == null) { + SystemPopulationUtil.applicationContext = applicationContext; + } + } + + //获取applicationContext + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + //通过name获取 Bean. + public static Object getBean(String name){ + return getApplicationContext().getBean(name); + } + + //通过class获取Bean. + public static T getBean(Class clazz){ + return getApplicationContext().getBean(clazz); + } + + //通过name,以及Clazz返回指定的Bean + public static T getBean(String name,Class clazz){ + return getApplicationContext().getBean(name, clazz); + } + +} \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/areatree/areatree-mapper.xml b/src/main/resources/mybatis/mapper/areatree/areatree-mapper.xml index b8ee85a..2335694 100644 --- a/src/main/resources/mybatis/mapper/areatree/areatree-mapper.xml +++ b/src/main/resources/mybatis/mapper/areatree/areatree-mapper.xml @@ -4,6 +4,15 @@ + + + + + + + + + @@ -16,6 +25,7 @@ + @@ -37,6 +47,26 @@ is_delete = 0 AND area_parent_id = #{areaParentId} + + + + - - - - - - -