From aa552facf6d833acab0d3e3e29bda2a0fb826ffe Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期一, 25 十一月 2019 16:14:13 +0800 Subject: [PATCH] 品牌缓存生效 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java | 85 ++++++++++++++++++++---------------------- 1 files changed, 40 insertions(+), 45 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java index 2c47f55..63f9ea9 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java @@ -121,8 +121,7 @@ @Lazy @Resource private UserInfoModifyRecordService userInfoModifyRecordService; - - + @Transactional @Override public LoginResult login(HttpServletRequest request, AcceptData acceptData, Boolean first, String appId, @@ -223,6 +222,8 @@ updateUserInfo.setLastLoginTime(System.currentTimeMillis()); updateUserInfo.setLoginType(loginType); updateUserInfo.setLastLoginIp(request.getRemoteHost()); + // 鏇存柊openId + updateUserInfo.setOpenid(weiXinUser.getOpenid()); userInfoMapper.updateByPrimaryKeySelective(updateUserInfo); // 鍒犻櫎閭�璇峰浘鐗� @@ -692,6 +693,7 @@ addUser(userInfo); } + @Transactional @Override public void addUser(UserInfo user) { @@ -724,12 +726,12 @@ e.printStackTrace(); } + // 娣诲姞璐﹀彿缁戝畾鍘嗗彶 if (!StringUtil.isNullOrEmpty(user.getPhone())) userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindPhone, user.getPhone()); if (!StringUtil.isNullOrEmpty(user.getWxUnionId())) userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, user.getWxUnionId()); - } @Override @@ -1067,7 +1069,7 @@ } finally { jedis.del(watchKey); jedis.unwatch(); - jedisPool.returnResource(jedis); + jedis.close(); } throw new UserAccountException(10, "璇风◢鍚庡啀璇�"); } @@ -1085,8 +1087,7 @@ // 閫氳繃Code鎹㈠彇淇℃伅 WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion()); - WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), - wxAccount.getAppSecret()); + WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret()); if (weiXinUser == null) { throw new UserAccountException(1, "寰俊甯愬彿鎺堟潈澶辫触"); } @@ -1123,23 +1124,24 @@ spreadUserImgService.deleteImgUrl(userInfo.getId()); } else { LogHelper.test("寰俊unionID涓嶅瓨鍦�:" + weiXinUser.getUnionid()); - + String portrait = null; if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) { InputStream asInputStream = HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl()); if (asInputStream != null) { FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, - String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); + String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), + System.currentTimeMillis() + "")); if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) portrait = result.getUrl(); } else { portrait = weiXinUser.getHeadimgurl(); } } - + if (StringUtil.isNullOrEmpty(portrait)) portrait = Constant.systemCommonConfig.getDefaultPortrait(); - + // 鍒涘缓鏂拌处鎴� userInfo = new UserInfo(); userInfo.setPortrait(portrait); @@ -1172,15 +1174,15 @@ } finally { jedis.del(watchKey); jedis.unwatch(); - jedisPool.returnResource(jedis); + jedis.close(); } throw new UserAccountException(10, "璇风◢鍚庡啀璇�"); } - @Transactional @Override - public UserInfo loginWeiXinNew(HttpServletRequest request, AcceptData acceptData, int loginType, String wxCode, String appId) throws UserAccountException { + public UserInfo loginWeiXinNew(HttpServletRequest request, AcceptData acceptData, int loginType, String wxCode, + String appId) throws UserAccountException { // 鏃ュ織淇℃伅 JSONObject logInfo = new JSONObject(); logInfo.put("appId", appId); @@ -1190,8 +1192,7 @@ // 閫氳繃Code鎹㈠彇淇℃伅 WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion()); - WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(wxCode, wxAccount.getAppId(), - wxAccount.getAppSecret()); + WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(wxCode, wxAccount.getAppId(), wxAccount.getAppSecret()); if (weiXinUser == null) { throw new UserAccountException(1, "寰俊甯愬彿鎺堟潈澶辫触"); } @@ -1204,7 +1205,6 @@ throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); } - UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid()); if (userInfo == null) { String longinKey = StringUtil.Md5("WXLogin:" + weiXinUser.getUnionid()); @@ -1223,8 +1223,6 @@ return userInfo; } - - /** * 鏇存柊璐︽埛鐧诲綍淇℃伅 * @@ -1289,8 +1287,7 @@ throw new UserAccountException(1, "鐢ㄦ埛涓嶅瓨鍦�"); } WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion()); - WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), - wxAccount.getAppSecret()); + WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret()); if (weiXinUser == null) { throw new UserAccountException(2, "寰俊甯愬彿鎺堟潈澶辫触"); } @@ -1306,7 +1303,7 @@ if (newUser != null) { throw new UserAccountException(4, "璇ュ井淇″彿宸茶鍏朵粬甯愬彿缁戝畾"); } - } else if (wxUnionId.equals(wxUnionIdExist)) { + } else if (wxUnionId.equalsIgnoreCase(wxUnionIdExist)) { throw new UserAccountException(3, "寰俊甯愬彿涓�鑷存棤闇�鏇存崲"); } @@ -1336,14 +1333,14 @@ String headimgurl = weiXinUser.getHeadimgurl(); InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl); if (asInputStream == null) { - LogHelper.test("寰俊澶村儚涓嬭浇澶辫触: " +weiXinUser.getUnionid()+ " " + headimgurl); + LogHelper.test("寰俊澶村儚涓嬭浇澶辫触: " + weiXinUser.getUnionid() + " " + headimgurl); } else { - FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, - String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); + FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String + .format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) { headimgurl = result.getUrl(); } else { - LogHelper.test("寰俊澶村儚涓婁紶澶辫触: " +weiXinUser.getUnionid()+ " " + headimgurl); + LogHelper.test("寰俊澶村儚涓婁紶澶辫触: " + weiXinUser.getUnionid() + " " + headimgurl); } } updateUserInfo.setPortrait(headimgurl); @@ -1367,49 +1364,49 @@ userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, wxUnionId); } - - + @Override - public UserInfo bindPhoneToLogin(String phone, String key, String appId, HttpServletRequest request) throws UserAccountException { + public UserInfo bindPhoneToLogin(String phone, String key, String appId, HttpServletRequest request) + throws UserAccountException { UserInfo phoneUser = userInfoMapper.getEffectiveUserInfoByPhone(phone); - if (phoneUser != null) + if (phoneUser != null) throw new UserAccountException(1, "鍙风爜宸茬粡琚崰鐢�"); - + // 鍒ゆ柇鎵嬫満鍙风爜鏄惁琚皝绂� ForbiddenUserIdentifyCode identifyCode1 = forbiddenUserIdentifyCodeService .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, phone); if (identifyCode1 != null && identifyCode1.getEffective() != null && identifyCode1.getEffective()) throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); - + String value = redisManager.getCommonString(key); if (StringUtil.isNullOrEmpty(value)) throw new UserAccountException(1, "寰俊鎺堟潈澶辨晥锛岃浣跨敤寰俊閲嶆柊鐧诲綍"); - + WeiXinUser weiXinUser = JsonUtil.getSimpleGson().fromJson(value, WeiXinUser.class); if (weiXinUser == null) throw new UserAccountException(1, "寰俊鎺堟潈澶辨晥锛岃浣跨敤寰俊閲嶆柊鐧诲綍"); - + UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid()); // 鐩存帴鐢ㄧ殑寰俊鐧诲綍 - if (userInfo != null) + if (userInfo != null) throw new UserAccountException(10, "璇ュ井淇″彿宸茶鍗犵敤"); - + String portrait = null; if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) { InputStream asInputStream = HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl()); if (asInputStream != null) { - FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, - String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); + FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String + .format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) portrait = result.getUrl(); } else { portrait = weiXinUser.getHeadimgurl(); } } - + if (StringUtil.isNullOrEmpty(portrait)) portrait = Constant.systemCommonConfig.getDefaultPortrait(); - + // 鍒涘缓鏂拌处鎴� userInfo = new UserInfo(); userInfo.setPhone(phone); @@ -1425,7 +1422,7 @@ userInfo.setLastLoginIp(request.getRemoteHost()); userInfo.setState(UserInfo.STATE_NORMAL); addUser(userInfo); - + Long uid = userInfo.getId(); ThreadUtil.run(new Runnable() { public void run() { @@ -1435,7 +1432,7 @@ } catch (Exception e) { e.printStackTrace(); } - + // 鍔犲叆缁戝畾璁板綍 UserAccountBindingHistory history = new UserAccountBindingHistory(); history.setContent(phone); @@ -1445,16 +1442,14 @@ userAccountBindingHistoryService.addUserAccountBindingHistory(history); userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindPhone, phone); - userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, weiXinUser.getUnionid()); + userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, weiXinUser.getUnionid()); } }); // 鍒犻櫎缂撳瓨 redisManager.removeCommonString(key); - + return userInfo; } - - @Override public void forbiddenUserAll(Long uid, String reason) { -- Gitblit v1.8.0