diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java index c29d0cb69d..563365d414 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java @@ -290,7 +290,14 @@ public interface IcResiUserService extends BaseService { */ List listHomeUserBrief(String houseId, String customerId); - List> dynamicQuery(String loginUserCustomerId, String formCode, String icResiUser, List showSqlColumns, List conditions, String agencyId, String finalStaffOrgPath); + List> dynamicQuery(String loginUserCustomerId, + String formCode, + String icResiUser, + List showSqlColumns, + List conditions, + String agencyId, + List finalStaffOrgPath, + List gridIds); /** * 租客房东黑名单查询个人数据 diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserExportServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserExportServiceImpl.java index ec754bb2b8..49ac9c8d2a 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserExportServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserExportServiceImpl.java @@ -20,7 +20,9 @@ import com.epmet.commons.tools.enums.FormItemTypeEnum; import com.epmet.commons.tools.enums.IcFormCodeEnum; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.redis.common.CustomerOrgRedis; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; +import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.*; import com.epmet.commons.tools.utils.poi.excel.handler.ExcelFillCellMergeStrategy; @@ -159,14 +161,49 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { writeSheet = EasyExcel.writerSheet("Sheet1").head(exportConfigData.getHeaders()).build(); } - String staffOrgPath = null; - if (StringUtils.isNotBlank(staffInfoCacheResult.getAgencyPIds()) && !NumConstant.ZERO_STR.equals(staffInfoCacheResult.getAgencyPIds())) { - staffOrgPath = staffInfoCacheResult.getAgencyPIds().concat(StrConstant.COLON).concat(staffInfoCacheResult.getAgencyId()); + allShowColumns.addAll(exportConfigData.getHiddenSqlColumns()); + + // 组织和网格单独处理 + Set queryAgencyIdList = new HashSet<>(); + Set queryGridIdList = new HashSet<>(); + + // 将以下几列单独提出来,组合起来,放入集合,自动去重 + searchForm.getConditions().stream().forEach(c -> { + if (IcResiUserConstant.IC_RESI_USER.equals(c.getTableName()) && CollectionUtils.isNotEmpty(c.getColumnValue()) + && StringUtils.isNotBlank(c.getColumnValue().get(NumConstant.ZERO))) { + if ("AGENCY_IDS".equals(c.getColumnName())) { + queryAgencyIdList.addAll(c.getColumnValue()); + } else if ("GRID_IDS".equals(c.getColumnName())) { + queryGridIdList.addAll(c.getColumnValue()); + } else if ("AGENCY_ID".equals(c.getColumnName())) { + queryAgencyIdList.addAll(c.getColumnValue()); + } else if ("GRID_ID".equals(c.getColumnName())) { + queryGridIdList.addAll(c.getColumnValue()); + } + } + }); + + // 移除grid grids agencyId agencyIds四种字段,改为 + searchForm.getConditions().removeIf(o->IcResiUserConstant.IC_RESI_USER.equals(o.getTableName()) && IcResiUserServiceImpl.ORG_FIELDS.contains(o.getColumnName())); + + //添加数据权限 + List staffOrgPaths; + //如果查询条件中 没有有居民表的agencyId,则查询该工作人员所属组织的信息 + if (queryAgencyIdList.isEmpty() && queryGridIdList.isEmpty()){ + String staffOrgPath = PidUtils.convertPid2OrgIdPath(staffInfoCacheResult.getAgencyId(), staffInfoCacheResult.getAgencyPIds()); + staffOrgPaths = Arrays.asList(staffOrgPath); } else { - staffOrgPath = staffInfoCacheResult.getAgencyId(); + // 将组织id列表,转化为组织orgIdPath列表 + staffOrgPaths = queryAgencyIdList.stream().map(agId -> { + AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(agId); + if (agencyInfo == null) { + String errorMsg = "查询机关单位失败:" + agId; + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), errorMsg, errorMsg); + } + return PidUtils.convertPid2OrgIdPath(agId, agencyInfo.getPids()); + }).collect(Collectors.toList()); } - allShowColumns.addAll(exportConfigData.getHiddenSqlColumns()); do { if(StringUtils.isNotBlank(exportResiUserFormDTO.getId())){ ResiUserQueryValueDTO idCondition=new ResiUserQueryValueDTO(); @@ -183,9 +220,17 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { searchForm.setConditions(conditions); } } - String finalStaffOrgPath = staffOrgPath; + List finalStaffOrgPath = staffOrgPaths; + List finalGridIds = new ArrayList<>(queryGridIdList); mapListPage = PageHelper.startPage(searchForm.getPageNo(), searchForm.getPageSize(), searchForm.getIsPage()).doSelectPage(() -> { - icResiUserService.dynamicQuery(searchForm.getCustomerId(), searchForm.getFormCode(), IcResiUserConstant.IC_RESI_USER, allShowColumns, searchForm.getConditions(), staffInfoCacheResult.getAgencyId(), finalStaffOrgPath); + icResiUserService.dynamicQuery(searchForm.getCustomerId(), + searchForm.getFormCode(), + IcResiUserConstant.IC_RESI_USER, + allShowColumns, + searchForm.getConditions(), + staffInfoCacheResult.getAgencyId(), + finalStaffOrgPath, + finalGridIds); }); if (!searchForm.getIsPage()){ searchForm.setPageNo(searchForm.getPageNo() + NumConstant.ONE); diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java index c4148c3d6b..c49ecc7554 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java @@ -2238,12 +2238,19 @@ public class IcResiUserServiceImpl extends BaseServiceImpl> dynamicQuery(String customerId, String formCode, String resultTableName, List showSqlColumns, List conditions, String currentStaffAgencyId, String staffOrgPath) { + public List> dynamicQuery(String customerId, + String formCode, + String resultTableName, + List showSqlColumns, + List conditions, + String currentStaffAgencyId, + List staffOrgPath, + List gridIds) { // List finalSubTables = getFinalSubables(customerId, formCode, resultTableName, conditions); List exportNeedTableList = showSqlColumns.stream().map(IcCustomExportResultDTO.SqlColumn::getTableName).collect(Collectors.toList()); Map> map = getFinalSubables(customerId, formCode, resultTableName, conditions, exportNeedTableList); return baseDao.dynamicQuery(customerId, resultTableName, conditions, map.get("finalSubTables"), showSqlColumns, - currentStaffAgencyId, Arrays.asList(staffOrgPath), null, map.get("groupByTables")); + currentStaffAgencyId, staffOrgPath, gridIds, map.get("groupByTables")); } @Override