|
@@ -1,16 +1,29 @@
|
|
|
package com.fdkankan.ucenter.controller.app;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.amazonaws.services.simpleworkflow.flow.annotations.NoWait;
|
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
import com.fdkankan.ucenter.common.BaseController;
|
|
|
+import com.fdkankan.ucenter.common.RedisKeyUtil;
|
|
|
import com.fdkankan.ucenter.common.Result;
|
|
|
+import com.fdkankan.ucenter.constant.CameraConstant;
|
|
|
+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.service.ICameraDetailService;
|
|
|
+import com.fdkankan.ucenter.service.ICameraService;
|
|
|
+import com.fdkankan.ucenter.service.IUserService;
|
|
|
import com.fdkankan.ucenter.service.impl.AppService;
|
|
|
import com.fdkankan.ucenter.service.impl.LoginService;
|
|
|
import com.fdkankan.ucenter.vo.request.AppLoginParam;
|
|
|
import com.fdkankan.ucenter.vo.request.LoginParam;
|
|
|
import com.fdkankan.ucenter.vo.request.RegisterParam;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
+import com.fdkankan.ucenter.vo.request.RequestCamera;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@RestController
|
|
@@ -21,6 +34,14 @@ public class AppController extends BaseController {
|
|
|
private AppService appService;
|
|
|
@Autowired
|
|
|
private LoginService loginService;
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private ICameraService cameraService;
|
|
|
+ @Autowired
|
|
|
+ private ICameraDetailService cameraDetailService;
|
|
|
+ @Autowired
|
|
|
+ RedisUtil redisUtil;
|
|
|
/**
|
|
|
* 登录
|
|
|
* phoneNum 用户名
|
|
@@ -110,4 +131,38 @@ public class AppController extends BaseController {
|
|
|
loginService.changePassword(param);
|
|
|
return Result.success();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户名登录
|
|
|
+ * @param token
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/checkToken", method = RequestMethod.POST)
|
|
|
+ public Result userLogin(@RequestHeader String token,@RequestBody(required = false) RequestCamera param){
|
|
|
+ if(ObjectUtils.isEmpty(token)){
|
|
|
+ return Result.failure(LoginConstant.FAILURE_CODE_3004,LoginConstant.FAILURE_MSG_3004);
|
|
|
+ }
|
|
|
+ String username = JwtUtil.getUsername(token);
|
|
|
+ if (ObjectUtils.isEmpty(username)){
|
|
|
+ return Result.failure(LoginConstant.FAILURE_CODE_3004,LoginConstant.FAILURE_MSG_3004);
|
|
|
+ }
|
|
|
+ if(!ObjectUtils.isEmpty(param) && !ObjectUtils.isEmpty(param.getChildName())){
|
|
|
+ User user = userService.getByUserName(username);
|
|
|
+ if(ObjectUtils.isEmpty(user) || ObjectUtils.isEmpty(user.getCompanyId())){
|
|
|
+ return Result.failure(LoginConstant.FAILURE_CODE_3003,LoginConstant.FAILURE_MSG_3003);
|
|
|
+ }
|
|
|
+ Camera camera = cameraService.getByChildName(param.getChildName());
|
|
|
+ if(ObjectUtils.isEmpty(camera)){
|
|
|
+ return Result.failure(CameraConstant.FAILURE_CODE_6003, CameraConstant.FAILURE_MSG_6003);
|
|
|
+ }
|
|
|
+ CameraDetail detailEntity = cameraDetailService.getByCameraId(camera.getId());
|
|
|
+ if(ObjectUtils.isEmpty(detailEntity) || ObjectUtils.isEmpty( detailEntity.getCompanyId()) || !detailEntity.getCompanyId().equals(user.getCompanyId())){
|
|
|
+ return Result.failure(CameraConstant.FAILURE_CODE_6003, CameraConstant.FAILURE_MSG_6003);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(redisUtil.hasKey(RedisKeyUtil.PREFIX_CACHE_CAMERA + username)){
|
|
|
+ return Result.failure(LoginConstant.FAILURE_CODE_3004,LoginConstant.FAILURE_MSG_3004);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
}
|