diff --git a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/dao/PoliceDao.java b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/dao/PoliceDao.java index bec70a7..982980e 100644 --- a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/dao/PoliceDao.java +++ b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/dao/PoliceDao.java @@ -66,7 +66,7 @@ public interface PoliceDao extends BaseDao { * @author zhangyuan * @since 2020/5/21 14:54 */ - List selectPoliceInfo(PoliceEntity entity); + List selectPoliceInfo(PoliceFormDTO dto); /** * 查询需要修改组织机构信息事件 diff --git a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/service/impl/PoliceServiceImpl.java b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/service/impl/PoliceServiceImpl.java index c6658be..56d385c 100644 --- a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/service/impl/PoliceServiceImpl.java +++ b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/service/impl/PoliceServiceImpl.java @@ -17,7 +17,6 @@ package com.elink.esua.epdc.modules.police.service.impl; -import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; @@ -116,14 +115,6 @@ public class PoliceServiceImpl extends BaseServiceImpl return ConvertUtils.sourceToTarget(entity, PoliceDTO.class); } - private List getChildDeptList(String tyepKey, Long deptId) { - Result> adminResult = adminFeignClient.listChildDeptLevelById(tyepKey, deptId); - if (!adminResult.success()) { - throw new RenException(adminResult.getMsg()); - } - return adminResult.getData(); - } - /** * 社区是否已有民警 * @@ -132,69 +123,44 @@ public class PoliceServiceImpl extends BaseServiceImpl * @author work@yujt.net.cn * @date 2020/5/22 16:56 */ - private boolean hasPolice(Long deptId) { - QueryWrapper wrapper = new QueryWrapper<>(); + private boolean hasGroup(Long deptId) { + QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("DEPT_ID", deptId); - return baseDao.selectCount(wrapper) > NumConstant.ZERO; - } - - /** - * 查询社区下未创建警民群的网格 - * - * @param deptList 社区下所有的网格 - * @param communityId 社区id - * @return java.util.List - * @author work@yujt.net.cn - * @date 2020/5/22 16:55 - */ - private List getDeptListWithoutGroup(List deptList, Long communityId) { - // 查询社区下已创建群组的网格 - List hasGroupList = groupDao.selectListOfGroupByDeptId(String.valueOf(communityId)); - if (CollUtil.isNotEmpty(hasGroupList)) { - for (int i = deptList.size() - 1; i >= 0; i--) { - for (DeptLevelAndLeaderDTO dto : hasGroupList) { - if (deptList.get(i).getDeptId().equals(dto.getDeptId())) { - deptList.remove(i); - break; - } - } - } - } - return deptList; + wrapper.eq("CATEGORY_CODE", GroupConstant.POLICE_GROUP_CATEGORY_CODE); + List list = new ArrayList<>(); + // 10正常,15禁言 + list.add(NumConstant.TEN); + list.add(NumConstant.FIFTEEN); + wrapper.in("STATE", list); + return groupDao.selectCount(wrapper) > NumConstant.ZERO; } @Override @Transactional(rollbackFor = Exception.class) public Result save(PoliceDTO dto) { Long communityId = dto.getDeptId(); - boolean hasPolice = hasPolice(communityId); + + DeptLevelAndLeaderDTO deptLevelAndLeaderDTO = getDeptlevelById(dto.getDeptId()); + + if (!GroupConstant.POLICE_GROUP_TYPE.equals(deptLevelAndLeaderDTO.getTypeKey())) { + throw new RenException("请选择社区机构"); + } + + boolean hasPolice = hasGroup(communityId); // 社区第一次添加民警,直接保存 PoliceEntity entity = ConvertUtils.sourceToTarget(dto, PoliceEntity.class); - ParentAndAllDeptDTO parentAndAllDeptDTO = getParentAndAllDeptDTO(String.valueOf(communityId)); DeptEntityUtils.loadDeptInfo( - ConvertUtils.sourceToTarget(parentAndAllDeptDTO, DeptEntityUtils.DeptDto.class), + ConvertUtils.sourceToTarget(deptLevelAndLeaderDTO, DeptEntityUtils.DeptDto.class), entity ); - entity.setDeptName(parentAndAllDeptDTO.getGrid()); + entity.setDeptName(deptLevelAndLeaderDTO.getDeptName()); insert(entity); - // 如果社区之前没有民警,就初始化所有的网格,增加警民群,有的话不再补充,等待补充操作。 + // 如果社区之前没有民警,就初始化所有的网格,增加警民群,有的话不再补充,等待补充操作。7.3改为初始化社区 if (!hasPolice) { - // 先查询该社区下所有网格 - List deptList = getChildDeptList(OrganizationTypeConstant.ORG_TYPE_GRID_PARTY, entity.getDeptId()); - if (CollUtil.isEmpty(deptList)) { - return new Result(); - } - // 未创建社区的网格 - List withoutGroupDeptList = getDeptListWithoutGroup(deptList, communityId); - if (CollUtil.isNotEmpty(withoutGroupDeptList)) { - withoutGroupDeptList.forEach( - deptForGroup -> { - createGroup(entity.getId(), deptForGroup.getDeptId(), deptForGroup.getDeptName()); - } - ); - } + // 警民群改为和社区ID绑定,首次创建民警时只需要创建一个群 + createGroup(entity.getId(), deptLevelAndLeaderDTO.getDeptId(), deptLevelAndLeaderDTO.getDeptName()); } return new Result(); } @@ -238,16 +204,14 @@ public class PoliceServiceImpl extends BaseServiceImpl @Override public PoliceResultDTO getPoliceAndGroup(PoliceFormDTO dto) { + // 根据用户网格,获取用户所在社区 + ParentAndAllDeptDTO parentAndAllDeptDTO = getParentAndAllDeptDTO(String.valueOf(dto.getGridId())); + dto.setParentDeptIds(parentAndAllDeptDTO.getParentDeptIds()); + PoliceResultDTO policeResultDTO = baseDao.selectPoliceGroupInfo(dto); if (policeResultDTO != null) { - PoliceEntity entity = ConvertUtils.sourceToTarget(dto, PoliceEntity.class); - ParentAndAllDeptDTO parentAndAllDeptDTO = getParentAndAllDeptDTO(String.valueOf(dto.getGridId())); - DeptEntityUtils.loadDeptInfo( - ConvertUtils.sourceToTarget(parentAndAllDeptDTO, DeptEntityUtils.DeptDto.class), - entity - ); - // 查询民警使用的gridID是最末级,而警民群保存的是其父级gridID,需要用最末级的parentID,来匹配警民群的AllID。 - policeResultDTO.setPoliceList(baseDao.selectPoliceInfo(entity)); + // 查询民警使用的gridID是最末级,而警民群保存的是其父级commID,需要用grid的parentIDs,来匹配警民群的AllIDs。 + policeResultDTO.setPoliceList(baseDao.selectPoliceInfo(dto)); } return policeResultDTO; } @@ -392,4 +356,23 @@ public class PoliceServiceImpl extends BaseServiceImpl groupEntity.setDeptId(gridId); groupDao.insert(groupEntity); } + + /** + * 根据网格ID获取冗余的组织机构信息 + * + * @param + * @return com.elink.esua.epdc.dto.ParentAndAllDeptDTO + * @author rongchao + * @since 2019-12-19 + */ + private DeptLevelAndLeaderDTO getDeptlevelById(Long gridId) { + // 获取组织结构冗余信息 + Result parentAndAllDeptDTOResult = adminFeignClient.getDeptlevelById(gridId); + DeptLevelAndLeaderDTO parentAndAllDeptDTO = parentAndAllDeptDTOResult.getData(); + + if (!parentAndAllDeptDTOResult.success()) { + throw new RenException(parentAndAllDeptDTOResult.getMsg()); + } + return parentAndAllDeptDTO; + } } \ No newline at end of file diff --git a/epdc-cloud-property/src/main/resources/mapper/group/GroupDao.xml b/epdc-cloud-property/src/main/resources/mapper/group/GroupDao.xml index 1fce3a0..9b4fd40 100644 --- a/epdc-cloud-property/src/main/resources/mapper/group/GroupDao.xml +++ b/epdc-cloud-property/src/main/resources/mapper/group/GroupDao.xml @@ -59,7 +59,7 @@ gp.DEL_FLAG = '0' AND gp.SECTION_CODE = 'theme_group' AND gp.CATEGORY_CODE = 'police_group' - AND gp.TYPE_KEY = 'grid_party' + AND gp.TYPE_KEY = 'community_party' AND gp.STATE = #{state} @@ -309,7 +309,7 @@ ORDER BY DEL_FLAG = '0' AND SECTION_CODE = 'theme_group' AND CATEGORY_CODE = 'police_group' - AND TYPE_KEY = 'grid_party' + AND TYPE_KEY = 'community_party' AND STATE IN ( 10, 15, 20 ) AND DEPT_ID = #{deptId} @@ -324,7 +324,7 @@ ORDER BY DEL_FLAG = '0' AND SECTION_CODE = 'theme_group' AND CATEGORY_CODE = 'police_group' - AND TYPE_KEY = 'grid_party' + AND TYPE_KEY = 'community_party' AND STATE IN ( 10, 15 ) AND PARENT_DEPT_IDS LIKE CONCAT( '%', #{deptId} ) diff --git a/epdc-cloud-property/src/main/resources/mapper/police/PoliceDao.xml b/epdc-cloud-property/src/main/resources/mapper/police/PoliceDao.xml index 77392a8..4f70131 100644 --- a/epdc-cloud-property/src/main/resources/mapper/police/PoliceDao.xml +++ b/epdc-cloud-property/src/main/resources/mapper/police/PoliceDao.xml @@ -64,12 +64,9 @@ eg.DEL_FLAG = '0' AND eg.SECTION_CODE = 'theme_group' AND eg.CATEGORY_CODE = 'police_group' - AND eg.TYPE_KEY = 'grid_party' + AND eg.TYPE_KEY = 'community_party' AND ( eg.STATE = '10' OR eg.STATE = '15' ) - - AND (eg.DEPT_ID = #{gridId} - OR find_in_set(#{gridId},eg.ALL_DEPT_IDS)) - + AND eg.ALL_DEPT_IDS = #{parentDeptIds} GROUP BY eg.ID @@ -115,6 +112,6 @@ FIND_IN_SET( #{deptId}, ALL_DEPT_IDS ) AND SECTION_CODE = 'theme_group' AND CATEGORY_CODE = 'police_group' - AND TYPE_KEY = 'grid_party' + AND TYPE_KEY = 'community_party' \ No newline at end of file