Browse Source

人房统计加载优化

master
lichao 2 years ago
parent
commit
09d0b20e66
  1. 12
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  2. 46
      epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/HouseStatisticsTask.java
  3. 58
      epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/ResiHouseStatisticsTask.java
  4. 38
      epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/ResiStatisticsTask.java
  5. 20
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/feign/GovOrgOpenFeignClient.java
  6. 10
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/feign/fallback/GovOrgOpenFeignClientFallback.java
  7. 38
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java
  8. 7
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java
  9. 252
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java
  10. 9
      epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java
  11. 6
      epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java
  12. 11
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java
  13. 2
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java
  14. 59
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java

12
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java

@ -1088,4 +1088,16 @@ public class RedisKeys {
public static String getHousechart(String orgType,String agencyId) {
return rootPrefix.concat("govorg:house:housechart:".concat(orgType).concat(StrConstant.COLON).concat(agencyId));
}
/**
* @Description: 获取人房数据统计 区域列表
* @param agencyId:
* @Return java.lang.String
* @Author: lichao
* @Date: 2023/11/1 13:58
*/
public static String getSubUserHouseList(String orgType,String agencyId) {
return rootPrefix.concat("govorg:house:subUserHouseList:".concat(orgType).concat(StrConstant.COLON).concat(agencyId));
}
}

46
epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/HouseStatisticsTask.java

@ -0,0 +1,46 @@
package com.epmet.task;
import com.epmet.commons.tools.utils.Result;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.GovOrgOpenFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Description: 房屋统计 定时任务 每天凌晨运行一遍
* @Return
* @Author: lichao
* @Date: 2023/11/01 13:47
*/
@Slf4j
@Component("houseStatisticsTask")
public class HouseStatisticsTask implements ITask {
@Autowired
private GovOrgOpenFeignClient govOrgOpenFeignClient;
@Override
public void run(String params) {
// houseChartRedis
Result houseChartRedis = govOrgOpenFeignClient.houseChartRedis();
if (houseChartRedis.success()) {
log.info("houseChartRedis定时任务执行成功");
} else {
log.error("houseChartRedis定时任务执行失败:" + houseChartRedis.getMsg());
}
// houseChartRedis
Result subUserHouseListRedis = govOrgOpenFeignClient.subUserHouseListRedis();
if (subUserHouseListRedis.success()) {
log.info("subUserHouseListRedis定时任务执行成功");
} else {
log.error("subUserHouseListRedis定时任务执行失败:" + subUserHouseListRedis.getMsg());
}
}
}

58
epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/ResiHouseStatisticsTask.java

@ -0,0 +1,58 @@
package com.epmet.task;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.DataSyncTaskParam;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.GovOrgOpenFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Description: 居民房屋统计 定时任务 每天凌晨运行一遍
* @Return
* @Author: lichao
* @Date: 2023/11/01 13:47
*/
@Slf4j
@Component("resiHouseStatisticsTask")
public class ResiHouseStatisticsTask implements ITask {
@Autowired
private EpmetUserOpenFeignClient userOpenFeignClient;
@Autowired
private GovOrgOpenFeignClient govOrgOpenFeignClient;
@Override
public void run(String params) {
// userChartRedis
Result userChartRedis = userOpenFeignClient.userChartRedis();
if (userChartRedis.success()) {
log.info("userChartRedis定时任务执行成功");
} else {
log.error("userChartRedis定时任务执行失败:" + userChartRedis.getMsg());
}
// houseChartRedis
Result houseChartRedis = govOrgOpenFeignClient.houseChartRedis();
if (houseChartRedis.success()) {
log.info("houseChartRedis定时任务执行成功");
} else {
log.error("houseChartRedis定时任务执行失败:" + houseChartRedis.getMsg());
}
// houseChartRedis
Result subUserHouseListRedis = govOrgOpenFeignClient.subUserHouseListRedis();
if (subUserHouseListRedis.success()) {
log.info("subUserHouseListRedis定时任务执行成功");
} else {
log.error("subUserHouseListRedis定时任务执行失败:" + subUserHouseListRedis.getMsg());
}
}
}

38
epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/ResiStatisticsTask.java

@ -0,0 +1,38 @@
package com.epmet.task;
import com.epmet.commons.tools.utils.Result;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.GovOrgOpenFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Description: 居民统计 定时任务 每天凌晨运行一遍
* @Return
* @Author: lichao
* @Date: 2023/11/01 13:47
*/
@Slf4j
@Component("resiStatisticsTask")
public class ResiStatisticsTask implements ITask {
@Autowired
private EpmetUserOpenFeignClient userOpenFeignClient;
@Override
public void run(String params) {
// userChartRedis
Result userChartRedis = userOpenFeignClient.userChartRedis();
if (userChartRedis.success()) {
log.info("userChartRedis定时任务执行成功");
} else {
log.error("userChartRedis定时任务执行失败:" + userChartRedis.getMsg());
}
}
}

20
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/feign/GovOrgOpenFeignClient.java

@ -765,4 +765,24 @@ public interface GovOrgOpenFeignClient {
*/
@PostMapping("/gov/org/agency/getAllCommunity/{customerId}")
Result<List<AgencyResultDTO>> getAllCommunity(@PathVariable(value = "customerId") String customerId);
/**
* 人房居民总数饼图 缓存处理
* @return
* @V23
*/
@PostMapping("/gov/org/house/housechartRedis")
Result houseChartRedis();
/**
* 人房下级人房概览列表Redis
* @return
* @V23
*/
@PostMapping("/gov/org/house/subuserhouselistRedis")
Result subUserHouseListRedis();
}

10
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/feign/fallback/GovOrgOpenFeignClientFallback.java

@ -484,4 +484,14 @@ public class GovOrgOpenFeignClientFallback implements GovOrgOpenFeignClient {
public Result<List<AgencyResultDTO>> getAllCommunity(String customerId) {
return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getAllCommunity", customerId);
}
@Override
public Result houseChartRedis() {
return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "houseChartRedis", "");
}
@Override
public Result subUserHouseListRedis() {
return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "subUserHouseListRedis", "");
}
}

38
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java

@ -390,6 +390,16 @@ public class HouseController implements ResultDataResolver {
return new Result<HouseChartResultDTO>().ok(houseService.houseChart(formDTO));
}
/**
* @Author lichao
* @Description 人房房屋总数饼图 redis
**/
@PostMapping("housechartRedis")
public Result houseChartRedis() {
return new Result<>().ok(houseService.houseChartRedis());
}
/**
* @Author sun
* @Description 人房下级人房概览列表
@ -401,6 +411,16 @@ public class HouseController implements ResultDataResolver {
return new Result<List<SubUserHouseListResultDTO>>().ok(houseService.subUserHouseList(formDTO));
}
/**
* @Author sun
* @Description 人房下级人房概览列表Redis
**/
@PostMapping("subuserhouselistRedis")
public Result subUserHouseListRedis() {
return new Result<>().ok(houseService.subUserHouseListRedis());
}
/**
* Desc: 根据类型更新排序
*
@ -692,6 +712,24 @@ public class HouseController implements ResultDataResolver {
return new Result<PageData<SubUserHouseListResultDTO>>().ok(r);
}
/**
* 针对社区的人房统计列表 筛选版
* @return
*/
@PostMapping("usingCommunityUserHouseStatsMust")
public Result<PageData<SubUserHouseListResultDTO>> communityUserHouseStatsMust(@RequestBody CommunityUserHouseStatsFormDTO input) {
String orgId = input.getOrgId();
String orgType = input.getOrgType();
Integer pageNo = input.getPageNo();
Integer pageSize = input.getPageSize();
PageData<SubUserHouseListResultDTO> r = houseService.usingCommunityUserHouseStatsMust(orgId, orgType, pageNo, pageSize);
return new Result<PageData<SubUserHouseListResultDTO>>().ok(r);
}
/**
* 群租房列表来源于烟台需求
* @param tokenDto

7
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java

@ -207,6 +207,9 @@ public interface HouseService {
PageData<SubUserHouseListResultDTO> usingCommunityUserHouseStats(String orgId, String orgType, Integer pageNo, Integer pageSize);
PageData<SubUserHouseListResultDTO> usingCommunityUserHouseStatsMust(String orgId, String orgType, Integer pageNo, Integer pageSize);
/**
* 群租房列表来源于烟台需求
* @param formDTO
@ -215,4 +218,8 @@ public interface HouseService {
PageData<GroupRentHouseResultDTO> groupRentHouseList(GroupRentHouseFormDTO formDTO);
PageData<HouseLangchaoListResultDTO> houseListForLangchao(HouseListLangchaoFormDTO formDTO);
boolean houseChartRedis();
boolean subUserHouseListRedis();
}

252
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java

@ -813,7 +813,7 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
resultDTO.setXzHouseTotalJSY(resultDTO.getXzHouseTotal() - lastMonthUserHouseStats.getXzHouseTotal());
resultDTO.setZzHouseTotalJSY(resultDTO.getZzHouseTotal() - lastMonthUserHouseStats.getZzHouseTotal());*/
// 24小时过期
// 24小时过期 redis LC 新增24小时失效的
redisTemplate.opsForValue().set(RedisKeys.getHousechart(formDTO.getOrgType(),formDTO.getOrgId()), resultDTO, RedisUtils.DEFAULT_EXPIRE, TimeUnit.SECONDS);
return resultDTO;
@ -839,6 +839,13 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
if ("village".equals(formDTO.getOrgType())) {
return new ArrayList<>();
}
// redis 加缓存 LC 24小时失效
if (redisTemplate.opsForValue().get(RedisKeys.getSubUserHouseList(formDTO.getOrgType(),formDTO.getOrgId()))!=null){
return (List<SubUserHouseListResultDTO>)redisTemplate.opsForValue().get(RedisKeys.getSubUserHouseList(formDTO.getOrgType(),formDTO.getOrgId()));
}
//2.根据入参值查询直属下级列表(组织、网格、小区列表)
List<String> idList = new ArrayList<>();
Map<String, String> map = new HashMap<>();
@ -873,6 +880,9 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
//3.分别查询直属下级列表的房屋、居民统计数据
resultList = houseUserChartList(idList, map, orgType);
// redis 加缓存 LC 24小时失效
redisTemplate.opsForValue().set(RedisKeys.getSubUserHouseList(formDTO.getOrgType(),formDTO.getOrgId()), resultList, RedisUtils.DEFAULT_EXPIRE, TimeUnit.SECONDS);
return resultList;
}
@ -1108,6 +1118,100 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
}
private List<SubUserHouseListResultDTO> houseUserChartListMust(List<String> idList, Map<String, String> map, String orgType) {
List<SubUserHouseListResultDTO> list = new ArrayList<>();
//1.直属下级列表的房屋数据
List<HouseChartResultDTO> houseList = new ArrayList<>();
HouseChartFormDTO houseDTO = new HouseChartFormDTO();
houseDTO.setOrgType(orgType);
for (String id : idList) {
houseDTO.setOrgId(id);
houseList.add(houseChart(houseDTO));
}
//start 2022.11.17需求:http://zentao.elinkservice.cn/story-view-718.html
//原来饼图是:居民总数、常住人口数、流动人口数 后改为下面的人户状况饼图,后面如果所有客户都上线了,就把第2步的查询注释掉。
//2.直属下级列表的居民数据
UserChartFormDTO userDTO = new UserChartFormDTO();
userDTO.setOrgType(orgType);
userDTO.setIdList(idList);
Result<List<UserChartResultDTO>> userResult = epmetUserOpenFeignClient.userChartList(userDTO);
if (!userResult.success()) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取居民人房统计数据失败" + userResult.getInternalMsg(), userResult.getMsg());
}
//end
//3.汇总封装数据
SubUserHouseListResultDTO dto = null;
for (String id : idList) {
dto = new SubUserHouseListResultDTO();
dto.setOrgId(id);
dto.setOrgName(map.get(id));
dto.setOrgType(orgType);
for (HouseChartResultDTO h : houseList) {
if (h.getOrgId().equals(id)) {
// 房屋总数
dto.setHouseTotal(h.getHouseTotal());
// 自住房屋数
dto.setZzHouseTotal(h.getZzHouseTotal());
// dto.setZzHouseRatio(h.getZzHouseRatio());
// 出租房屋数
dto.setCzHouseTotal(h.getCzHouseTotal());
// dto.setCzHouseRatio(h.getCzHouseRatio());
// 闲置房屋数
dto.setXzHouseTotal(h.getXzHouseTotal());
// dto.setXzHouseRatio(h.getXzHouseRatio());
// dto.setWscHouseTotal(h.getWscHouseTotal());
// dto.setWscHouseRatio(h.getWscHouseRatio());
}
}
for (UserChartResultDTO u : userResult.getData()) {
if (u.getOrgId().equals(id)) {
// 人口总数
dto.setUserTotal(u.getUserTotal());
// 常住人口数
dto.setCzUserTotal(u.getCzUserTotal());
// dto.setCzUserRatio(u.getCzUserRatio());
// 流动人口数
dto.setLdUserTotal(u.getLdUserTotal());
// dto.setLdUserRatio(u.getLdUserRatio());
}
}
// 为每一个子级组织,查询开通了多少个社区
/* if ("agency".equals(dto.getOrgType())) {
AgencyService agencyService = SpringContextUtils.getBean(AgencyService.class);
if (agencyService != null) {
UsingCommunityStatsResultDTO usingCommunityStats = agencyService.usingCommunityStats(dto.getOrgId(), dto.getOrgType());
if (usingCommunityStats != null) {
dto.setUsingCommunityNum(usingCommunityStats.getUsingCommunityNum());
}
}
} else if ("grid".equals(dto.getOrgType())) {
// 网格这项数据为0
dto.setUsingCommunityNum(0);
}*/
/*for (RHZKStatisticsResultDTO r : rhzkResult.getData()) {
if (StringUtils.isNotBlank(r.getOrgId())){
if (r.getOrgId().equals(id)){
dto.setRhyzUserTotal(r.getRhyzUserTotal());
dto.setRhyzUserRatio(r.getRhyzUserRatio());
dto.setRzhbzUserTotal(r.getRzhbzUserTotal());
dto.setRzhbzUserRatio(r.getRzhbzUserRatio());
dto.setHzrbzUserTotal(r.getHzrbzUserTotal());
dto.setHzrbzUserRatio(r.getHzrbzUserRatio());
dto.setZbqcUserTotal(r.getZbqcUserTotal());
dto.setZbqcUserRatio(r.getZbqcUserRatio());
dto.setUserTotal(r.getUserTotal());
}
}
}*/
list.add(dto);
}
return list;
}
@Override
public void downloadZip(HttpServletResponse response, IcHouseListFormDTO formDTO) throws Exception {
if(NeighborhoodConstant.GRID.equals(formDTO.getLevel())){
@ -1537,6 +1641,37 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
return new PageData<SubUserHouseListResultDTO>(communityUserHouseStats, new PageInfo<>(communityIds).getTotal());
}
@Override
public PageData<SubUserHouseListResultDTO> usingCommunityUserHouseStatsMust(String orgId, String orgType, Integer pageNo, Integer pageSize) {
String customerId = EpmetRequestHolder.getLoginUserCustomerId();
if (StringUtils.isBlank(orgId)) {
// 没有传参数,使用当前登录人员所属的组织去查询
String userId = EpmetRequestHolder.getLoginUserId();
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(customerId, userId);
if (staffInfo == null) {
String errorMsg = String.format("查询当前工作人员信息失败。staffId:%s", userId);
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), errorMsg, errorMsg);
}
orgId = staffInfo.getAgencyId();
orgType = "agency";
}
PageHelper.startPage(pageNo, pageSize);
List<String> communityIds = customerAgencyDao.getUsingCommunityList(customerId, orgId, CustomerOrgRedis.getOrgIdPath(orgId, orgType), null);
// List<String> communityIds = customerAgencyDao.getCommunitysByOrgIdPath(customerId, orgId, CustomerOrgRedis.getOrgIdPath(orgId, orgType));
// 填充组织信息
Map<String, String> communityMap = communityIds.stream().collect(Collectors.toMap(id -> id, id -> concatAgencyNamePath(id)));
List<SubUserHouseListResultDTO> communityUserHouseStats = houseUserChartListMust(communityIds, communityMap, "agency");
return new PageData<SubUserHouseListResultDTO>(communityUserHouseStats, new PageInfo<>(communityIds).getTotal());
}
public String concatAgencyNamePath(String agencyId) {
List<String> agencyNamePathList = new ArrayList();
@ -1611,4 +1746,119 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
PageInfo<HouseLangchaoListResultDTO> pageInfo = new PageInfo<>(list);
return new PageData<>(list,pageInfo.getTotal());
}
@Override
public boolean houseChartRedis() {
List<AgencyResultDTO> agencyResultDTOS = agencyservice.getAllCommunity("1535072605621841922");
for (AgencyResultDTO agencyResultDTO : agencyResultDTOS) {
try {
HouseChartFormDTO formDTO = new HouseChartFormDTO();
formDTO.setOrgId(agencyResultDTO.getAgencyId());
formDTO.setOrgType("agency");
HouseChartResultDTO resultDTO = new HouseChartResultDTO();
//计算百分比使用,保留小数点后两位
NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMaximumFractionDigits(NumConstant.TWO);
//2.根据入参值查询对应的房屋统计数据
List<HouseChartResultDTO> list = icHouseDao.houseChart(formDTO.getOrgId(), formDTO.getOrgType());
//3.汇总数据
AtomicInteger houseTotal = new AtomicInteger();
list.forEach(l -> {
houseTotal.addAndGet(l.getNum());
if (l.getRentFlag() == 0) {
resultDTO.setZzHouseTotal(l.getNum());
} else if (l.getRentFlag() == 1) {
resultDTO.setCzHouseTotal(l.getNum());
} else if (l.getRentFlag() == 2) {
resultDTO.setXzHouseTotal(l.getNum());
} else if (l.getRentFlag() == 3) {
resultDTO.setWscHouseTotal(l.getNum());
}
});
resultDTO.setHouseTotal(houseTotal.get());
resultDTO.setZzHouseRatio(Double.valueOf((resultDTO.getHouseTotal() == 0 || resultDTO.getZzHouseTotal() > resultDTO.getHouseTotal()) ? "0" : numberFormat.format(((float) resultDTO.getZzHouseTotal() / (float) resultDTO.getHouseTotal()) * 100)));
resultDTO.setCzHouseRatio(Double.valueOf((resultDTO.getHouseTotal() == 0 || resultDTO.getCzHouseTotal() > resultDTO.getHouseTotal()) ? "0" : numberFormat.format(((float) resultDTO.getCzHouseTotal() / (float) resultDTO.getHouseTotal()) * 100)));
resultDTO.setXzHouseRatio(Double.valueOf((resultDTO.getHouseTotal() == 0 || resultDTO.getXzHouseTotal() > resultDTO.getHouseTotal()) ? "0" : numberFormat.format(((float) resultDTO.getXzHouseTotal() / (float) resultDTO.getHouseTotal()) * 100)));
resultDTO.setWscHouseRatio(Double.valueOf((resultDTO.getHouseTotal() == 0 || resultDTO.getWscHouseTotal() > resultDTO.getHouseTotal()) ? "0" : numberFormat.format(((float) resultDTO.getWscHouseTotal() / (float) resultDTO.getHouseTotal()) * 100)));
resultDTO.setOrgId(formDTO.getOrgId());
resultDTO.setOrgType(formDTO.getOrgType());
// 24小时过期 redis LC 新增24小时失效的
redisTemplate.opsForValue().set(RedisKeys.getHousechart(formDTO.getOrgType(),formDTO.getOrgId()), resultDTO, RedisUtils.DEFAULT_EXPIRE, TimeUnit.SECONDS);
}catch (Exception e){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取该组织的housechart失败"+agencyResultDTO.getAgencyId(), "获取该组织的housechart失败");
}
}
return true;
}
@Override
public boolean subUserHouseListRedis() {
List<AgencyResultDTO> agencyResultDTOS = agencyservice.getAllCommunity("1535072605621841922");
for (AgencyResultDTO agencyResultDTO : agencyResultDTOS) {
try {
List<SubUserHouseListResultDTO> resultList = new ArrayList<>();
HouseChartFormDTO formDTO = new HouseChartFormDTO();
formDTO.setOrgId(agencyResultDTO.getAgencyId());
formDTO.setOrgType("agency");
//2.根据入参值查询直属下级列表(组织、网格、小区列表)
List<String> idList = new ArrayList<>();
Map<String, String> map = new HashMap<>();
String orgType = "";
if ("agency".equals(formDTO.getOrgType())) {
//获取组织缓存,判断组织级别
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(formDTO.getOrgId());
if (null == agencyInfo) {
throw new RenException(String.format("查询组织信息失败%s", formDTO.getOrgId()));
}
//直属下级网格列表
if ("community".equals(agencyInfo.getLevel())) {
orgType = "grid";
List<GridListResultDTO> list = customerGridDao.selectGridList(formDTO.getOrgId());
idList = list.stream().map(GridListResultDTO::getGridId).collect(Collectors.toList());
map = list.stream().collect(Collectors.toMap(GridListResultDTO::getGridId, GridListResultDTO::getGridName, (k1, k2) -> k1));
} else {
//直属下级组织列表
orgType = "agency";
List<AgencyListResultDTO> list = customerAgencyDao.selectAgencyList(formDTO.getOrgId());
idList = list.stream().map(AgencyListResultDTO::getAgencyId).collect(Collectors.toList());
map = list.stream().collect(Collectors.toMap(AgencyListResultDTO::getAgencyId, AgencyListResultDTO::getAgencyName, (k1, k2) -> k1));
}
} else if ("grid".equals(formDTO.getOrgType())) {
//网格直属小区列表
orgType = "village";
List<IcNeighborHoodDTO> list = icNeighborHoodDao.selectNeighborList(formDTO.getOrgId());
idList = list.stream().map(IcNeighborHoodDTO::getId).collect(Collectors.toList());
map = list.stream().collect(Collectors.toMap(IcNeighborHoodDTO::getId, IcNeighborHoodDTO::getNeighborHoodName, (k1, k2) -> k1));
}
//3.分别查询直属下级列表的房屋、居民统计数据
resultList = houseUserChartList(idList, map, orgType);
// redis 加缓存 LC 24小时失效
redisTemplate.opsForValue().set(RedisKeys.getSubUserHouseList(formDTO.getOrgType(),formDTO.getOrgId()), resultList, RedisUtils.DEFAULT_EXPIRE, TimeUnit.SECONDS);
}catch (Exception e){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取该组织的subUserHouseListRedis失败"+agencyResultDTO.getAgencyId(), "获取该组织的subUserHouseListRedis失败");
}
}
return true;
}
}

9
epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java

@ -1051,4 +1051,13 @@ public interface EpmetUserOpenFeignClient {
*/
@PostMapping("/epmetuser/registerrelation/pageQueryRegisterUser")
Result<PageData<RegisterRelationDTO>> pageQueryRegisterUser(@RequestBody RegisterRelationPageFormDTO pageFormDTO);
/**
* 人房居民总数饼图 缓存处理
* @return
* @V23
*/
@PostMapping("/epmetuser/icresiuser/userchartRedis")
Result userChartRedis();
}

6
epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java

@ -782,4 +782,10 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien
public Result<PageData<RegisterRelationDTO>> pageQueryRegisterUser(RegisterRelationPageFormDTO pageFormDTO) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "pageQueryRegisterUser", pageFormDTO);
}
@Override
public Result userChartRedis() {
return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "userChartRedis", "");
}
}

11
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java

@ -1205,6 +1205,17 @@ public class IcResiUserController implements ResultDataResolver {
return new Result<List<UserChartResultDTO>>().ok(icResiUserService.userChartList(formDTO));
}
/**
* @Author lichao
* @Description 人房居民总数饼图 缓存处理
**/
@PostMapping("userchartRedis")
public Result userChartRedis() {
return new Result<>().ok(icResiUserService.userChartRedis());
}
/**
* 根据房屋主键查询户内家庭成员简信息
*

2
epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java

@ -606,4 +606,6 @@ public interface IcResiUserService extends BaseService<IcResiUserEntity> {
void exportResiForLangchao(HttpServletResponse response) throws Exception;
PageData<ResiLangchaoListResultDTO> resiListForLangchao(ResiListLangchaoFormDTO formDTO);
boolean userChartRedis();
}

59
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java

@ -4287,4 +4287,63 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi
return new PageData<>(list,pageData.getTotal());
}
@Override
public boolean userChartRedis() {
List<AgencyResultDTO> agencyResultDTOS = govOrgOpenFeignClient.getAllCommunity("1535072605621841922").getData();
for (AgencyResultDTO agencyResultDTO : agencyResultDTOS) {
try {
UserChartFormDTO formDTO = new UserChartFormDTO();
formDTO.setOrgId(agencyResultDTO.getAgencyId());
formDTO.setOrgType("agency");
UserChartResultDTO resultDTO = new UserChartResultDTO();
//计算百分比使用,保留小数点后两位
NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMaximumFractionDigits(NumConstant.TWO);
//获取无效组织网格Id列表
if("agency".equals(formDTO.getOrgType())){
//查询组织数据时排除掉当前组织及下级无效组织列表
Result<DelAgencyGridIdResultDTO> result = govOrgOpenFeignClient.getDelAgencyGridIdList(formDTO.getOrgId());
if (!result.success()) {
throw new EpmetException(String.format("获取当前组织及下级已删除组织、网格列表失败,组织Id->%s", formDTO.getUserId()));
}
formDTO.setAgencyIdList(result.getData().getAgencyIdList());
formDTO.setGridIdList(result.getData().getGridIdList());
}
//2.根据入参值查询对应的房屋统计数据
List<UserChartResultDTO> list = baseDao.userChart(formDTO.getOrgId(), formDTO.getOrgType(), formDTO.getAgencyIdList(), formDTO.getGridIdList());
//3.汇总数据
AtomicInteger userTotal = new AtomicInteger();
AtomicInteger czUserTotal = new AtomicInteger();
AtomicInteger ldUserTotal = new AtomicInteger();
list.forEach(l -> {
userTotal.addAndGet(l.getNum());
if ("liudongrenkou".equals(l.getIsFloating())) {
ldUserTotal.addAndGet(l.getNum());
} else {
czUserTotal.addAndGet(l.getNum());
}
});
resultDTO.setUserTotal(userTotal.get());
resultDTO.setCzUserTotal(czUserTotal.get());
resultDTO.setLdUserTotal(ldUserTotal.get());
resultDTO.setCzUserRatio(Double.valueOf((resultDTO.getUserTotal() == 0 || resultDTO.getCzUserTotal() > resultDTO.getUserTotal()) ? "0" : numberFormat.format(((float) resultDTO.getCzUserTotal() / (float) resultDTO.getUserTotal()) * 100)));
resultDTO.setLdUserRatio(Double.valueOf((resultDTO.getUserTotal() == 0 || resultDTO.getLdUserTotal() > resultDTO.getUserTotal()) ? "0" : numberFormat.format(((float) resultDTO.getLdUserTotal() / (float) resultDTO.getUserTotal()) * 100)));
resultDTO.setOrgId(formDTO.getOrgId());
resultDTO.setOrgType(formDTO.getOrgType());
// 24小时过期
redisTemplate.opsForValue().set(RedisKeys.getUserchart(formDTO.getOrgType(),formDTO.getOrgId()), resultDTO, RedisUtils.DEFAULT_EXPIRE, TimeUnit.SECONDS);
}catch (Exception e){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取该组织的userchart失败"+agencyResultDTO.getAgencyId(), "获取该组织的userchart失败");
}
}
return true;
}
}

Loading…
Cancel
Save