Browse Source

临时解决方案 组织树 先缓存

dev_shibei_match
jianjun 4 years ago
parent
commit
22474ae651
  1. 6
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  2. 19
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerAgencyController.java
  3. 14
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerAgencyServiceImpl.java

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

@ -630,10 +630,10 @@ public class RedisKeys {
/** /**
* desc:临时方案 * desc:临时方案
* @param userId * @param agencyId
* @return * @return
*/ */
public static String getOrgTreeCacheKey(String userId) { public static String getOrgTreeCacheKey(String agencyId) {
return rootPrefix.concat("ic:temp:orgtree").concat("userId"); return rootPrefix.concat("ic:temp:orgtree").concat(agencyId);
} }
} }

19
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerAgencyController.java

@ -20,8 +20,6 @@ package com.epmet.controller;
import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ExcelUtils; import com.epmet.commons.tools.utils.ExcelUtils;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
@ -55,8 +53,6 @@ import java.util.Set;
@RestController @RestController
@RequestMapping("customeragency") @RequestMapping("customeragency")
public class CustomerAgencyController { public class CustomerAgencyController {
@Autowired
private RedisUtils redisUtils;
@Autowired @Autowired
private CustomerAgencyService customerAgencyService; private CustomerAgencyService customerAgencyService;
@ -369,18 +365,9 @@ public class CustomerAgencyController {
* @Date 2021/9/8 15:20 * @Date 2021/9/8 15:20
*/ */
@PostMapping("agencygridtree") @PostMapping("agencygridtree")
public Result<AgencyTreeResultDTO> getOrgTreeData(/*@LoginUser */TokenDto tokenDTO) { public Result<AgencyTreeResultDTO> getOrgTreeData(@LoginUser TokenDto tokenDTO) {
tokenDTO.setUserId("dffe71e021a61b900f9025f4f07f6955"); //tokenDTO.setUserId("dffe71e021a61b900f9025f4f07f6955");
String orgTreeCacheKey = RedisKeys.getOrgTreeCacheKey(tokenDTO.getUserId()); return new Result<AgencyTreeResultDTO>().ok(customerAgencyService.getOrgTreeData(tokenDTO.getUserId()));
Object o = redisUtils.get(orgTreeCacheKey);
AgencyTreeResultDTO result = null;
if (o == null){
result = customerAgencyService.getOrgTreeData(tokenDTO.getUserId());
redisUtils.set(orgTreeCacheKey,result,RedisUtils.MINUTE_THIRTY_EXPIRE);
}else {
result = (AgencyTreeResultDTO) o;
}
return new Result<AgencyTreeResultDTO>().ok(result);
} }
} }

14
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerAgencyServiceImpl.java

@ -16,6 +16,7 @@
*/ */
package com.epmet.service.impl; package com.epmet.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
@ -24,6 +25,8 @@ import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.CustomerAgencyConstant; import com.epmet.constant.CustomerAgencyConstant;
@ -81,6 +84,8 @@ public class CustomerAgencyServiceImpl extends BaseServiceImpl<CustomerAgencyDao
private EpmetUserFeignClient epmetUserFeignClient; private EpmetUserFeignClient epmetUserFeignClient;
@Autowired @Autowired
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; private EpmetUserOpenFeignClient epmetUserOpenFeignClient;
@Autowired
private RedisUtils redisUtils;
@Override @Override
public PageData<CustomerAgencyDTO> page(Map<String, Object> params) { public PageData<CustomerAgencyDTO> page(Map<String, Object> params) {
@ -1122,8 +1127,17 @@ public class CustomerAgencyServiceImpl extends BaseServiceImpl<CustomerAgencyDao
result.setOrgLevel(rootAgency.getAgencyId().concat("-").concat(rootAgency.getLevel())); result.setOrgLevel(rootAgency.getAgencyId().concat("-").concat(rootAgency.getLevel()));
result.setLongitude(rootAgency.getLongitude()); result.setLongitude(rootAgency.getLongitude());
result.setLatitude(rootAgency.getLatitude()); result.setLatitude(rootAgency.getLatitude());
String orgTreeCacheKey = RedisKeys.getOrgTreeCacheKey(rootAgency.getAgencyId());
Object o = redisUtils.get(orgTreeCacheKey);
if (o == null){
ExtStaffPermissionResultDTO res = baseDao.selectAgencyById(rootAgency.getAgencyId()); ExtStaffPermissionResultDTO res = baseDao.selectAgencyById(rootAgency.getAgencyId());
convert2AgencyTreeResult(result,res.getSubAgencyList(),res.getGridList()); convert2AgencyTreeResult(result,res.getSubAgencyList(),res.getGridList());
redisUtils.set(orgTreeCacheKey,result, RedisUtils.MINUTE_THIRTY_EXPIRE);
}else {
result = (AgencyTreeResultDTO) o;
}
return result; return result;
} }
/** /**

Loading…
Cancel
Save