瀏覽代碼

app登录

lyhzzz 3 年之前
父節點
當前提交
617552d66b

+ 1 - 0
src/main/java/com/fdkankan/user/common/RedisKeyUtil.java

@@ -5,4 +5,5 @@ public class RedisKeyUtil {
     public static final String PREFIX_MSG_NOT_CODE = "msg:not:code:";//短信重发验证
     public static final String PREFIX_MSG_AUTH_CODE = "msg:auth:code:";
 
+    public static final String PREFIX_CACHE_CAMERA = "camera:";
 }

+ 28 - 0
src/main/java/com/fdkankan/user/controller/AppController.java

@@ -0,0 +1,28 @@
+package com.fdkankan.user.controller;
+
+import com.fdkankan.user.common.Result;
+import com.fdkankan.user.service.impl.AppService;
+import com.fdkankan.user.service.impl.LoginService;
+import com.fdkankan.user.vo.request.LoginParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/api/sso/app")
+public class AppController {
+
+    @Autowired
+    private AppService appService;
+    /**
+     * 登录
+     * phoneNum 用户名
+     * password 密码
+     */
+    @PostMapping("/userLogin")
+    public Result login(@RequestBody LoginParam param){
+        return Result.success(appService.login(param));
+    }
+}

+ 21 - 3
src/main/java/com/fdkankan/user/controller/FolderController.java

@@ -1,11 +1,13 @@
 package com.fdkankan.user.controller;
 
 
+import cn.hutool.jwt.JWT;
+import com.fdkankan.common.util.JwtUtil;
+import com.fdkankan.user.common.Result;
 import com.fdkankan.user.service.IFolderService;
+import com.fdkankan.user.vo.request.FolderParam;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * <p>
@@ -21,5 +23,21 @@ public class FolderController {
 
     @Autowired
     IFolderService folderService;
+
+    /**
+     * 新增文件夹
+     * name   文件夹名称
+     * type   文件夹类型,0我的场景,1协作场景
+     * parentId   上层文件夹id
+     */
+    @PostMapping("/save")
+    public Result save(@RequestBody FolderParam param, @RequestHeader String token){
+        String username = JwtUtil.getUsername(token);
+        param.setUserName(username);
+        folderService.add(param);
+        return Result.success();
+    }
+
+
 }
 

+ 2 - 2
src/main/java/com/fdkankan/user/mapper/ISceneCooperationMapper.java

@@ -18,7 +18,7 @@ import java.util.List;
 @Mapper
 public interface ISceneCooperationMapper extends BaseMapper<SceneCooperation> {
 
-    Integer getCooperationScenePlusNum(@Param("userId")Long userId,  @Param("sceneSource")List<Integer> sceneSourceList);
+    Long getCooperationScenePlusNum(@Param("userId")Long userId,  @Param("sceneSource")List<Integer> sceneSourceList);
 
-    Integer getCooperationSceneProNum(Long userId, List<Integer> sceneSourceList);
+    Long getCooperationSceneProNum(Long userId, List<Integer> sceneSourceList);
 }

+ 2 - 0
src/main/java/com/fdkankan/user/service/IFolderService.java

@@ -2,6 +2,7 @@ package com.fdkankan.user.service;
 
 import com.fdkankan.user.entity.Folder;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.user.vo.request.FolderParam;
 
 /**
  * <p>
@@ -13,4 +14,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IFolderService extends IService<Folder> {
 
+    void add(FolderParam param);
 }

+ 1 - 1
src/main/java/com/fdkankan/user/service/ISceneCooperationService.java

@@ -19,7 +19,7 @@ import java.util.List;
  */
 public interface ISceneCooperationService extends IService<SceneCooperation> {
 
-    Integer getCooperationSceneNum(Long userId, List<Integer> sceneSourceList);
+    Long getCooperationSceneNum(Long userId, List<Integer> sceneSourceList);
 
     void deleteCooperationList(List<ScenePro> sceneProList, List<ScenePlus> scenePlusList) ;
 

+ 1 - 1
src/main/java/com/fdkankan/user/service/IScenePlusService.java

@@ -15,7 +15,7 @@ import java.util.List;
  */
 public interface IScenePlusService extends IService<ScenePlus> {
 
-    Integer getCountByUserId(Long userId, List<Integer> sceneSourceList);
+    Long getCountByUserId(Long userId, List<Integer> sceneSourceList);
 
     List<ScenePlus> getListByCameraId(Long cameraId);
 

+ 2 - 0
src/main/java/com/fdkankan/user/service/ISceneProService.java

@@ -32,4 +32,6 @@ public interface ISceneProService extends IService<ScenePro> {
     List<ScenePro> getListByCameraIds(List<Long> cameraIds);
 
     List<ScenePro> getListByNums(List<String> numList);
+
+    Long getCountByUserId(Long id, List<Integer> resourceList);
 }

+ 87 - 0
src/main/java/com/fdkankan/user/service/impl/AppService.java

@@ -0,0 +1,87 @@
+package com.fdkankan.user.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.common.util.Base64Converter;
+import com.fdkankan.common.util.JwtUtil;
+import com.fdkankan.common.util.SecurityUtil;
+import com.fdkankan.redis.util.RedisUtil;
+import com.fdkankan.user.common.RedisKeyUtil;
+import com.fdkankan.user.constant.LoginConstant;
+import com.fdkankan.user.entity.User;
+import com.fdkankan.user.service.ICameraDetailService;
+import com.fdkankan.user.service.IScenePlusService;
+import com.fdkankan.user.service.ISceneProService;
+import com.fdkankan.user.service.IUserService;
+import com.fdkankan.user.vo.request.LoginParam;
+import com.fdkankan.user.vo.response.LoginVo;
+import com.fdkankan.user.vo.response.UserVo;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+@Service
+public class AppService {
+
+    @Autowired
+    private IUserService userService;
+    @Autowired
+    private RedisUtil redisUtil;
+    @Autowired
+    private ICameraDetailService cameraDetailService;
+    @Autowired
+    ISceneProService sceneProService;
+    @Autowired
+    IScenePlusService scenePlusService;
+
+    public LoginVo login(LoginParam param) {
+        if (StringUtils.isEmpty(param.getPassword()) || StringUtils.isEmpty(param.getPhoneNum())){
+            throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
+        }
+        String password = Base64Converter.decode(Base64Converter.subText(param.getPassword()));
+        String passwordCode = SecurityUtil.MD5(password);
+        User user = userService.getByUserName(param.getPhoneNum());
+        if(user == null){
+            throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
+        }
+        if(!user.getPassword().equals(passwordCode)){
+            throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
+        }
+        String token = this.redisLogin(user.getUserName(), JSONObject.toJSONString(user));
+
+        Long count = cameraDetailService.getCountByUserId(user.getId());
+        if(param.getCameraType() == null){
+            param.setCameraType(  4);
+        }
+        List<Integer> resourceList = new ArrayList<>();
+        if(param.getCameraType() == 4){
+            resourceList = Arrays.asList(1,2,12,13,14);
+        }else {
+            resourceList = Collections.singletonList(3);
+        }
+        Long sceneProCount = sceneProService.getCountByUserId(user.getId(),resourceList);
+        Long scenePlusCount = scenePlusService.getCountByUserId(user.getId(),resourceList);
+        UserVo userVo = new UserVo();
+        userVo.setCameraCount(count);
+        userVo.setSceneCount(sceneProCount + scenePlusCount);
+        BeanUtils.copyProperties(user,userVo);
+        LoginVo vo = new LoginVo();
+        vo.setToken(token);
+        vo.setUser(userVo);
+        return vo;
+    }
+
+
+    public String redisLogin(String userName,String value){
+        String token = JwtUtil.createJWT(-1,userName,"app");
+        String redisKey = RedisKeyUtil.PREFIX_CACHE_CAMERA+ userName;
+        redisUtil.set(redisKey, token,21600);
+        return token;
+    }
+}

+ 26 - 0
src/main/java/com/fdkankan/user/service/impl/FolderServiceImpl.java

@@ -1,11 +1,18 @@
 package com.fdkankan.user.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fdkankan.user.entity.Folder;
+import com.fdkankan.user.entity.User;
 import com.fdkankan.user.mapper.IFolderMapper;
 import com.fdkankan.user.service.IFolderService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.user.service.IUserService;
+import com.fdkankan.user.vo.request.FolderParam;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  * 文件夹表 服务实现类
@@ -17,4 +24,23 @@ import org.springframework.stereotype.Service;
 @Service
 public class FolderServiceImpl extends ServiceImpl<IFolderMapper, Folder> implements IFolderService {
 
+    @Autowired
+    IUserService userService;
+
+    @Override
+    public void add(FolderParam param) {
+        User user = userService.getByUserName(param.getUserName());
+        List<Folder> list = findByParentIdAndName(param.getParentId(), param.getName(), user.getId(), param.getType());
+    }
+
+    private List<Folder> findByParentIdAndName(Long parentId, String name, Long userId,Integer type){
+        LambdaQueryWrapper<Folder> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(Folder::getName,name)
+                .eq(Folder::getUserId,userId)
+                .eq(Folder::getParentId,parentId);
+        if(type !=null){
+            wrapper.eq(Folder::getType,type);
+        }
+        return this.list(wrapper);
+    }
 }

+ 0 - 1
src/main/java/com/fdkankan/user/service/impl/LoginService.java

@@ -27,7 +27,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
-import java.security.GeneralSecurityException;
 import java.util.Date;
 
 @Service

+ 3 - 3
src/main/java/com/fdkankan/user/service/impl/SceneCooperationServiceImpl.java

@@ -48,9 +48,9 @@ public class SceneCooperationServiceImpl extends ServiceImpl<ISceneCooperationMa
     ISceneResourceService sceneResourceService;
 
     @Override
-    public Integer getCooperationSceneNum(Long userId, List<Integer> sceneSourceList) {
-        Integer cooperationSceneProNum = this.getBaseMapper().getCooperationSceneProNum(userId, sceneSourceList);
-        Integer cooperationScenePlusNum = this.getBaseMapper().getCooperationScenePlusNum(userId, sceneSourceList);
+    public Long getCooperationSceneNum(Long userId, List<Integer> sceneSourceList) {
+        Long cooperationSceneProNum = this.getBaseMapper().getCooperationSceneProNum(userId, sceneSourceList);
+        Long cooperationScenePlusNum = this.getBaseMapper().getCooperationScenePlusNum(userId, sceneSourceList);
         return cooperationSceneProNum + cooperationScenePlusNum;
     }
 

+ 2 - 2
src/main/java/com/fdkankan/user/service/impl/ScenePlusServiceImpl.java

@@ -23,11 +23,11 @@ import java.util.List;
 public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlus> implements IScenePlusService {
 
     @Override
-    public Integer getCountByUserId(Long userId, List<Integer> sceneSourceList) {
+    public Long getCountByUserId(Long userId, List<Integer> sceneSourceList) {
         LambdaQueryWrapper<ScenePlus> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(ScenePlus::getUserId, userId);
         wrapper.eq(ScenePlus::getSceneSource, sceneSourceList);
-        return Math.toIntExact(this.count(wrapper));
+        return this.count(wrapper);
     }
 
 

+ 8 - 1
src/main/java/com/fdkankan/user/service/impl/SceneProServiceImpl.java

@@ -73,7 +73,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         queryWrapper.eq(ScenePro::getSceneSource, sceneSourceList);
         queryWrapper.eq(ScenePro::getIsUpgrade, 0);
         Integer sceneNum = Math.toIntExact(this.count(queryWrapper));
-        Integer count = scenePlusService.getCountByUserId(userId,sceneSourceList);
+        Long count = scenePlusService.getCountByUserId(userId,sceneSourceList);
         sceneNumVo.setCooperationSceneNum(sceneCooperationService.getCooperationSceneNum(userId,sceneSourceList));
         sceneNumVo.setSceneNum(sceneNum + count);
         sceneNumVo.setTotalNum(sceneNumVo.getSceneNum() + sceneNumVo.getCooperationSceneNum());
@@ -233,4 +233,11 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
                 .eq(ScenePro::getIsUpgrade,0);
         return this.list(wrapper);
     }
+    @Override
+    public Long getCountByUserId(Long userId, List<Integer> resourceList) {
+        LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(ScenePro::getUserId,userId);
+        wrapper.in(ScenePro::getSceneSource,resourceList);
+        return this.count(wrapper);
+    }
 }

+ 4 - 0
src/main/java/com/fdkankan/user/vo/request/FolderParam.java

@@ -4,4 +4,8 @@ import lombok.Data;
 
 @Data
 public class FolderParam {
+    private String userName;
+    private String name;
+    private Integer type;
+    private Long parentId;
 }

+ 1 - 0
src/main/java/com/fdkankan/user/vo/request/LoginParam.java

@@ -7,4 +7,5 @@ public class LoginParam {
     private String areaNum;
     private String phoneNum;        //用户名
     private String password;        //密码
+    private Integer cameraType;
 }

+ 3 - 3
src/main/java/com/fdkankan/user/vo/response/SceneNumVo.java

@@ -6,8 +6,8 @@ import java.io.Serializable;
 
 @Data
 public class SceneNumVo implements Serializable {
-    private Integer cooperationSceneNum = 0;    //协作场景数量
-    private Integer sceneNum = 0;               //场景数量
-    private Integer totalNum = 0;
+    private Long cooperationSceneNum = 0L;    //协作场景数量
+    private Long sceneNum = 0L;               //场景数量
+    private Long totalNum = 0L;
    // private Integer type;                   //场景类型 0看看,1看见,2深时
 }

+ 2 - 0
src/main/java/com/fdkankan/user/vo/response/UserVo.java

@@ -18,4 +18,6 @@ public class UserVo {
 
     private Long cameraId;
     private Integer cameraLogin;
+
+    private Long sceneCount;
 }

+ 2 - 2
src/main/resources/mapper/user/SceneCooperationMapper.xml

@@ -3,7 +3,7 @@
 <mapper namespace="com.fdkankan.user.mapper.ISceneCooperationMapper">
 
 
-    <select id="getCooperationSceneProNum" resultType="java.lang.Integer">
+    <select id="getCooperationSceneProNum" resultType="java.lang.Long">
         SELECT count(0) FROM t_scene_cooperation a
         LEFT JOIN t_scene_pro b ON a.scene_num = b.num
         WHERE a.rec_status = 'A' AND b.rec_status = 'A' AND b.is_upgrade = 0
@@ -12,7 +12,7 @@
             #{index}
         </foreach>
     </select>
-    <select id="getCooperationScenePlusNum" resultType="java.lang.Integer">
+    <select id="getCooperationScenePlusNum" resultType="java.lang.Long">
         SELECT count(0) FROM t_scene_cooperation a
         LEFT JOIN t_scene_plus b ON a.scene_num = b.num
         WHERE a.rec_status = 'A' AND b.tb_status = 0