|
|
|
|
@ -0,0 +1,469 @@
|
|
|
|
|
package com.flossom.miniProgram.utils.shuyun;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
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.*;
|
|
|
|
|
import com.flossom.common.core.exception.ServiceException;
|
|
|
|
|
import com.flossom.common.redis.service.RedisService;
|
|
|
|
|
import com.flossom.miniProgram.utils.HttpClientUtils;
|
|
|
|
|
import com.shuyun.open.sdk.bean.HttpMethod;
|
|
|
|
|
import com.shuyun.open.sdk.core.GateWayClient;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.ZoneId;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数云工具类
|
|
|
|
|
*/
|
|
|
|
|
@Component
|
|
|
|
|
public class ShuYunApiUtils {
|
|
|
|
|
|
|
|
|
|
protected final static Logger logger = LoggerFactory.getLogger(ShuYunApiUtils.class);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数云配置类
|
|
|
|
|
*/
|
|
|
|
|
private static ShuYunConfig shuYunConfig;
|
|
|
|
|
|
|
|
|
|
private static RedisService redisService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
public void setShuYunConfig(ShuYunConfig shuYunConfig) {
|
|
|
|
|
ShuYunApiUtils.shuYunConfig = shuYunConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
public void setRedisService(RedisService redisService) {
|
|
|
|
|
ShuYunApiUtils.redisService = redisService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数云http请求code
|
|
|
|
|
*/
|
|
|
|
|
public class ShuYunHttpStatusConstants {
|
|
|
|
|
/**
|
|
|
|
|
* 请求成功
|
|
|
|
|
*/
|
|
|
|
|
public static final int SUCCESS = 10000;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 请求成功,但是业务处理错误,或者执行结果不符合预期
|
|
|
|
|
* 但不是处理异常
|
|
|
|
|
*/
|
|
|
|
|
public static final int HALF_SUCCESS = 14000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取 accessToken,缓存没有就请求数云回调接口,通过异步回调将 accessToken 传递过来
|
|
|
|
|
*/
|
|
|
|
|
public static String getAccessToken() {
|
|
|
|
|
Long expiryTime = redisService.getCacheMapValue(CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE, CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE_EXPIRY);
|
|
|
|
|
if (expiryTime == null || expiryTime == 0 || LocalDateTime.now().atZone(ZoneId.systemDefault()).toEpochSecond() > expiryTime) {
|
|
|
|
|
String accessTokenUrl = StringUtils.replace(shuYunConfig.getActionMethod().getAccessToken(), "{appid}", shuYunConfig.getAppid());
|
|
|
|
|
logger.info("刷新 accessToken 地址:{}", accessTokenUrl);
|
|
|
|
|
try {
|
|
|
|
|
String result = HttpClientUtils.get(accessTokenUrl);
|
|
|
|
|
logger.info("请求数云接口获取 accessToken 结果:{}", result);
|
|
|
|
|
R r = JSON.parseObject(result, R.class);
|
|
|
|
|
if (r.getCode() != R.SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口获取accessToken失败,将直接使用旧的accessToken,失败原因:{}", result);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口获取accessToken失败,将直接使用旧的accessToken,失败原因:{}", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String accessTokenStr = redisService.getCacheMapValue(CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE, CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE_VALUE);
|
|
|
|
|
if (StringUtils.isNotBlank(accessTokenStr)) {
|
|
|
|
|
AccessToken accessToken = JSON.parseObject(accessTokenStr, AccessToken.class);
|
|
|
|
|
return accessToken.getAccessToken();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 第一次获取会失败,因为回调是异步的,如果还没回调回来,我们就从 redis 获取缓存了
|
|
|
|
|
*/
|
|
|
|
|
logger.error("从 redis 获取数云 accessToken 失败,缓存中没有 accessToken,有可能是第一次调用");
|
|
|
|
|
throw new ServiceException("从 redis 获取数云 accessToken 失败,缓存中没有 accessToken,有可能是第一次调用");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 请求基础封装方法 (增加泛型适配)
|
|
|
|
|
*
|
|
|
|
|
* @param httpMethod 请求方式
|
|
|
|
|
* @param queryParams get请求时,url地址后的参数
|
|
|
|
|
* @param bodyParams post、put 请求时,请求体的数据
|
|
|
|
|
* @param actionMethod 请求方法地址
|
|
|
|
|
*/
|
|
|
|
|
public static <T> R<T> shuYunHttpRequest(HttpMethod httpMethod, Map queryParams, Object bodyParams, String actionMethod, Class<T> clazz) throws ServiceException {
|
|
|
|
|
logger.info("数云接口请求地址:{},参数:queryParams = {}、bodyParams = {}", actionMethod, queryParams, JSON.toJSONString(bodyParams));
|
|
|
|
|
String result = GateWayClient.askGateWay(
|
|
|
|
|
httpMethod, shuYunConfig.getUrl(),
|
|
|
|
|
queryParams, JSON.toJSONString(bodyParams),
|
|
|
|
|
shuYunConfig.getAppid(), shuYunConfig.getSecurity(),
|
|
|
|
|
getAccessToken(), actionMethod);
|
|
|
|
|
logger.info("返回响应:{}", result);
|
|
|
|
|
R<T> r = JSON.parseObject(result, new TypeReference<R<T>>(clazz) {
|
|
|
|
|
});
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.SUCCESS || r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
return r;
|
|
|
|
|
} else {
|
|
|
|
|
logger.error("调用数云接口发生未知错误:{}", result);
|
|
|
|
|
throw new ServiceException(r.getMsg());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保留旧版本
|
|
|
|
|
*/
|
|
|
|
|
@Deprecated
|
|
|
|
|
public static R shuYunHttpRequest2(HttpMethod httpMethod, Map queryParams, Object bodyParams, String actionMethod) throws ServiceException {
|
|
|
|
|
logger.info("数云接口请求地址:{},参数:queryParams = {}、bodyParams = {}", actionMethod, queryParams, JSON.toJSONString(bodyParams));
|
|
|
|
|
String result = GateWayClient.askGateWay(
|
|
|
|
|
httpMethod, shuYunConfig.getUrl(),
|
|
|
|
|
queryParams, JSON.toJSONString(bodyParams),
|
|
|
|
|
shuYunConfig.getAppid(), shuYunConfig.getSecurity(),
|
|
|
|
|
getAccessToken(), actionMethod);
|
|
|
|
|
logger.info("返回响应:{}", result);
|
|
|
|
|
R r = JSON.parseObject(result, R.class);
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.SUCCESS || r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
return r;
|
|
|
|
|
} else {
|
|
|
|
|
logger.error("调用数云接口发生未知错误:{}", result);
|
|
|
|
|
throw new ServiceException(r.getMsg());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static <T> R<T> httpQueryParamsRequest(HttpMethod httpMethod, Map queryParams, String actionMethod, Class<T> clazz) throws ServiceException {
|
|
|
|
|
return shuYunHttpRequest(httpMethod, queryParams, null, actionMethod, clazz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static <T> R<T> httpBodyParamsRequest(HttpMethod httpMethod, Object bodyParams, String actionMethod, Class<T> clazz) throws ServiceException {
|
|
|
|
|
return shuYunHttpRequest(httpMethod, null, bodyParams, actionMethod, clazz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 会员注册
|
|
|
|
|
* https://open.shuyun.com/#/apidoc?type=41&apiId=40
|
|
|
|
|
*/
|
|
|
|
|
public static R registerMember(ShuYunMember member) {
|
|
|
|
|
try {
|
|
|
|
|
return httpBodyParamsRequest(HttpMethod.POST, member, shuYunConfig.getActionMethod().getRegisterMember(), Object.class);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口注册会员失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口注册会员失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 会员信息查询(单查询)
|
|
|
|
|
* https://open.shuyun.com/#/apidoc?type=41&apiId=149
|
|
|
|
|
*/
|
|
|
|
|
public static ShuYunMember queryMember(String memberId, String platCode, String shopId) {
|
|
|
|
|
Map<String, String> params = MapUtil.newHashMap();
|
|
|
|
|
params.put("id", memberId);
|
|
|
|
|
params.put("platCode", platCode);
|
|
|
|
|
params.put("shopId", shopId);
|
|
|
|
|
try {
|
|
|
|
|
R<ShuYunMember> r = httpBodyParamsRequest(HttpMethod.POST, params, shuYunConfig.getActionMethod().getQueryMember(), ShuYunMember.class);
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.SUCCESS) {
|
|
|
|
|
return r.getData();
|
|
|
|
|
}
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
logger.error("请求数云接口-会员信息查询失败:{}", r.getMsg());
|
|
|
|
|
throw new ServiceException("请求数云接口-会员信息查询失败");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-会员信息查询失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-会员信息查询失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改会员信息
|
|
|
|
|
* 注意:手机号不能修改
|
|
|
|
|
* https://open.shuyun.com/#/apidoc?type=41&apiId=36
|
|
|
|
|
*/
|
|
|
|
|
public static R modifyMember(ShuYunMember member) {
|
|
|
|
|
try {
|
|
|
|
|
return httpBodyParamsRequest(HttpMethod.PUT, member, shuYunConfig.getActionMethod().getModifyMember(), Object.class);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-修改会员信息(除手机号)失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-修改会员信息(除手机号)失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改会员手机号
|
|
|
|
|
* https://open.shuyun.com/#/apidoc?type=41&apiId=37
|
|
|
|
|
*/
|
|
|
|
|
public static R modifyMemberMobile(String memberId, String platCode, String shopId, String mobile) {
|
|
|
|
|
Map<String, String> params = MapUtil.newHashMap();
|
|
|
|
|
params.put("id", memberId);
|
|
|
|
|
params.put("platCode", platCode);
|
|
|
|
|
params.put("shopId", shopId);
|
|
|
|
|
params.put("mobile", mobile);
|
|
|
|
|
try {
|
|
|
|
|
return httpBodyParamsRequest(HttpMethod.PUT, params, shuYunConfig.getActionMethod().getModifyMemberMobile(), Object.class);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-修改会员手机号失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-修改会员手机号失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解绑会员
|
|
|
|
|
* https://open.shuyun.com/#/apidoc?type=41&apiId=74
|
|
|
|
|
*/
|
|
|
|
|
public static R unbindMember(String memberId, String platCode, String shopId) {
|
|
|
|
|
Map<String, String> params = MapUtil.newHashMap();
|
|
|
|
|
params.put("id", memberId);
|
|
|
|
|
params.put("platCode", platCode);
|
|
|
|
|
params.put("shopId", shopId);
|
|
|
|
|
try {
|
|
|
|
|
return httpBodyParamsRequest(HttpMethod.POST, params, shuYunConfig.getActionMethod().getUnbindMember(), Object.class);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-解绑会员失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-解绑会员失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 会员积分变更
|
|
|
|
|
* https://open.shuyun.com/#/apidoc?type=41&apiId=34
|
|
|
|
|
*/
|
|
|
|
|
public static R pointChange(ShuYunPointChange shuYunPointChange) {
|
|
|
|
|
try {
|
|
|
|
|
return httpBodyParamsRequest(HttpMethod.POST, shuYunPointChange, shuYunConfig.getActionMethod().getPointChange(), Object.class);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-会员积分变更失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-会员积分变更失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 积分变更记录查询(分页)
|
|
|
|
|
* https://open.shuyun.com/#/apidoc?type=41&apiId=33
|
|
|
|
|
*/
|
|
|
|
|
public static ShuYunPageUtil<ShuYunPointChangeLog> pointChangeLogSearch(ShuYunPageReq shuYunPageReq) {
|
|
|
|
|
try {
|
|
|
|
|
R r = httpQueryParamsRequest(HttpMethod.GET, BeanUtil.beanToMap(shuYunPageReq),
|
|
|
|
|
shuYunConfig.getActionMethod().getPointChangeLogSearch(), Object.class);
|
|
|
|
|
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("请求数云接口-会员积分变更记录查询失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询即将过期积分
|
|
|
|
|
* https://open.shuyun.com/#/apidoc?type=41&apiId=249
|
|
|
|
|
*/
|
|
|
|
|
public static Integer pointWillDueSearch(String tenant, String platId, String cardPlanId, String timeType, String startTime, String endTime) {
|
|
|
|
|
Map<String, String> params = MapUtil.newHashMap();
|
|
|
|
|
params.put("tenant", tenant);
|
|
|
|
|
params.put("platId", platId);
|
|
|
|
|
params.put("platCode", shuYunConfig.getPlatCode());
|
|
|
|
|
params.put("shopId", shuYunConfig.getShopId());
|
|
|
|
|
params.put("cardPlanId", cardPlanId);
|
|
|
|
|
params.put("timeType", timeType);
|
|
|
|
|
params.put("startTime", startTime);
|
|
|
|
|
params.put("endTime", endTime);
|
|
|
|
|
try {
|
|
|
|
|
R<Integer> r = httpQueryParamsRequest(HttpMethod.GET, params, shuYunConfig.getActionMethod().getPointWillDueSearch(), Integer.class);
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
logger.info("查询成功,没有数据");
|
|
|
|
|
}
|
|
|
|
|
if (r.getCode() != ShuYunHttpStatusConstants.SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口-查询会员即将过期积分失败:{}", r.getMsg());
|
|
|
|
|
}
|
|
|
|
|
return r.getData();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-查询会员即将过期积分失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-查询会员即将过期积分失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建标签
|
|
|
|
|
* https://open.shuyun.com/#/apidoc?type=23&apiId=86
|
|
|
|
|
*/
|
|
|
|
|
public static Integer tagCreate(ShuYunTag shuYunTag) {
|
|
|
|
|
try {
|
|
|
|
|
R<Map> r = httpBodyParamsRequest(HttpMethod.POST, shuYunTag, shuYunConfig.getActionMethod().getTagCreate(), Map.class);
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口-创建标签失败:{}", r.getMsg());
|
|
|
|
|
throw new ServiceException("请求数云接口-创建标签失败");
|
|
|
|
|
}
|
|
|
|
|
if (r.getData() != null) {
|
|
|
|
|
return (Integer) (r.getData().get("tagId"));
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-创建标签失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-创建标签失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询标签
|
|
|
|
|
* https://open.shuyun.com/#/apidoc?type=23&apiId=85
|
|
|
|
|
*
|
|
|
|
|
* @param type 标签类型:1(自定义)
|
|
|
|
|
* @param allValueType 标签显示:true(全部标签);false(基本标签)
|
|
|
|
|
*/
|
|
|
|
|
public static List<ShuYunGroupTag> tagSearch(String type, String allValueType) {
|
|
|
|
|
Map<String, String> params = MapUtil.newHashMap();
|
|
|
|
|
params.put("type", type);
|
|
|
|
|
params.put("allValueType", allValueType);
|
|
|
|
|
try {
|
|
|
|
|
R r = httpQueryParamsRequest(HttpMethod.GET, params, shuYunConfig.getActionMethod().getTagSearch(), Object.class);
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口-创建标签失败:{}", r.getMsg());
|
|
|
|
|
throw new ServiceException("请求数云接口-创建标签失败");
|
|
|
|
|
}
|
|
|
|
|
return JSON.parseObject(r.getData().toString(), new TypeReference<List<ShuYunGroupTag>>() {
|
|
|
|
|
});
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-创建标签失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-创建标签失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除标签
|
|
|
|
|
* https://open.shuyun.com/#/apidoc?type=23&apiId=153
|
|
|
|
|
*/
|
|
|
|
|
public static R tagDelete(String tagId) {
|
|
|
|
|
Map<String, String> params = MapUtil.newHashMap();
|
|
|
|
|
params.put("tagId", tagId);
|
|
|
|
|
try {
|
|
|
|
|
R r = httpBodyParamsRequest(HttpMethod.DELETE, params,
|
|
|
|
|
shuYunConfig.getActionMethod().getTagDelete(), Object.class);
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口-删除标签失败:{}", r.getMsg());
|
|
|
|
|
throw new ServiceException("请求数云接口-删除标签失败");
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-删除标签失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-删除标签失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改标签
|
|
|
|
|
* https://open.shuyun.com/#/apidoc?type=23&apiId=198
|
|
|
|
|
*/
|
|
|
|
|
public static R tagUpdate(ShuYunTag shuYunTag) {
|
|
|
|
|
try {
|
|
|
|
|
R r = httpBodyParamsRequest(HttpMethod.PUT, shuYunTag,
|
|
|
|
|
shuYunConfig.getActionMethod().getTagUpdate(), Object.class);
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口-修改标签失败:{}", r.getMsg());
|
|
|
|
|
throw new ServiceException("请求数云接口-修改标签失败");
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-修改标签失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-修改标签失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 给客户打上单个标签
|
|
|
|
|
*/
|
|
|
|
|
public static R markUserTag(ShuYunUserTagReq shuYunUserTagReq) {
|
|
|
|
|
try {
|
|
|
|
|
R r = httpBodyParamsRequest(HttpMethod.POST, shuYunUserTagReq,
|
|
|
|
|
shuYunConfig.getActionMethod().getMarkUserTag(), Object.class);
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口-给客户打上单个标签失败:{}", r.getMsg());
|
|
|
|
|
throw new ServiceException("请求数云接口-给客户打上单个标签失败");
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-给客户打上单个标签失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-给客户打上单个标签失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询客户已经被打上的标签
|
|
|
|
|
*/
|
|
|
|
|
public static List<ShuYunTagResponse> searchUserTag(String tagType, String platCode, String shopId, String platAccount, String allValueType) {
|
|
|
|
|
Map<String, Object> params = MapUtil.newHashMap();
|
|
|
|
|
// 标签类型:0:云标签, 1:自定义标签
|
|
|
|
|
params.put("tagType", tagType);
|
|
|
|
|
// 平台代码
|
|
|
|
|
params.put("platCode", platCode);
|
|
|
|
|
// 店铺ID(数云内部店铺ID)
|
|
|
|
|
params.put("shopId", shopId);
|
|
|
|
|
// 平台账号
|
|
|
|
|
params.put("platAccount", platAccount);
|
|
|
|
|
// 标签显示:true(全部标签);false(基本标签)
|
|
|
|
|
params.put("allValueType", allValueType);
|
|
|
|
|
try {
|
|
|
|
|
R r = httpQueryParamsRequest(HttpMethod.GET, params,
|
|
|
|
|
shuYunConfig.getActionMethod().getSearchUserTag(), Object.class);
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口-查询客户已经被打上的标签失败:{}", r.getMsg());
|
|
|
|
|
throw new ServiceException("请求数云接口-查询客户已经被打上的标签标签失败");
|
|
|
|
|
}
|
|
|
|
|
return JSON.parseObject(r.getData().toString(), new TypeReference<List<ShuYunTagResponse>>() {
|
|
|
|
|
});
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-查询客户已经被打上的标签失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-查询客户已经被打上的标签失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除客户已经被打上的标签
|
|
|
|
|
*/
|
|
|
|
|
public static R deleteUserTag(String platCode, String shopId, String platAccount, Integer tagId) {
|
|
|
|
|
Map<String, Object> params = MapUtil.newHashMap();
|
|
|
|
|
// 平台代码
|
|
|
|
|
params.put("platCode", platCode);
|
|
|
|
|
// 店铺ID(数云内部店铺ID)
|
|
|
|
|
params.put("shopId", shopId);
|
|
|
|
|
// 平台账号
|
|
|
|
|
params.put("platAccount", platAccount);
|
|
|
|
|
// 标签ID
|
|
|
|
|
params.put("tagId", tagId);
|
|
|
|
|
try {
|
|
|
|
|
R r = httpBodyParamsRequest(HttpMethod.DELETE, params,
|
|
|
|
|
shuYunConfig.getActionMethod().getDeleteUserTag(), Object.class);
|
|
|
|
|
if (r.getCode() == ShuYunHttpStatusConstants.HALF_SUCCESS) {
|
|
|
|
|
logger.error("请求数云接口-删除客户已经被打上的标签失败:{}", r.getMsg());
|
|
|
|
|
throw new ServiceException("请求数云接口-删除客户已经被打上的标签失败");
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("请求数云接口-删除客户已经被打上的标签失败:{}", e.getMessage());
|
|
|
|
|
throw new ServiceException("请求数云接口-删除客户已经被打上的标签失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|