| @@ -186,7 +186,8 @@ public class WxUserGrantController extends BaseController { | |||
| String session_key = null; | |||
| String openId = null; | |||
| String unionId = null; | |||
| boolean bHaveUnionId = false; | |||
| boolean boolHaveUnionId = false; | |||
| boolean boolFindByUnionId = false; | |||
| Long userId = null; | |||
| try { | |||
| @@ -196,7 +197,7 @@ public class WxUserGrantController extends BaseController { | |||
| openId = session.getOpenid(); | |||
| unionId = session.getUnionid(); | |||
| if (StringUtils.isNotBlank(unionId)) { | |||
| bHaveUnionId = true; | |||
| boolHaveUnionId = true; | |||
| } | |||
| logger.info("session_key: " + session_key + ", openId: " + openId + ", unionId: " + unionId); | |||
| @@ -213,24 +214,26 @@ public class WxUserGrantController extends BaseController { | |||
| newUser.setTenantId(wxAuthorizerInfo.getTenantId()); | |||
| newUser.setAppId(appId); | |||
| newUser.setOpenId(openId); | |||
| if (bHaveUnionId) { | |||
| if (boolHaveUnionId) { | |||
| newUser.setUnionId(unionId); | |||
| } | |||
| WxCUser oldUser = null; | |||
| if (bHaveUnionId) { | |||
| if (boolHaveUnionId) { | |||
| // 优先根据unionId查询 | |||
| WxCUser userQ = new WxCUser(); | |||
| userQ.setTenantId(wxAuthorizerInfo.getTenantId()); | |||
| userQ.setUnionId(unionId); | |||
| oldUser = wxCUserService.getByObject(userQ); | |||
| if(oldUser != null) { | |||
| boolFindByUnionId = true; | |||
| } | |||
| } | |||
| if (oldUser == null) { | |||
| oldUser = wxCUserService.getByOpenId(newUser); | |||
| } | |||
| if (oldUser != null) { | |||
| // 已有用户 | |||
| userId = oldUser.getId(); | |||
| token = oldUser.createToken(new Date()); | |||
| resultMap.put("token", token); | |||
| @@ -241,7 +244,7 @@ public class WxUserGrantController extends BaseController { | |||
| oldUser.setSessionKey(session_key); | |||
| oldUser.setAppId(appId); | |||
| oldUser.setOpenId(openId); | |||
| if (bHaveUnionId) { | |||
| if (boolHaveUnionId) { | |||
| oldUser.setUnionId(unionId); | |||
| } | |||
| if (StringUtils.isNotBlank(wxAuthorizerInfo.getOpenAppid())) { | |||
| @@ -272,9 +275,10 @@ public class WxUserGrantController extends BaseController { | |||
| userTokenService.saveOrUpdate(oldUser); | |||
| // 登录后处理 | |||
| int score = wxCUserService.actionAfterLogin(oldUser); | |||
| int score = wxCUserService.actionAfterLogin(oldUser, boolFindByUnionId); | |||
| resultMap.put("score", score); | |||
| } else { | |||
| // 新用户 | |||
| newUser.setTenantId(wxAuthorizerInfo.getTenantId()); | |||
| token = newUser.createToken(new Date()); | |||
| @@ -309,7 +313,7 @@ public class WxUserGrantController extends BaseController { | |||
| request.setAttribute(Constant.TENANT_ID, newUser.getTenantId()); | |||
| // 登录后处理 | |||
| int score = wxCUserService.actionAfterLogin(newUser); | |||
| int score = wxCUserService.actionAfterLogin(newUser, null); | |||
| resultMap.put("score", score); | |||
| } | |||
| @@ -14,4 +14,7 @@ public class FmInsideCLoginMsg extends BaseMsg{ | |||
| private String tenantId; | |||
| @io.swagger.annotations.ApiModelProperty(value = "用户ID", name = "cUserId") | |||
| private Long cUserId; | |||
| @io.swagger.annotations.ApiModelProperty(value = "是否从unionId更新", name = "findByUnionId") | |||
| private Boolean findByUnionId; | |||
| } | |||
| @@ -110,14 +110,14 @@ public interface WxCUserService { | |||
| * 登录后发消息 | |||
| * @param user | |||
| */ | |||
| void actionMsgAfterLogin(WxCUser user); | |||
| void actionMsgAfterLogin(WxCUser user, Boolean findByUnionId); | |||
| /** | |||
| * 登录后处理 | |||
| * @param user | |||
| * @return | |||
| */ | |||
| int actionAfterLogin(WxCUser user); | |||
| int actionAfterLogin(WxCUser user, Boolean findByUnionId); | |||
| /** | |||
| * 积分 | |||
| @@ -9,7 +9,6 @@ import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxCreditHistory; | |||
| import com.iformall.domain.po.msg.FmInsideCLoginMsg; | |||
| import com.iformall.domain.po.msg.FmInsideCouponVerifyMsg; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxCUserMapper; | |||
| @@ -23,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Service | |||
| public class WxCUserServiceImpl implements WxCUserService { | |||
| @@ -216,17 +216,18 @@ public class WxCUserServiceImpl implements WxCUserService { | |||
| } | |||
| @Override | |||
| public void actionMsgAfterLogin(WxCUser user) { | |||
| public void actionMsgAfterLogin(WxCUser user, Boolean findByUnionId) { | |||
| FmInsideCLoginMsg loginMsg = new FmInsideCLoginMsg(); | |||
| loginMsg.setMsgType(EnumMsgRecordType.INSIDE_C_LOGIN.getCode()); | |||
| loginMsg.setTenantId(user.getTenantId()); | |||
| loginMsg.setCUserId(user.getId()); | |||
| loginMsg.setFindByUnionId(findByUnionId); | |||
| mqBaseProducer.sendMessage(loginMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| } | |||
| @Override | |||
| public int actionAfterLogin(WxCUser user) { | |||
| public int actionAfterLogin(WxCUser user, Boolean findByUnionId) { | |||
| int score = 0; | |||
| int credit = 0; | |||
| // 成长值 | |||
| @@ -267,6 +268,23 @@ public class WxCUserServiceImpl implements WxCUserService { | |||
| saveOrUpdate(cUser); | |||
| } | |||
| } | |||
| // 用户从unionId来的,可能会有重复 | |||
| if(findByUnionId != null) { | |||
| if(findByUnionId) { | |||
| WxCUser userQ = new WxCUser(); | |||
| userQ.setOpenAppId(user.getAppId()); | |||
| userQ.setOpenId(user.getOpenId()); | |||
| List<WxCUser> userList = wxCUserMapper.findList(userQ); | |||
| if(userList.size() > 1) { | |||
| for(WxCUser tempUser: userList) { | |||
| if(tempUser.getUnionId() == null) { | |||
| // 删除 无unionId的用户 | |||
| wxCUserMapper.deleteByPrimaryKey(tempUser.getId()); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| return score; | |||
| } | |||