|
@@ -1,18 +1,21 @@
|
|
package com.fdkankan.ucenter.service.impl;
|
|
package com.fdkankan.ucenter.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.fdkankan.common.constant.AppConstant;
|
|
|
|
+import com.fdkankan.common.constant.CameraConstant;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.util.Base64Converter;
|
|
import com.fdkankan.common.util.Base64Converter;
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
|
|
+import com.fdkankan.common.util.RandomUtil;
|
|
import com.fdkankan.common.util.SecurityUtil;
|
|
import com.fdkankan.common.util.SecurityUtil;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.ucenter.common.RedisKeyUtil;
|
|
import com.fdkankan.ucenter.common.RedisKeyUtil;
|
|
import com.fdkankan.ucenter.constant.LoginConstant;
|
|
import com.fdkankan.ucenter.constant.LoginConstant;
|
|
|
|
+import com.fdkankan.ucenter.entity.Camera;
|
|
|
|
+import com.fdkankan.ucenter.entity.CameraDetail;
|
|
import com.fdkankan.ucenter.entity.User;
|
|
import com.fdkankan.ucenter.entity.User;
|
|
-import com.fdkankan.ucenter.service.ICameraDetailService;
|
|
|
|
-import com.fdkankan.ucenter.service.IScenePlusService;
|
|
|
|
-import com.fdkankan.ucenter.service.ISceneProService;
|
|
|
|
-import com.fdkankan.ucenter.service.IUserService;
|
|
|
|
|
|
+import com.fdkankan.ucenter.service.*;
|
|
|
|
+import com.fdkankan.ucenter.vo.request.AppLoginParam;
|
|
import com.fdkankan.ucenter.vo.request.LoginParam;
|
|
import com.fdkankan.ucenter.vo.request.LoginParam;
|
|
import com.fdkankan.ucenter.vo.response.LoginVo;
|
|
import com.fdkankan.ucenter.vo.response.LoginVo;
|
|
import com.fdkankan.ucenter.vo.response.UserVo;
|
|
import com.fdkankan.ucenter.vo.response.UserVo;
|
|
@@ -39,6 +42,11 @@ public class AppService {
|
|
ISceneProService sceneProService;
|
|
ISceneProService sceneProService;
|
|
@Autowired
|
|
@Autowired
|
|
IScenePlusService scenePlusService;
|
|
IScenePlusService scenePlusService;
|
|
|
|
+ @Autowired
|
|
|
|
+ ICameraService cameraService;
|
|
|
|
+ @Autowired
|
|
|
|
+ LoginService loginService;
|
|
|
|
+
|
|
|
|
|
|
public LoginVo login(LoginParam param) {
|
|
public LoginVo login(LoginParam param) {
|
|
if (StringUtils.isEmpty(param.getPassword()) || StringUtils.isEmpty(param.getPhoneNum())){
|
|
if (StringUtils.isEmpty(param.getPassword()) || StringUtils.isEmpty(param.getPhoneNum())){
|
|
@@ -53,8 +61,13 @@ public class AppService {
|
|
if(!user.getPassword().equals(passwordCode)){
|
|
if(!user.getPassword().equals(passwordCode)){
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
|
|
}
|
|
}
|
|
- String token = this.redisLogin(user.getUserName(), JSONObject.toJSONString(user));
|
|
|
|
|
|
+ String token = this.redisLogin(user.getUserName(), 21800L);
|
|
|
|
+
|
|
|
|
+ return commonLogin(user,param,token);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+
|
|
|
|
+ private LoginVo commonLogin(User user,LoginParam param,String token){
|
|
Long count = cameraDetailService.getCountByUserId(user.getId());
|
|
Long count = cameraDetailService.getCountByUserId(user.getId());
|
|
if(param.getCameraType() == null){
|
|
if(param.getCameraType() == null){
|
|
param.setCameraType( 4);
|
|
param.setCameraType( 4);
|
|
@@ -77,11 +90,76 @@ public class AppService {
|
|
return vo;
|
|
return vo;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- public String redisLogin(String userName,String value){
|
|
|
|
|
|
+ public String redisLogin(String userName,Long time){
|
|
String token = JwtUtil.createJWT(-1,userName,"app");
|
|
String token = JwtUtil.createJWT(-1,userName,"app");
|
|
String redisKey = RedisKeyUtil.PREFIX_CACHE_CAMERA+ userName;
|
|
String redisKey = RedisKeyUtil.PREFIX_CACHE_CAMERA+ userName;
|
|
- redisUtil.set(redisKey, token,21600);
|
|
|
|
|
|
+ redisUtil.set(redisKey, token,time);
|
|
return token;
|
|
return token;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void appLogin(AppLoginParam param) {
|
|
|
|
+ if(StringUtils.isEmpty(param.getAppUserName()) || StringUtils.isEmpty(param.getAppPassword())
|
|
|
|
+ || StringUtils.isEmpty(param.getUuid())){
|
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
|
+ }
|
|
|
|
+ commonCheckCamera(param);
|
|
|
|
+ redisUtil.set(param.getUuid(),param.getAppUserName(),60 * 5);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void commonCheckCamera(AppLoginParam param){
|
|
|
|
+ Camera camera = cameraService.getBySnCodeAndPassword(param.getAppUserName(),param.getAppPassword());
|
|
|
|
+ if(camera == null){
|
|
|
|
+ throw new BusinessException(CameraConstant.FAILURE_6003);
|
|
|
|
+ }
|
|
|
|
+ CameraDetail detail = cameraDetailService.getByCameraId(camera.getId());
|
|
|
|
+ if (detail == null ){
|
|
|
|
+ throw new BusinessException(AppConstant.FAILURE_CODE_4012, AppConstant.FAILURE_MSG_4012);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public JSONObject login2(AppLoginParam param) {
|
|
|
|
+ if(StringUtils.isEmpty(param.getAppUserName()) || StringUtils.isEmpty(param.getAppPassword())){
|
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
|
+ }
|
|
|
|
+ commonCheckCamera(param);
|
|
|
|
+ String token = redisLogin(param.getAppUserName(), 604800L);
|
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
|
+ obj.put("token", token);
|
|
|
|
+ return obj;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public LoginVo quickLogin(LoginParam param) {
|
|
|
|
+ if(StringUtils.isEmpty(param.getPhoneNum()) || StringUtils.isEmpty(param.getMsgAuthCode())){
|
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
|
+ }
|
|
|
|
+ loginService.checkSms(param.getMsgAuthCode(),param.getPhoneNum(),true);
|
|
|
|
+
|
|
|
|
+ User user = userService.getByUserName(param.getPhoneNum());
|
|
|
|
+ if(user == null){
|
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
|
|
|
|
+ }
|
|
|
|
+ String token = redisLogin(param.getPhoneNum(), 21600L);
|
|
|
|
+ return commonLogin(user,param,token);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void logout(String token) {
|
|
|
|
+ String username = JwtUtil.getUsername(token);
|
|
|
|
+ String redisKey = RedisKeyUtil.PREFIX_CACHE_CAMERA+ username;
|
|
|
|
+ if(redisUtil.hasKey(redisKey)){
|
|
|
|
+ redisUtil.del(redisKey);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public JSONObject getNickName() {
|
|
|
|
+ String nickName = null;
|
|
|
|
+ Long count = 0L;
|
|
|
|
+ do {
|
|
|
|
+ nickName = "mob" + RandomUtil.generateShortUuid();
|
|
|
|
+ count = userService.getCountByNickName(nickName);
|
|
|
|
+ } while (count > 0);
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("nickName",nickName);
|
|
|
|
+ return jsonObject;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|