| @@ -0,0 +1,19 @@ | |||||
| ALTER TABLE `wx_c_user` | |||||
| ADD COLUMN `open_app_id` VARCHAR(18) NULL AFTER `update_date`, | |||||
| ADD COLUMN `mp_open_id` VARCHAR(28) NULL AFTER `open_app_id`, | |||||
| ADD COLUMN `mp_app_id` VARCHAR(18) NULL AFTER `mp_open_id`, | |||||
| ADD COLUMN `mp_subscribe` TINYINT(2) NULL AFTER `mp_app_id`, | |||||
| ADD COLUMN `mp_subscribe_time` datetime NULL AFTER `mp_subscribe`, | |||||
| ADD COLUMN `mp_subscribe_scene` VARCHAR(20) NULL AFTER `mp_subscribe_time`, | |||||
| ADD COLUMN `subs_open_id` VARCHAR(28) NULL AFTER `mp_subscribe_scene`, | |||||
| ADD COLUMN `subs_app_id` VARCHAR(18) NULL AFTER `subs_open_id`, | |||||
| ADD COLUMN `subs_subscribe` TINYINT(2) NULL AFTER `subs_app_id`, | |||||
| ADD COLUMN `subs_subscribe_time` datetime NULL AFTER `subs_subscribe`, | |||||
| ADD COLUMN `subs_subscribe_scene` VARCHAR(20) NULL AFTER `subs_subscribe_time`, | |||||
| CHANGE COLUMN `open_id` `open_id` VARCHAR(28) NOT NULL COMMENT '微信openId' , | |||||
| CHANGE COLUMN `union_id` `union_id` VARCHAR(29) NULL DEFAULT NULL COMMENT '微信unionId' , | |||||
| CHANGE COLUMN `phone` `phone` VARCHAR(20) NULL DEFAULT NULL COMMENT '用户绑定的手机号' , | |||||
| CHANGE COLUMN `register_ip` `register_ip` VARCHAR(20) NULL DEFAULT NULL COMMENT '用户注册IP' , | |||||
| CHANGE COLUMN `app_id` `app_id` VARCHAR(20) NULL DEFAULT NULL COMMENT '小程序的appId' , | |||||
| CHANGE COLUMN `latitude` `latitude` DECIMAL(10,5) NULL DEFAULT NULL COMMENT '维度' , | |||||
| CHANGE COLUMN `longitude` `longitude` DECIMAL(10,5) NULL DEFAULT NULL COMMENT '经度' ; | |||||
| @@ -47,6 +47,9 @@ import java.util.Map; | |||||
| public class WxUserGrantController extends BaseController { | public class WxUserGrantController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | |||||
| private WxCUserTokenService userTokenService; | |||||
| @Autowired | @Autowired | ||||
| private WxCUserService wxCUserService; | private WxCUserService wxCUserService; | ||||
| @@ -170,13 +173,13 @@ public class WxUserGrantController extends BaseController { | |||||
| user1.setExtraInfo(extraInfo.toJSONString()); | user1.setExtraInfo(extraInfo.toJSONString()); | ||||
| user1.setLoginCount(user1.getLoginCount()+1); | user1.setLoginCount(user1.getLoginCount()+1); | ||||
| wxCUserService.saveOrUpdate(user1); | |||||
| // 成长值 | |||||
| userTokenService.saveOrUpdate(user1); | |||||
| // 成长值 | |||||
| try { | try { | ||||
| score = wxCUserService.scoreCalculate(user1, false); | |||||
| score = wxScoreRulesService.addScore(EnumScoreType.LOGIN, user1); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | |||||
| logger.error("c_user score " + e.getMessage()); | |||||
| } | } | ||||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_LOGIN,user1); | wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_LOGIN,user1); | ||||
| } else { | } else { | ||||
| @@ -199,7 +202,7 @@ public class WxUserGrantController extends BaseController { | |||||
| user.setExtraInfo(extraInfo.toJSONString()); | user.setExtraInfo(extraInfo.toJSONString()); | ||||
| user.setLoginCount(0); | user.setLoginCount(0); | ||||
| wxCUserService.saveOrUpdate(user); | |||||
| userTokenService.saveOrUpdate(user); | |||||
| resultMap.put("token", token); | resultMap.put("token", token); | ||||
| request.setAttribute(Constant.LOGIN_USER_KEY, user.getId()); | request.setAttribute(Constant.LOGIN_USER_KEY, user.getId()); | ||||
| @@ -207,7 +210,7 @@ public class WxUserGrantController extends BaseController { | |||||
| // 成长值 | // 成长值 | ||||
| try { | try { | ||||
| score = wxCUserService.scoreCalculate(user, true); | |||||
| score = wxScoreRulesService.addScore(EnumScoreType.LOGIN, user); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| } | } | ||||
| @@ -5,7 +5,7 @@ import com.iformall.annotation.AuthIgnore; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.domain.po.WxCUser; | import com.iformall.domain.po.WxCUser; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.WxCUserService; | |||||
| import com.iformall.service.WxCUserTokenService; | |||||
| import com.iformall.utils.Constant; | import com.iformall.utils.Constant; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -25,7 +25,7 @@ import javax.servlet.http.HttpServletResponse; | |||||
| @Component | @Component | ||||
| public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | ||||
| @Autowired | @Autowired | ||||
| private WxCUserService wxCUserService; | |||||
| private WxCUserTokenService userTokenService; | |||||
| @Override | @Override | ||||
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||||
| @@ -54,7 +54,7 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||||
| } | } | ||||
| // 查询token信息 | // 查询token信息 | ||||
| WxCUser wxCUser = wxCUserService.getByToken(token); | |||||
| WxCUser wxCUser = userTokenService.getByToken(token); | |||||
| if(wxCUser == null || wxCUser.getExpireTime().getTime() < System.currentTimeMillis()){ | if(wxCUser == null || wxCUser.getExpireTime().getTime() < System.currentTimeMillis()){ | ||||
| throw new MallinkException(ErrorCode.NET_TOKEN_INVALID.getCode(), "URL:" + request.getRequestURL() + " token失效,请重新登录"); | throw new MallinkException(ErrorCode.NET_TOKEN_INVALID.getCode(), "URL:" + request.getRequestURL() + " token失效,请重新登录"); | ||||
| } | } | ||||
| @@ -2,7 +2,7 @@ package com.iformall.resolver; | |||||
| import com.iformall.annotation.LoginUser; | import com.iformall.annotation.LoginUser; | ||||
| import com.iformall.domain.po.WxCUser; | import com.iformall.domain.po.WxCUser; | ||||
| import com.iformall.service.WxCUserService; | |||||
| import com.iformall.service.WxCUserTokenService; | |||||
| import com.iformall.utils.Constant; | import com.iformall.utils.Constant; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.core.MethodParameter; | import org.springframework.core.MethodParameter; | ||||
| @@ -22,7 +22,7 @@ import org.springframework.web.method.support.ModelAndViewContainer; | |||||
| @Component | @Component | ||||
| public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { | public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { | ||||
| @Autowired | @Autowired | ||||
| private WxCUserService wxCUserService; | |||||
| private WxCUserTokenService userTokenService; | |||||
| @Override | @Override | ||||
| public boolean supportsParameter(MethodParameter parameter) { | public boolean supportsParameter(MethodParameter parameter) { | ||||
| @@ -39,7 +39,7 @@ public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgu | |||||
| } | } | ||||
| //获取用户信息 | //获取用户信息 | ||||
| WxCUser user = wxCUserService.getByToken((String)object); | |||||
| WxCUser user = userTokenService.getByToken((String)object); | |||||
| return user; | return user; | ||||
| } | } | ||||
| @@ -135,6 +135,29 @@ public class WxCUser implements Serializable { | |||||
| @io.swagger.annotations.ApiModelProperty(value="是否关注公众号",name="isSubscribe") | @io.swagger.annotations.ApiModelProperty(value="是否关注公众号",name="isSubscribe") | ||||
| private Integer isSubscribe; | private Integer isSubscribe; | ||||
| @io.swagger.annotations.ApiModelProperty(value="微信开放平台appId",name="openAppId") | |||||
| private String openAppId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="服务号openId",name="mpOpenId") | |||||
| private String mpOpenId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="服务号appId",name="mpAppId") | |||||
| private String mpAppId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="是否关注服务号",name="mpSubscribe") | |||||
| private Integer mpSubscribe; | |||||
| @io.swagger.annotations.ApiModelProperty(value="关注服务号时间",name="mpSubscribeTime") | |||||
| private Date mpSubscribeTime; | |||||
| @io.swagger.annotations.ApiModelProperty(value="关注服务号Scene",name="mpSubscribeScene") | |||||
| private String mpSubscribeScene; | |||||
| @io.swagger.annotations.ApiModelProperty(value="订阅号openId",name="subsOpenId") | |||||
| private String subsOpenId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="订阅号appId",name="subsAppId") | |||||
| private String subsAppId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="是否关注订阅号",name="subsSubscribe") | |||||
| private Integer subsSubscribe; | |||||
| @io.swagger.annotations.ApiModelProperty(value="关注订阅号时间",name="subsSubscribeTime") | |||||
| private Date subsSubscribeTime; | |||||
| @io.swagger.annotations.ApiModelProperty(value="关注订阅号Scene",name="subsSubscribeScene") | |||||
| private String subsSubscribeScene; | |||||
| //渠道名称 | //渠道名称 | ||||
| @Transient | @Transient | ||||
| @@ -377,7 +400,95 @@ public class WxCUser implements Serializable { | |||||
| this.isSubscribe = isSubscribe; | this.isSubscribe = isSubscribe; | ||||
| } | } | ||||
| public static enum Field | |||||
| public String getOpenAppId() { | |||||
| return openAppId; | |||||
| } | |||||
| public void setOpenAppId(String openAppId) { | |||||
| this.openAppId = openAppId; | |||||
| } | |||||
| public String getMpOpenId() { | |||||
| return mpOpenId; | |||||
| } | |||||
| public void setMpOpenId(String mpOpenId) { | |||||
| this.mpOpenId = mpOpenId; | |||||
| } | |||||
| public String getMpAppId() { | |||||
| return mpAppId; | |||||
| } | |||||
| public void setMpAppId(String mpAppId) { | |||||
| this.mpAppId = mpAppId; | |||||
| } | |||||
| public Integer getMpSubscribe() { | |||||
| return mpSubscribe; | |||||
| } | |||||
| public void setMpSubscribe(Integer mpSubscribe) { | |||||
| this.mpSubscribe = mpSubscribe; | |||||
| } | |||||
| public Date getMpSubscribeTime() { | |||||
| return mpSubscribeTime; | |||||
| } | |||||
| public void setMpSubscribeTime(Date mpSubscribeTime) { | |||||
| this.mpSubscribeTime = mpSubscribeTime; | |||||
| } | |||||
| public String getMpSubscribeScene() { | |||||
| return mpSubscribeScene; | |||||
| } | |||||
| public void setMpSubscribeScene(String mpSubscribeScene) { | |||||
| this.mpSubscribeScene = mpSubscribeScene; | |||||
| } | |||||
| public String getSubsOpenId() { | |||||
| return subsOpenId; | |||||
| } | |||||
| public void setSubsOpenId(String subsOpenId) { | |||||
| this.subsOpenId = subsOpenId; | |||||
| } | |||||
| public String getSubsAppId() { | |||||
| return subsAppId; | |||||
| } | |||||
| public void setSubsAppId(String subsAppId) { | |||||
| this.subsAppId = subsAppId; | |||||
| } | |||||
| public Integer getSubsSubscribe() { | |||||
| return subsSubscribe; | |||||
| } | |||||
| public void setSubsSubscribe(Integer subsSubscribe) { | |||||
| this.subsSubscribe = subsSubscribe; | |||||
| } | |||||
| public Date getSubsSubscribeTime() { | |||||
| return subsSubscribeTime; | |||||
| } | |||||
| public void setSubsSubscribeTime(Date subsSubscribeTime) { | |||||
| this.subsSubscribeTime = subsSubscribeTime; | |||||
| } | |||||
| public String getSubsSubscribeScene() { | |||||
| return subsSubscribeScene; | |||||
| } | |||||
| public void setSubsSubscribeScene(String subsSubscribeScene) { | |||||
| this.subsSubscribeScene = subsSubscribeScene; | |||||
| } | |||||
| public static enum Field | |||||
| { | { | ||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | ||||
| ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") | ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") | ||||
| @@ -1,8 +1,5 @@ | |||||
| package com.iformall.service; | package com.iformall.service; | ||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.domain.dto.WxCUserBasicInfoDto; | import com.iformall.domain.dto.WxCUserBasicInfoDto; | ||||
| import com.iformall.domain.po.WxCUser; | import com.iformall.domain.po.WxCUser; | ||||
| @@ -27,14 +24,6 @@ public interface WxCUserService { | |||||
| */ | */ | ||||
| WxCUser getById(Long id); | WxCUser getById(Long id); | ||||
| /** | |||||
| * 根据token获得实体 | |||||
| * | |||||
| * @param token | |||||
| * @return | |||||
| */ | |||||
| WxCUser getByToken(String token); | |||||
| /** | /** | ||||
| * 根据openId获得实体 | * 根据openId获得实体 | ||||
| * | * | ||||
| @@ -75,8 +64,4 @@ public interface WxCUserService { | |||||
| PageInfo<WxCUser> listByChannel(WxCUser user, Integer pageIndex, Integer pageSize); | PageInfo<WxCUser> listByChannel(WxCUser user, Integer pageIndex, Integer pageSize); | ||||
| long countByChannel(WxCUser user); | long countByChannel(WxCUser user); | ||||
| /** | |||||
| * 计算当前用户成长值 | |||||
| */ | |||||
| int scoreCalculate(WxCUser user, boolean isNew); | |||||
| } | } | ||||
| @@ -0,0 +1,21 @@ | |||||
| package com.iformall.service; | |||||
| import com.iformall.domain.po.WxCUser; | |||||
| public interface WxCUserTokenService { | |||||
| /** | |||||
| * 根据token获得实体 | |||||
| * | |||||
| * @param token | |||||
| * @return | |||||
| */ | |||||
| WxCUser getByToken(String token); | |||||
| /** | |||||
| * 保存或更新实体 | |||||
| * | |||||
| * @param record | |||||
| */ | |||||
| int saveOrUpdate(WxCUser record); | |||||
| } | |||||
| @@ -5,51 +5,22 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.domain.dto.WxCUserBasicInfoDto; | import com.iformall.domain.dto.WxCUserBasicInfoDto; | ||||
| import com.iformall.domain.po.WxCUser; | import com.iformall.domain.po.WxCUser; | ||||
| import com.iformall.enums.EnumScoreType; | |||||
| import com.iformall.mapper.WxCUserMapper; | import com.iformall.mapper.WxCUserMapper; | ||||
| import com.iformall.mapper.WxCouponOrderMapper; | |||||
| import com.iformall.mapper.WxScoreHistoryMapper; | |||||
| import com.iformall.mapper.WxScoreRulesMapper; | |||||
| import com.iformall.service.WxCUserService; | import com.iformall.service.WxCUserService; | ||||
| import com.iformall.service.WxScoreRulesService; | |||||
| 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.Date; | import java.util.Date; | ||||
| import java.util.concurrent.TimeUnit; | |||||
| @Service | @Service | ||||
| public class WxCUserServiceImpl implements WxCUserService { | public class WxCUserServiceImpl implements WxCUserService { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| private String tokenPrev = "weapp:token:"; | |||||
| @Autowired | @Autowired | ||||
| WxCUserMapper wxCUserMapper; | WxCUserMapper wxCUserMapper; | ||||
| @Autowired | |||||
| WxCouponOrderMapper wxCouponOrderMapper; | |||||
| @Autowired | |||||
| WxScoreRulesMapper wxScoreRulesMapper; | |||||
| @Autowired | |||||
| WxScoreRulesService wxScoreRulesService; | |||||
| @Autowired | |||||
| WxScoreHistoryMapper wxScoreHistoryMapper; | |||||
| @Autowired | |||||
| @Qualifier("cuserTokenRedisTemplate") | |||||
| RedisTemplate<String, WxCUser> cUserTokenRedisTemplate; | |||||
| @Override | @Override | ||||
| public PageInfo<WxCUser> listAsPage(WxCUser record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxCUser> listAsPage(WxCUser record, Integer pageIndex, Integer pageSize) { | ||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCUserMapper.findList(record)); | return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCUserMapper.findList(record)); | ||||
| @@ -65,26 +36,6 @@ public class WxCUserServiceImpl implements WxCUserService { | |||||
| return wxCUserMapper.findByOpenId(record); | return wxCUserMapper.findByOpenId(record); | ||||
| } | } | ||||
| @Override | |||||
| public WxCUser getByToken(String token) { | |||||
| logger.info("获取用户信息start ..."); | |||||
| String key = tokenPrev + token; | |||||
| ValueOperations<String, WxCUser> operations = cUserTokenRedisTemplate.opsForValue(); | |||||
| // 缓存 | |||||
| boolean hasKey = cUserTokenRedisTemplate.hasKey(key); | |||||
| if(hasKey) { | |||||
| // 从缓存获取用户信息 | |||||
| WxCUser user = operations.get(key); | |||||
| return user; | |||||
| } | |||||
| WxCUser user = wxCUserMapper.findByToken(token); | |||||
| // 插入缓存 | |||||
| operations.set(key, user, 3600, TimeUnit.SECONDS); | |||||
| return user; | |||||
| } | |||||
| @Override | @Override | ||||
| public int saveOrUpdate(WxCUser user) { | public int saveOrUpdate(WxCUser user) { | ||||
| int ret = 0; | int ret = 0; | ||||
| @@ -101,13 +52,6 @@ public class WxCUserServiceImpl implements WxCUserService { | |||||
| user.setUpdateDate(curr); | user.setUpdateDate(curr); | ||||
| ret = wxCUserMapper.updateByPrimaryKeySelective(user); | ret = wxCUserMapper.updateByPrimaryKeySelective(user); | ||||
| } | } | ||||
| String key = tokenPrev + user.getToken(); | |||||
| // 缓存已存在,删除 | |||||
| boolean hasKey = cUserTokenRedisTemplate.hasKey(key); | |||||
| if(hasKey) { | |||||
| cUserTokenRedisTemplate.delete(key); | |||||
| logger.info("更新用户,从缓存中删除用户 token >> " + user.getToken()); | |||||
| } | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| @@ -131,11 +75,4 @@ public class WxCUserServiceImpl implements WxCUserService { | |||||
| public long countByChannel(WxCUser user) { | public long countByChannel(WxCUser user) { | ||||
| return wxCUserMapper.countByChannel(user); | return wxCUserMapper.countByChannel(user); | ||||
| } | } | ||||
| @Override | |||||
| public int scoreCalculate(WxCUser user, boolean isNew) { | |||||
| return wxScoreRulesService.addScore(EnumScoreType.LOGIN,user); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,82 @@ | |||||
| package com.iformall.service.impl; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.domain.po.WxCUser; | |||||
| import com.iformall.mapper.WxCUserMapper; | |||||
| import com.iformall.mapper.WxCouponOrderMapper; | |||||
| import com.iformall.mapper.WxScoreHistoryMapper; | |||||
| import com.iformall.mapper.WxScoreRulesMapper; | |||||
| import com.iformall.service.WxCUserTokenService; | |||||
| import com.iformall.service.WxScoreRulesService; | |||||
| 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.Date; | |||||
| import java.util.concurrent.TimeUnit; | |||||
| @Service | |||||
| public class WxCUserTokenServiceImpl implements WxCUserTokenService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| private String tokenPrev = "weapp:token:"; | |||||
| @Autowired | |||||
| WxCUserMapper wxCUserMapper; | |||||
| @Autowired | |||||
| @Qualifier("cuserTokenRedisTemplate") | |||||
| RedisTemplate<String, WxCUser> cUserTokenRedisTemplate; | |||||
| @Override | |||||
| public WxCUser getByToken(String token) { | |||||
| logger.info("获取用户信息start ..."); | |||||
| String key = tokenPrev + token; | |||||
| ValueOperations<String, WxCUser> operations = cUserTokenRedisTemplate.opsForValue(); | |||||
| // 缓存 | |||||
| boolean hasKey = cUserTokenRedisTemplate.hasKey(key); | |||||
| if(hasKey) { | |||||
| // 从缓存获取用户信息 | |||||
| WxCUser user = operations.get(key); | |||||
| return user; | |||||
| } | |||||
| WxCUser user = wxCUserMapper.findByToken(token); | |||||
| // 插入缓存 | |||||
| operations.set(key, user, 3600, TimeUnit.SECONDS); | |||||
| return user; | |||||
| } | |||||
| @Override | |||||
| public int saveOrUpdate(WxCUser user) { | |||||
| int ret = 0; | |||||
| Date curr = new Date(); | |||||
| if (user.getId() == null) { | |||||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| user.setId(idWorker.nextId()); | |||||
| user.setLoginCount(1); | |||||
| user.setCreateDate(curr); | |||||
| user.setUpdateDate(curr); | |||||
| ret = wxCUserMapper.insertSelective(user); | |||||
| } else { | |||||
| user.setUpdateDate(curr); | |||||
| ret = wxCUserMapper.updateByPrimaryKeySelective(user); | |||||
| } | |||||
| String key = tokenPrev + user.getToken(); | |||||
| // 缓存已存在,删除 | |||||
| boolean hasKey = cUserTokenRedisTemplate.hasKey(key); | |||||
| if(hasKey) { | |||||
| cUserTokenRedisTemplate.delete(key); | |||||
| logger.info("更新用户,从缓存中删除用户 token >> " + user.getToken()); | |||||
| } | |||||
| return ret; | |||||
| } | |||||
| } | |||||
| @@ -31,7 +31,18 @@ | |||||
| <result column="longitude" jdbcType="DECIMAL" property="longitude"/> | <result column="longitude" jdbcType="DECIMAL" property="longitude"/> | ||||
| <result column="login_count" jdbcType="INTEGER" property="loginCount"/> | <result column="login_count" jdbcType="INTEGER" property="loginCount"/> | ||||
| <result column="extra_info" jdbcType="VARCHAR" property="extraInfo"/> | <result column="extra_info" jdbcType="VARCHAR" property="extraInfo"/> | ||||
| <result column="is_ubscribe" jdbcType="TINYINT" property="isSubscribe"/> | |||||
| <result column="is_subscribe" jdbcType="TINYINT" property="isSubscribe"/> | |||||
| <result column="open_app_id" jdbcType="VARCHAR" property="openAppId"/> | |||||
| <result column="mp_open_id" jdbcType="VARCHAR" property="mpOpenId"/> | |||||
| <result column="mp_app_id" jdbcType="VARCHAR" property="mpAppId"/> | |||||
| <result column="mp_subscribe" jdbcType="TINYINT" property="mpSubscribe"/> | |||||
| <result column="mp_subscribe_time" jdbcType="TIMESTAMP" property="mpSubscribeTime"/> | |||||
| <result column="mp_subscribe_scene" jdbcType="VARCHAR" property="mpSubscribeScene"/> | |||||
| <result column="subs_open_id" jdbcType="VARCHAR" property="subsOpenId"/> | |||||
| <result column="subs_app_id" jdbcType="VARCHAR" property="subsAppId"/> | |||||
| <result column="subs_subscribe" jdbcType="TINYINT" property="subsSubscribe"/> | |||||
| <result column="subs_subscribe_time" jdbcType="TIMESTAMP" property="subsSubscribeTime"/> | |||||
| <result column="subs_subscribe_scene" jdbcType="VARCHAR" property="subsSubscribeScene"/> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| @@ -39,7 +50,10 @@ | |||||
| `city`,`province`,`language`,`country_code`,`register_ip`,`verify_code_phone`, | `city`,`province`,`language`,`country_code`,`register_ip`,`verify_code_phone`, | ||||
| `qrcode_source`,`scene`,`scene_address`,`session_key`,`score`, | `qrcode_source`,`scene`,`scene_address`,`session_key`,`score`, | ||||
| `update_date`,`create_date`,`app_id`,`token`,`expire_time`,`latitude`, `longitude`, | `update_date`,`create_date`,`app_id`,`token`,`expire_time`,`latitude`, `longitude`, | ||||
| `login_count`, `extra_info`, `is_subscribe` | |||||
| `login_count`, `extra_info`, `is_subscribe`, | |||||
| `open_app_id`, | |||||
| `mp_open_id`,`mp_app_id`,`mp_subscribe`,`mp_subscribe_time`,`mp_subscribe_scene`, | |||||
| `subs_open_id`,`subs_app_id`,`subs_subscribe`,`subs_subscribe_time`,`subs_subscribe_scene` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -165,6 +179,26 @@ | |||||
| and `is_subscribe` = #{isSubscribe} | and `is_subscribe` = #{isSubscribe} | ||||
| </if> | </if> | ||||
| <if test=" null != openAppId "> | |||||
| and `open_app_id` = #{openAppId} | |||||
| </if> | |||||
| <if test=" null != mpOpenId "> | |||||
| and `mp_open_id` = #{mpOpenId} | |||||
| </if> | |||||
| <if test=" null != mpAppId "> | |||||
| and `mp_app_id` = #{mpAppId} | |||||
| </if> | |||||
| <if test=" null != subsOpenId "> | |||||
| and `subs_open_id` = #{subsOpenId} | |||||
| </if> | |||||
| <if test=" null != subsAppId "> | |||||
| and `subs_app_id` = #{subsAppId} | |||||
| </if> | |||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | and id in | ||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | ||||
| @@ -186,6 +220,12 @@ | |||||
| where `app_id` = #{appId} and `open_id` = #{openId} | where `app_id` = #{appId} and `open_id` = #{openId} | ||||
| </select> | </select> | ||||
| <select id="findByUnionId" parameterType="com.iformall.domain.po.WxCUser" resultMap="BaseResultMap"> | |||||
| select * from wx_c_user | |||||
| where `open_app_id` = #{openAppId} and `union_id` = #{unionId} | |||||
| </select> | |||||
| <select id="findByToken" resultMap="BaseResultMap"> | <select id="findByToken" resultMap="BaseResultMap"> | ||||
| select * from wx_c_user | select * from wx_c_user | ||||
| where `token` = #{token} | where `token` = #{token} | ||||
| @@ -3,7 +3,7 @@ package com.iformall.interceptor; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.domain.po.WxCUser; | import com.iformall.domain.po.WxCUser; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.WxCUserService; | |||||
| import com.iformall.service.WxCUserTokenService; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -15,7 +15,6 @@ import org.springframework.stereotype.Component; | |||||
| import org.springframework.web.socket.WebSocketHandler; | import org.springframework.web.socket.WebSocketHandler; | ||||
| import org.springframework.web.socket.server.HandshakeInterceptor; | import org.springframework.web.socket.server.HandshakeInterceptor; | ||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpSession; | import javax.servlet.http.HttpSession; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| @@ -30,7 +29,7 @@ public class AuthHandshakeInterceptor implements HandshakeInterceptor { | |||||
| private Logger logger = LoggerFactory.getLogger(this.getClass()); | private Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | @Autowired | ||||
| WxCUserService wxCUserService; | |||||
| WxCUserTokenService userTokenService; | |||||
| public static final String LOGIN_USER_KEY = "LOGIN_USER_KEY"; | public static final String LOGIN_USER_KEY = "LOGIN_USER_KEY"; | ||||
| public static final String TENANT_ID = "TENANT_ID"; | public static final String TENANT_ID = "TENANT_ID"; | ||||
| @@ -52,7 +51,7 @@ public class AuthHandshakeInterceptor implements HandshakeInterceptor { | |||||
| } | } | ||||
| // 查询token信息 | // 查询token信息 | ||||
| WxCUser wxCUser = wxCUserService.getByToken(token); | |||||
| WxCUser wxCUser = userTokenService.getByToken(token); | |||||
| if(wxCUser == null || wxCUser.getExpireTime().getTime() < System.currentTimeMillis()){ | if(wxCUser == null || wxCUser.getExpireTime().getTime() < System.currentTimeMillis()){ | ||||
| throw new MallinkException(ErrorCode.NET_TOKEN_INVALID.getCode(), "URL:" + serverHttpRequest.getServletRequest().getRequestURI() + " token失效,请重新登录"); | throw new MallinkException(ErrorCode.NET_TOKEN_INVALID.getCode(), "URL:" + serverHttpRequest.getServletRequest().getRequestURI() + " token失效,请重新登录"); | ||||
| } | } | ||||