|
|
|
|
@ -1,11 +1,11 @@
|
|
|
|
|
package com.flossom.system.utils.shuyun;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
|
|
import com.flossom.common.core.constant.CacheConstants;
|
|
|
|
|
import com.flossom.common.core.domain.R;
|
|
|
|
|
import com.flossom.common.core.domain.shuyun.AccessToken;
|
|
|
|
|
import com.flossom.common.core.domain.shuyun.ShuYunMember;
|
|
|
|
|
import com.flossom.common.core.domain.shuyun.ShuYunPointChange;
|
|
|
|
|
import com.flossom.common.core.domain.shuyun.*;
|
|
|
|
|
import com.flossom.common.core.exception.ServiceException;
|
|
|
|
|
import com.flossom.common.redis.service.RedisService;
|
|
|
|
|
import com.flossom.system.utils.HttpClientUtils;
|
|
|
|
|
@ -47,6 +47,21 @@ public class ShuYunApiUtils {
|
|
|
|
|
ShuYunApiUtils.redisService = redisService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数云http请求code
|
|
|
|
|
*/
|
|
|
|
|
public class ShuYunHttpStatusConstants {
|
|
|
|
|
/**
|
|
|
|
|
* 请求成功
|
|
|
|
|
*/
|
|
|
|
|
public static final int SUCCESS = 10000;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 请求成功,但是结果不符合预期
|
|
|
|
|
*/
|
|
|
|
|
public static final int HALF_SUCCESS = 14000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取 accessToken,缓存没有就请求数云回调接口,将 accessToken 传递过来
|
|
|
|
|
*/
|
|
|
|
|
@ -63,7 +78,7 @@ public class ShuYunApiUtils {
|
|
|
|
|
logger.error("请求数云接口获取accessToken失败,将直接使用旧的accessToken,失败原因:{}", result);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口获取accessToken失败,将直接使用旧的accessToken,失败原因:{}", e);
|
|
|
|
|
logger.error("请求数云接口获取accessToken失败,将直接使用旧的accessToken,失败原因:{}", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String accessTokenStr = redisService.getCacheMapValue(CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE, CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE_VALUE);
|
|
|
|
|
@ -99,11 +114,11 @@ public class ShuYunApiUtils {
|
|
|
|
|
actionMethod);
|
|
|
|
|
logger.info("返回响应:{}", result);
|
|
|
|
|
R r = JSON.parseObject(result, R.class);
|
|
|
|
|
if (r.getCode() == 10000 || r.getCode() == 14000) {
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.SUCCESS || r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
return r;
|
|
|
|
|
} else {
|
|
|
|
|
logger.error("调用数云接口发生未知错误:{}", result);
|
|
|
|
|
throw new ServiceException("调用数云接口发生未知错误");
|
|
|
|
|
throw new ServiceException(r.getMsg());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -116,7 +131,7 @@ public class ShuYunApiUtils {
|
|
|
|
|
shuYunHttpRequest(HttpMethod.POST, null, JSON.toJSONString(member),
|
|
|
|
|
shuYunConfig.getActionMethod().getRegisterMember());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口注册会员失败:{}", e);
|
|
|
|
|
logger.error("请求数云接口注册会员失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口注册会员失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -128,12 +143,16 @@ public class ShuYunApiUtils {
|
|
|
|
|
try {
|
|
|
|
|
R r = shuYunHttpRequest(HttpMethod.POST, null, JSON.toJSONString(member),
|
|
|
|
|
shuYunConfig.getActionMethod().getQueryMember());
|
|
|
|
|
if (r.getCode() == 10000) {
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.SUCCESS) {
|
|
|
|
|
return JSON.parseObject(r.getData().toString(), ShuYunMember.class);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
logger.error("请求数云接口-会员积分查询失败:{}", r.getMsg());
|
|
|
|
|
throw new ServiceException("请求数云接口-会员积分查询失败");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-查询会员信息失败:{}", e);
|
|
|
|
|
logger.error("请求数云接口-查询会员信息失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-查询会员信息失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -147,7 +166,7 @@ public class ShuYunApiUtils {
|
|
|
|
|
shuYunHttpRequest(HttpMethod.PUT, null, JSON.toJSONString(member),
|
|
|
|
|
shuYunConfig.getActionMethod().getModifyMember());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-修改会员信息(除手机号)失败:{}", e);
|
|
|
|
|
logger.error("请求数云接口-修改会员信息(除手机号)失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-修改会员信息(除手机号)失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -160,7 +179,7 @@ public class ShuYunApiUtils {
|
|
|
|
|
shuYunHttpRequest(HttpMethod.PUT, null, JSON.toJSONString(member),
|
|
|
|
|
shuYunConfig.getActionMethod().getModifyMemberMobile());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-修改会员手机号失败:{}", e);
|
|
|
|
|
logger.error("请求数云接口-修改会员手机号失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-修改会员手机号失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -173,22 +192,98 @@ public class ShuYunApiUtils {
|
|
|
|
|
shuYunHttpRequest(HttpMethod.POST, null, JSON.toJSONString(member),
|
|
|
|
|
shuYunConfig.getActionMethod().getUnbindMember());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-解绑会员失败:{}", e);
|
|
|
|
|
logger.error("请求数云接口-解绑会员失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-解绑会员失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 积分变更
|
|
|
|
|
* 会员积分变更
|
|
|
|
|
*/
|
|
|
|
|
public static void pointChange(ShuYunPointChange shuYunPointChange) {
|
|
|
|
|
try {
|
|
|
|
|
shuYunHttpRequest(HttpMethod.POST, null, JSON.toJSONString(shuYunPointChange),
|
|
|
|
|
shuYunConfig.getActionMethod().getPointChange());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-会员积分变更失败:{}", e);
|
|
|
|
|
logger.error("请求数云接口-会员积分变更失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-会员积分变更失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 积分变更记录查询(分页)
|
|
|
|
|
*/
|
|
|
|
|
public static ShuYunPageUtil<ShuYunPointChangeLog> pointChangeLogSearch(ShuYunPageReq shuYunPageReq) {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
R r = shuYunHttpRequest(HttpMethod.GET, BeanUtil.beanToMap(shuYunPageReq), null,
|
|
|
|
|
shuYunConfig.getActionMethod().getPointChangeLogSearch());
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
logger.info("查询成功,没有数据");
|
|
|
|
|
return new ShuYunPageUtil<>();
|
|
|
|
|
}
|
|
|
|
|
if (r.getCode() != ShuYunHttpStatusConstants.SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口-会员积分变更记录查询失败:{}", r.getMsg());
|
|
|
|
|
}
|
|
|
|
|
return JSON.parseObject(r.getData().toString(), new TypeReference<ShuYunPageUtil<ShuYunPointChangeLog>>(){});
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-会员积分变更记录查询失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-会员积分变更记录查询失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询即将过期积分
|
|
|
|
|
* TODO:(未完成)
|
|
|
|
|
*/
|
|
|
|
|
public static int pointWillDueSearch(Map map) {
|
|
|
|
|
try {
|
|
|
|
|
R r = shuYunHttpRequest(HttpMethod.GET, map, null,
|
|
|
|
|
shuYunConfig.getActionMethod().getPointWillDueSearch());
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
logger.info("查询成功,没有数据");
|
|
|
|
|
}
|
|
|
|
|
if (r.getCode() != ShuYunHttpStatusConstants.SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口-查询会员即将过期积分失败:{}", r.getMsg());
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-查询会员即将过期积分失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-查询会员即将过期积分失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建标签
|
|
|
|
|
*/
|
|
|
|
|
public static void tagCreate(ShuYunTag shuYunTag) {
|
|
|
|
|
try {
|
|
|
|
|
R r = shuYunHttpRequest(HttpMethod.POST, null, JSON.toJSONString(shuYunTag),
|
|
|
|
|
shuYunConfig.getActionMethod().getTagCreate());
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口-创建标签失败:{}", r.getMsg());
|
|
|
|
|
throw new ServiceException("请求数云接口-创建标签失败");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-创建标签失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-创建标签失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void tagSearch(Map params) {
|
|
|
|
|
try {
|
|
|
|
|
R r = shuYunHttpRequest(HttpMethod.GET, params, null,
|
|
|
|
|
shuYunConfig.getActionMethod().getTagSearch());
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口-创建标签失败:{}", r.getMsg());
|
|
|
|
|
throw new ServiceException("请求数云接口-创建标签失败");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-创建标签失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-创建标签失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|