提交 553a2d67 authored 作者: hzh's avatar hzh

代码优化

上级 7d963feb
package org.dromara.mall.api.weishi;
/**
* @author wenhe
*/
public interface RemoteWeishiService {
/**
* 获取token
*/
void getToken();
}
package org.dromara.job.snailjob.mall.weishi;
import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
import com.aizuda.snailjob.client.model.ExecuteResult;
import lombok.AllArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.mall.api.weishi.RemoteWeishiService;
import org.springframework.stereotype.Component;
/**
* 获取token
*
* @author wenhe
*/
@AllArgsConstructor
@Component
@JobExecutor(name = "WeishiJob")
public class WeishiJob {
@DubboReference
private RemoteWeishiService weishiService;
public ExecuteResult jobExecute(JobArgs jobArgs) {
weishiService.getToken();
return ExecuteResult.success("跟新卫士token成功");
}
}
......@@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.*;
import java.time.Duration;
import java.util.List;
import static org.dromara.mall.enums.weishi.WeishiConstants.WEISHI_TOKEN;
/**
* @author hzh
* @date 2025-05-12
......@@ -120,9 +122,6 @@ public class WeishiController {
return R.ok();
}
private static final String WEISHI_TOKEN = "mall:third:weishi:token";
/**
* 获取token
*
......
package org.dromara.mall.dubbo.weishi;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.redis.utils.RedisUtils;
import org.dromara.common.weishi.model.res.AuthResponse;
import org.dromara.common.weishi.service.WeishiService;
import org.dromara.mall.api.weishi.RemoteWeishiService;
import org.springframework.stereotype.Service;
import java.time.Duration;
import static org.dromara.mall.enums.weishi.WeishiConstants.WEISHI_TOKEN;
/**
* @author hzh
* @date 2025-05-13
**/
@RequiredArgsConstructor
@Service
@DubboService
public class RemoteWeishiServiceImpl implements RemoteWeishiService {
private final WeishiService weishiService;
@Override
public void getToken() {
String token = RedisUtils.getCacheObject(WEISHI_TOKEN);
if (StringUtils.isEmpty(token)) {
AuthResponse res = weishiService.authorize();
RedisUtils.setCacheObject(WEISHI_TOKEN, res.getAccess_token(), Duration.ofSeconds(res.getExpires_in().longValue()));
}
}
}
package org.dromara.mall.enums.weishi;
public interface WeishiConstants {
/**
* token
*/
String WEISHI_TOKEN = "mall:third:weishi:token";
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论