123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- 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.IUserRoleService;
- 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 com.fdkankan.ucenter.vo.request.RequestCamera;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.util.ObjectUtils;
- import org.springframework.web.bind.annotation.*;
- import java.util.Set;
- @RestController
- @RequestMapping("/ucenter/sso/app")
- @Slf4j
- public class AppController extends BaseController {
- @Autowired
- private AppService appService;
- @Autowired
- private LoginService loginService;
- @Autowired
- private IUserService userService;
- @Autowired
- private ICameraService cameraService;
- @Autowired
- private ICameraDetailService cameraDetailService;
- @Autowired
- private IUserRoleService userRoleService;
- @Autowired
- RedisUtil redisUtil;
- /**
- * 登录
- * phoneNum 用户名
- * password 密码
- */
- @PostMapping("/userLogin")
- public Result userLogin(@RequestBody LoginParam param){
- return Result.success(appService.login(param));
- }
- /**
- * app扫码登录
- * appUserName 相机设备嘛
- * appPassword 相机密码
- * uuid
- */
- @PostMapping("/login")
- public Result login(@RequestBody AppLoginParam param){
- appService.appLogin(param);
- return Result.success();
- }
- /**
- * app登录
- * appUserName 相机设备嘛
- * appPassword 相机密码
- */
- @PostMapping("/login2")
- public Result login2(@RequestBody AppLoginParam param){
- return Result.success(appService.login2(param));
- }
- /**
- * 验证码登陆
- * @return
- */
- @PostMapping("/quickLogin")
- public Result quickLogin(@RequestBody LoginParam param){
- return Result.success(appService.quickLogin(param));
- }
- /**
- * 注册
- * @param param
- * @return
- */
- @PostMapping("/register")
- public Result register(@RequestBody RegisterParam param){
- param.setConfirmPwd(param.getPassword());
- param.setClear("YES");
- loginService.register(param);
- return Result.success();
- }
- /**
- * 登出
- */
- @RequestMapping(value = "/logout", method = RequestMethod.POST)
- public Result logout() {
- appService.logout(getToken());
- return Result.success();
- }
- /**
- * app 获取随机昵称
- */
- @PostMapping("/getNickName")
- public Result getNickName(){
- return Result.success(appService.getNickName());
- }
- /**
- * 检测手机号码是否注册
- */
- @PostMapping("/checkUserName")
- public Result checkUserName(@RequestBody AppLoginParam param){
- loginService.checkUser(param.getAppUserName(),false);
- return Result.success();
- }
- /**
- * 重置密码
- */
- @PostMapping("/resetPassword")
- public Result resetPassword(@RequestBody RegisterParam param){
- param.setConfirmPwd(param.getPassword());
- param.setClear("YES");
- 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){
- log.info("checkToken-token:{}",token);
- 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());
- Set<Long> roleIds = userRoleService.getByUser(user);
- 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(roleIds.contains(8L) && ( detailEntity.getUserId()== null || !detailEntity.getUserId().equals(user.getId()))){
- return Result.failure(LoginConstant.FAILURE_CODE_3037, LoginConstant.FAILURE_MSG_3037);
- }
- }
- if(!redisUtil.hasKey(RedisKeyUtil.PREFIX_CACHE_CAMERA + username)){
- return Result.failure(LoginConstant.FAILURE_CODE_3004,LoginConstant.FAILURE_MSG_3004);
- }
- return Result.success();
- }
- }
|