瀏覽代碼

cache

release_toaliyun_real
xhxu 5 年之前
父節點
當前提交
6dd07e802e
共有 19 個檔案被更改,包括 497 行新增162 行删除
  1. +36
    -4
      mallinkAdmin/src/main/java/com/iformall/config/RedisConfig.java
  2. +2
    -2
      mallinkAdmin/src/main/java/com/iformall/config/ShiroConfig.java
  3. +5
    -6
      mallinkAdmin/src/main/resources/db/migration/V202007311200__FOR_MEMBER_ONLY_001.sql
  4. +36
    -0
      mallinkBApi/src/main/java/com/iformall/config/RedisConfig.java
  5. +36
    -0
      mallinkCApi/src/main/java/com/iformall/config/RedisConfig.java
  6. +19
    -16
      mallinkCApi/src/main/java/com/iformall/controller/WxUserGrantController.java
  7. +37
    -4
      mallinkCallback/src/main/java/com/iformall/config/RedisConfig.java
  8. +37
    -4
      mallinkMQConsumer/src/main/java/com/iformall/config/RedisConfig.java
  9. +37
    -0
      mallinkPosApi/src/main/java/com/iformall/config/RedisConfig.java
  10. +36
    -4
      mallinkSchedule/src/main/java/com/iformall/config/RedisConfig.java
  11. +1
    -1
      mallinkService/src/main/java/com/iformall/domain/po/WxCUser.java
  12. +4
    -0
      mallinkService/src/main/java/com/iformall/service/WxAppinfoService.java
  13. +1
    -1
      mallinkService/src/main/java/com/iformall/service/WxMallService.java
  14. +1
    -1
      mallinkService/src/main/java/com/iformall/service/impl/CUserTokenServiceImpl.java
  15. +83
    -0
      mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java
  16. +44
    -107
      mallinkService/src/main/java/com/iformall/service/impl/WxMallServiceImpl.java
  17. +9
    -4
      mallinkService/src/main/java/com/iformall/utils/Constant.java
  18. +36
    -4
      mallinkSysAdmin/src/main/java/com/iformall/config/RedisConfig.java
  19. +37
    -4
      mallinkWebSocketServer/src/main/java/com/iformall/config/RedisConfig.java

+ 36
- 4
mallinkAdmin/src/main/java/com/iformall/config/RedisConfig.java 查看文件

@@ -20,10 +20,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* Created by Stormeye on 2018/10/1.
@@ -177,6 +174,23 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("subMallListRedisTemplate")
public RedisTemplate<String, List<WxMall>> getSubMallListRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, List<WxMall>> template = new RedisTemplate<String, List<WxMall>>();

Jackson2JsonRedisSerializer<List> j = new Jackson2JsonRedisSerializer<List>(List.class);
// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("couponChannelRedisTemplate")
public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>();
@@ -247,4 +261,22 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("wxAppinfoRedisTemplate")
public RedisTemplate<String, WxAppinfo> getWxAppinfoRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, WxAppinfo> template = new RedisTemplate<>();

Jackson2JsonRedisSerializer<WxAppinfo> j = new Jackson2JsonRedisSerializer(WxAppinfo.class);

// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

}

+ 2
- 2
mallinkAdmin/src/main/java/com/iformall/config/ShiroConfig.java 查看文件

@@ -153,8 +153,8 @@ public class ShiroConfig {
//配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了
filterChainDefinitionMap.put("/logout", "authc");

filterChainDefinitionMap.put("/**", "corsFilter,token,authc");
// filterChainDefinitionMap.put("/**", "anon");
// filterChainDefinitionMap.put("/**", "corsFilter,token,authc");
filterChainDefinitionMap.put("/**", "anon");


shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);


+ 5
- 6
mallinkAdmin/src/main/resources/db/migration/V202007311200__FOR_MEMBER_ONLY_001.sql 查看文件

@@ -119,23 +119,22 @@ ALTER TABLE `wx_mall`
MODIFY COLUMN `img_url` varchar(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '商场图标' AFTER `service_phone`,
MODIFY COLUMN `img_url_h` varchar(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '商场图标_横' AFTER `img_url`;


--活动报名表 wx_activity_join(如果新旧会员同时报名一个活动会导致数据重复)
--用户车牌表 wx_c_user_car 新旧会员都绑定了同一车牌的情况
CREATE DEFINER=`root`@`%` PROCEDURE `cuser_old_to_new`(IN `oldCuserId` bigint,IN `newCuserId` bigint)
BEGIN
DECLARE err_flag INT DEFAULT FALSE;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET err_flag = TRUE;

UPDATE wx_c_user SET user_id = newCuserId WHERE user_id = oldCuserId ;
--活动报名表(如果新旧会员同时报名一个活动会导致数据重复)
--UPDATE wx_activity_join SET user_id = newCuserId WHERE user_id = oldCuserId ;
--会员标签表需单独做合并
--UPDATE wx_c_user_tags SET user_id = newCuserId WHERE user_id = oldCuserId ;
UPDATE wx_activity_join SET user_id = newCuserId WHERE user_id = oldCuserId ;
UPDATE wx_game_action_log SET user_id = newCuserId WHERE user_id = oldCuserId ;
UPDATE wx_order_group SET user_id = newCuserId WHERE user_id = oldCuserId ;
UPDATE wx_order_press SET user_id = newCuserId WHERE user_id = oldCuserId ;
UPDATE wx_question_log SET user_id = newCuserId WHERE user_id = oldCuserId ;

--新旧会员都绑定了同一车牌的情况
--UPDATE wx_c_user_car SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ;
UPDATE wx_c_user_car SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ;
UPDATE wx_c_user_from_b SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ;
UPDATE wx_coupon_order SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ;
UPDATE wx_credit_history SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ;


+ 36
- 0
mallinkBApi/src/main/java/com/iformall/config/RedisConfig.java 查看文件

@@ -24,6 +24,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
@@ -142,6 +143,23 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("subMallListRedisTemplate")
public RedisTemplate<String, List<WxMall>> getSubMallListRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, List<WxMall>> template = new RedisTemplate<String, List<WxMall>>();

Jackson2JsonRedisSerializer<List> j = new Jackson2JsonRedisSerializer<List>(List.class);
// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("couponChannelRedisTemplate")
public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>();
@@ -210,6 +228,24 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("wxAppinfoRedisTemplate")
public RedisTemplate<String, WxAppinfo> getWxAppinfoRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, WxAppinfo> template = new RedisTemplate<>();

Jackson2JsonRedisSerializer<WxAppinfo> j = new Jackson2JsonRedisSerializer(WxAppinfo.class);

// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("stringValueOperations")
public ValueOperations<String, String> getStringValueOperations(RedisConnectionFactory connectionFactory) {
StringRedisTemplate template = new StringRedisTemplate();


+ 36
- 0
mallinkCApi/src/main/java/com/iformall/config/RedisConfig.java 查看文件

@@ -23,7 +23,9 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
@@ -159,6 +161,23 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("subMallListRedisTemplate")
public RedisTemplate<String, List<WxMall>> getSubMallListRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, List<WxMall>> template = new RedisTemplate<String, List<WxMall>>();

Jackson2JsonRedisSerializer<List> j = new Jackson2JsonRedisSerializer<List>(List.class);
// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("couponDetailRedisTemplate")
public RedisTemplate<String, WxCouponCVo> getCouponDetailRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, WxCouponCVo> template = new RedisTemplate<String, WxCouponCVo>();
@@ -230,6 +249,23 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("wxAppinfoRedisTemplate")
public RedisTemplate<String, WxAppinfo> getWxAppinfoRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, WxAppinfo> template = new RedisTemplate<>();

Jackson2JsonRedisSerializer<WxAppinfo> j = new Jackson2JsonRedisSerializer(WxAppinfo.class);

// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("stringValueOperations")
public ValueOperations<String, String> getStringValueOperations(RedisConnectionFactory connectionFactory) {


+ 19
- 16
mallinkCApi/src/main/java/com/iformall/controller/WxUserGrantController.java 查看文件

@@ -159,6 +159,7 @@ public class WxUserGrantController extends BaseController {
// 通过authorizerInfo得到tenant_id
WxAuthorizerInfo wxAuthorizerInfo = null;
WxAppinfo wxAppinfo = null;
WxMall wxMall = null;
WxMaService wxMaService = null;

wxAuthorizerInfo = wxAuthorizerInfoService.getByAppId(appId);
@@ -169,8 +170,20 @@ public class WxUserGrantController extends BaseController {
return new ResultData(ErrorCode.APP_ID_NOT_ENABLE);
}

WxMall wxMall = mallService.getById(Long.valueOf(wxAuthorizerInfo.getTenantId()));
wxAppinfo = wxAppinfoService.getByAppIdFromRedis(appId);
if(wxAppinfo == null){
return new ResultData(ErrorCode.APP_ID_NOT_FOUND);
}
if(wxAppinfo.getEnable().equals(EnumEnableType.Enable.getCode())){
return new ResultData(ErrorCode.APP_ID_NOT_ENABLE);
}

wxMall = mallService.getByTenantId(wxAuthorizerInfo.getTenantId());
if(wxMall == null){
return new ResultData(ErrorCode.MALL_INFO_NOT_FOUND);
}
resultMap.put("selectedMall", wxMall.getTenantId());

// 集团版,获取子集团list
List<WxMall> mallList = null;
if(StringUtils.isNotBlank(wxMall.getParentTenantId())){
@@ -181,7 +194,7 @@ public class WxUserGrantController extends BaseController {
}
if(mallList != null && mallList.size() >0){
mallList.stream().forEach(cs -> {
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(cs.getTenantInfo(), EnumPayWay.PAY_WAY_WECHAT);
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cs.getTenantId(), EnumPayWay.PAY_WAY_WECHAT);
cs.setAppId(cAppInfo.getAppId());
});
resultMap.put("subMalls", JSON.toJSONString(mallList));
@@ -190,28 +203,18 @@ public class WxUserGrantController extends BaseController {
if (isFmOpen) {
wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId);
} else {
wxAppinfo = getAppInfo(appId);
if (wxAppinfo == null) {
return new ResultData(ErrorCode.APP_ID_NOT_FOUND);
}
if (!wxAppinfo.getEnable().equals(EnumEnableType.Enable.getCode())) {
return new ResultData(ErrorCode.APP_ID_NOT_ENABLE);
}
wxMaService = getWeappServiceByAppInfo(wxAppinfo);

if (StringUtils.isBlank(wxAppinfo.getAccessToken())) {
// 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用
updateAppAccessToken(wxAppinfo, wxMaService);
wxMaService = getWeappServiceByAppInfo(wxAppinfo);

} else {
// 检查token是否已过期, 1小时就重新获取
Date curDate = new Date();
if (curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.H_EXPIRE) {
updateAppAccessToken(wxAppinfo, wxMaService);
wxMaService = getWeappServiceByAppInfo(wxAppinfo);
}
}
wxMaService = getWeappServiceByAppInfo(wxAppinfo);
}

String token = null;
@@ -248,7 +251,7 @@ public class WxUserGrantController extends BaseController {
String ipaddress = IPUtil.getIpAddr(request);

WxCUser newUser = new WxCUser();
newUser.updateTenantInfo(wxAuthorizerInfo);
newUser.updateTenantInfo(wxMall.getTenantInfo());
newUser.setAppId(appId);
newUser.setOpenId(openId);
if (boolHaveUnionId) {
@@ -259,7 +262,7 @@ public class WxUserGrantController extends BaseController {
if (boolHaveUnionId) {
// 优先根据unionId查询
WxCUser userQ = new WxCUser();
userQ.updateTenantInfo(wxAuthorizerInfo);
userQ.updateTenantInfo(wxMall.getTenantInfo());
userQ.setUnionId(unionId);
oldUser = wxCUserService.getByObject(userQ);
if(oldUser != null) {
@@ -346,7 +349,7 @@ public class WxUserGrantController extends BaseController {
resultMap.put("score", score);
} else {
// 新用户
newUser.updateTenantInfo(wxAuthorizerInfo);
newUser.updateTenantInfo(wxMall.getTenantInfo());
if(StringUtils.isNotBlank(wxMall.getParentTenantId())){
newUser.setParentTenantId(wxMall.getParentTenantId());
}


+ 37
- 4
mallinkCallback/src/main/java/com/iformall/config/RedisConfig.java 查看文件

@@ -20,10 +20,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* Created by Stormeye on 2018/10/1.
@@ -194,6 +191,23 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("subMallListRedisTemplate")
public RedisTemplate<String, List<WxMall>> getSubMallListRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, List<WxMall>> template = new RedisTemplate<String, List<WxMall>>();

Jackson2JsonRedisSerializer<List> j = new Jackson2JsonRedisSerializer<List>(List.class);
// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("couponChannelRedisTemplate")
public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>();
@@ -245,4 +259,23 @@ public class RedisConfig extends CachingConfigurerSupport {
template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("wxAppinfoRedisTemplate")
public RedisTemplate<String, WxAppinfo> getWxAppinfoRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, WxAppinfo> template = new RedisTemplate<>();

Jackson2JsonRedisSerializer<WxAppinfo> j = new Jackson2JsonRedisSerializer(WxAppinfo.class);

// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

}

+ 37
- 4
mallinkMQConsumer/src/main/java/com/iformall/config/RedisConfig.java 查看文件

@@ -20,10 +20,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* Created by Stormeye on 2018/10/1.
@@ -179,6 +176,23 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("subMallListRedisTemplate")
public RedisTemplate<String, List<WxMall>> getSubMallListRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, List<WxMall>> template = new RedisTemplate<String, List<WxMall>>();

Jackson2JsonRedisSerializer<List> j = new Jackson2JsonRedisSerializer<List>(List.class);
// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("couponChannelRedisTemplate")
public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>();
@@ -231,4 +245,23 @@ public class RedisConfig extends CachingConfigurerSupport {
template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("wxAppinfoRedisTemplate")
public RedisTemplate<String, WxAppinfo> getWxAppinfoRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, WxAppinfo> template = new RedisTemplate<>();

Jackson2JsonRedisSerializer<WxAppinfo> j = new Jackson2JsonRedisSerializer(WxAppinfo.class);

// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

}

+ 37
- 0
mallinkPosApi/src/main/java/com/iformall/config/RedisConfig.java 查看文件

@@ -22,6 +22,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
@@ -157,6 +158,23 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("subMallListRedisTemplate")
public RedisTemplate<String, List<WxMall>> getSubMallListRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, List<WxMall>> template = new RedisTemplate<String, List<WxMall>>();

Jackson2JsonRedisSerializer<List> j = new Jackson2JsonRedisSerializer<List>(List.class);
// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("couponChannelRedisTemplate")
public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>();
@@ -209,4 +227,23 @@ public class RedisConfig extends CachingConfigurerSupport {
template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("wxAppinfoRedisTemplate")
public RedisTemplate<String, WxAppinfo> getWxAppinfoRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, WxAppinfo> template = new RedisTemplate<>();

Jackson2JsonRedisSerializer<WxAppinfo> j = new Jackson2JsonRedisSerializer(WxAppinfo.class);

// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

}

+ 36
- 4
mallinkSchedule/src/main/java/com/iformall/config/RedisConfig.java 查看文件

@@ -20,10 +20,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* Created by Stormeye on 2018/10/1.
@@ -179,6 +176,23 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("subMallListRedisTemplate")
public RedisTemplate<String, List<WxMall>> getSubMallListRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, List<WxMall>> template = new RedisTemplate<String, List<WxMall>>();

Jackson2JsonRedisSerializer<List> j = new Jackson2JsonRedisSerializer<List>(List.class);
// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("couponChannelRedisTemplate")
public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>();
@@ -232,4 +246,22 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("wxAppinfoRedisTemplate")
public RedisTemplate<String, WxAppinfo> getWxAppinfoRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, WxAppinfo> template = new RedisTemplate<>();

Jackson2JsonRedisSerializer<WxAppinfo> j = new Jackson2JsonRedisSerializer(WxAppinfo.class);

// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

}

+ 1
- 1
mallinkService/src/main/java/com/iformall/domain/po/WxCUser.java 查看文件

@@ -140,7 +140,7 @@ public class WxCUser extends BaseCUserEntity {
//生成一个token
this.setToken(UUID.randomUUID().toString()+Constant.TOKEN_WXC_END);
//过期时间
this.setExpireTime(new Date(currentDate.getTime() + Constant.EXPIRE));
this.setExpireTime(new Date(currentDate.getTime() + Constant.S_D_EXPIRE));
}
return this.getToken();
}


+ 4
- 0
mallinkService/src/main/java/com/iformall/service/WxAppinfoService.java 查看文件

@@ -77,4 +77,8 @@ public interface WxAppinfoService {
*/
void deleteById(Long id);

WxAppinfo getByAppIdFromRedis(String appId);
WxAppinfo getByIdFromRedis(Long id);

WxAppinfo getCAppInfoFromRedis(String tenantId, EnumPayWay payWayWechat);
}

+ 1
- 1
mallinkService/src/main/java/com/iformall/service/WxMallService.java 查看文件

@@ -67,7 +67,6 @@ public interface WxMallService {

WxMall getByTenantInfoExt(TenantEntity tenantEntity);

@Deprecated
WxMall getByTenantId(String id);

@Deprecated
@@ -83,4 +82,5 @@ public interface WxMallService {
void undateSubmall(String parentTenantId, List<String> tenantIds);

List<WxMall> listAsSelectMall(Long id);

}

+ 1
- 1
mallinkService/src/main/java/com/iformall/service/impl/CUserTokenServiceImpl.java 查看文件

@@ -46,7 +46,7 @@ public class CUserTokenServiceImpl implements CUserTokenService {
user = wxCUserMapper.findByToken(token);
}
// 插入缓存
operations.set(key, user, 3600, TimeUnit.SECONDS);
operations.set(key, user, 7, TimeUnit.DAYS);
logger.info("DB中获取用户信息End-" + token);
return user;
}


+ 83
- 0
mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java 查看文件

@@ -11,12 +11,17 @@ import com.iformall.enums.EnumAppType;
import com.iformall.enums.EnumPayWay;
import com.iformall.mapper.WxAppinfoMapper;
import com.iformall.service.WxAppinfoService;
import com.iformall.utils.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class WxAppinfoServiceImpl implements WxAppinfoService {
@@ -25,6 +30,10 @@ public class WxAppinfoServiceImpl implements WxAppinfoService {
@Autowired
WxAppinfoMapper wxAppinfoMapper;

@Autowired
@Qualifier("wxAppinfoRedisTemplate")
RedisTemplate<String, WxAppinfo> wxAppinfoRedisTemplate;

@Override
public WxAppinfo getCAppInfo(TenantEntity tenantEntity,EnumPayWay payWay) {
WxAppinfo appInfo = null;
@@ -91,12 +100,86 @@ public class WxAppinfoServiceImpl implements WxAppinfoService {
record.setId(idWorker.nextId());
wxAppinfoMapper.insert(record);
} else {
this.deleteRedis(record.getId());
wxAppinfoMapper.updateById(record);
}
}

@Override
public void deleteById(Long id) {
this.deleteRedis(id);
wxAppinfoMapper.deleteById(id);
}

@Override
public WxAppinfo getByAppIdFromRedis(String appId) {
WxAppinfo record = null;
String key = Constant.appinfoPrev + appId;
ValueOperations<String, WxAppinfo> operations = wxAppinfoRedisTemplate.opsForValue();

if(wxAppinfoRedisTemplate.hasKey(key)){
record = operations.get(key);
return record;
}
record = this.getByAppId(appId);
if(record != null){
operations.set(key, record, 7, TimeUnit.DAYS);
}
return record;
}

@Override
public WxAppinfo getByIdFromRedis(Long id) {
WxAppinfo record = null;
String key = Constant.appinfoPrev + id;
ValueOperations<String, WxAppinfo> operations = wxAppinfoRedisTemplate.opsForValue();

if(wxAppinfoRedisTemplate.hasKey(key)){
record = operations.get(key);
return record;
}
record = this.getById(id);
if(record != null){
operations.set(key, record, 7, TimeUnit.DAYS);
}
return record;
}

@Override
public WxAppinfo getCAppInfoFromRedis(String tenantId, EnumPayWay payWayWechat) {
WxAppinfo record = null;
String key = Constant.appinfoPrev + tenantId + "-" + payWayWechat.getPlat()
+ "-" + EnumAppType.C.getCode();
ValueOperations<String, WxAppinfo> operations = wxAppinfoRedisTemplate.opsForValue();
if(wxAppinfoRedisTemplate.hasKey(key)){
record = operations.get(key);
return record;
}
record = this.getCAppInfo(new TenantEntity() {{
setTenantId(tenantId);
}}, payWayWechat);
if(record != null){
operations.set(key, record, 7, TimeUnit.DAYS);
}
return record;
}

private void deleteRedis(Long id){
WxAppinfo record = this.getById(id);
if(record != null){
String key1 = Constant.appinfoPrev + record.getAppId();
if(wxAppinfoRedisTemplate.hasKey(key1)){
wxAppinfoRedisTemplate.delete(key1);
}
String key2 = Constant.appinfoPrev + record.getId();
if(wxAppinfoRedisTemplate.hasKey(key2)){
wxAppinfoRedisTemplate.delete(key2);
}
String key3 = Constant.appinfoPrev + record.getTenantId()
+ "-" + record.getPlat() + "-" + record.getType();
if(wxAppinfoRedisTemplate.hasKey(key3)){
wxAppinfoRedisTemplate.delete(key3);
}
}
}
}

+ 44
- 107
mallinkService/src/main/java/com/iformall/service/impl/WxMallServiceImpl.java 查看文件

@@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import com.iformall.common.IdWorker;

import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -44,6 +43,10 @@ public class WxMallServiceImpl implements WxMallService {
@Qualifier("mallRedisTemplate")
RedisTemplate<String, WxMall> mallRedisTemplate;

@Autowired
@Qualifier("subMallListRedisTemplate")
RedisTemplate<String, List<WxMall>> subMallListRedisTemplate;

@Override
public String wxMallInit(WxProjectConfig wxProjectConfig) {

@@ -92,116 +95,38 @@ public class WxMallServiceImpl implements WxMallService {

@Override
public WxMall getById(Long id) {
String key = getRedisKeyByTenantInfo(new TenantEntity(){{
setTenantId(String.valueOf(id));
}});
ValueOperations<String, WxMall> operations = mallRedisTemplate.opsForValue();

// 缓存
boolean hasKey = mallRedisTemplate.hasKey(key);
if(hasKey) {
// 从缓存获取用户信息
WxMall mall = operations.get(key);
return mall;
}
WxMall mall = wxMallMapper.selectById(id);
// 插入缓存
logger.info("getById: " + mall.toString());
operations.set(key, mall, 3600, TimeUnit.SECONDS);
return mall;
return this.getByTenantId(String.valueOf(id));
}

@Override
public int save(WxMall record) {
// if (record.getId() == null) {
// //record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
// final IdWorker idWorker = IdWorker.get();
// Long id = idWorker.nextId();
// record.setId(id);
// }
//
// if(StringUtils.isBlank(record.getTenantId())) {
// record.setTenantId(String.valueOf(record.getId()));
// }

int ret = wxMallMapper.insert(record);

String key = getRedisKeyByTenantInfo(record.getTenantInfo());
// 缓存已存在,删除
boolean hasKey = mallRedisTemplate.hasKey(key);
if(hasKey) {
mallRedisTemplate.delete(key);
logger.info("更新mall,从缓存中删除mall token >> " + record.getId());
}
this.deleteRedis(record.getTenantInfo());
return ret;
}

@Override
public int update(WxMall record) {
int ret = wxMallMapper.updateById(record);

String key = getRedisKeyByTenantInfo(record.getTenantInfo());
// 缓存已存在,删除
boolean hasKey = mallRedisTemplate.hasKey(key);
if(hasKey) {
mallRedisTemplate.delete(key);
logger.info("更新mall,从缓存中删除mall >> " + record.getId());
}
this.deleteRedis(record.getTenantInfo());
return ret;
}

@Override
public void deleteById(Long id) {
WxMall record = this.getById(id);
this.deleteRedis(record.getTenantInfo());
wxMallMapper.deleteById(id);

String key = getRedisKeyByTenantInfo(new TenantEntity() {{
setTenantId(String.valueOf(id));
}});
// 缓存已存在,删除
boolean hasKey = mallRedisTemplate.hasKey(key);
if(hasKey) {
mallRedisTemplate.delete(key);
logger.info("更新mall,从缓存中删除mall >> " + id);
}
}

@Override
public WxMall getByTenantInfo(TenantEntity tenantEntity) {
String key = getRedisKeyByTenantInfo(tenantEntity);

ValueOperations<String, WxMall> operations = mallRedisTemplate.opsForValue();
// 缓存
boolean hasKey = mallRedisTemplate.hasKey(key);
if(hasKey) {
// 从缓存获取用户信息
WxMall mall = operations.get(key);
return mall;
}
// 不存在,从数据库中获取
WxMall q = new WxMall() {{
if (StringUtils.isBlank(tenantEntity.getParentTenantId())) {
setTenantId(tenantEntity.getTenantId());
} else {
setTenantId(tenantEntity.getTenantId());
setParentTenantId(tenantEntity.getParentTenantId());
}
}};
WxMall mall = null;
try {
mall = wxMallMapper.getByTenantInfo(q);
} catch (Exception e) {
logger.error(e.getMessage());
}
// 插入缓存
if (mall != null) {
operations.set(key, mall, 3600, TimeUnit.SECONDS);
}
return mall;
return this.getByTenantId(tenantEntity.getTenantId());
}

@Override
public WxMall getByTenantInfoExt(TenantEntity tenantEntity) {
WxMall mall = getByTenantInfo(tenantEntity);
WxMall mall = this.getByTenantInfo(tenantEntity);
if (mall == null) {
return null;
}
@@ -235,29 +160,22 @@ public class WxMallServiceImpl implements WxMallService {
}

@Override
public WxMall getByTenantId(String id) {
String key = getRedisKeyByTenantInfo(new TenantEntity() {{
setTenantId(id);
}});
public WxMall getByTenantId(String tenantId) {
WxMall mall = null;
String key = Constant.mallinfoPrev + tenantId;
ValueOperations<String, WxMall> operations = mallRedisTemplate.opsForValue();

// 缓存
boolean hasKey = mallRedisTemplate.hasKey(key);
if(hasKey) {
// 从缓存获取用户信息
WxMall mall = operations.get(key);
if(mallRedisTemplate.hasKey(key)) {
mall = operations.get(key);
return mall;
}
WxMall mall = wxMallMapper.getByTenantId(id);
logger.info("getByTenantId: " + mall.toString());
// 插入缓存
operations.set(key, mall, 3600, TimeUnit.SECONDS);
mall = wxMallMapper.getByTenantId(tenantId);
operations.set(key, mall, 7, TimeUnit.DAYS);
return mall;
}

@Override
public WxMall getByTenantIdExt(String id) {
WxMall wxMall = wxMallMapper.getByTenantId(id);
WxMall wxMall = this.getByTenantId(id);
if(wxMall == null) {
return null;
}
@@ -292,15 +210,26 @@ public class WxMallServiceImpl implements WxMallService {

@Override
public List<WxMall> getSubByParentTenantId(String parentTenantId) {
String key = Constant.subMallinfoPrev + parentTenantId;
ValueOperations<String, List<WxMall>> operations = subMallListRedisTemplate.opsForValue();
if(subMallListRedisTemplate.hasKey(key)) {
List<WxMall> wxMalls = operations.get(key);
return wxMalls;
}
WxMall q = new WxMall();
q.setParentTenantId(parentTenantId);
List<WxMall> mallList = wxMallMapper.selectList(new QueryWrapper<>(q));

operations.set(key, mallList, 7, TimeUnit.DAYS);
return mallList;
}

@Override
public void undateSubmall(String parentTenantId, List<String> tenantIds) {
wxMallMapper.undateSubmall(parentTenantId, tenantIds);
this.deleteRedis(new TenantEntity(){{
setTenantId(parentTenantId);
}});
}

@Override
@@ -308,13 +237,21 @@ public class WxMallServiceImpl implements WxMallService {
return wxMallMapper.listAsSelectMall(id);
}

private String getRedisKeyByTenantInfo(TenantEntity tenantEntity) {
StringBuilder sb = new StringBuilder();
sb.append(Constant.TENANT_KEY_PREV).append(tenantEntity.getTenantId());
if (StringUtils.isBlank(tenantEntity.getParentTenantId())) {
sb.append("-").append(tenantEntity.getParentTenantId());
private void deleteRedis(TenantEntity tenantEntity){
String key1 = Constant.mallinfoPrev + tenantEntity.getTenantId();
if(mallRedisTemplate.hasKey(key1)){
mallRedisTemplate.delete(key1);
}
String key2 = Constant.subMallinfoPrev + tenantEntity.getTenantId();
if(subMallListRedisTemplate.hasKey(key2)){
subMallListRedisTemplate.delete(key2);
}
if(StringUtils.isNotBlank(tenantEntity.getParentTenantId())){
String key3 = Constant.subMallinfoPrev + tenantEntity.getParentTenantId();
if(subMallListRedisTemplate.hasKey(key3)){
subMallListRedisTemplate.delete(key3);
}
}
return sb.toString();
}

}

+ 9
- 4
mallinkService/src/main/java/com/iformall/utils/Constant.java 查看文件

@@ -21,6 +21,9 @@ public class Constant {
// TOKEN过期时间, 24小时后过期
public final static int EXPIRE = H_EXPIRE * 24;

// TOKEN过期时间, 7天后过期
public final static int S_D_EXPIRE = EXPIRE * 7;

// C端token
public static final String tokenPrev = "weapp:token:";

@@ -47,14 +50,16 @@ public class Constant {
// 积分规则 key prev
public static final String CREDIT_RULES_KEY_PREV = "setting:creditrules:";

// 获取mall信息
public static final String MALL_KEY_PREV = "mall:";
public static final String TENANT_KEY_PREV = "tenant:";

// 导入会员
public static final String importMemPrev = "importmem:";
public static final String importInvestCustomerPrev = "importinvestcustomer:";

//限制接口访问次数
public static final String INTERFACE_VISIT_LIMIT_KEY = "INTERFACE:LIMIT:";

//获取mall信息
public static final String appinfoPrev = "appinfo:";
public static final String mallinfoPrev = "mallinfo:";
public static final String subMallinfoPrev = "mallinfo:subMallinfo:";

}

+ 36
- 4
mallinkSysAdmin/src/main/java/com/iformall/config/RedisConfig.java 查看文件

@@ -20,10 +20,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* Created by Stormeye on 2018/10/1.
@@ -194,6 +191,23 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("subMallListRedisTemplate")
public RedisTemplate<String, List<WxMall>> getSubMallListRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, List<WxMall>> template = new RedisTemplate<String, List<WxMall>>();

Jackson2JsonRedisSerializer<List> j = new Jackson2JsonRedisSerializer<List>(List.class);
// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("couponChannelRedisTemplate")
public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>();
@@ -245,4 +259,22 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("wxAppinfoRedisTemplate")
public RedisTemplate<String, WxAppinfo> getWxAppinfoRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, WxAppinfo> template = new RedisTemplate<>();

Jackson2JsonRedisSerializer<WxAppinfo> j = new Jackson2JsonRedisSerializer(WxAppinfo.class);

// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

}

+ 37
- 4
mallinkWebSocketServer/src/main/java/com/iformall/config/RedisConfig.java 查看文件

@@ -20,10 +20,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.time.Duration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* Created by Stormeye on 2018/10/1.
@@ -179,6 +176,23 @@ public class RedisConfig extends CachingConfigurerSupport {
return template;
}

@Bean("subMallListRedisTemplate")
public RedisTemplate<String, List<WxMall>> getSubMallListRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, List<WxMall>> template = new RedisTemplate<String, List<WxMall>>();

Jackson2JsonRedisSerializer<List> j = new Jackson2JsonRedisSerializer<List>(List.class);
// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("couponChannelRedisTemplate")
public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>();
@@ -230,4 +244,23 @@ public class RedisConfig extends CachingConfigurerSupport {
template.setConnectionFactory(connectionFactory);
return template;
}

@Bean("wxAppinfoRedisTemplate")
public RedisTemplate<String, WxAppinfo> getWxAppinfoRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, WxAppinfo> template = new RedisTemplate<>();

Jackson2JsonRedisSerializer<WxAppinfo> j = new Jackson2JsonRedisSerializer(WxAppinfo.class);

// value值的序列化
template.setValueSerializer(j);
template.setHashKeySerializer(j);

// key的序列化
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.setConnectionFactory(connectionFactory);
return template;
}

}

Loading…
取消
儲存