diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/CommonGovOrgFeignClient.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/CommonGovOrgFeignClient.java new file mode 100644 index 0000000000..3ece646100 --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/CommonGovOrgFeignClient.java @@ -0,0 +1,29 @@ +package com.epmet.commons.tools.feign; + +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.feign.fallback.CommonAggFeignClientFallBackFactory; +import com.epmet.commons.tools.feign.fallback.CommonGovOrgFeignClientFallBackFactory; +import com.epmet.commons.tools.redis.common.bean.GridInfoCache; +import com.epmet.commons.tools.utils.Result; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @Author zxc + * @DateTime 2022/3/17 1:42 下午 + * @DESC + */ +@FeignClient(name = ServiceConstant.GOV_ORG_SERVER, fallbackFactory = CommonGovOrgFeignClientFallBackFactory.class) +public interface CommonGovOrgFeignClient { + + /** + * @Description 查询网格信息 + * @param gridId + * @author zxc + * @date 2021/11/5 2:54 下午 + */ + @PostMapping("/gov/org/grid/getbaseinfo") + Result getGridInfo(@RequestParam("gridId")String gridId); + +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/fallback/CommonGovOrgFeignClientFallBackFactory.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/fallback/CommonGovOrgFeignClientFallBackFactory.java new file mode 100644 index 0000000000..bcde96c380 --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/fallback/CommonGovOrgFeignClientFallBackFactory.java @@ -0,0 +1,23 @@ +package com.epmet.commons.tools.feign.fallback; + +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.feign.CommonGovOrgFeignClient; +import com.epmet.commons.tools.redis.common.bean.GridInfoCache; +import com.epmet.commons.tools.utils.ModuleUtils; +import com.epmet.commons.tools.utils.Result; +import org.springframework.stereotype.Component; + +/** + * @Author zxc + * @DateTime 2022/3/17 1:46 下午 + * @DESC + */ +@Component +public class CommonGovOrgFeignClientFallBackFactory implements CommonGovOrgFeignClient { + + @Override + public Result getGridInfo(String gridId) { + return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getGridInfo", gridId); + } + +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerOrgRedis.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerOrgRedis.java index c44a7030db..94c413431a 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerOrgRedis.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerOrgRedis.java @@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil; import com.alibaba.fastjson.JSON; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.feign.CommonAggFeignClient; +import com.epmet.commons.tools.feign.CommonGovOrgFeignClient; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; @@ -32,6 +33,8 @@ public class CustomerOrgRedis { @Autowired private CommonAggFeignClient commonAggFeignClient; + @Autowired + private CommonGovOrgFeignClient govOrgFeignClient; private static CustomerOrgRedis customerOrgRedis; private static final String ROLE_MAP_KEY = "roleMap"; @@ -42,6 +45,7 @@ public class CustomerOrgRedis { customerOrgRedis = this; customerOrgRedis.redisUtils = this.redisUtils; customerOrgRedis.commonAggFeignClient = this.commonAggFeignClient; + customerOrgRedis.govOrgFeignClient = this.govOrgFeignClient; } /** @@ -57,7 +61,7 @@ public class CustomerOrgRedis { if (!CollectionUtils.isEmpty(grid)) { return ConvertUtils.mapToEntity(grid, GridInfoCache.class); } - Result gridInfoResult = customerOrgRedis.commonAggFeignClient.getGridInfo(gridId); + Result gridInfoResult = customerOrgRedis.govOrgFeignClient.getGridInfo(gridId); if (!gridInfoResult.success()){ throw new RenException("查询网格信息失败..."); } @@ -65,9 +69,10 @@ public class CustomerOrgRedis { //throw new RenException("没有此网格信息..."); return null; } - log.info("select grid info is {}", JSON.toJSONString(gridInfoResult.getData())); + // feign 方法中已经放缓存 + /*log.info("select grid info is {}", JSON.toJSONString(gridInfoResult.getData())); Map map = BeanUtil.beanToMap(gridInfoResult.getData(), false, true); - customerOrgRedis.redisUtils.hMSet(key, map); + customerOrgRedis.redisUtils.hMSet(key, map);*/ return gridInfoResult.getData(); }