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 f82ea58..a49e2bc 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 @@ -48,6 +48,7 @@ import javax.annotation.Resource; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Optional; import static java.util.stream.Collectors.toList; @@ -156,6 +157,7 @@ public class PoliceServiceImpl extends BaseServiceImpl public void delete(String[] ids) { // 逻辑删除(@TableLogic 注解) baseDao.deleteBatchIds(Arrays.asList(ids)); + groupDao.deleteGroupByProjectIds(Arrays.asList(ids)); } @Override @@ -165,30 +167,37 @@ public class PoliceServiceImpl extends BaseServiceImpl for (PoliceDTO dto : ids) { // 社区ID下有多少个网格信息 List deptList = adminFeignClient.listChildDeptLevelById(OrganizationTypeConstant.ORG_TYPE_GRID_PARTY, dto.getDeptId()).getData(); + List deptIdList = deptList.stream().map(DeptLevelAndLeaderDTO::getDeptId).collect(toList()); // 现有的群的网格信息 List existedDeptList = groupDao.selectListOfGroupByDeptId(dto.getDeptId() + ""); + List existedDeptIdList = existedDeptList.stream().map(DeptLevelAndLeaderDTO::getDeptId).collect(toList()); // 求差集,即为还没有创建过群的网格ID - List reduce = deptList.stream().filter(item -> !existedDeptList.contains(item)).collect(toList()); + List reduce = deptIdList.stream().filter(item -> !existedDeptIdList.contains(item)).collect(toList()); // 补建群 - reduce.forEach(dept -> { - ParentAndAllDeptDTO parentAndAllDeptDTOChild = getParentAndAllDeptDTO(dept.getDeptId() + ""); - GroupEntity groupEntity = new GroupEntity(); - DeptEntityUtils.loadDeptInfo( - ConvertUtils.sourceToTarget(parentAndAllDeptDTOChild, DeptEntityUtils.DeptDto.class), - groupEntity - ); - groupEntity.setReferenceBusinessId(dto.getId()); - groupEntity.setState(GroupStateEnum.GROUP_STATE_EXAMINATION_PASSED.getValue()); - groupEntity.setGroupAvatar(GroupConstant.PROPERTY_GROUP_AVATAR); - groupEntity.setGroupName(dto.getDeptName() + "警民群"); - groupEntity.setGroupCategory(GroupConstant.POLICE_GROUP_CATEGORY); - groupEntity.setGrid(dept.getDeptName()); - groupEntity.setGridId(dept.getDeptId()); - groupDao.insert(groupEntity); + reduce.forEach(deptId -> { + // 通过deptID反向找出该网格信息 + Optional deptOptional = deptList.stream().filter(item -> item.getDeptId().equals(deptId)).findFirst(); + if (deptOptional.isPresent()) { + // 存在 + DeptLevelAndLeaderDTO dept = deptOptional.get(); + ParentAndAllDeptDTO parentAndAllDeptDTOChild = getParentAndAllDeptDTO(dept.getDeptId() + ""); + GroupEntity groupEntity = new GroupEntity(); + DeptEntityUtils.loadDeptInfo( + ConvertUtils.sourceToTarget(parentAndAllDeptDTOChild, DeptEntityUtils.DeptDto.class), + groupEntity + ); + groupEntity.setReferenceBusinessId(dto.getId()); + groupEntity.setState(GroupStateEnum.GROUP_STATE_EXAMINATION_PASSED.getValue()); + groupEntity.setGroupAvatar(GroupConstant.PROPERTY_GROUP_AVATAR); + groupEntity.setGroupName(dept.getDeptName() + "警民群"); + groupEntity.setGroupCategory(GroupConstant.POLICE_GROUP_CATEGORY); + groupEntity.setGrid(dept.getDeptName()); + groupEntity.setGridId(dept.getDeptId()); + groupDao.insert(groupEntity); + } }); } - baseDao.deleteBatchIds(Arrays.asList(ids)); } /**