| @@ -0,0 +1,177 @@ | |||||
| package com.iformall.service.cuser; | |||||
| import com.iformall.domain.po.CUser; | |||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| import com.iformall.domain.po.WxCUserFrom; | |||||
| import com.iformall.domain.po.base.BaseCUserEntity; | |||||
| import com.iformall.domain.po.base.TenantEntity; | |||||
| import com.iformall.domain.po.msg.FmInsideCLoginMsg; | |||||
| import com.iformall.enums.*; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.mq.MqBaseProducer; | |||||
| import com.iformall.service.MemCouponFromDspService; | |||||
| import com.iformall.service.WxCUserBasicInfoService; | |||||
| import com.iformall.service.WxCUserTagsService; | |||||
| import com.iformall.service.WxScoreRulesService; | |||||
| import com.iformall.service.cuser.tt.TtCUserServiceAdapter; | |||||
| import com.iformall.service.cuser.wx.WxCUserServiceAdapter; | |||||
| import com.iformall.utils.Constant; | |||||
| import com.iformall.utils.RedisCacheUtils; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| 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.stereotype.Service; | |||||
| import java.util.Date; | |||||
| import java.util.Map; | |||||
| import java.util.concurrent.ConcurrentHashMap; | |||||
| @Service | |||||
| public class BasicCUserService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||||
| @Autowired | |||||
| private WxCUserTagsService wxCUserTagsService; | |||||
| @Autowired | |||||
| private MemCouponFromDspService memCouponFromDspService; | |||||
| @Autowired | |||||
| private MqBaseProducer mqBaseProducer; | |||||
| @Autowired | |||||
| private WxScoreRulesService wxScoreRulesService; | |||||
| @Autowired | |||||
| @Qualifier("baseCUserTokenRedisTemplate") | |||||
| RedisTemplate<String, BaseCUserEntity> baseCUserTokenRedisTemplate; | |||||
| @Autowired | |||||
| @Qualifier("objectCommonRedisTemplate") | |||||
| RedisTemplate<String, Object> objectCommonRedisTemplate; | |||||
| public void actionMsgAfterLogin(WxCUserFrom wxCUserFrom) { | |||||
| wxCUserFrom.setCreateDate(new Date()); | |||||
| FmInsideCLoginMsg loginMsg = new FmInsideCLoginMsg(); | |||||
| loginMsg.updateTenantInfo(wxCUserFrom); | |||||
| loginMsg.setMsgType(EnumMsgRecordType.INSIDE_C_LOGIN.getCode()); | |||||
| loginMsg.setWxCUserFrom(wxCUserFrom); | |||||
| mqBaseProducer.sendMessage(loginMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||||
| } | |||||
| public void actionAfterLogin(CUser user) { | |||||
| // 成长值 | |||||
| try { | |||||
| wxScoreRulesService.addScore(user, EnumScoreType.LOGIN, user); | |||||
| } catch (MallinkException e) { | |||||
| logger.error("c_user 成长值 " + e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error("c_user 成长值 " + e.getMessage()); | |||||
| } | |||||
| // 用户登陆后 更新最后一次活跃时间 | |||||
| if (user.getUserId() != null) { | |||||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(user.getUserId(),user.getFinalTenantId()); | |||||
| if (wxCUserBasicInfo != null) { | |||||
| WxCUserBasicInfo basicInfo = new WxCUserBasicInfo(); | |||||
| basicInfo.setId(wxCUserBasicInfo.getId()); | |||||
| basicInfo.setFinalTenantId(user.getFinalTenantId()); | |||||
| basicInfo.setActiveTime(new Date()); | |||||
| int loingcount = 0; | |||||
| try { | |||||
| loingcount = Integer.parseInt(wxCUserBasicInfo.getLoginCount().toString()); | |||||
| }catch(Exception e) { | |||||
| } | |||||
| basicInfo.setLoginCount(loingcount+1); | |||||
| wxCUserBasicInfoService.update(basicInfo); | |||||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_LOGIN, user,user,null); | |||||
| } | |||||
| } | |||||
| cleanCuserToken(user.getToken()); | |||||
| } | |||||
| public Long saveToBasicInfoByCUser(TenantEntity tenantEntity,String userPhone,String userName,String avatarUrl,Integer sex,Long userId) { | |||||
| if (StringUtils.isBlank(userPhone)) | |||||
| return null; | |||||
| WxCUserBasicInfo byId = null; | |||||
| if (null != userId) { | |||||
| byId = wxCUserBasicInfoService.getById(userId,tenantEntity.getFinalTenantId()); | |||||
| } | |||||
| WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(tenantEntity, userPhone); | |||||
| if (basicInfo != null) { | |||||
| if (byId != null) { | |||||
| if (!byId.getId().equals(basicInfo.getId())) { | |||||
| //数据库存在此手机号的会员,并且当前微信存在另一手机号会员 | |||||
| logger.error("会员" + userId + "更换手机号时,当前手机号会员表已存在:" + userPhone); | |||||
| return Long.valueOf(-1); | |||||
| } | |||||
| } | |||||
| if (!basicInfo.getTenantId().contains("," + tenantEntity.getTenantId() + ",")) { | |||||
| basicInfo.setTenantId(basicInfo.getTenantId() + tenantEntity.getTenantId() + ","); | |||||
| } | |||||
| basicInfo.setNickName(userName); | |||||
| basicInfo.setAvatarUrl(avatarUrl); | |||||
| basicInfo.setSex(sex); | |||||
| wxCUserBasicInfoService.update(basicInfo); | |||||
| cleanBasicUser(basicInfo.getId()); | |||||
| return basicInfo.getId(); | |||||
| } else { | |||||
| if (byId != null) { | |||||
| if (!byId.getTenantId().contains("," + tenantEntity.getTenantId() + ",")) { | |||||
| byId.setTenantId(byId.getTenantId() + tenantEntity.getTenantId() + ","); | |||||
| } | |||||
| byId.setPhone(userPhone); | |||||
| byId.setNickName(userName); | |||||
| byId.setAvatarUrl(avatarUrl); | |||||
| byId.setSex(sex); | |||||
| wxCUserBasicInfoService.update(byId); | |||||
| cleanBasicUser(byId.getId()); | |||||
| return byId.getId(); | |||||
| } else { | |||||
| basicInfo = new WxCUserBasicInfo(); | |||||
| basicInfo.setTenantId("," + tenantEntity.getTenantId() + ","); | |||||
| basicInfo.setFinalTenantId(tenantEntity.getFinalTenantId()); | |||||
| basicInfo.setPhone(userPhone); | |||||
| basicInfo.setNickName(userName); | |||||
| basicInfo.setAvatarUrl(avatarUrl); | |||||
| basicInfo.setSex(sex); | |||||
| wxCUserBasicInfoService.save(basicInfo); | |||||
| cleanBasicUser(basicInfo.getId()); | |||||
| // 首次授权, 增加成长值及积分 | |||||
| // 成长值 | |||||
| wxScoreRulesService.addScore(tenantEntity, EnumScoreType.WECHAT_PHONE, basicInfo); | |||||
| // 增加积分 | |||||
| wxCUserBasicInfoService.addCredit(basicInfo.getId(),tenantEntity,EnumScoreType.WECHAT_PHONE); | |||||
| // 外部注券 | |||||
| memCouponFromDspService.couponOrderFromDsp(tenantEntity, userPhone); | |||||
| return basicInfo.getId(); | |||||
| } | |||||
| } | |||||
| } | |||||
| public void cleanCuserToken(String token){ | |||||
| String key = Constant.tokenPrev + token; | |||||
| if(baseCUserTokenRedisTemplate.hasKey(key)){ | |||||
| baseCUserTokenRedisTemplate.delete(key); | |||||
| } | |||||
| } | |||||
| public void cleanBasicUser(Long memberId){ | |||||
| String key = "webapp:member:"+memberId; | |||||
| RedisCacheUtils.removeCache(objectCommonRedisTemplate, key); | |||||
| String shortKey = "webapp:short:member:"+memberId; | |||||
| RedisCacheUtils.removeCache(objectCommonRedisTemplate, shortKey); | |||||
| } | |||||
| } | |||||
| @@ -4,23 +4,14 @@ import java.util.Date; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.concurrent.ConcurrentHashMap; | import java.util.concurrent.ConcurrentHashMap; | ||||
| import com.iformall.domain.po.CUser; | |||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| import com.iformall.domain.po.WxCUserFrom; | |||||
| import com.iformall.domain.po.base.BaseCUserEntity; | import com.iformall.domain.po.base.BaseCUserEntity; | ||||
| import com.iformall.domain.po.base.TenantEntity; | |||||
| import com.iformall.domain.po.msg.FmInsideCLoginMsg; | |||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.mq.MqBaseProducer; | import com.iformall.mq.MqBaseProducer; | ||||
| import com.iformall.service.MemCouponFromDspService; | import com.iformall.service.MemCouponFromDspService; | ||||
| import com.iformall.service.WxCUserBasicInfoService; | import com.iformall.service.WxCUserBasicInfoService; | ||||
| import com.iformall.service.WxCUserTagsService; | import com.iformall.service.WxCUserTagsService; | ||||
| import com.iformall.service.WxScoreRulesService; | import com.iformall.service.WxScoreRulesService; | ||||
| import com.iformall.service.cuser.tt.TtCUserServiceAdapter; | import com.iformall.service.cuser.tt.TtCUserServiceAdapter; | ||||
| import com.iformall.utils.Constant; | |||||
| import com.iformall.utils.RedisCacheUtils; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| 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; | ||||
| @@ -43,29 +34,6 @@ public class CUserServiceFactory { | |||||
| @Autowired | @Autowired | ||||
| private TtCUserServiceAdapter ttCuserService; | private TtCUserServiceAdapter ttCuserService; | ||||
| @Autowired | |||||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||||
| @Autowired | |||||
| private WxCUserTagsService wxCUserTagsService; | |||||
| @Autowired | |||||
| private MemCouponFromDspService memCouponFromDspService; | |||||
| @Autowired | |||||
| private MqBaseProducer mqBaseProducer; | |||||
| @Autowired | |||||
| private WxScoreRulesService wxScoreRulesService; | |||||
| @Autowired | |||||
| @Qualifier("baseCUserTokenRedisTemplate") | |||||
| RedisTemplate<String, BaseCUserEntity> baseCUserTokenRedisTemplate; | |||||
| @Autowired | |||||
| @Qualifier("objectCommonRedisTemplate") | |||||
| RedisTemplate<String, Object> objectCommonRedisTemplate; | |||||
| public CUserServiceApapter getCUserService(EnumAppPlat plat) { | public CUserServiceApapter getCUserService(EnumAppPlat plat) { | ||||
| return getcUserServiceMap().get(plat.getCode()); | return getcUserServiceMap().get(plat.getCode()); | ||||
| @@ -81,121 +49,4 @@ public class CUserServiceFactory { | |||||
| return serviceMap; | return serviceMap; | ||||
| } | } | ||||
| public void actionMsgAfterLogin(WxCUserFrom wxCUserFrom) { | |||||
| wxCUserFrom.setCreateDate(new Date()); | |||||
| FmInsideCLoginMsg loginMsg = new FmInsideCLoginMsg(); | |||||
| loginMsg.updateTenantInfo(wxCUserFrom); | |||||
| loginMsg.setMsgType(EnumMsgRecordType.INSIDE_C_LOGIN.getCode()); | |||||
| loginMsg.setWxCUserFrom(wxCUserFrom); | |||||
| mqBaseProducer.sendMessage(loginMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||||
| } | |||||
| public void actionAfterLogin(CUser user) { | |||||
| // 成长值 | |||||
| try { | |||||
| wxScoreRulesService.addScore(user, EnumScoreType.LOGIN, user); | |||||
| } catch (MallinkException e) { | |||||
| logger.error("c_user 成长值 " + e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error("c_user 成长值 " + e.getMessage()); | |||||
| } | |||||
| // 用户登陆后 更新最后一次活跃时间 | |||||
| if (user.getUserId() != null) { | |||||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(user.getUserId(),user.getFinalTenantId()); | |||||
| if (wxCUserBasicInfo != null) { | |||||
| WxCUserBasicInfo basicInfo = new WxCUserBasicInfo(); | |||||
| basicInfo.setId(wxCUserBasicInfo.getId()); | |||||
| basicInfo.setFinalTenantId(user.getFinalTenantId()); | |||||
| basicInfo.setActiveTime(new Date()); | |||||
| int loingcount = 0; | |||||
| try { | |||||
| loingcount = Integer.parseInt(wxCUserBasicInfo.getLoginCount().toString()); | |||||
| }catch(Exception e) { | |||||
| } | |||||
| basicInfo.setLoginCount(loingcount+1); | |||||
| wxCUserBasicInfoService.update(basicInfo); | |||||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_LOGIN, user,user,null); | |||||
| } | |||||
| } | |||||
| cleanCuserToken(user.getToken()); | |||||
| } | |||||
| public Long saveToBasicInfoByCUser(TenantEntity tenantEntity,String userPhone,String userName,String avatarUrl,Integer sex,Long userId) { | |||||
| if (StringUtils.isBlank(userPhone)) | |||||
| return null; | |||||
| WxCUserBasicInfo byId = null; | |||||
| if (null != userId) { | |||||
| byId = wxCUserBasicInfoService.getById(userId,tenantEntity.getFinalTenantId()); | |||||
| } | |||||
| WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(tenantEntity, userPhone); | |||||
| if (basicInfo != null) { | |||||
| if (byId != null) { | |||||
| if (!byId.getId().equals(basicInfo.getId())) { | |||||
| //数据库存在此手机号的会员,并且当前微信存在另一手机号会员 | |||||
| logger.error("会员" + userId + "更换手机号时,当前手机号会员表已存在:" + userPhone); | |||||
| return Long.valueOf(-1); | |||||
| } | |||||
| } | |||||
| if (!basicInfo.getTenantId().contains("," + tenantEntity.getTenantId() + ",")) { | |||||
| basicInfo.setTenantId(basicInfo.getTenantId() + tenantEntity.getTenantId() + ","); | |||||
| } | |||||
| basicInfo.setNickName(userName); | |||||
| basicInfo.setAvatarUrl(avatarUrl); | |||||
| basicInfo.setSex(sex); | |||||
| wxCUserBasicInfoService.update(basicInfo); | |||||
| cleanBasicUser(basicInfo.getId()); | |||||
| return basicInfo.getId(); | |||||
| } else { | |||||
| if (byId != null) { | |||||
| if (!byId.getTenantId().contains("," + tenantEntity.getTenantId() + ",")) { | |||||
| byId.setTenantId(byId.getTenantId() + tenantEntity.getTenantId() + ","); | |||||
| } | |||||
| byId.setPhone(userPhone); | |||||
| byId.setNickName(userName); | |||||
| byId.setAvatarUrl(avatarUrl); | |||||
| byId.setSex(sex); | |||||
| wxCUserBasicInfoService.update(byId); | |||||
| cleanBasicUser(byId.getId()); | |||||
| return byId.getId(); | |||||
| } else { | |||||
| basicInfo = new WxCUserBasicInfo(); | |||||
| basicInfo.setTenantId("," + tenantEntity.getTenantId() + ","); | |||||
| basicInfo.setFinalTenantId(tenantEntity.getFinalTenantId()); | |||||
| basicInfo.setPhone(userPhone); | |||||
| basicInfo.setNickName(userName); | |||||
| basicInfo.setAvatarUrl(avatarUrl); | |||||
| basicInfo.setSex(sex); | |||||
| wxCUserBasicInfoService.save(basicInfo); | |||||
| cleanBasicUser(basicInfo.getId()); | |||||
| // 首次授权, 增加成长值及积分 | |||||
| // 成长值 | |||||
| wxScoreRulesService.addScore(tenantEntity, EnumScoreType.WECHAT_PHONE, basicInfo); | |||||
| // 增加积分 | |||||
| wxCUserBasicInfoService.addCredit(basicInfo.getId(),tenantEntity,EnumScoreType.WECHAT_PHONE); | |||||
| // 外部注券 | |||||
| memCouponFromDspService.couponOrderFromDsp(tenantEntity, userPhone); | |||||
| return basicInfo.getId(); | |||||
| } | |||||
| } | |||||
| } | |||||
| public void cleanCuserToken(String token){ | |||||
| String key = Constant.tokenPrev + token; | |||||
| if(baseCUserTokenRedisTemplate.hasKey(key)){ | |||||
| baseCUserTokenRedisTemplate.delete(key); | |||||
| } | |||||
| } | |||||
| public void cleanBasicUser(Long memberId){ | |||||
| String key = "webapp:member:"+memberId; | |||||
| RedisCacheUtils.removeCache(objectCommonRedisTemplate, key); | |||||
| String shortKey = "webapp:short:member:"+memberId; | |||||
| RedisCacheUtils.removeCache(objectCommonRedisTemplate, shortKey); | |||||
| } | |||||
| } | } | ||||
| @@ -1,6 +1,5 @@ | |||||
| package com.iformall.service.cuser.tt; | package com.iformall.service.cuser.tt; | ||||
| import cn.binarywang.wx.miniapp.api.WxMaService; | |||||
| import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | ||||
| import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; | ||||
| import cn.binarywang.wx.miniapp.bean.WxMaUserInfo; | import cn.binarywang.wx.miniapp.bean.WxMaUserInfo; | ||||
| @@ -18,6 +17,7 @@ import com.iformall.mapper.TtCUserMapper; | |||||
| import com.iformall.service.WxAppinfoService; | import com.iformall.service.WxAppinfoService; | ||||
| import com.iformall.service.WxCUserBasicInfoService; | import com.iformall.service.WxCUserBasicInfoService; | ||||
| import com.iformall.service.WxCUserTagsService; | import com.iformall.service.WxCUserTagsService; | ||||
| import com.iformall.service.cuser.BasicCUserService; | |||||
| import com.iformall.service.cuser.CUserServiceApapter; | import com.iformall.service.cuser.CUserServiceApapter; | ||||
| import com.iformall.service.cuser.CUserServiceFactory; | import com.iformall.service.cuser.CUserServiceFactory; | ||||
| import com.iformall.utils.Constant; | import com.iformall.utils.Constant; | ||||
| @@ -34,7 +34,7 @@ import java.util.Date; | |||||
| import java.util.List; | import java.util.List; | ||||
| @Service | @Service | ||||
| public class TtCUserServiceAdapter extends CUserServiceFactory implements CUserServiceApapter{ | |||||
| public class TtCUserServiceAdapter extends BasicCUserService implements CUserServiceApapter{ | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @@ -12,7 +12,7 @@ import com.iformall.enums.EnumYesOrNo; | |||||
| import com.iformall.service.WxAppinfoService; | import com.iformall.service.WxAppinfoService; | ||||
| import com.iformall.service.WxCUserBasicInfoService; | import com.iformall.service.WxCUserBasicInfoService; | ||||
| import com.iformall.service.WxCUserTagsService; | import com.iformall.service.WxCUserTagsService; | ||||
| import com.iformall.service.cuser.CUserServiceFactory; | |||||
| import com.iformall.service.cuser.BasicCUserService; | |||||
| import com.iformall.service.wechat.FmOpenService; | import com.iformall.service.wechat.FmOpenService; | ||||
| import com.iformall.utils.Constant; | import com.iformall.utils.Constant; | ||||
| import com.iformall.utils.MaUtil; | import com.iformall.utils.MaUtil; | ||||
| @@ -34,7 +34,7 @@ import java.util.Date; | |||||
| import java.util.List; | import java.util.List; | ||||
| @Service | @Service | ||||
| public class WxCUserServiceAdapter extends CUserServiceFactory implements CUserServiceApapter{ | |||||
| public class WxCUserServiceAdapter extends BasicCUserService implements CUserServiceApapter{ | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||