Authored by gemingdan

Merge branch 'gray'

package com.yoho.unions.common.redis;
import com.yoho.core.redis.cluster.annotation.Redis;
import com.yoho.core.redis.cluster.operations.nosync.YHHashOperations;
import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.unions.common.utils.SerializeUtils;
import com.yoho.unions.helper.CacheKeyHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* Created by mingdan.ge on 2020/7/6.
*/
@Component
public class UnionRedisHashCache {
private final static Logger logger = LoggerFactory.getLogger(UnionRedisHashCache.class);
@Redis("yohoUnionNoSyncRedis")
YHHashOperations hashOperations;
@Redis("yohoUnionNoSyncRedis")
YHRedisTemplate yHRedisTemplate;
/**
* 获取所有的values
*
* @param key 缓存key
* @param clazz 转换的对象类型
* @return
*/
public <T> List<T> values(String key, Class<T> clazz) {
logger.debug("Enter values hashOperation redis value. key is {}, clazz is {}", key, clazz);
try {
if (StringUtils.isBlank(key)) {
return null;
}
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance().appendFixed(key);
List<String> valueList = hashOperations.values(redisKeyBuilder);
logger.debug("values hashOperation value list size is {}", valueList == null ? 0 : valueList.size());
if (CollectionUtils.isEmpty(valueList)) {
return null;
}
List<T> list = new ArrayList<>();
for (String str : valueList) {
list.add(SerializeUtils.string2Value(str, clazz));
}
return list;
} catch (Exception e) {
logger.warn("values hashOperation redis failed. key is {}, error msg is {}", key, e.getMessage());
}
return null;
}
/**
* 根据key和hashkey获取数据
*
* @param cacheKey key前缀
* @param obj key后缀
* @param hashKey
* @param clazz
* @param <T>
* @return
*/
public <T> T get(String cacheKey,Object obj, String hashKey, Class<T> clazz) {
try {
if (StringUtils.isEmpty(cacheKey) || StringUtils.isEmpty(hashKey)) {
return null;
}
logger.info("UnionRedisHashCache get ,cacheKey is: {},obj is: {},hashkey {}", cacheKey,obj, hashKey);
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance().appendFixed(cacheKey).appendVar(obj);
String value = this.hashOperations.get(redisKeyBuilder, hashKey);
if (StringUtils.isEmpty(value)) {
return null;
}
return CacheKeyHelper.string2Value(value, clazz);
} catch (Exception e) {
logger.warn("UnionRedisHashCache get failed!!! cacheKey is: {},obj is: {},hashkey is {},e is {}", cacheKey,obj, hashKey,e);
}
return null;
}
/**
* 根据key获取hash数据size
*
* @param cacheKey key前缀
* @param obj key后缀
* @return size
*/
public int size(String cacheKey,Object obj) {
try {
if (StringUtils.isEmpty(cacheKey)) {
return 0;
}
logger.info("UnionRedisHashCache get size,cacheKey is: {},obj is: {}", cacheKey,obj);
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance().appendFixed(cacheKey).appendVar(obj);
Long size = this.hashOperations.size(redisKeyBuilder);
if (size == null||size<0) {
return 0;
}
return size.intValue();
} catch (Exception e) {
logger.warn("UnionRedisHashCache get size failed!!! cacheKey is: {},obj is: {},e is {}", cacheKey,obj,e);
}
return 0;
}
/**
* 存储hash结构数据
*
* @param cacheKey key前缀
* @param obj key后缀
* @param hashKey
* @param value
* @param timeout
* @param unit
* @param <T>
*/
public <T> void put(String cacheKey,Object obj, String hashKey, T value, long timeout, TimeUnit unit) {
try {
if (StringUtils.isEmpty(cacheKey) || StringUtils.isEmpty(hashKey)) {
logger.warn("UnionRedisHashCache put failed!!! cacheKey is: {},obj is: {},hashkey {}", cacheKey,obj, hashKey);
return;
}
String v = CacheKeyHelper.value2String(value);
if (StringUtils.isEmpty(v)) {
logger.warn("UnionRedisHashCache put failed!!! value {}", v);
return;
}
logger.info("UnionRedisHashCache put, cacheKey is: {},obj is: {},hashkey is {},value is {}", cacheKey,obj, hashKey,value);
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance().appendFixed(cacheKey).appendVar(obj);
this.hashOperations.put(redisKeyBuilder, hashKey, v);
this.yHRedisTemplate.longExpire(redisKeyBuilder, timeout, unit);
} catch (Exception e) {
logger.warn("UnionRedisHashCache put failed!!! cacheKey is: {},obj is: {},hashkey is {},value is {},e is {}", cacheKey,obj, hashKey,value,e);
}
}
/**
* 清除
*
* @param cacheKey key前缀
* @param obj key后缀
* @param hashKey
*/
public void delete(String cacheKey,Object obj, String... hashKey) {
logger.debug("Enter delete hash redis value. cacheKey is {}, hashKey is {}", cacheKey, hashKey);
try {
if(null == cacheKey ){
return ;
}
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance().appendFixed(cacheKey).appendVar(obj);
if (null == hashKey || 0 == hashKey.length) {
this.yHRedisTemplate.delete(redisKeyBuilder);
} else {
String[] hkey = new String[hashKey.length];
for (int i = 0; i < hashKey.length; i++) {
hkey[i] = hashKey[i];
}
this.hashOperations.delete(redisKeyBuilder, hkey);
}
} catch (Exception e) {
logger.warn("Redis exception. hash redis delete . cacheKey is {},obj is {}, hashKey is {}, exception msg is {}", cacheKey, obj,hashKey, e.getMessage());
}
}
}
... ...
package com.yoho.unions.common.redis;
import com.alibaba.fastjson.JSON;
import com.yoho.core.redis.cluster.annotation.Redis;
import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate;
import com.yoho.core.redis.cluster.operations.nosync.YHValueOperations;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
/**
* Created by mingdan.ge on 2020/7/6.
*/
@Component
public class UnionRedisValueCache {
private final static Logger log = LoggerFactory.getLogger(UnionRedisValueCache.class);
@Redis("yohoUnionNoSyncRedis")
YHValueOperations yhValueOperations;
@Redis("yohoUnionNoSyncRedis")
YHRedisTemplate yHRedisTemplate;
/**
* longExpire
* @param key
* @param time
* @param unit
* @return
*/
public boolean longExpire(String key,long time,TimeUnit unit){
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance().appendFixed(key);
return this.yHRedisTemplate.longExpire(redisKeyBuilder, time, unit);
}
/**
* delete
* @param key
* @return
*/
public void delete(String key) {
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance().appendFixed(key);
yHRedisTemplate.delete(redisKeyBuilder);
}
/**
* 设置
* @param key
* @param value
*/
public <T> void set(String key, T value ,long timeout, TimeUnit unit) {
try {
String v = RedisUtil.value2String(value);
if (v == null) {
return;
}
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance().appendFixed(key);
yhValueOperations.set(redisKeyBuilder, v, timeout, unit);
}catch (Exception e){
log.warn("UnionRedisValueCache exception. value redis set . key is {}, value is {}, error msg is {}", key, value, e.getMessage());
}
}
/**
* 设置
* @param key
* @param value
*/
public <T> boolean setIfAbsent(String key, T value) {
String v = RedisUtil.value2String(value);
if (v == null) {
return false;
}
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance().appendFixed(key);
return yhValueOperations.setIfAbsent(redisKeyBuilder, v);
}
/**
* 获取值
* @param key
* @param clazz
* @return
*/
public <T> T get(Object key, Class<T> clazz) {
try {
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance().appendFixed(key);
String v = yhValueOperations.get(redisKeyBuilder);
if (v == null) {
return null;
}
return RedisUtil.string2Value(v, clazz);
}catch (Exception e){
log.warn("get UnionRedisValueCache value operation failed. key is {}, error msg is {}", key, e.getMessage());
}
return null;
}
/**
* increment
* @param key
* @param delta
* @return
*/
public Long increment(String key, long delta) {
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance().appendFixed(key);
return yhValueOperations.increment(redisKeyBuilder, delta);
}
public static <T> T string2Value(String value, Class<T> clazz) {
if (StringUtils.isEmpty(value)) {
return null;
}
if (clazz.getName().equalsIgnoreCase("java.lang.String")) {
return (T) value;
}
return (T) JSON.parseObject(value, clazz);
}
}
... ...
... ... @@ -134,6 +134,9 @@ public class UnionRebateRest {
return result;
}
/**
* 查询所有配置的brand-后台
* */
@RequestMapping("/queryAllBrandList")
@ResponseBody
public JSONArray queryAllBrandList(){
... ...
... ... @@ -2,7 +2,7 @@ package com.yoho.unions.server.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yoho.unions.common.constant.CallBackConstant;
import com.yoho.unions.common.redis.GlobalRedisValueCache;
import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.common.utils.HttpUtils;
import com.yoho.unions.dal.model.UnionCallbackOrder;
... ... @@ -23,7 +23,7 @@ public class TouTiaoOrderCallBackServiceImpl extends OrderCallBackServiceImpl{
static Logger log = LoggerFactory.getLogger(TouTiaoOrderCallBackServiceImpl.class);
@Resource
GlobalRedisValueCache globalRedisValueCache;
RedisValueCache redisValueCache;
@Override
public void callback(UnionCallbackOrder order){
... ... @@ -36,7 +36,7 @@ public class TouTiaoOrderCallBackServiceImpl extends OrderCallBackServiceImpl{
log.warn("touTiaoOrder.callback end,callbackurl is null,redis key is null,order is {}.",order);
return;
}
String callbackurl = globalRedisValueCache.get(key, String.class);
String callbackurl = redisValueCache.get(key, String.class);
if (StringUtils.isBlank(callbackurl)) {
log.warn("touTiaoOrder.callback end,callbackurl is null,redis key is {},ordercode is {}.",key, order.getOrderCode());
return;
... ...
... ... @@ -4,9 +4,8 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yoho.unions.common.constant.CallBackConstant;
import com.yoho.unions.common.redis.GlobalRedisValueCache;
import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.common.utils.HttpUtils;
import org.apache.commons.lang.StringUtils;
... ... @@ -32,7 +31,7 @@ public class TouTiaoServiceImpl extends UnionServiceImpl implements IUnionServic
private static final String CL_KEY = "yh:union:cl:";
@Resource
GlobalRedisValueCache globalRedisValueCache;
RedisValueCache redisValueCache;
public ClickUnionRequestBO clickHttpRequestTOBO(HttpServletRequest request,ClickUnionRequestBO bo){
... ... @@ -103,9 +102,9 @@ public class TouTiaoServiceImpl extends UnionServiceImpl implements IUnionServic
private void addToRedis(ClickUnionRequestBO clickBO, ActivateUnionRequestBO activateUnionRequestBO) {
log.info("Toutiao addToRedis.idfa is {},udid is {},callback is {}.",activateUnionRequestBO.getIdfa(),activateUnionRequestBO.getUdid(),clickBO.getCallbackurl());
if (StringUtils.isNotBlank(activateUnionRequestBO.getIdfa())) {
globalRedisValueCache.set(CallBackConstant.TOUTIAO_CALLBACKURL_REDIS_KEY + activateUnionRequestBO.getIdfa(), clickBO.getCallbackurl(), 7 * 24 * 3600, TimeUnit.SECONDS);
redisValueCache.set(CallBackConstant.TOUTIAO_CALLBACKURL_REDIS_KEY + activateUnionRequestBO.getIdfa(), clickBO.getCallbackurl(), 7 * 24 * 3600, TimeUnit.SECONDS);
} else if (StringUtils.isNotBlank(activateUnionRequestBO.getUdid())) {
globalRedisValueCache.set(CallBackConstant.TOUTIAO_CALLBACKURL_REDIS_KEY + activateUnionRequestBO.getUdid(), clickBO.getCallbackurl(), 7 * 24 * 3600, TimeUnit.SECONDS);
redisValueCache.set(CallBackConstant.TOUTIAO_CALLBACKURL_REDIS_KEY + activateUnionRequestBO.getUdid(), clickBO.getCallbackurl(), 7 * 24 * 3600, TimeUnit.SECONDS);
}
//调用成功需要保存点击数据用于其他类型时间回调,例如次留
String dateStr = DateUtil.getToday( "MMdd");
... ...
... ... @@ -13,15 +13,13 @@ import com.netflix.config.DynamicIntProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.yoho.core.common.utils.MD5;
import com.yoho.core.config.ConfigReader;
import com.yoho.core.redis.cluster.annotation.Redis;
import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate;
import com.yoho.error.event.DeviceActiveEvent;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.union.UnionTypeModel;
import com.yoho.service.model.union.request.*;
import com.yoho.service.model.union.response.*;
import com.yoho.unions.common.enums.ClientTypeEnum;
import com.yoho.unions.common.redis.RedisListCache;
import com.yoho.unions.common.redis.GlobalRedisValueCache;
import com.yoho.unions.common.redis.RedisTemplate;
import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.common.service.IBusinessExportService;
... ... @@ -89,15 +87,8 @@ public class UnionServiceImpl implements IUnionService, IBusinessExportService,
// @Redis("yohoNoSyncRedis")
// RedisTemplate yHRedisTemplate;
// @Redis("yohoNoSyncRedis")
// YHValueOperations yhValueOperations;
// @Redis("yohoNoSyncRedis")
// RedisValueCache yhValueOperations;
@Autowired
RedisTemplate redisTemplate;
@Autowired
RedisValueCache yhValueOperations;
@Value("${exclude.union.type:100000000000349}")
private String EXCLUDE_UNION_TYPE;
... ... @@ -117,9 +108,8 @@ public class UnionServiceImpl implements IUnionService, IBusinessExportService,
@Resource
RedisValueCache redisValueCache;
@Resource
RedisListCache redisListCache;
GlobalRedisValueCache globalRedisValueCache;
@Resource
IMktMarketingUrlDAO mktMarketingUrlDAO;
... ... @@ -1558,7 +1548,7 @@ public class UnionServiceImpl implements IUnionService, IBusinessExportService,
private boolean getDistributeLock(String unionType, String deviceType) {
String key = UNION_KEY + "NX:" + unionType + ":" + deviceType;
try {
boolean lock = yhValueOperations.setIfAbsent(key, "lock");
boolean lock = globalRedisValueCache.setIfAbsent(key, "lock");
if (!lock) {
return false;
}
... ...
... ... @@ -283,6 +283,7 @@ public class UnionShareRebateServiceImpl implements IUnionShareRebateService,IBu
skns.add(r.getSkn());
brands.add(r.getBrand());
});
//redis
List<UnionShareRebateSkn> sknList=unionShareRebateSknMapper.selectListBySkns(skns);
List<UnionShareRebateBrand> brandList=unionShareRebateBrandMapper.selectListByBrands(brands);
Map<Integer, UnionShareRebateSkn> sknMap = sknList.stream().collect(Collectors.toMap(UnionShareRebateSkn::getSkn, skn -> skn));
... ... @@ -298,6 +299,7 @@ public class UnionShareRebateServiceImpl implements IUnionShareRebateService,IBu
@Override
public UnionSknRebateBo querySknRebate(UnionSknRebateBo bo) {
//redis
String rebatesRatioDefault=configReader.getString(NEW_USER_REBATES_RATIO_KEY, "6");
UnionSknRebateBo rebatePercent=getProductRebatePercentBo(bo.getSkn(), bo.getBrand(),false,null,null, rebatesRatioDefault);
return rebatePercent;
... ...
... ... @@ -16,10 +16,7 @@ import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.alibaba.fastjson.JSON;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.core.rest.exception.ServiceNotAvaibleException;
import com.yoho.core.rest.exception.ServiceNotFoundException;
import com.yoho.service.model.request.AreaReqBO;
import com.yoho.service.model.resource.ResourcesBO;
import com.yoho.service.model.resource.ResourcesServices;
... ... @@ -28,7 +25,7 @@ import com.yoho.service.model.response.AreaRspBo;
import com.yoho.service.model.union.bo.*;
import com.yoho.service.model.union.request.*;
import com.yoho.service.model.union.response.*;
import com.yoho.unions.common.redis.GlobalRedisValueCache;
import com.yoho.unions.common.redis.*;
import com.yoho.unions.common.service.IQNUploadService;
import com.yoho.unions.constant.SendModelEnum;
import com.yoho.unions.dal.*;
... ... @@ -37,10 +34,7 @@ import com.yoho.unions.helper.SendMessageHelper;
import com.yoho.unions.server.service.IUnionShareRebateService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.record.ContinueRecord;
import org.apache.poi.hssf.record.PageBreakRecord;
import org.elasticsearch.common.collect.Maps;
import org.omg.CORBA.OBJ_ADAPTER;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
... ... @@ -63,9 +57,6 @@ import com.yoho.unions.common.enums.BankEnum;
import com.yoho.unions.common.enums.ShareOrdersKeyEnum;
import com.yoho.unions.common.enums.ShareOrdersStatusEnum;
import com.yoho.unions.common.enums.SocialMediaTypeEnum;
import com.yoho.unions.common.redis.RedisHashCache;
import com.yoho.unions.common.redis.RedisTemplate;
import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.common.service.IBusinessExportService;
import com.yoho.unions.common.service.ISendSmsService;
import com.yoho.unions.common.utils.BankUtils;
... ... @@ -160,11 +151,11 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
IUnionShareRebateService unionShareRebateService;
@Resource
RedisValueCache redisValueCache;
@Resource
RedisTemplate redisTemplate;
UnionRedisValueCache unionRedisValueCache;
@Resource( name = "yhProducer")
private YhProducer yhProducer;
@Resource(name = "core-config-reader")
private ConfigReader configReader;
... ... @@ -175,7 +166,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
ServiceCaller serviceCaller;
@Autowired
private RedisHashCache redisHashCache;
private UnionRedisHashCache unionRedisHashCache;
@Autowired
private ISendSmsService sendSmsService;
... ... @@ -415,7 +406,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
updateReq.setStatus((byte) 0);
updateReq.setUpdateTime(DateUtil.getCurrentTimeSecond());
int result = unionShareUserBankMapper.updateByPrimaryKeySelective(updateReq);
redisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(),unionShareUserBank.getUid());
unionRedisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(),unionShareUserBank.getUid());
return result;
}
... ... @@ -545,7 +536,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
//审核不通过发短信--停用
// sendSmsService.smsSendByMobile(UNION_SHARE_USER_APPLY_REJECT_SMS_CONTENT, Lists.newArrayList(unionShareUserApply.getMobile()));
redisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),unionShareUserApply.getUid());
unionRedisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),unionShareUserApply.getUid());
return result;
} else {
//批量拒绝
... ... @@ -572,7 +563,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
// List<String> mobileList = unionShareUserApplies.stream().map(UnionShareUserApply::getMobile).collect(Collectors.toList());
// sendSmsService.smsSendByMobile(UNION_SHARE_USER_APPLY_REJECT_SMS_CONTENT, Lists.newArrayList(mobileList));
redisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),uids);
unionRedisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),uids);
return result;
}
}
... ... @@ -620,8 +611,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
// 绑定unionType
relateUnionType(unionShareUserApply.getUid(),req.getId(),unionShareUserApply.getInviterUnionType(), unionShareUserApply.getMobile());
}
redisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),unionShareUserApply.getUid());
redisHashCache.delete(ShareOrdersKeyEnum.INVITE_LIST.getPreKey(),unionShareUserApply.getUid());
unionRedisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),unionShareUserApply.getUid());
unionRedisHashCache.delete(ShareOrdersKeyEnum.INVITE_LIST.getPreKey(),unionShareUserApply.getUid());
return result;
} else {
//批量通过
... ... @@ -655,8 +646,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
} catch (Exception e) {
logger.error("relateUnionType error ,uid is {}",u.getUid());
}
redisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),u.getUid());
redisHashCache.delete(ShareOrdersKeyEnum.INVITE_LIST.getPreKey(),u.getUid());
unionRedisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),u.getUid());
unionRedisHashCache.delete(ShareOrdersKeyEnum.INVITE_LIST.getPreKey(),u.getUid());
});
logger.info("agreeApply end,req is {}", req);
return result;
... ... @@ -1073,8 +1064,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
newObj.setUpdateTime(newObj.getCreateTime());
unionShareUserInviteMapper.insertSelective(newObj);
//清缓存
redisHashCache.delete(ShareOrdersKeyEnum.INVITE_LIST.getPreKey(),inviterUid);
redisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),inviterUid,"shareTotal");
unionRedisHashCache.delete(ShareOrdersKeyEnum.INVITE_LIST.getPreKey(),inviterUid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),inviterUid,"shareTotal");
return;
}
//老用户更新粉丝注册有赚7天内订单统计数据
... ... @@ -1103,8 +1094,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
logger.info("updateInviterHistory end.inviterUid is {},unionShareUser is {},isNew is {},updateObj is {}.",inviterUid,unionShareUser,isNew,updateObj);
//清缓存
redisHashCache.delete(ShareOrdersKeyEnum.INVITE_LIST.getPreKey(),inviterUid);
redisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),inviterUid,"shareTotal");
unionRedisHashCache.delete(ShareOrdersKeyEnum.INVITE_LIST.getPreKey(),inviterUid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),inviterUid,"shareTotal");
}
@Database(ForceMaster = true)
... ... @@ -1519,7 +1510,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
if (result > 0) {
sendBankCardToErp(insertReq);
}
redisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(),bo.getUid());
unionRedisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(),bo.getUid());
return result;
}
... ... @@ -2722,7 +2713,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
logger.info("queryActivityByDate.date is {},type is {}.",date,type);
int dateInt=Integer.valueOf(DateUtil.getDateStrBySecond(date, "yyyyMMdd"));
String activitiesCache = getFromRedis(ShareOrdersKeyEnum.ACTIVITY_ING_LIST, dateInt, String.class, type.toString());
// String activitiesCache = redisValueCache.get(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey()+dateStr, String.class);
// String activitiesCache = unionRedisValueCache.get(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey()+dateStr, String.class);
List<UnionShareOrdersActivity> activities;
if (activitiesCache != null) {
activities = JSONObject.parseArray(activitiesCache, UnionShareOrdersActivity.class);
... ... @@ -2741,7 +2732,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
logger.info("queryActivityByDate.add to redis.value is {}",activities);
addToRedis(ShareOrdersKeyEnum.ACTIVITY_ING_LIST,dateInt,activities,type.toString());
// redisValueCache.set(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey()+dateStr,activities,ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getCacheTime(),TimeUnit.SECONDS);
// unionRedisValueCache.set(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey()+dateStr,activities,ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getCacheTime(),TimeUnit.SECONDS);
return activities;
}
//获取某时间段可参与活动的单数
... ... @@ -2847,10 +2838,10 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
String dateStr=DateUtil.getDateStrBySecond(DateUtil.getLastDayStartInt(0),"yyyyMMdd");
String date1Str=DateUtil.getDateStrBySecond(DateUtil.getLastDayStartInt(1),"yyyyMMdd");
String date7Str=DateUtil.getDateStrBySecond(DateUtil.getLastDayStartInt(7),"yyyyMMdd");
redisTemplate.delete(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey()+dateStr);
redisTemplate.delete(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey()+date1Str);
redisTemplate.delete(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey()+date7Str);
redisHashCache.delete(ShareOrdersKeyEnum.ACTIVITY.getPreKey(),activityId);
unionRedisValueCache.delete(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey()+dateStr);
unionRedisValueCache.delete(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey()+date1Str);
unionRedisValueCache.delete(ShareOrdersKeyEnum.ACTIVITY_ING_LIST.getPreKey()+date7Str);
unionRedisHashCache.delete(ShareOrdersKeyEnum.ACTIVITY.getPreKey(),activityId);
}
/**
... ... @@ -3921,31 +3912,31 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
//存入redis,注意param的顺序
public void addToRedis(ShareOrdersKeyEnum se, int key,Object value, String... param) {
redisHashCache.put(se.getPreKey(),key,se.getHashKey(param),value,se.getCacheTime(), TimeUnit.SECONDS);
unionRedisHashCache.put(se.getPreKey(),key,se.getHashKey(param),value,se.getCacheTime(), TimeUnit.SECONDS);
}
//从redis取数据
public <T> T getFromRedis(ShareOrdersKeyEnum se, int key,Class<T> clazz, String... param) {
return redisHashCache.get(se.getPreKey(), key, se.getHashKey(param), clazz);
return unionRedisHashCache.get(se.getPreKey(), key, se.getHashKey(param), clazz);
}
//从redis删数据
public void delFromRedis(ShareOrdersKeyEnum se, int key, String... param) {
if (param == null || param.length == 0) {
redisHashCache.delete(se.getPreKey(), key);
unionRedisHashCache.delete(se.getPreKey(), key);
} else {
redisHashCache.delete(se.getPreKey(), key, se.getHashKey(param));
unionRedisHashCache.delete(se.getPreKey(), key, se.getHashKey(param));
}
}
public void clearShareOrderRedis(int uid) {
//清缓存
logger.info("clearShareOrderRedis,uid is {}",uid);
redisHashCache.delete(ShareOrdersKeyEnum.ORDER_INFO.getPreKey(),uid);
redisHashCache.delete(ShareOrdersKeyEnum.ORDER_LIST.getPreKey(),uid);
redisHashCache.delete(ShareOrdersKeyEnum.SETTLEMENT_LIST.getPreKey(),uid);
redisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(),uid);
redisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),uid);
redisHashCache.delete(ShareOrdersKeyEnum.RECENTLY_ORDER_LIMIT_TEN.getPreKey(),uid);
redisHashCache.delete(ShareOrdersKeyEnum.INVITE_YOHO_LIST.getPreKey(),uid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.ORDER_INFO.getPreKey(),uid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.ORDER_LIST.getPreKey(),uid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.SETTLEMENT_LIST.getPreKey(),uid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(),uid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),uid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.RECENTLY_ORDER_LIMIT_TEN.getPreKey(),uid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.INVITE_YOHO_LIST.getPreKey(),uid);
}
@Override
... ... @@ -4256,9 +4247,9 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
date.forEach(d -> {
updateOneMonthData(promoteUid, d);
});
redisHashCache.delete(ShareOrdersKeyEnum.RANK_INFO.getPreKey(),promoteUid);
redisHashCache.delete(ShareOrdersKeyEnum.ORDER_STATISTICS_INFO.getPreKey(),promoteUid);
redisHashCache.delete(ShareOrdersKeyEnum.ESTIMATE_LIST.getPreKey(),promoteUid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.RANK_INFO.getPreKey(),promoteUid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.ORDER_STATISTICS_INFO.getPreKey(),promoteUid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.ESTIMATE_LIST.getPreKey(),promoteUid);
}
/**
... ... @@ -4273,9 +4264,9 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
updateOneMonthData(promoteUid, d);
});
}
redisHashCache.delete(ShareOrdersKeyEnum.RANK_INFO.getPreKey(),promoteUid);
redisHashCache.delete(ShareOrdersKeyEnum.ORDER_STATISTICS_INFO.getPreKey(),promoteUid);
redisHashCache.delete(ShareOrdersKeyEnum.ESTIMATE_LIST.getPreKey(),promoteUid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.RANK_INFO.getPreKey(),promoteUid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.ORDER_STATISTICS_INFO.getPreKey(),promoteUid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.ESTIMATE_LIST.getPreKey(),promoteUid);
}
... ... @@ -4358,7 +4349,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
if (bo.getNum() > -1) {
//不是手动执行,需要排除分布式其他机器已执行情况
UnionShareVirtualAddBo addBo=redisValueCache.get(VIRTUAL_ADD_KEY, UnionShareVirtualAddBo.class);
UnionShareVirtualAddBo addBo= unionRedisValueCache.get(VIRTUAL_ADD_KEY, UnionShareVirtualAddBo.class);
if (addBo == null) {
logger.info("dealWithVirtualUserTask end,query redis for virtual end.does not need");
return;
... ... @@ -4380,8 +4371,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
unionShareOrdersMonthMapper.updateByPrimaryKeySelective(un);
});
logger.info("dealWithVirtualUserTask.bo is {},today is {},clear redis",bo,date);
redisTemplate.delete(VIRTUAL_ADD_KEY);
redisHashCache.delete(ShareOrdersKeyEnum.RANK_LIST.getPreKey(),date);
unionRedisValueCache.delete(VIRTUAL_ADD_KEY);
unionRedisHashCache.delete(ShareOrdersKeyEnum.RANK_LIST.getPreKey(),date);
logger.info("dealWithVirtualUserTask.bo is {},today is {},clear redis end",bo,date);
}
... ... @@ -4394,7 +4385,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
addBo.setDate(date);
addBo.setTime(DateUtil.getCurrentTimeSecond());
logger.info("setVirtualAddToRedis.add to redis,addBo is {}",addBo);
redisValueCache.set(VIRTUAL_ADD_KEY,addBo,50,TimeUnit.HOURS);
unionRedisValueCache.set(VIRTUAL_ADD_KEY,addBo,50,TimeUnit.HOURS);
}
/**
... ... @@ -4424,7 +4415,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}else{
throw new ServiceException(ServiceError.UNION_IDENTITYCARD_EXIST_ERROR);
}
redisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(), bo.getUid());
unionRedisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(), bo.getUid());
return result;
}
... ... @@ -4474,7 +4465,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
@Override
public void reject(int uid) {
unionShareUserIdentityCardMapper.updateStatusByUid(uid);
redisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(), uid);
unionRedisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(), uid);
try {
sendMessageHelper.sendMessage(uid, 5, DateUtil.getCurrentTimeSecond(), null);
} catch (Exception e) {
... ... @@ -4484,7 +4475,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
private ResourcesBO getResourcesBO() {
// 从缓存查询
ResourcesBO resourcesCache=redisValueCache.get(ShareOrdersKeyEnum.IMG_RESOURCE_URL.getKey(),ResourcesBO.class);
ResourcesBO resourcesCache= unionRedisValueCache.get(ShareOrdersKeyEnum.IMG_RESOURCE_URL.getKey(),ResourcesBO.class);
if(resourcesCache!=null){
return resourcesCache;
}
... ... @@ -4498,7 +4489,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
bo = serviceCaller.call(ResourcesServices.getResourcesPrimaryHome, request, ResourcesBO.class);
logger.debug("UnionShareServiceImpl ResourcesBO bo{}",JSON.toJSONString(bo));
// 存缓存
redisValueCache.set(ShareOrdersKeyEnum.IMG_RESOURCE_URL.getKey(),bo,IMG_URL_EXPIRE_TIME,TimeUnit.SECONDS);
unionRedisValueCache.set(ShareOrdersKeyEnum.IMG_RESOURCE_URL.getKey(),bo,IMG_URL_EXPIRE_TIME,TimeUnit.SECONDS);
return bo;
}
... ...
... ... @@ -3,6 +3,10 @@ redis:
servers:
- 192.168.102.45:6379
auth: redis9646
yohoUnionNoSyncRedis :
servers:
- 192.168.102.45:6379
auth: redis9646
yohoGlobalRedis :
servers:
- 192.168.102.45:6379
... ...
... ... @@ -4,6 +4,12 @@ redis:
- ${redis.union.readonly.proxy.address}:${redis.union.readonly.proxy.port}
auth: ${redis.union.readonly.proxy.auth}
yohoUnionNoSyncRedis :
servers:
- ${redis.notsync.twemproxy.addresses}
auth: ${redis.notsync.twemproxy.auth}
timeout: 300
yohoGlobalRedis :
servers:
- ${redis.global.address}
... ...