Commit e59d841cfb5b0c3ff9d85385890e72fb0f5e8e93
Merge branch 'dev' of http://git3.nong12.com/b2c/gateway into dev
# Conflicts: # mobsite-getway-service/src/main/java/com/diligrp/mobsite/getway/service/buyer/user/impl/UserServiceImpl.java
Showing
5 changed files
with
128 additions
and
36 deletions
mobsite-getway-domain/src/main/java/com/diligrp/mobsite/getway/domain/common/RedisKey.java
@@ -22,7 +22,11 @@ public final class RedisKey { | @@ -22,7 +22,11 @@ public final class RedisKey { | ||
22 | public static final String USER_DEVICEID = ZDAPP_GETWAY+":USER:DEVICEID"; | 22 | public static final String USER_DEVICEID = ZDAPP_GETWAY+":USER:DEVICEID"; |
23 | public static final String USER_REGISTERNO = ZDAPP_GETWAY+":USER:REGISTERNO"; | 23 | public static final String USER_REGISTERNO = ZDAPP_GETWAY+":USER:REGISTERNO"; |
24 | 24 | ||
25 | - public static final String USER_SHOPID = ZDAPP_GETWAY+":USER:SHOPID"; | 25 | + public static final String USER_SELLER_SHOPID = ZDAPP_GETWAY+":SELLER:SHOPID"; |
26 | + | ||
27 | + public static final String USER_BUYER_CURRENTSHOPID = ZDAPP_GETWAY+":BUYER:SHOPID"; | ||
28 | + | ||
29 | + public static final String USER_BUYER_SHOPUSERID = ZDAPP_GETWAY+":BUYER:SHOPUSERID"; | ||
26 | 30 | ||
27 | //门卫登录信息 | 31 | //门卫登录信息 |
28 | public static final String GUARD_LOGININFO = ZDAPP_GETWAY+":GUARD:LOGININFO"; | 32 | public static final String GUARD_LOGININFO = ZDAPP_GETWAY+":GUARD:LOGININFO"; |
mobsite-getway-domain/src/main/java/com/diligrp/mobsite/getway/domain/protocol/login/LoginResp.java
@@ -29,7 +29,7 @@ public class LoginResp extends BaseResp { | @@ -29,7 +29,7 @@ public class LoginResp extends BaseResp { | ||
29 | * 账户ID | 29 | * 账户ID |
30 | */ | 30 | */ |
31 | @ApiModelProperty(value = "用户id") | 31 | @ApiModelProperty(value = "用户id") |
32 | - private Long accountId; | 32 | + private Long buyerId; |
33 | /** | 33 | /** |
34 | * 账户名 | 34 | * 账户名 |
35 | */ | 35 | */ |
@@ -49,25 +49,36 @@ public class LoginResp extends BaseResp { | @@ -49,25 +49,36 @@ public class LoginResp extends BaseResp { | ||
49 | private String headImg; | 49 | private String headImg; |
50 | 50 | ||
51 | 51 | ||
52 | - | ||
53 | - /** | ||
54 | - * get value of LoginResp.accountId | ||
55 | - * @return the accountId | ||
56 | - * @createTime Aug 13, 2014 9:58:39 AM | ||
57 | - * @author weili | ||
58 | - */ | ||
59 | - public Long getAccountId() { | ||
60 | - return accountId; | 52 | + @ApiModelProperty(value = "当前绑定的店铺id") |
53 | + private Long currentShopId; | ||
54 | + | ||
55 | + @ApiModelProperty(value = "店铺购买者ID") | ||
56 | + private Long shopBuyerId; | ||
57 | + | ||
58 | + | ||
59 | + public Long getBuyerId() { | ||
60 | + return buyerId; | ||
61 | } | 61 | } |
62 | 62 | ||
63 | - /** | ||
64 | - * set value of LoginResp.accountId | ||
65 | - * @param accountId the accountId to set | ||
66 | - * @createTime Aug 13, 2014 9:58:39 AM | ||
67 | - * @author weili | ||
68 | - */ | ||
69 | - public void setAccountId(Long accountId) { | ||
70 | - this.accountId = accountId; | 63 | + public void setBuyerId(Long buyerId) { |
64 | + this.buyerId = buyerId; | ||
65 | + } | ||
66 | + | ||
67 | + | ||
68 | + public Long getCurrentShopId() { | ||
69 | + return currentShopId; | ||
70 | + } | ||
71 | + | ||
72 | + public void setCurrentShopId(Long currentShopId) { | ||
73 | + this.currentShopId = currentShopId; | ||
74 | + } | ||
75 | + | ||
76 | + public Long getShopBuyerId() { | ||
77 | + return shopBuyerId; | ||
78 | + } | ||
79 | + | ||
80 | + public void setShopBuyerId(Long shopBuyerId) { | ||
81 | + this.shopBuyerId = shopBuyerId; | ||
71 | } | 82 | } |
72 | 83 | ||
73 | /** | 84 | /** |
mobsite-getway-rpc/src/main/java/com/diligrp/mobsite/getway/rpc/impl/PassportRPCImpl.java
@@ -103,17 +103,17 @@ public class PassportRPCImpl extends BaseServiceImpl implements PassportRPC { | @@ -103,17 +103,17 @@ public class PassportRPCImpl extends BaseServiceImpl implements PassportRPC { | ||
103 | resp.setMsg(msg); | 103 | resp.setMsg(msg); |
104 | 104 | ||
105 | //缓存userId | 105 | //缓存userId |
106 | - String cookieRedisKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, Constant.USER_ROLE_SELLER+String.valueOf(resp.getSellerId())); | 106 | + String cookieRedisKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, Constant.USER_ROLE_SIGN_SELLER+String.valueOf(resp.getSellerId())); |
107 | redisUtil.setStringByExpire(cookieRedisKey, String.valueOf(resp.getSellerId()), loginExpireTime); | 107 | redisUtil.setStringByExpire(cookieRedisKey, String.valueOf(resp.getSellerId()), loginExpireTime); |
108 | 108 | ||
109 | //缓存shopId | 109 | //缓存shopId |
110 | - String shopIdKey = redisUtil.makeKey(RedisKey.USER_SHOPID, Constant.USER_ROLE_SELLER+String.valueOf(resp.getSellerId())); | ||
111 | - redisUtil.setStringByExpire(shopIdKey, String.valueOf(resp.getShopId()), loginExpireTime); | 110 | + //String shopIdKey = redisUtil.makeKey(RedisKey.USER_SELLER_SHOPID, Constant.USER_ROLE_SIGN_SELLER+String.valueOf(resp.getSellerId())); |
111 | + //redisUtil.setStringByExpire(shopIdKey, String.valueOf(resp.getShopId()), loginExpireTime); | ||
112 | 112 | ||
113 | 113 | ||
114 | //缓存设备id,userId作为key | 114 | //缓存设备id,userId作为key |
115 | if (!Validator.isNull(req.getDeviceId())) { | 115 | if (!Validator.isNull(req.getDeviceId())) { |
116 | - String onlyOneLoginRedisKey = redisUtil.makeKey(RedisKey.USER_DEVICEID, Constant.USER_ROLE_SELLER+String.valueOf(resp.getSellerId())); | 116 | + String onlyOneLoginRedisKey = redisUtil.makeKey(RedisKey.USER_DEVICEID, Constant.USER_ROLE_SIGN_SELLER+String.valueOf(resp.getSellerId())); |
117 | redisUtil.setStringByExpire(onlyOneLoginRedisKey, req.getDeviceId(), loginExpireTime); | 117 | redisUtil.setStringByExpire(onlyOneLoginRedisKey, req.getDeviceId(), loginExpireTime); |
118 | } | 118 | } |
119 | return resp; | 119 | return resp; |
@@ -202,7 +202,74 @@ public class PassportRPCImpl extends BaseServiceImpl implements PassportRPC { | @@ -202,7 +202,74 @@ public class PassportRPCImpl extends BaseServiceImpl implements PassportRPC { | ||
202 | @Override | 202 | @Override |
203 | public LoginResp buyerLogin(LoginReq req) { | 203 | public LoginResp buyerLogin(LoginReq req) { |
204 | 204 | ||
205 | - return null; | 205 | + Map<String,String> params = new HashMap<String, String>(); |
206 | + params.put("userName", req.getAccountName()); | ||
207 | + params.put("password", req.getPassword()); | ||
208 | + params.put("src", "zadeapp"); | ||
209 | + BaseOutput<String> output = null; | ||
210 | + try { | ||
211 | + output = super.httpPost("/api/login/login.html", params, null,passportSign); | ||
212 | + } catch (Exception e) { | ||
213 | + log.error("调用passport用户验证接口失败",e); | ||
214 | + throw new ServiceException(); | ||
215 | + } | ||
216 | + | ||
217 | + JSONObject jsonBody = JSONObject.parseObject(output.getData()); | ||
218 | + int code = 0; | ||
219 | + try { | ||
220 | + code = jsonBody.getIntValue("code"); | ||
221 | + } catch (Exception e) { | ||
222 | + log.error("passport返回数据:msg={}",jsonBody); | ||
223 | + throw new ServiceException(ResultCode.BUSINESS_FAILED,"登录失败请重新登录"); | ||
224 | + } | ||
225 | + | ||
226 | + String msg = jsonBody.getString("msg"); | ||
227 | + | ||
228 | + if (code == PASSPORT_LOGIN_CODE_LOCKED || code == PASSPORT_LOGIN_CODE_ACCOUNT_NOT_EXIST | ||
229 | + || code == PASSPORT_LOGIN_CODE_PASSWORD_WRONG) { | ||
230 | + throw new ServiceException(code,msg); | ||
231 | + }else if (code != ResultCode.SUCCESS) { | ||
232 | + throw new ServiceException(ResultCode.BUSINESS_FAILED,msg); | ||
233 | + } | ||
234 | + | ||
235 | + //resp.setToken(jsonBody.getString("token")); | ||
236 | + JSONObject jsonUser = jsonBody.getJSONObject("accountInfo"); | ||
237 | + LoginResp resp = new LoginResp(); | ||
238 | + resp.setBuyerId(jsonUser.getLong("accountId")); | ||
239 | + resp.setHeadImg(jsonUser.getString("img")); | ||
240 | + resp.setMobile("13985454555"); | ||
241 | + resp.setAccountName(""); | ||
242 | + resp.setCurrentShopId(123L); | ||
243 | + resp.setShopBuyerId(122L); | ||
244 | + resp.setCode(code); | ||
245 | + resp.setMsg(msg); | ||
246 | + | ||
247 | + //缓存userId | ||
248 | + String cookieRedisKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, Constant.USER_ROLE_SIGN_BUYER+String.valueOf(resp.getBuyerId())); | ||
249 | + redisUtil.setStringByExpire(cookieRedisKey, String.valueOf(resp.getBuyerId()), loginExpireTime); | ||
250 | + | ||
251 | + //缓存设备id,userId作为key | ||
252 | + if (!Validator.isNull(req.getDeviceId())) { | ||
253 | + String onlyOneLoginRedisKey = redisUtil.makeKey(RedisKey.USER_DEVICEID, Constant.USER_ROLE_SIGN_BUYER+String.valueOf(resp.getBuyerId())); | ||
254 | + redisUtil.setStringByExpire(onlyOneLoginRedisKey, req.getDeviceId(), loginExpireTime); | ||
255 | + } | ||
256 | + | ||
257 | + //缓存currentShopId | ||
258 | + //if (!Validator.isNull(resp.getCurrentShopId())){ | ||
259 | + // String currentShopIdKey = redisUtil.makeKey(RedisKey.USER_BUYER_CURRENTSHOPID, Constant.USER_ROLE_SIGN_BUYER+String.valueOf(resp.getBuyerId())); | ||
260 | + // redisUtil.setStringByExpire(currentShopIdKey, String.valueOf(resp.getCurrentShopId()), loginExpireTime); | ||
261 | + //} | ||
262 | + | ||
263 | + | ||
264 | + //缓存shopBuyerId | ||
265 | + //if (!Validator.isNull(resp.getShopBuyerId())){ | ||
266 | + // String shopUserIdKey = redisUtil.makeKey(RedisKey.USER_BUYER_SHOPUSERID, Constant.USER_ROLE_SIGN_BUYER+String.valueOf(resp.getBuyerId())); | ||
267 | + // redisUtil.setStringByExpire(shopUserIdKey, String.valueOf(resp.getShopBuyerId()), loginExpireTime); | ||
268 | + //} | ||
269 | + | ||
270 | + | ||
271 | + | ||
272 | + return resp; | ||
206 | } | 273 | } |
207 | 274 | ||
208 | } | 275 | } |
mobsite-getway-service/src/main/java/com/diligrp/mobsite/getway/service/buyer/user/impl/UserServiceImpl.java
@@ -147,14 +147,15 @@ public class UserServiceImpl implements UserService { | @@ -147,14 +147,15 @@ public class UserServiceImpl implements UserService { | ||
147 | if (!Validator.isEmpty(req.getRegisterNo())) { | 147 | if (!Validator.isEmpty(req.getRegisterNo())) { |
148 | // 缓存 | 148 | // 缓存 |
149 | String redisKey = redisUtil.makeKey(RedisKey.USER_REGISTERNO, | 149 | String redisKey = redisUtil.makeKey(RedisKey.USER_REGISTERNO, |
150 | - Constant.USER_ROLE_BUYER + String.valueOf(resp.getAccountId())); | 150 | + Constant.USER_ROLE_SIGN_BUYER + String.valueOf(resp.getBuyerId())); |
151 | 151 | ||
152 | GetRegisterNoResp mappers = redisUtil.getObject(redisKey, GetRegisterNoResp.class); | 152 | GetRegisterNoResp mappers = redisUtil.getObject(redisKey, GetRegisterNoResp.class); |
153 | // 绑定极光ID | 153 | // 绑定极光ID |
154 | RegisterNoMapper mapper = new RegisterNoMapper(); | 154 | RegisterNoMapper mapper = new RegisterNoMapper(); |
155 | mapper.setRegisterNo(req.getRegisterNo()); | 155 | mapper.setRegisterNo(req.getRegisterNo()); |
156 | mapper.setSysFlag(RegisterNoMapper.SYS_FLAG_JPUSH); | 156 | mapper.setSysFlag(RegisterNoMapper.SYS_FLAG_JPUSH); |
157 | - mapper.setUserid(resp.getAccountId()); | 157 | + mapper.setUserid(resp.getBuyerId()); |
158 | + mapper.setUserType(Constant.USER_ROLE_BUYER); | ||
158 | mapper.setDeviceType(req.getDeviceType()); | 159 | mapper.setDeviceType(req.getDeviceType()); |
159 | try { | 160 | try { |
160 | // 清除当前极光号userid缓存 | 161 | // 清除当前极光号userid缓存 |
@@ -177,7 +178,8 @@ public class UserServiceImpl implements UserService { | @@ -177,7 +178,8 @@ public class UserServiceImpl implements UserService { | ||
177 | private void cleanOldredis(RegisterNoMapper mapper) { | 178 | private void cleanOldredis(RegisterNoMapper mapper) { |
178 | RegisterNoMapper oldmapper = registerNoMapperManager.bindRegisterNo(mapper); | 179 | RegisterNoMapper oldmapper = registerNoMapperManager.bindRegisterNo(mapper); |
179 | if (!Validator.isNull(oldmapper)) { | 180 | if (!Validator.isNull(oldmapper)) { |
180 | - String oldKey = redisUtil.makeKey(RedisKey.USER_REGISTERNO, String.valueOf(oldmapper.getUserid())); | 181 | + String oldKey = redisUtil.makeKey(RedisKey.USER_REGISTERNO, |
182 | + Constant.USER_ROLE_SIGN_BUYER + String.valueOf(oldmapper.getUserid())); | ||
181 | redisUtil.deleteByKey(oldKey); | 183 | redisUtil.deleteByKey(oldKey); |
182 | } | 184 | } |
183 | } | 185 | } |
@@ -419,12 +421,13 @@ public class UserServiceImpl implements UserService { | @@ -419,12 +421,13 @@ public class UserServiceImpl implements UserService { | ||
419 | 421 | ||
420 | String userId = req.getUserId().toString(); | 422 | String userId = req.getUserId().toString(); |
421 | // 先清缓存再清数据库 | 423 | // 先清缓存再清数据库 |
422 | - String reNOCache = redisUtil.makeKey(RedisKey.USER_REGISTERNO, Constant.USER_ROLE_BUYER + userId); | 424 | + String reNOCache = redisUtil.makeKey(RedisKey.USER_REGISTERNO, Constant.USER_ROLE_SIGN_BUYER + userId); |
423 | 425 | ||
424 | RegisterNoMapper mapper = new RegisterNoMapper(); | 426 | RegisterNoMapper mapper = new RegisterNoMapper(); |
425 | mapper.setRegisterNo(req.getRegisterNo()); | 427 | mapper.setRegisterNo(req.getRegisterNo()); |
426 | mapper.setSysFlag(RegisterNoMapper.SYS_FLAG_JPUSH); | 428 | mapper.setSysFlag(RegisterNoMapper.SYS_FLAG_JPUSH); |
427 | mapper.setUserid(req.getUserId()); | 429 | mapper.setUserid(req.getUserId()); |
430 | + mapper.setUserType(Constant.USER_ROLE_BUYER); | ||
428 | mapper.setDeviceType(req.getDeviceType()); | 431 | mapper.setDeviceType(req.getDeviceType()); |
429 | try { | 432 | try { |
430 | redisUtil.deleteByKey(reNOCache); | 433 | redisUtil.deleteByKey(reNOCache); |
@@ -493,19 +496,25 @@ public class UserServiceImpl implements UserService { | @@ -493,19 +496,25 @@ public class UserServiceImpl implements UserService { | ||
493 | @Override | 496 | @Override |
494 | public GetRegisterNoResp getRegisterNo(GetRegisterNoReq req) { | 497 | public GetRegisterNoResp getRegisterNo(GetRegisterNoReq req) { |
495 | GetRegisterNoResp resp = new GetRegisterNoResp(); | 498 | GetRegisterNoResp resp = new GetRegisterNoResp(); |
496 | - if (Validator.isNull(req.getUserId()) || Validator.isNull(req.getUserRole())) { | 499 | + if (Validator.isNull(req.getUserId()) || Validator.isNull(req.getUserType())) { |
497 | resp.setCode(ResultCode.REQUET_PARAMS_ERROR); | 500 | resp.setCode(ResultCode.REQUET_PARAMS_ERROR); |
498 | - resp.setMsg("用户ID和用户角色不能为空"); | 501 | + resp.setMsg("用户ID和用户类型不能为空"); |
499 | return resp; | 502 | return resp; |
500 | } | 503 | } |
501 | // 先从缓存取 | 504 | // 先从缓存取 |
502 | - String redisKey = redisUtil.makeKey(RedisKey.USER_REGISTERNO, | ||
503 | - req.getUserRole() + String.valueOf(req.getUserId())); | 505 | + String redisKey = ""; |
506 | + if (req.getUserType() == Constant.USER_ROLE_BUYER) { | ||
507 | + redisKey = redisUtil.makeKey(RedisKey.USER_REGISTERNO, | ||
508 | + Constant.USER_ROLE_SIGN_BUYER + String.valueOf(req.getUserId())); | ||
509 | + } else if (req.getUserType() == Constant.USER_ROLE_SELLER) { | ||
510 | + redisKey = redisUtil.makeKey(RedisKey.USER_REGISTERNO, | ||
511 | + Constant.USER_ROLE_SIGN_SELLER + String.valueOf(req.getUserId())); | ||
512 | + } | ||
504 | GetRegisterNoResp recache = redisUtil.getObject(redisKey, GetRegisterNoResp.class); | 513 | GetRegisterNoResp recache = redisUtil.getObject(redisKey, GetRegisterNoResp.class); |
505 | if (!Validator.isNull(recache) && !Validator.isEmpty(recache.getRegisterNos())) { | 514 | if (!Validator.isNull(recache) && !Validator.isEmpty(recache.getRegisterNos())) { |
506 | resp.setRegisterNos(recache.getRegisterNos()); | 515 | resp.setRegisterNos(recache.getRegisterNos()); |
507 | } else { | 516 | } else { |
508 | - List<RegisterNoMapper> mapppers = registerNoMapperManager.getRegisterNo(req.getUserId()); | 517 | + List<RegisterNoMapper> mapppers = registerNoMapperManager.getRegisterNo(req.getUserType(), req.getUserId()); |
509 | if (!Validator.isEmpty(mapppers)) { | 518 | if (!Validator.isEmpty(mapppers)) { |
510 | 519 | ||
511 | resp.setRegisterNos(mapppers); | 520 | resp.setRegisterNos(mapppers); |
@@ -523,6 +532,7 @@ public class UserServiceImpl implements UserService { | @@ -523,6 +532,7 @@ public class UserServiceImpl implements UserService { | ||
523 | GetRegisterNobyUidsResp resp = new GetRegisterNobyUidsResp(); | 532 | GetRegisterNobyUidsResp resp = new GetRegisterNobyUidsResp(); |
524 | Map<String, Object> param = new HashMap<String, Object>(); | 533 | Map<String, Object> param = new HashMap<String, Object>(); |
525 | param.put("userids", req.getUserIds()); | 534 | param.put("userids", req.getUserIds()); |
535 | + param.put("userType", req.getUserType()); | ||
526 | if (!Validator.isNull(req.getPlatform())) { | 536 | if (!Validator.isNull(req.getPlatform())) { |
527 | param.put("device_type", req.getPlatform().toString()); | 537 | param.put("device_type", req.getPlatform().toString()); |
528 | } | 538 | } |
mobsite-getway-web/src/main/java/com/diligrp/mobsite/getway/web/filter/LoginTimeoutInterceptor.java
@@ -49,9 +49,9 @@ public class LoginTimeoutInterceptor extends HandlerInterceptorAdapter { | @@ -49,9 +49,9 @@ public class LoginTimeoutInterceptor extends HandlerInterceptorAdapter { | ||
49 | } | 49 | } |
50 | 50 | ||
51 | //检测token信息 | 51 | //检测token信息 |
52 | - //if (!checkTokenInfo(body,request)) { | ||
53 | - // return false; | ||
54 | - //} | 52 | + if (!checkTokenInfo(body,request)) { |
53 | + return false; | ||
54 | + } | ||
55 | 55 | ||
56 | return super.preHandle(request, response, handler); | 56 | return super.preHandle(request, response, handler); |
57 | } | 57 | } |