diff --git a/cloud-common-plugin-map/src/main/java/com/cm/plugin/map/dao/IGridDao.java b/cloud-common-plugin-map/src/main/java/com/cm/plugin/map/dao/IGridDao.java index 2d8431b..83aa4b8 100644 --- a/cloud-common-plugin-map/src/main/java/com/cm/plugin/map/dao/IGridDao.java +++ b/cloud-common-plugin-map/src/main/java/com/cm/plugin/map/dao/IGridDao.java @@ -107,6 +107,15 @@ public interface IGridDao { */ List listGridByRelationIds(List relationIds) throws SearchException; + /** + * 网格列表group + * + * @param relationIds + * @return + * @throws SearchException + */ + List listGridGroupByRelationIds(List relationIds) throws SearchException; + /** * 获取网格点列表 * @@ -115,4 +124,5 @@ public interface IGridDao { * @throws SearchException */ List listPointByGridIds(List gridIds) throws SearchException; + } diff --git a/cloud-common-plugin-map/src/main/java/com/cm/plugin/map/service/IGridService.java b/cloud-common-plugin-map/src/main/java/com/cm/plugin/map/service/IGridService.java index 90c96bd..0c6234b 100644 --- a/cloud-common-plugin-map/src/main/java/com/cm/plugin/map/service/IGridService.java +++ b/cloud-common-plugin-map/src/main/java/com/cm/plugin/map/service/IGridService.java @@ -2,11 +2,12 @@ package com.cm.plugin.map.service; import com.cm.common.exception.RemoveException; import com.cm.common.exception.SearchException; +import com.cm.common.pojo.ListPage; +import com.cm.common.result.SuccessResultList; import com.cm.plugin.map.pojo.dto.GridDTO; import com.cm.plugin.map.pojo.dto.GridRelationDTO; import com.cm.plugin.map.pojo.vo.GridPointVO; import com.cm.plugin.map.pojo.vo.GridVO; -import org.springframework.stereotype.Service; import java.util.List; @@ -56,6 +57,22 @@ public interface IGridService { */ void deleteGridByGridIds(List gridIds) throws RemoveException; + /** + * 删除空网格(没有节点的网格) + * + * @param deleteGridIds + */ + void deleteEmptyGrid(List gridIds); + + /** + * 删除网格 + * + * @param gridId + * @param relationId + * @throws RemoveException + */ + void deleteGridRelation(String gridId, String relationId) throws RemoveException; + /** * 获取网格关系列表 * @@ -110,4 +127,13 @@ public interface IGridService { */ List listGridByRelationIds(List relationIds) throws SearchException; + /** + * 获取网格分页列表 + * + * @param relationIds + * @return + */ + SuccessResultList> listPageGridByRelationIds(ListPage page, List relationIds); + + } diff --git a/cloud-common-plugin-map/src/main/java/com/cm/plugin/map/service/impl/GridServiceImpl.java b/cloud-common-plugin-map/src/main/java/com/cm/plugin/map/service/impl/GridServiceImpl.java index 08d2ac3..29b1e5e 100644 --- a/cloud-common-plugin-map/src/main/java/com/cm/plugin/map/service/impl/GridServiceImpl.java +++ b/cloud-common-plugin-map/src/main/java/com/cm/plugin/map/service/impl/GridServiceImpl.java @@ -4,6 +4,8 @@ import com.alibaba.druid.util.StringUtils; import com.cm.common.base.AbstractService; import com.cm.common.exception.RemoveException; import com.cm.common.exception.SearchException; +import com.cm.common.pojo.ListPage; +import com.cm.common.result.SuccessResultList; import com.cm.common.utils.HashMapUtil; import com.cm.common.utils.UUIDUtil; import com.cm.plugin.map.dao.IGridDao; @@ -13,12 +15,12 @@ import com.cm.plugin.map.pojo.dto.GridRelationDTO; import com.cm.plugin.map.pojo.vo.GridPointVO; import com.cm.plugin.map.pojo.vo.GridVO; import com.cm.plugin.map.service.IGridService; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; 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.*; /** * When you feel like quitting. Think about why you started @@ -104,6 +106,39 @@ public class GridServiceImpl extends AbstractService implements IGridService { gridDao.deleteGridRelation(params); } + @Override + public void deleteEmptyGrid(List gridIds) { + if (gridIds.isEmpty()) { + return; + } + // 所有的网格和人员关联关系列表 + List gridRelationDTOs = listGridRelationByGridIds(gridIds); + // 得到为空的网格 + List emptyGridIds = new ArrayList<>(); + for (String gridId : gridIds) { + boolean isEmpty = true; + for (GridRelationDTO gridRelationDTO : gridRelationDTOs) { + if (StringUtils.equals(gridId, gridRelationDTO.getGridId())) { + isEmpty = false; + break; + } + } + if (isEmpty) { + emptyGridIds.add(gridId); + } + } + // 删除空网格 + deleteGridByGridIds(emptyGridIds); + } + + @Override + public void deleteGridRelation(String gridId, String relationId) throws RemoveException { + Map params = getHashMap(4); + params.put("gridId", gridId); + params.put("relationId", relationId); + gridDao.deleteGridRelation(params); + } + @Override public List listGridRelationByRelationId(String relationId) throws SearchException { Map params = getHashMap(2); @@ -150,21 +185,48 @@ public class GridServiceImpl extends AbstractService implements IGridService { if (relationIds == null || relationIds.size() == 0) { return new ArrayList<>(); } + // List gridDTOs = gridDao.listGridGroupByRelationIds(relationIds); List gridDTOs = gridDao.listGridByRelationIds(relationIds); if (gridDTOs.isEmpty()) { return gridDTOs; } + // 聚合后的网格 + List gridGroupDTOs = listGridGroup(gridDTOs); + // 只能展示包含关联人员列表的网格,比如:查询AB,那么可以展示的应该是AB...而不能是A + for (int i = 0; i < gridGroupDTOs.size(); i++) { + GridDTO gridDTO = gridGroupDTOs.get(i); + // 关联人数多于片区人数,排除 + if (relationIds.size() > gridDTO.getRelationIdArray().size()) { + gridGroupDTOs.remove(i); + i--; + continue; + } + // 判断关联人是否全部被片区包含 + boolean isAllExist = true; + for (String relationId : relationIds) { + if (!gridDTO.getRelationId().contains(relationId)) { + isAllExist = false; + break; + } + } + // 不是全部包含,就删除 + if (!isAllExist) { + gridGroupDTOs.remove(i); + i--; + continue; + } + } List gridIds = new ArrayList<>(); - for (GridDTO gridDTO : gridDTOs) { + for (GridDTO gridDTO : gridGroupDTOs) { gridIds.add(gridDTO.getGridId()); } // 获取所有点 List gridPointDTOs = gridDao.listPointByGridIds(gridIds); if (gridPointDTOs.isEmpty()) { - return gridDTOs; + return gridGroupDTOs; } // 构建所有点 - for (GridDTO gridDTO : gridDTOs) { + for (GridDTO gridDTO : gridGroupDTOs) { List pointArray = new ArrayList<>(); for (GridPointDTO gridPointDTO : gridPointDTOs) { if (StringUtils.equals(gridDTO.getGridId(), gridPointDTO.getGridId())) { @@ -173,7 +235,48 @@ public class GridServiceImpl extends AbstractService implements IGridService { } gridDTO.setPointArray(pointArray); } - return gridDTOs; + return gridGroupDTOs; + } + + /** + * 得到聚合后的列表 + * + * @param gridDTOs + * @return + */ + private List listGridGroup(List gridDTOs) { + Map gridMap = new HashMap<>(16); + for (GridDTO gridDTO : gridDTOs) { + GridDTO grid = gridMap.get(gridDTO.getGridId()); + if (grid == null) { + grid = gridDTO; + List getRelationIdArray = new ArrayList<>(); + getRelationIdArray.add(gridDTO.getRelationId()); + gridDTO.setRelationIdArray(getRelationIdArray); + gridMap.put(gridDTO.getGridId(), gridDTO); + } + // 合并relationId + grid.getRelationIdArray().add(gridDTO.getRelationId()); + } + List gridGroups = new ArrayList<>(); + for (Map.Entry kv : gridMap.entrySet()) { + GridDTO gridDTO = kv.getValue(); + Collections.sort(gridDTO.getRelationIdArray()); + gridDTO.setRelationId(gridDTO.getRelationIdArray().toString()); + gridGroups.add(gridDTO); + } + return gridGroups; + } + + @Override + public SuccessResultList> listPageGridByRelationIds(ListPage page, List relationIds) { + if (relationIds == null || relationIds.size() == 0) { + return new SuccessResultList<>(new ArrayList<>(), 1, 0L); + } + PageHelper.startPage(page.getPage(), page.getRows()); + List gridDTOs = gridDao.listGridByRelationIds(relationIds); + PageInfo pageInfo = new PageInfo<>(gridDTOs); + return new SuccessResultList<>(gridDTOs, pageInfo.getPageNum(), pageInfo.getTotal()); } /** diff --git a/cloud-common-plugin-map/src/main/resources/mybatis/mapper/grid-mapper.xml b/cloud-common-plugin-map/src/main/resources/mybatis/mapper/grid-mapper.xml index 103c14c..bcdbda0 100644 --- a/cloud-common-plugin-map/src/main/resources/mybatis/mapper/grid-mapper.xml +++ b/cloud-common-plugin-map/src/main/resources/mybatis/mapper/grid-mapper.xml @@ -92,19 +92,22 @@ DELETE FROM map_grid_relation - WHERE + grid_id = #{gridId} + AND grid_id IN #{gridIds[${index}]} + AND relation_id = #{relationId} + @@ -193,6 +196,30 @@ + +