|
@@ -12,6 +12,7 @@ import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.customer.contants.XiaomanContant;
|
|
|
import com.fjhx.customer.entity.xiaoman.dto.XiaomanConfigDto;
|
|
|
import com.fjhx.customer.entity.xiaoman.dto.XiaomanConfigSelectDto;
|
|
|
import com.fjhx.customer.entity.xiaoman.dto.XiaomanCustomerDto;
|
|
@@ -22,10 +23,12 @@ import com.fjhx.customer.entity.xiaoman.vo.XiaomanConfigVo;
|
|
|
import com.fjhx.customer.entity.xiaoman.vo.XiaomanCustomerVo;
|
|
|
import com.fjhx.customer.mapper.xiaoman.XiaomanConfigMapper;
|
|
|
import com.fjhx.customer.service.xiaoman.XiaomanConfigService;
|
|
|
+import com.ruoyi.common.core.redis.RedisCache;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -42,6 +45,9 @@ import static com.ruoyi.common.utils.wrapper.IWrapper.getWrapper;
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class XiaomanConfigServiceImpl extends ServiceImpl<XiaomanConfigMapper, XiaomanConfig> implements XiaomanConfigService {
|
|
|
+ @Resource
|
|
|
+ RedisCache redisCache;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public void getToken(XiaomanConfig config) {
|
|
@@ -66,6 +72,7 @@ public class XiaomanConfigServiceImpl extends ServiceImpl<XiaomanConfigMapper, X
|
|
|
jsonObject.put("refresh_token", config.getRefreshToken());
|
|
|
XiaoManTokenVO token = getToken(config, jsonObject.toJSONString(), config.getRefreshTokenUrl());
|
|
|
updateConfig(config, token);
|
|
|
+ cacheToken();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -84,6 +91,7 @@ public class XiaomanConfigServiceImpl extends ServiceImpl<XiaomanConfigMapper, X
|
|
|
String body = jsonObject.toJSONString();
|
|
|
XiaoManTokenVO token = getToken(config, body, config.getTokenUrl());
|
|
|
updateConfig(config, token);
|
|
|
+ cacheToken();
|
|
|
}
|
|
|
|
|
|
private void updateConfig(XiaomanConfig config, XiaoManTokenVO token) {
|
|
@@ -114,17 +122,6 @@ public class XiaomanConfigServiceImpl extends ServiceImpl<XiaomanConfigMapper, X
|
|
|
}
|
|
|
|
|
|
|
|
|
- @Override
|
|
|
- public XiaomanConfig getConfig() {
|
|
|
- List<XiaomanConfig> list = this.list();
|
|
|
- if (CollectionUtil.isEmpty(list)) {
|
|
|
- throw new RuntimeException("小满配置表数据为空");
|
|
|
- } else if (list.size() > 1) {
|
|
|
- throw new RuntimeException("小满配置表数据大于1条");
|
|
|
- }
|
|
|
- return list.get(0);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
@Override
|
|
|
public Page<XiaomanConfigVo> getPage(XiaomanConfigSelectDto dto) {
|
|
@@ -146,6 +143,28 @@ public class XiaomanConfigServiceImpl extends ServiceImpl<XiaomanConfigMapper, X
|
|
|
.set(XiaomanConfig::getPassword, StrUtil.isNotBlank(xiaomanConfigDto.getPassword())? DigestUtil.sha256Hex(xiaomanConfigDto.getPassword()) : DigestUtil.sha256Hex("#"))
|
|
|
.eq(XiaomanConfig::getId, xiaomanConfigDto.getId())
|
|
|
.update();
|
|
|
- this.getToken(this.getConfig());
|
|
|
+ this.getToken(this.getCache());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void cacheToken() {
|
|
|
+ redisCache.setCacheObject(XiaomanContant.TOKEN_KEY, this.getConfig());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XiaomanConfig getCache() {
|
|
|
+ return redisCache.getCacheObject(XiaomanContant.TOKEN_KEY);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private XiaomanConfig getConfig() {
|
|
|
+ List<XiaomanConfig> list = this.list();
|
|
|
+ if (CollectionUtil.isEmpty(list)) {
|
|
|
+ throw new RuntimeException("小满配置表数据为空");
|
|
|
+ } else if (list.size() > 1) {
|
|
|
+ throw new RuntimeException("小满配置表数据大于1条");
|
|
|
+ }
|
|
|
+ return list.get(0);
|
|
|
}
|
|
|
}
|