10 changed files with 263 additions and 0 deletions
@ -0,0 +1,26 @@ |
|||
package com.epmet.commons.tools.dto.form; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2022/9/15 10:25 |
|||
* @DESC |
|||
*/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class DingMiniInfoFormDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 2661531490851265637L; |
|||
|
|||
public interface DingMiniInfoForm{} |
|||
|
|||
@NotBlank(message = "suiteKey不能为空",groups = DingMiniInfoForm.class) |
|||
private String suiteKey; |
|||
} |
@ -0,0 +1,24 @@ |
|||
package com.epmet.commons.tools.feign; |
|||
|
|||
import com.epmet.commons.tools.constant.ServiceConstant; |
|||
import com.epmet.commons.tools.dto.form.DingMiniInfoFormDTO; |
|||
import com.epmet.commons.tools.feign.fallback.CommonThirdFeignClientFallBackFactory; |
|||
import com.epmet.commons.tools.redis.common.bean.DingMiniInfoCache; |
|||
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.RequestBody; |
|||
|
|||
|
|||
/** |
|||
* @Description |
|||
* @Author zxc |
|||
*/ |
|||
@FeignClient(name = ServiceConstant.EPMET_THIRD_SERVER, fallbackFactory = CommonThirdFeignClientFallBackFactory.class) |
|||
// @FeignClient(name = ServiceConstant.EPMET_THIRD_SERVER, fallbackFactory = CommonAggFeignClientFallBackFactory.class,url = "localhost:8110")
|
|||
public interface CommonThirdFeignClient { |
|||
|
|||
@PostMapping("/third/dingTalk/getDingMiniInfo") |
|||
Result<DingMiniInfoCache> getDingMiniInfo(@RequestBody DingMiniInfoFormDTO formDTO); |
|||
|
|||
} |
@ -0,0 +1,20 @@ |
|||
package com.epmet.commons.tools.feign.fallback; |
|||
|
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
import com.epmet.commons.tools.feign.CommonThirdFeignClient; |
|||
import feign.hystrix.FallbackFactory; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
public class CommonThirdFeignClientFallBackFactory implements FallbackFactory<CommonThirdFeignClient> { |
|||
|
|||
private CommonThirdFeignClientFallback fallback = new CommonThirdFeignClientFallback(); |
|||
|
|||
@Override |
|||
public CommonThirdFeignClient create(Throwable cause) { |
|||
log.error(String.format("FeignClient调用发生异常,异常信息:%s", ExceptionUtils.getThrowableErrorStackTrace(cause))); |
|||
return fallback; |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
package com.epmet.commons.tools.feign.fallback; |
|||
|
|||
import com.epmet.commons.tools.constant.ServiceConstant; |
|||
import com.epmet.commons.tools.dto.form.DingMiniInfoFormDTO; |
|||
import com.epmet.commons.tools.feign.CommonThirdFeignClient; |
|||
import com.epmet.commons.tools.redis.common.bean.DingMiniInfoCache; |
|||
import com.epmet.commons.tools.utils.ModuleUtils; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* |
|||
* @Author zxc |
|||
* @Description |
|||
* @Date |
|||
**/ |
|||
@Component |
|||
public class CommonThirdFeignClientFallback implements CommonThirdFeignClient { |
|||
|
|||
@Override |
|||
public Result<DingMiniInfoCache> getDingMiniInfo(DingMiniInfoFormDTO formDTO) { |
|||
return ModuleUtils.feignConError(ServiceConstant.EPMET_THIRD_SERVER, "getDingMiniInfo", formDTO); |
|||
} |
|||
} |
@ -0,0 +1,58 @@ |
|||
package com.epmet.commons.tools.redis.common; |
|||
|
|||
import com.epmet.commons.tools.dto.form.DingMiniInfoFormDTO; |
|||
import com.epmet.commons.tools.exception.EpmetException; |
|||
import com.epmet.commons.tools.feign.CommonThirdFeignClient; |
|||
import com.epmet.commons.tools.redis.RedisKeys; |
|||
import com.epmet.commons.tools.redis.RedisUtils; |
|||
import com.epmet.commons.tools.redis.common.bean.DingMiniInfoCache; |
|||
import com.epmet.commons.tools.utils.ConvertUtils; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.util.CollectionUtils; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2022/9/15 10:01 |
|||
* @DESC |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
public class CustomerDingDingRedis { |
|||
|
|||
@Autowired |
|||
private CommonThirdFeignClient thirdFeignClient; |
|||
@Autowired |
|||
private RedisUtils redisUtils; |
|||
|
|||
private static CustomerDingDingRedis customerDingDingRedis; |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
customerDingDingRedis = this; |
|||
customerDingDingRedis.thirdFeignClient = this.thirdFeignClient; |
|||
customerDingDingRedis.redisUtils = this.redisUtils; |
|||
} |
|||
|
|||
public static DingMiniInfoCache getDingMiniInfo(String suiteKey){ |
|||
String key = RedisKeys.getDingMiniInfoKey(suiteKey); |
|||
Map<String, Object> miniInfoMap = customerDingDingRedis.redisUtils.hGetAll(key); |
|||
if (!CollectionUtils.isEmpty(miniInfoMap)){ |
|||
return ConvertUtils.mapToEntity(miniInfoMap,DingMiniInfoCache.class); |
|||
} |
|||
Result<DingMiniInfoCache> dingMiniInfoResult = customerDingDingRedis.thirdFeignClient.getDingMiniInfo(new DingMiniInfoFormDTO(suiteKey)); |
|||
if (!dingMiniInfoResult.success()){ |
|||
throw new EpmetException("查询dingMiniInfo失败..."); |
|||
} |
|||
if (null == dingMiniInfoResult.getData()){ |
|||
return null; |
|||
} |
|||
return dingMiniInfoResult.getData(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,52 @@ |
|||
package com.epmet.commons.tools.redis.common.bean; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2022/9/15 10:11 |
|||
* @DESC |
|||
*/ |
|||
@Data |
|||
public class DingMiniInfoCache implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -6956910978074595334L; |
|||
|
|||
private String id; |
|||
|
|||
/** |
|||
* |
|||
*/ |
|||
private String suiteId; |
|||
|
|||
/** |
|||
* |
|||
*/ |
|||
private String appId; |
|||
|
|||
/** |
|||
* |
|||
*/ |
|||
private String miniAppId; |
|||
|
|||
/** |
|||
* |
|||
*/ |
|||
private String suiteName; |
|||
|
|||
/** |
|||
* |
|||
*/ |
|||
private String suiteKey; |
|||
|
|||
/** |
|||
* |
|||
*/ |
|||
private String suiteSecret; |
|||
|
|||
private String token; |
|||
|
|||
private String aesKey; |
|||
} |
Loading…
Reference in new issue