| @@ -20,10 +20,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | |||||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | import org.springframework.data.redis.serializer.StringRedisSerializer; | ||||
| import java.time.Duration; | 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. | * Created by Stormeye on 2018/10/1. | ||||
| @@ -177,6 +174,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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") | @Bean("couponChannelRedisTemplate") | ||||
| public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | ||||
| RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | ||||
| @@ -247,4 +261,22 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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; | |||||
| } | |||||
| } | } | ||||
| @@ -153,8 +153,8 @@ public class ShiroConfig { | |||||
| //配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了 | //配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了 | ||||
| filterChainDefinitionMap.put("/logout", "authc"); | filterChainDefinitionMap.put("/logout", "authc"); | ||||
| filterChainDefinitionMap.put("/**", "corsFilter,token,authc"); | |||||
| // filterChainDefinitionMap.put("/**", "anon"); | |||||
| // filterChainDefinitionMap.put("/**", "corsFilter,token,authc"); | |||||
| filterChainDefinitionMap.put("/**", "anon"); | |||||
| shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); | shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); | ||||
| @@ -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` 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`; | 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) | CREATE DEFINER=`root`@`%` PROCEDURE `cuser_old_to_new`(IN `oldCuserId` bigint,IN `newCuserId` bigint) | ||||
| BEGIN | BEGIN | ||||
| DECLARE err_flag INT DEFAULT FALSE; | DECLARE err_flag INT DEFAULT FALSE; | ||||
| DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET err_flag = TRUE; | DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET err_flag = TRUE; | ||||
| UPDATE wx_c_user SET user_id = newCuserId WHERE user_id = oldCuserId ; | 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_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_group SET user_id = newCuserId WHERE user_id = oldCuserId ; | ||||
| UPDATE wx_order_press 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_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_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_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 ; | UPDATE wx_credit_history SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; | ||||
| @@ -24,6 +24,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; | |||||
| import java.time.Duration; | import java.time.Duration; | ||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| /** | /** | ||||
| @@ -142,6 +143,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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") | @Bean("couponChannelRedisTemplate") | ||||
| public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | ||||
| RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | ||||
| @@ -210,6 +228,24 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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") | @Bean("stringValueOperations") | ||||
| public ValueOperations<String, String> getStringValueOperations(RedisConnectionFactory connectionFactory) { | public ValueOperations<String, String> getStringValueOperations(RedisConnectionFactory connectionFactory) { | ||||
| StringRedisTemplate template = new StringRedisTemplate(); | StringRedisTemplate template = new StringRedisTemplate(); | ||||
| @@ -23,7 +23,9 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | |||||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | import org.springframework.data.redis.serializer.StringRedisSerializer; | ||||
| import java.time.Duration; | import java.time.Duration; | ||||
| import java.util.ArrayList; | |||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| /** | /** | ||||
| @@ -159,6 +161,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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") | @Bean("couponDetailRedisTemplate") | ||||
| public RedisTemplate<String, WxCouponCVo> getCouponDetailRedisTemplate(RedisConnectionFactory connectionFactory) { | public RedisTemplate<String, WxCouponCVo> getCouponDetailRedisTemplate(RedisConnectionFactory connectionFactory) { | ||||
| RedisTemplate<String, WxCouponCVo> template = new RedisTemplate<String, WxCouponCVo>(); | RedisTemplate<String, WxCouponCVo> template = new RedisTemplate<String, WxCouponCVo>(); | ||||
| @@ -230,6 +249,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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") | @Bean("stringValueOperations") | ||||
| public ValueOperations<String, String> getStringValueOperations(RedisConnectionFactory connectionFactory) { | public ValueOperations<String, String> getStringValueOperations(RedisConnectionFactory connectionFactory) { | ||||
| @@ -159,6 +159,7 @@ public class WxUserGrantController extends BaseController { | |||||
| // 通过authorizerInfo得到tenant_id | // 通过authorizerInfo得到tenant_id | ||||
| WxAuthorizerInfo wxAuthorizerInfo = null; | WxAuthorizerInfo wxAuthorizerInfo = null; | ||||
| WxAppinfo wxAppinfo = null; | WxAppinfo wxAppinfo = null; | ||||
| WxMall wxMall = null; | |||||
| WxMaService wxMaService = null; | WxMaService wxMaService = null; | ||||
| wxAuthorizerInfo = wxAuthorizerInfoService.getByAppId(appId); | wxAuthorizerInfo = wxAuthorizerInfoService.getByAppId(appId); | ||||
| @@ -169,8 +170,20 @@ public class WxUserGrantController extends BaseController { | |||||
| return new ResultData(ErrorCode.APP_ID_NOT_ENABLE); | 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()); | resultMap.put("selectedMall", wxMall.getTenantId()); | ||||
| // 集团版,获取子集团list | // 集团版,获取子集团list | ||||
| List<WxMall> mallList = null; | List<WxMall> mallList = null; | ||||
| if(StringUtils.isNotBlank(wxMall.getParentTenantId())){ | if(StringUtils.isNotBlank(wxMall.getParentTenantId())){ | ||||
| @@ -181,7 +194,7 @@ public class WxUserGrantController extends BaseController { | |||||
| } | } | ||||
| if(mallList != null && mallList.size() >0){ | if(mallList != null && mallList.size() >0){ | ||||
| mallList.stream().forEach(cs -> { | 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()); | cs.setAppId(cAppInfo.getAppId()); | ||||
| }); | }); | ||||
| resultMap.put("subMalls", JSON.toJSONString(mallList)); | resultMap.put("subMalls", JSON.toJSONString(mallList)); | ||||
| @@ -190,28 +203,18 @@ public class WxUserGrantController extends BaseController { | |||||
| if (isFmOpen) { | if (isFmOpen) { | ||||
| wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | ||||
| } else { | } 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())) { | if (StringUtils.isBlank(wxAppinfo.getAccessToken())) { | ||||
| // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 | // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 | ||||
| updateAppAccessToken(wxAppinfo, wxMaService); | updateAppAccessToken(wxAppinfo, wxMaService); | ||||
| wxMaService = getWeappServiceByAppInfo(wxAppinfo); | |||||
| } else { | } else { | ||||
| // 检查token是否已过期, 1小时就重新获取 | // 检查token是否已过期, 1小时就重新获取 | ||||
| Date curDate = new Date(); | Date curDate = new Date(); | ||||
| if (curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.H_EXPIRE) { | if (curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.H_EXPIRE) { | ||||
| updateAppAccessToken(wxAppinfo, wxMaService); | updateAppAccessToken(wxAppinfo, wxMaService); | ||||
| wxMaService = getWeappServiceByAppInfo(wxAppinfo); | |||||
| } | } | ||||
| } | } | ||||
| wxMaService = getWeappServiceByAppInfo(wxAppinfo); | |||||
| } | } | ||||
| String token = null; | String token = null; | ||||
| @@ -248,7 +251,7 @@ public class WxUserGrantController extends BaseController { | |||||
| String ipaddress = IPUtil.getIpAddr(request); | String ipaddress = IPUtil.getIpAddr(request); | ||||
| WxCUser newUser = new WxCUser(); | WxCUser newUser = new WxCUser(); | ||||
| newUser.updateTenantInfo(wxAuthorizerInfo); | |||||
| newUser.updateTenantInfo(wxMall.getTenantInfo()); | |||||
| newUser.setAppId(appId); | newUser.setAppId(appId); | ||||
| newUser.setOpenId(openId); | newUser.setOpenId(openId); | ||||
| if (boolHaveUnionId) { | if (boolHaveUnionId) { | ||||
| @@ -259,7 +262,7 @@ public class WxUserGrantController extends BaseController { | |||||
| if (boolHaveUnionId) { | if (boolHaveUnionId) { | ||||
| // 优先根据unionId查询 | // 优先根据unionId查询 | ||||
| WxCUser userQ = new WxCUser(); | WxCUser userQ = new WxCUser(); | ||||
| userQ.updateTenantInfo(wxAuthorizerInfo); | |||||
| userQ.updateTenantInfo(wxMall.getTenantInfo()); | |||||
| userQ.setUnionId(unionId); | userQ.setUnionId(unionId); | ||||
| oldUser = wxCUserService.getByObject(userQ); | oldUser = wxCUserService.getByObject(userQ); | ||||
| if(oldUser != null) { | if(oldUser != null) { | ||||
| @@ -346,7 +349,7 @@ public class WxUserGrantController extends BaseController { | |||||
| resultMap.put("score", score); | resultMap.put("score", score); | ||||
| } else { | } else { | ||||
| // 新用户 | // 新用户 | ||||
| newUser.updateTenantInfo(wxAuthorizerInfo); | |||||
| newUser.updateTenantInfo(wxMall.getTenantInfo()); | |||||
| if(StringUtils.isNotBlank(wxMall.getParentTenantId())){ | if(StringUtils.isNotBlank(wxMall.getParentTenantId())){ | ||||
| newUser.setParentTenantId(wxMall.getParentTenantId()); | newUser.setParentTenantId(wxMall.getParentTenantId()); | ||||
| } | } | ||||
| @@ -20,10 +20,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | |||||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | import org.springframework.data.redis.serializer.StringRedisSerializer; | ||||
| import java.time.Duration; | 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. | * Created by Stormeye on 2018/10/1. | ||||
| @@ -194,6 +191,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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") | @Bean("couponChannelRedisTemplate") | ||||
| public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | ||||
| RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | ||||
| @@ -245,4 +259,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| template.setConnectionFactory(connectionFactory); | template.setConnectionFactory(connectionFactory); | ||||
| return template; | 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; | |||||
| } | |||||
| } | } | ||||
| @@ -20,10 +20,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | |||||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | import org.springframework.data.redis.serializer.StringRedisSerializer; | ||||
| import java.time.Duration; | 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. | * Created by Stormeye on 2018/10/1. | ||||
| @@ -179,6 +176,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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") | @Bean("couponChannelRedisTemplate") | ||||
| public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | ||||
| RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | ||||
| @@ -231,4 +245,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| template.setConnectionFactory(connectionFactory); | template.setConnectionFactory(connectionFactory); | ||||
| return template; | 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; | |||||
| } | |||||
| } | } | ||||
| @@ -22,6 +22,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; | |||||
| import java.time.Duration; | import java.time.Duration; | ||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| /** | /** | ||||
| @@ -157,6 +158,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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") | @Bean("couponChannelRedisTemplate") | ||||
| public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | ||||
| RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | ||||
| @@ -209,4 +227,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| template.setConnectionFactory(connectionFactory); | template.setConnectionFactory(connectionFactory); | ||||
| return template; | 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; | |||||
| } | |||||
| } | } | ||||
| @@ -20,10 +20,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | |||||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | import org.springframework.data.redis.serializer.StringRedisSerializer; | ||||
| import java.time.Duration; | 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. | * Created by Stormeye on 2018/10/1. | ||||
| @@ -179,6 +176,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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") | @Bean("couponChannelRedisTemplate") | ||||
| public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | ||||
| RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | ||||
| @@ -232,4 +246,22 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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; | |||||
| } | |||||
| } | } | ||||
| @@ -140,7 +140,7 @@ public class WxCUser extends BaseCUserEntity { | |||||
| //生成一个token | //生成一个token | ||||
| this.setToken(UUID.randomUUID().toString()+Constant.TOKEN_WXC_END); | 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(); | return this.getToken(); | ||||
| } | } | ||||
| @@ -77,4 +77,8 @@ public interface WxAppinfoService { | |||||
| */ | */ | ||||
| void deleteById(Long id); | void deleteById(Long id); | ||||
| WxAppinfo getByAppIdFromRedis(String appId); | |||||
| WxAppinfo getByIdFromRedis(Long id); | |||||
| WxAppinfo getCAppInfoFromRedis(String tenantId, EnumPayWay payWayWechat); | |||||
| } | } | ||||
| @@ -67,7 +67,6 @@ public interface WxMallService { | |||||
| WxMall getByTenantInfoExt(TenantEntity tenantEntity); | WxMall getByTenantInfoExt(TenantEntity tenantEntity); | ||||
| @Deprecated | |||||
| WxMall getByTenantId(String id); | WxMall getByTenantId(String id); | ||||
| @Deprecated | @Deprecated | ||||
| @@ -83,4 +82,5 @@ public interface WxMallService { | |||||
| void undateSubmall(String parentTenantId, List<String> tenantIds); | void undateSubmall(String parentTenantId, List<String> tenantIds); | ||||
| List<WxMall> listAsSelectMall(Long id); | List<WxMall> listAsSelectMall(Long id); | ||||
| } | } | ||||
| @@ -46,7 +46,7 @@ public class CUserTokenServiceImpl implements CUserTokenService { | |||||
| user = wxCUserMapper.findByToken(token); | user = wxCUserMapper.findByToken(token); | ||||
| } | } | ||||
| // 插入缓存 | // 插入缓存 | ||||
| operations.set(key, user, 3600, TimeUnit.SECONDS); | |||||
| operations.set(key, user, 7, TimeUnit.DAYS); | |||||
| logger.info("DB中获取用户信息End-" + token); | logger.info("DB中获取用户信息End-" + token); | ||||
| return user; | return user; | ||||
| } | } | ||||
| @@ -11,12 +11,17 @@ import com.iformall.enums.EnumAppType; | |||||
| import com.iformall.enums.EnumPayWay; | import com.iformall.enums.EnumPayWay; | ||||
| import com.iformall.mapper.WxAppinfoMapper; | import com.iformall.mapper.WxAppinfoMapper; | ||||
| import com.iformall.service.WxAppinfoService; | import com.iformall.service.WxAppinfoService; | ||||
| import com.iformall.utils.Constant; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | 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 org.springframework.stereotype.Service; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.concurrent.TimeUnit; | |||||
| @Service | @Service | ||||
| public class WxAppinfoServiceImpl implements WxAppinfoService { | public class WxAppinfoServiceImpl implements WxAppinfoService { | ||||
| @@ -25,6 +30,10 @@ public class WxAppinfoServiceImpl implements WxAppinfoService { | |||||
| @Autowired | @Autowired | ||||
| WxAppinfoMapper wxAppinfoMapper; | WxAppinfoMapper wxAppinfoMapper; | ||||
| @Autowired | |||||
| @Qualifier("wxAppinfoRedisTemplate") | |||||
| RedisTemplate<String, WxAppinfo> wxAppinfoRedisTemplate; | |||||
| @Override | @Override | ||||
| public WxAppinfo getCAppInfo(TenantEntity tenantEntity,EnumPayWay payWay) { | public WxAppinfo getCAppInfo(TenantEntity tenantEntity,EnumPayWay payWay) { | ||||
| WxAppinfo appInfo = null; | WxAppinfo appInfo = null; | ||||
| @@ -91,12 +100,86 @@ public class WxAppinfoServiceImpl implements WxAppinfoService { | |||||
| record.setId(idWorker.nextId()); | record.setId(idWorker.nextId()); | ||||
| wxAppinfoMapper.insert(record); | wxAppinfoMapper.insert(record); | ||||
| } else { | } else { | ||||
| this.deleteRedis(record.getId()); | |||||
| wxAppinfoMapper.updateById(record); | wxAppinfoMapper.updateById(record); | ||||
| } | } | ||||
| } | } | ||||
| @Override | @Override | ||||
| public void deleteById(Long id) { | public void deleteById(Long id) { | ||||
| this.deleteRedis(id); | |||||
| wxAppinfoMapper.deleteById(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); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Qualifier; | |||||
| import org.springframework.data.redis.core.RedisTemplate; | import org.springframework.data.redis.core.RedisTemplate; | ||||
| import org.springframework.data.redis.core.ValueOperations; | import org.springframework.data.redis.core.ValueOperations; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import com.iformall.common.IdWorker; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||
| @@ -44,6 +43,10 @@ public class WxMallServiceImpl implements WxMallService { | |||||
| @Qualifier("mallRedisTemplate") | @Qualifier("mallRedisTemplate") | ||||
| RedisTemplate<String, WxMall> mallRedisTemplate; | RedisTemplate<String, WxMall> mallRedisTemplate; | ||||
| @Autowired | |||||
| @Qualifier("subMallListRedisTemplate") | |||||
| RedisTemplate<String, List<WxMall>> subMallListRedisTemplate; | |||||
| @Override | @Override | ||||
| public String wxMallInit(WxProjectConfig wxProjectConfig) { | public String wxMallInit(WxProjectConfig wxProjectConfig) { | ||||
| @@ -92,116 +95,38 @@ public class WxMallServiceImpl implements WxMallService { | |||||
| @Override | @Override | ||||
| public WxMall getById(Long id) { | 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 | @Override | ||||
| public int save(WxMall record) { | 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); | 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; | return ret; | ||||
| } | } | ||||
| @Override | @Override | ||||
| public int update(WxMall record) { | public int update(WxMall record) { | ||||
| int ret = wxMallMapper.updateById(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; | return ret; | ||||
| } | } | ||||
| @Override | @Override | ||||
| public void deleteById(Long id) { | public void deleteById(Long id) { | ||||
| WxMall record = this.getById(id); | |||||
| this.deleteRedis(record.getTenantInfo()); | |||||
| wxMallMapper.deleteById(id); | 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 | @Override | ||||
| public WxMall getByTenantInfo(TenantEntity tenantEntity) { | 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 | @Override | ||||
| public WxMall getByTenantInfoExt(TenantEntity tenantEntity) { | public WxMall getByTenantInfoExt(TenantEntity tenantEntity) { | ||||
| WxMall mall = getByTenantInfo(tenantEntity); | |||||
| WxMall mall = this.getByTenantInfo(tenantEntity); | |||||
| if (mall == null) { | if (mall == null) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| @@ -235,29 +160,22 @@ public class WxMallServiceImpl implements WxMallService { | |||||
| } | } | ||||
| @Override | @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(); | 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; | 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; | return mall; | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMall getByTenantIdExt(String id) { | public WxMall getByTenantIdExt(String id) { | ||||
| WxMall wxMall = wxMallMapper.getByTenantId(id); | |||||
| WxMall wxMall = this.getByTenantId(id); | |||||
| if(wxMall == null) { | if(wxMall == null) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| @@ -292,15 +210,26 @@ public class WxMallServiceImpl implements WxMallService { | |||||
| @Override | @Override | ||||
| public List<WxMall> getSubByParentTenantId(String parentTenantId) { | 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(); | WxMall q = new WxMall(); | ||||
| q.setParentTenantId(parentTenantId); | q.setParentTenantId(parentTenantId); | ||||
| List<WxMall> mallList = wxMallMapper.selectList(new QueryWrapper<>(q)); | List<WxMall> mallList = wxMallMapper.selectList(new QueryWrapper<>(q)); | ||||
| operations.set(key, mallList, 7, TimeUnit.DAYS); | |||||
| return mallList; | return mallList; | ||||
| } | } | ||||
| @Override | @Override | ||||
| public void undateSubmall(String parentTenantId, List<String> tenantIds) { | public void undateSubmall(String parentTenantId, List<String> tenantIds) { | ||||
| wxMallMapper.undateSubmall(parentTenantId, tenantIds); | wxMallMapper.undateSubmall(parentTenantId, tenantIds); | ||||
| this.deleteRedis(new TenantEntity(){{ | |||||
| setTenantId(parentTenantId); | |||||
| }}); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -308,13 +237,21 @@ public class WxMallServiceImpl implements WxMallService { | |||||
| return wxMallMapper.listAsSelectMall(id); | 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(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -21,6 +21,9 @@ public class Constant { | |||||
| // TOKEN过期时间, 24小时后过期 | // TOKEN过期时间, 24小时后过期 | ||||
| public final static int EXPIRE = H_EXPIRE * 24; | public final static int EXPIRE = H_EXPIRE * 24; | ||||
| // TOKEN过期时间, 7天后过期 | |||||
| public final static int S_D_EXPIRE = EXPIRE * 7; | |||||
| // C端token | // C端token | ||||
| public static final String tokenPrev = "weapp:token:"; | public static final String tokenPrev = "weapp:token:"; | ||||
| @@ -47,14 +50,16 @@ public class Constant { | |||||
| // 积分规则 key prev | // 积分规则 key prev | ||||
| public static final String CREDIT_RULES_KEY_PREV = "setting:creditrules:"; | 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 importMemPrev = "importmem:"; | ||||
| public static final String importInvestCustomerPrev = "importinvestcustomer:"; | public static final String importInvestCustomerPrev = "importinvestcustomer:"; | ||||
| //限制接口访问次数 | //限制接口访问次数 | ||||
| public static final String INTERFACE_VISIT_LIMIT_KEY = "INTERFACE:LIMIT:"; | 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:"; | |||||
| } | } | ||||
| @@ -20,10 +20,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | |||||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | import org.springframework.data.redis.serializer.StringRedisSerializer; | ||||
| import java.time.Duration; | 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. | * Created by Stormeye on 2018/10/1. | ||||
| @@ -194,6 +191,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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") | @Bean("couponChannelRedisTemplate") | ||||
| public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | ||||
| RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | ||||
| @@ -245,4 +259,22 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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; | |||||
| } | |||||
| } | } | ||||
| @@ -20,10 +20,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | |||||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | import org.springframework.data.redis.serializer.StringRedisSerializer; | ||||
| import java.time.Duration; | 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. | * Created by Stormeye on 2018/10/1. | ||||
| @@ -179,6 +176,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| return template; | 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") | @Bean("couponChannelRedisTemplate") | ||||
| public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | public RedisTemplate<String, PageInfo<WxCouponChannelVo>> getCouponChannelRedisTemplate(RedisConnectionFactory connectionFactory) { | ||||
| RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | RedisTemplate<String, PageInfo<WxCouponChannelVo>> template = new RedisTemplate<>(); | ||||
| @@ -230,4 +244,23 @@ public class RedisConfig extends CachingConfigurerSupport { | |||||
| template.setConnectionFactory(connectionFactory); | template.setConnectionFactory(connectionFactory); | ||||
| return template; | 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; | |||||
| } | |||||
| } | } | ||||