فهرست منبع

整理了一下

wuweihao 5 سال پیش
والد
کامیت
af86d847f5

+ 6 - 0
README.md

@@ -7,5 +7,11 @@
   修改用户名,会影响密码的,若果要修改,只能重置密码(而且要先在db手动改好用户名,再重置密码)
   
   @WebControllerLog 日志注解格式:部门信息-新增部门,必须要有"-"
+  
+##需求
+    角色管理、资源管理不要
+    角色-资源直接在数据库配好
+    直接在数据库,把角色跟资源配置好就可以了
+    添加用户时,直接授权角色就可以
 
 

+ 1 - 1
xiaoan-common/src/main/java/com/xiaoan/common/interceptor/AuthHeaderSettingFilter.java

@@ -51,7 +51,7 @@ public class AuthHeaderSettingFilter implements Filter {
         if (token == null && !req.getRequestURI().contains("/admin/login")) {
             if ("dev".equals(active) ){
                     // admin 用户测试用
-                    token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXlsb2FkIjoie1wicm9sZVwiOltcImFkbWluXCJdLFwiaWRcIjo5LFwidXNlck5hbWVcIjpcIjE1OTk5OTk5OTk5XCJ9IiwidXNlck5hbWUiOiIxNTk5OTk5OTk5OSIsImV4cCI6MTU4NDIzMzkyNX0.Uk71Pyt1WC7gHpxof7ktbgk---r85fyrKB_s2tUq0QI";
+                    token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxNTk5OTk5OTk5OSIsInJvbGUiOlsiYWRtaW4iXSwiaWQiOjksInVzZXJOYW1lIjoiMTU5OTk5OTk5OTkiLCJpYXQiOjE1ODM4MjI4MTksImp0aSI6ImZjMWUyYjUwLWU4MDgtNDVhNy1iZTliLTEwOWIxODc4YmNjNyJ9.liO1iotkDSf5NeOyd624_ME3yx4HthdfT5GQRIBGtTg";
                     //如果请求中带有这个参数,则进行过滤加一个header头
                     requestWrapper.addHeader("Authorization", token);
                     String userName = "15999999999";

+ 3 - 1
xiaoan-dao/src/main/java/com/xiaoan/dao/backend/DepartmentRepository.java

@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Select;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 
 
@@ -12,8 +13,9 @@ import org.springframework.transaction.annotation.Transactional;
  * Created by Hb_zzZ on 2020/2/27.
  */
 @Mapper
+@Component
 public interface DepartmentRepository extends IBaseRepository<DepartmentEntity, Long> {
 
-    @Select(value = "select d.* from tb_department d where d.name = ?1")
+    @Select(value = "select * from tb_department d where d.name = #{name}")
     DepartmentEntity findByName(String name);
 }

+ 1 - 1
xiaoan-domain/src/main/java/com/xiaoan/domain/backend/UserEntity.java

@@ -26,7 +26,7 @@ public class UserEntity extends BaseModel implements Serializable {
 
 
     /**
-     * 用户
+     * 用户
      */
     private String userNum;
 

+ 1 - 1
xiaoan-domain/src/main/java/com/xiaoan/domain/dto/request/DepartmentRequest.java

@@ -7,7 +7,7 @@ import lombok.Data;
  * Created by Hb_zzZ on 2020/2/27.
  */
 @Data
-public class DepartmentRequest extends PageDto {
+public class DepartmentRequest {
 
     private Long id;
 

+ 17 - 0
xiaoan-domain/src/main/java/com/xiaoan/domain/dto/request/LoginRequest.java

@@ -0,0 +1,17 @@
+package com.xiaoan.domain.dto.request;
+
+import lombok.Data;
+
+/**
+ * Created by owen on 2020/2/18 0018 17:09
+ */
+@Data
+public class LoginRequest {
+
+
+    private String userName;
+
+    private String password;
+
+
+}

+ 1 - 1
xiaoan-domain/src/main/java/com/xiaoan/domain/dto/request/RoleRequest.java

@@ -9,7 +9,7 @@ import java.util.Set;
  * Created by owen on 2020/2/18 0018 17:09
  */
 @Data
-public class RoleRequest extends PageDto{
+public class RoleRequest {
 
     private Long id;
 

+ 1 - 3
xiaoan-domain/src/main/java/com/xiaoan/domain/dto/request/UserRequest.java

@@ -12,8 +12,6 @@ public class UserRequest{
 
     private String userName;
 
-    private String password;
-
     private String realName; // 真实姓名
 
     /**
@@ -29,5 +27,5 @@ public class UserRequest{
 
     private Long roleId; // 角色id
 
-    private String searchKey; //搜索条件
+//    private String searchKey; //搜索条件
 }

+ 40 - 18
xiaoan-web/src/main/java/com/xiaoan/web/backend/DepartmentController.java

@@ -5,6 +5,7 @@ import com.xiaoan.common.constant.MsgCode;
 import com.xiaoan.common.model.PageDto;
 import com.xiaoan.common.util.ResultJson;
 import com.xiaoan.domain.backend.DepartmentEntity;
+import com.xiaoan.domain.backend.RoleEntity;
 import com.xiaoan.domain.dto.request.DepartmentRequest;
 import com.xiaoan.service.backend.DepartmentService;
 import com.xiaoan.web.aop.WebControllerLog;
@@ -15,12 +16,12 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.transaction.annotation.Transactional;
-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;
+import org.springframework.web.bind.annotation.*;
 import tk.mybatis.mapper.entity.Condition;
 
+import java.util.Date;
+import java.util.List;
+
 /**
  * Created by Hb_zzZ on 2020/2/27.
  *
@@ -46,32 +47,53 @@ public class DepartmentController extends BaseController {
     }
 
     @ApiOperation("新增部门")
-    @WebControllerLog(description = "部门信息-新增部门")
+    @WebControllerLog(description = "部门信息-新增/修改部门")
     @PostMapping("save")
     public ResultJson save(@RequestBody DepartmentRequest param){
         if(StringUtils.isEmpty(param.getName()) || StringUtils.isEmpty(param.getNum())){
             return new ResultJson(MsgCode.FAILURE_CODE_3001, MsgCode.FAILURE_MSG_3001);
         }
 
-        DepartmentEntity departmentEntity = departmentService.findByName(param.getName());
-        if(departmentEntity != null){
-            return new ResultJson(MsgCode.FAILURE_CODE_5001, MsgCode.FAILURE_MSG_5001);
+        DepartmentEntity entity = departmentService.findById(param.getId());
+        if (entity != null) {
+            BeanUtils.copyProperties(param, entity);
+            entity.setUpdateTime(new Date());
+
+            departmentService.update(entity);
+
+
+        } else {
+            entity = departmentService.findByName(param.getName());
+            if(entity != null){
+                return new ResultJson(MsgCode.FAILURE_CODE_5001, MsgCode.FAILURE_MSG_5001);
+            }
+
+            entity = new DepartmentEntity();
+            BeanUtils.copyProperties(param, entity);
+            departmentService.save(entity);
+
         }
 
-        departmentEntity = new DepartmentEntity();
-        BeanUtils.copyProperties(param, departmentEntity);
-        departmentService.save(departmentEntity);
+
+
+
+
         return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
     }
 
+    @WebControllerLog(description = "部门信息-删除部门")
     @ApiOperation("部门信息-删除部门")
-    @PostMapping("delete")
-    public ResultJson delete(@RequestBody DepartmentRequest param){
-        if(param.getId() == null){
-            return new ResultJson(MsgCode.FAILURE_CODE_3001, MsgCode.FAILURE_MSG_3001);
-        }
-
-        departmentService.deleteById(param.getId());
+    @PostMapping("delete/{id}")
+    public ResultJson delete(@PathVariable Long id){
+        departmentService.deleteById(id);
         return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
     }
+
+    @WebControllerLog(description = "部门信息-获取部门")
+    @ApiOperation("获取部门")
+    @GetMapping("find")
+    public ResultJson find(){
+        List<DepartmentEntity> result = departmentService.findAll(new Condition(DepartmentEntity.class), "create_time desc");
+        return new ResultJson(MsgCode.SUCCESS_CODE, result);
+    }
 }

+ 2 - 1
xiaoan-web/src/main/java/com/xiaoan/web/backend/IndexController.java

@@ -4,6 +4,7 @@ import com.xiaoan.common.constant.MsgCode;
 import com.xiaoan.common.util.PasswordUtils;
 import com.xiaoan.common.util.ResultJson;
 import com.xiaoan.domain.backend.UserEntity;
+import com.xiaoan.domain.dto.request.LoginRequest;
 import com.xiaoan.domain.dto.request.UserRequest;
 import com.xiaoan.service.backend.ResourceService;
 import com.xiaoan.service.backend.RoleService;
@@ -48,7 +49,7 @@ public class IndexController {
 
     @ApiOperation("查询用户信息")
     @PostMapping(value = "admin/login")
-    public ResultJson login(@RequestBody UserRequest param) throws Exception {
+    public ResultJson login(@RequestBody LoginRequest param) throws Exception {
         log.warn("run login , userName:{}, password:{}", param.getUserName(), param.getPassword());
         // 1.获取用户
         UserEntity userEntity = userService.findByUserName(param.getUserName());

+ 4 - 4
xiaoan-web/src/main/java/com/xiaoan/web/backend/IssueController.java

@@ -77,11 +77,11 @@ public class IssueController extends BaseController {
     /**
      * 只有管理员才能回复问题
      */
-    @RequiresRoles("admin")
+//    @RequiresRoles("admin")
     @WebControllerLog(description = "问题反馈-回复问题")
     @ApiOperation("回复问题")
-    @PostMapping("edit/{id}/{item}")
-    public ResultJson edit(@PathVariable Long id, @PathVariable String item){
+    @GetMapping("reply/{id}/{item}")
+    public ResultJson reply(@PathVariable Long id, @PathVariable String item){
 
         IssueEntity entity = issueService.findById(id);
         if (entity == null) {
@@ -102,7 +102,7 @@ public class IssueController extends BaseController {
     @RequiresRoles("admin")
     @WebControllerLog(description = "问题反馈-删除问题")
     @ApiOperation("删除问题")
-    @PostMapping("delete/{id}")
+    @GetMapping("delete/{id}")
     public ResultJson save(@PathVariable Long id){
         issueService.deleteById(id);
         return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);

+ 7 - 12
xiaoan-web/src/main/java/com/xiaoan/web/backend/PersonalCenterController.java

@@ -13,6 +13,7 @@ import com.xiaoan.service.backend.SceneService;
 import com.xiaoan.service.backend.UserService;
 import com.xiaoan.web.aop.WebControllerLog;
 import com.xiaoan.web.shiro.JWTUtil;
+import com.xiaoan.web.shiro.JwtUtil2;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
@@ -36,22 +37,16 @@ public class PersonalCenterController extends BaseController {
     private SceneService sceneService;
 
     @Autowired
-    private UserService userService;
-
-    @Autowired
     private CameraService cameraService;
 
     @WebControllerLog(description = "个人中心-我的场景/搜索")
     @ApiOperation("获取场景列表/搜索")
     @PostMapping("scene/list")
     public ResultJson findSceneList(@RequestBody SceneProRequest param){
-//        List<Long> ids = null;
-//        if(StringUtils.isNotEmpty(param.getSearchKey())){
-//            ids = userService.findUserIdByRealName(param.getSearchKey());
-//        }
 
         List<SceneResponse> list = null;
-        List userRole = JWTUtil.getUserRole(getToken());
+//        List userRole = JWTUtil.getUserRole(getToken());
+        List userRole = JwtUtil2.getUserRole(getToken());
         if (userRole.contains("admin")) {
             list = sceneService.findAllBySearchKey(param, null);
         } else {
@@ -66,7 +61,7 @@ public class PersonalCenterController extends BaseController {
 
     @WebControllerLog(description = "个人中心-我的场景/删除")
     @ApiOperation("删除场景")
-    @PostMapping("scene/delete/{id}")
+    @GetMapping("scene/delete/{id}")
     public ResultJson delete(@PathVariable Long id){
         sceneService.deleteById(id);
         return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
@@ -79,7 +74,7 @@ public class PersonalCenterController extends BaseController {
      */
     @WebControllerLog(description = "个人中心-我的场景/编辑")
     @ApiOperation("编辑场景")
-    @PostMapping("scene/edit/{id}")
+    @GetMapping("scene/edit/{id}")
     public ResultJson edit(@PathVariable Long id){
         SceneProEntity proEntity = sceneService.findById(id);
         String webSite = proEntity.getWebSite();
@@ -93,7 +88,7 @@ public class PersonalCenterController extends BaseController {
     public ResultJson cameraList(@RequestBody PageDto param){
 
         List<CameraEntity> list = null;
-        List userRole = JWTUtil.getUserRole(getToken());
+        List userRole = JwtUtil2.getUserRole(getToken());
         if (userRole.contains("admin")) {
             list = cameraService.findAllBySearchKey(param, null);
         } else {
@@ -115,7 +110,7 @@ public class PersonalCenterController extends BaseController {
      */
     @ApiOperation("新增相机")
     @WebControllerLog(description = "设备管理-新增相机")
-    @PostMapping("save/{code}")
+    @GetMapping("camera/save/{code}")
     public ResultJson save(@PathVariable String code){
         if(StringUtils.isEmpty(code)){
             return new ResultJson(MsgCode.FAILURE_CODE_3001, MsgCode.FAILURE_MSG_3001);

+ 40 - 14
xiaoan-web/src/main/java/com/xiaoan/web/backend/RoleController.java

@@ -4,6 +4,8 @@ import com.github.pagehelper.PageInfo;
 import com.xiaoan.common.constant.MsgCode;
 import com.xiaoan.common.model.PageDto;
 import com.xiaoan.common.util.ResultJson;
+import com.xiaoan.dao.backend.RoleRepository;
+import com.xiaoan.dao.backend.UserRepository;
 import com.xiaoan.domain.backend.DepartmentEntity;
 import com.xiaoan.domain.backend.RoleEntity;
 import com.xiaoan.domain.dto.request.RoleRequest;
@@ -11,6 +13,7 @@ import com.xiaoan.service.backend.RoleService;
 import com.xiaoan.web.aop.WebControllerLog;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.log4j.Log4j2;
 import org.apache.shiro.authz.annotation.Logical;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.BeanUtils;
@@ -29,6 +32,7 @@ import java.util.List;
  * Created by owen on 2020/2/18 0018 12:17
  * 需要admin权限
  */
+@Log4j2
 @Api(tags = "RoleController", description = "后台角色管理")
 @RestController
 @RequestMapping("api/manage/role")
@@ -39,6 +43,9 @@ public class RoleController extends BaseController {
     @Autowired
     private RoleService roleService;
 
+    @Autowired
+    private RoleRepository roleRepository;
+
     @WebControllerLog(description = "角色权限-查询列表")
     @ApiOperation("分页获取角色列表/搜索")
 //    @PostMapping("list")
@@ -67,27 +74,46 @@ public class RoleController extends BaseController {
     @ApiOperation("新增或修改角色信息")
     @PostMapping("save")
     public ResultJson save(@RequestBody RoleRequest param){
-        RoleEntity roleEntity = null;
+//        RoleEntity roleEntity = null;
+//        int n = 0;
+//        if (param.getId() != null) {
+//            roleEntity = roleService.findById(param.getId());
+//            if(roleEntity == null){
+//                return new ResultJson(MsgCode.FAILURE_CODE_6001, MsgCode.FAILURE_MSG_6001);
+//            }
+//            // 每次修改,删除角色资源表信息,重新添加
+//            roleService.deleteRoleResource(param.getId());
+//
+//            BeanUtils.copyProperties(param, roleEntity);
+//            n = roleService.update(roleEntity);
+//        }else {
+//            roleEntity = new RoleEntity();
+//
+//            BeanUtils.copyProperties(param, roleEntity);
+//            roleEntity.setUpdateTime(new Date());
+//
+//
+//            n = roleService.save(roleEntity);
+//        }
+
+        RoleEntity roleEntity = roleService.findById(param.getId());
+
         int n = 0;
-        if (param.getId() != null) {
-            roleEntity = roleService.findById(param.getId());
-            if(roleEntity == null){
-                return new ResultJson(MsgCode.FAILURE_CODE_6001, MsgCode.FAILURE_MSG_6001);
-            }
-            // 每次修改,删除角色资源表信息,重新添加
-            roleService.deleteRoleResource(param.getId());
 
-            BeanUtils.copyProperties(param, roleEntity);
-            n = roleService.update(roleEntity);
-        }else {
+        if (roleEntity == null) {
             roleEntity = new RoleEntity();
+            // 保存的时候,如果有id,会出错
+            param.setId(null);
+            BeanUtils.copyProperties(param, roleEntity);
+            n = roleService.save(roleEntity);
 
+        } else {
             BeanUtils.copyProperties(param, roleEntity);
             roleEntity.setUpdateTime(new Date());
+            n = roleService.update(roleEntity);
 
-//        roleEntity.setCreateBy(getTokenUserName());
-
-            n = roleService.save(roleEntity);
+            // 每次修改,删除角色资源表信息,重新添加
+            roleService.deleteRoleResource(param.getId());
         }
 
         if (n >= 0){

+ 1 - 5
xiaoan-web/src/main/java/com/xiaoan/web/backend/SceneController.java

@@ -73,10 +73,6 @@ public class SceneController extends BaseController {
     @ApiOperation("获取场景列表")
     @PostMapping("list")
     public ResultJson list(@RequestBody SceneProRequest param){
-//        List<Long> ids = null;
-//        if(StringUtils.isNotEmpty(param.getSearchKey())){
-//            ids = userService.findUserIdByRealName(param.getSearchKey());
-//        }
 
         List<SceneResponse> list = null;
 //        List userRole = JWTUtil.getUserRole(getToken());
@@ -98,7 +94,7 @@ public class SceneController extends BaseController {
      */
     @ApiOperation("下载场景")
     @WebControllerLog(description = "场景管理-下载场景")
-    @RequestMapping(value = "/downloadTexData/{sceneNum}")
+    @GetMapping(value = "/downloadTexData/{sceneNum}")
     public ResultJson downloadTexData(@PathVariable String sceneNum)  {
 
         if(StringUtils.isEmpty(sceneNum)){

+ 25 - 12
xiaoan-web/src/main/java/com/xiaoan/web/backend/StatisticsController.java

@@ -1,22 +1,19 @@
 package com.xiaoan.web.backend;
 
-import com.github.pagehelper.PageInfo;
 import com.xiaoan.common.constant.MsgCode;
 import com.xiaoan.common.util.ResultJson;
-import com.xiaoan.domain.backend.DepartmentEntity;
-import com.xiaoan.domain.backend.UserEntity;
 import com.xiaoan.service.backend.SceneService;
 import com.xiaoan.service.backend.UserService;
+import com.xiaoan.web.aop.WebControllerLog;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
-import tk.mybatis.mapper.entity.Condition;
 
 import java.util.HashMap;
-import java.util.List;
 
 /**
  * Created by owen on 2020/3/9 0009 10:35
@@ -36,17 +33,33 @@ public class StatisticsController {
     @Autowired
     private SceneService sceneService;
 
-    @GetMapping
+    /**
+     * 加了日志注解,会出错,在filter里出错
+     */
+//    @WebControllerLog(description = "数据统计-获取数据")
+//    @WebControllerLog(description = "数据统计-获取数据")
+    @ApiOperation("获取数据")
+    @GetMapping()
     private ResultJson getData() {
 
         HashMap<Object, Object> map = new HashMap<>();
-        map.put("使用人次", userService.findAllByViewCount());
-        map.put("系统用户数", userService.count());
-        map.put("场景浏览量", sceneService.findAllByViewCount());
-        map.put("场景个数", sceneService.count());
 
-        map.put("系统使用TOP5", userService.findAllByViewCountLimit(5));
-        map.put("场景浏览TOP5", sceneService.findAllByViewCountLimit(5));
+        // 系统使用人次
+        map.put("systemViewCount", userService.findAllByViewCount());
+        // 系统用户数
+        map.put("systemUserCount", userService.count());
+
+        // 场景浏览量
+        map.put("sceneViewCount", sceneService.findAllByViewCount());
+
+        // 场景个数
+        map.put("sceneCount", sceneService.count());
+
+        // 系统使用TOP5
+        map.put("systemTop", userService.findAllByViewCountLimit(5));
+
+        // 场景浏览TOP5
+        map.put("sceneTop", sceneService.findAllByViewCountLimit(5));
 
         return new ResultJson(MsgCode.SUCCESS_CODE, map);
 

+ 19 - 17
xiaoan-web/src/main/java/com/xiaoan/web/backend/UserController.java

@@ -49,34 +49,36 @@ public class UserController extends BaseController {
     @ApiOperation("新增或修改用户信息")
     @PostMapping("save")
     public ResultJson save(@RequestBody UserRequest param){
-        UserEntity userEntity = null;
         int n = 0;
-        if (param.getId() != null){
-             userEntity = userService.findById(param.getId());
-            if(userEntity == null){
-                return new ResultJson(MsgCode.FAILURE_CODE_4001, MsgCode.FAILURE_CODE_4001);
-            }
-            // 每次修改,删除用户角色表信息,重新添加
-            userService.deleteUserRole(param.getId());
 
-            BeanUtils.copyProperties(param, userEntity);
-            userService.update(userEntity);
-        }else {
+        UserEntity entity = userService.findById(param.getId());
+        if (entity == null ){
+            entity = userService.findByUserName(param.getUserName());
+            if (entity != null) {
+                return new ResultJson(MsgCode.ERROR_CODE, "用户名已存在");
+            }
 
-            userEntity = new UserEntity();
+            entity = new UserEntity();
+            param.setId(null);
 
-            BeanUtils.copyProperties(param, userEntity);
-            userEntity.setPassword(PasswordUtils.encrypt(param.getUserName(), "123456", PasswordUtils.getStaticSalt()));
+            BeanUtils.copyProperties(param, entity);
+            entity.setPassword(PasswordUtils.encrypt(param.getUserName(), "123456", PasswordUtils.getStaticSalt()));
 
-//           userEntity.setCreateBy(getTokenUserName());
+            n = userService.save(entity);
+        } else {
+            // 每次修改,删除用户角色表信息,重新添加
+            userService.deleteUserRole(param.getId());
 
-            n = userService.save(userEntity);
+            BeanUtils.copyProperties(param, entity);
+            entity.setUpdateTime(new Date());
+            n = userService.update(entity);
         }
 
 
         if (n >= 0) {
             if (param.getRoleId() != null) {
-                userService.saveUserRole(userEntity.getId(), param.getRoleId());
+                // 一个用户只有一个角色
+                userService.saveUserRole(entity.getId(), param.getRoleId());
                 return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
             }
         }