ソースを参照

修改了添加角色时,查询资源的逻辑

wuweihao 5 年 前
コミット
635e964e43

+ 8 - 5
README.md

@@ -47,12 +47,15 @@ http://localhost:8085/xiaoan-web/#/login
         端口:9998
 
 
-## test 环境
+## sit 环境
 server
-    192.168.0.134
-    192.168.1.181
-    123456
+    192.168.0.163:22
+    root:1234
 
     mysql
         root 
-        123456
+        123456
+        
+    http://192.168.0.163:8088/dist
+    
+    /root/user/java/apache-tomcat-8.0.52-4dkankan-xiaoan/webapps

+ 1 - 1
xiaoan-common/src/main/java/com/xiaoan/common/constant/MsgCode.java

@@ -27,7 +27,7 @@ public class MsgCode {
     public static final String msg_ADMIN_4001 = "用户不存在";
 
     public static final int e_ADMIN_4002 = 4002;
-    public static final String msg_ADMIN_4002 = "密码不正";
+    public static final String msg_ADMIN_4002 = "密码不正";
 
     public static final int e_ADMIN_4003 = 4003;
     public static final String msg_ADMIN_4003 = "该账户已停用,请跟管理员联系";

+ 4 - 3
xiaoan-dao/src/main/java/com/xiaoan/dao/backend/CameraRepository.java

@@ -20,9 +20,10 @@ public interface CameraRepository extends IBaseMapper<CameraEntity, Long> {
     CameraEntity findByWifiName(String code);
 
 
-    @Select(value = "select z.id, z.sn_code, z.child_name, z.wifi_name, z.create_time, z.update_time, d.type from t_camera z left join t_camera_detail d on z.id = d.camera_id where " +
-            "(z.sn_code like #{searchKey} or #{searchKey} is null)" +
-            " or ( z.wifi_name like #{searchKey} or #{searchKey} is null)" +
+    @Select(value = "select z.id, z.sn_code, z.child_name, z.wifi_name, z.create_time, z.update_time, d.type from" +
+            " t_camera z left join t_camera_detail d on z.id = d.camera_id where z.rec_status = 'A' " +
+            " and (z.sn_code like #{searchKey} or #{searchKey} is null)" +
+            " and ( z.wifi_name like #{searchKey} or #{searchKey} is null)" +
             " and (d.user_id = #{userId} or #{userId} is null) " +
             " order by z.create_time desc")
     List<CameraResponse> findAllBySearchKey(String searchKey, Long userId);

+ 0 - 17
xiaoan-dao/src/main/java/com/xiaoan/dao/backend/LogRepository.java

@@ -28,27 +28,10 @@ public interface LogRepository extends IBaseMapper<LogEntity, Long> {
 
 
 
-//    @Select(value = "select l.type, l.description, l.create_time, u.user_name, u.real_name from tb_log l left join tb_user u on l.user_id = u.id " +
-//            "where ((l.create_time >= #{startTime}) and (l.create_time <= #{endTime})) " +
-//            "and ((u.user_name like #{searchKey} or #{searchKey} is null) " +
-//            "or (u.real_name like #{searchKey} or #{searchKey} is null) " +
-//            "or (l.description like #{searchKey} or #{searchKey} is null) " +
-//            "or (l.type like #{searchKey} or #{searchKey} is null))" +
-//            "order by create_time desc")
-//    List<LogResponse> search(String searchKey, String startTime, String endTime);
-
-
     /**
      * 注意日期,需要传字符串类型
      */
     @SelectProvider(type = LogProvider.class, method = "findAllBySearchKey")
     List<LogResponse> search(PageDto param);
 
-//    @Select(value = "select l.type, l.description, l.create_time, u.user_name, u.real_name from tb_log l left join tb_user u on l.user_id = u.id " +
-//            "where ((u.user_name like #{itemName} or #{itemName} is null) " +
-//            "or (u.real_name like #{itemName} or #{itemName} is null) " +
-//            "or (l.description like #{itemName} or #{itemName} is null) " +
-//            "or (l.type like #{itemName} or #{itemName} is null)) " +
-//            "and l.user_id = #{userId} order by create_time desc")
-//    List<LogResponse> searchByUserId(String itemName, Long userId, Date startTime, Date endTime);
 }

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

@@ -26,7 +26,7 @@ public interface SceneRepository extends IBaseMapper<SceneProEntity, Long> {
     @Select(value = "select SUM(view_count) from t_scene_pro where rec_status = 'A' ")
     Integer findAllByViewCount();
 
-    @Select(value = "select id, thumb, view_count from t_scene_pro where rec_status = 'A' ORDER BY view_count desc LIMIT #{num}")
+    @Select(value = "select id, thumb, view_count, scene_name from t_scene_pro where rec_status = 'A' ORDER BY view_count desc LIMIT #{num}")
     List<SceneResponse> findAllByViewCountLimit(int num);
 
     @Select(value = "select * from t_scene_pro where rec_status = 'A' and status = '-2' and num = #{sceneNum}")

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

@@ -32,7 +32,7 @@ public class ResourceEntity extends BaseModel implements Serializable {
 //    @Column(length = 10)
 //    private String icon;
 
-    @JSONField(serialize = false)
+//    @JSONField(serialize = false)
     @Column(name = "resource_key")
     private String resourceKey;
 

+ 10 - 33
xiaoan-service/src/main/java/com/xiaoan/service/backend/impl/ResourceServiceImpl.java

@@ -13,6 +13,7 @@ import com.xiaoan.service.backend.util.ResourceTreeUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import tk.mybatis.mapper.entity.Condition;
 
 import java.math.BigInteger;
 import java.util.*;
@@ -158,37 +159,6 @@ public class ResourceServiceImpl extends BaseServiceImpl<ResourceEntity, Long> i
     }
 
 
-    /**
-     * 根据角色id获取权限
-     *
-     * 会把所有权限都会列出来的,通过Authority判断是否有权限
-     */
-//    @Override
-//    public List<ResourceTree> getResourcesAllByRolePermission(Long roleId) {
-//        // 资源Mapper
-//        HashMap<Long, ResourceEntity> allResourceMapper = this.getAllResourceMapper();
-//
-//        // 设置用户权限
-//        List<ResourceEntity> resourcePer = findResourceByRoleId(roleId);
-//        for (ResourceEntity i: resourcePer) {
-//            Long id = i.getId();
-//            ResourceEntity resourceEntity = allResourceMapper.get(id);
-//            resourceEntity.setAuthority(true);
-//            allResourceMapper.put(id, resourceEntity);
-//        }
-//
-//        // 获取用户菜单
-//        List<ResourceEntity> permission = new ArrayList<>();
-//
-//        for (Map.Entry<Long, ResourceEntity> entry : allResourceMapper.entrySet()) {
-//            permission.add(entry.getValue());
-//        }
-//
-//        ResourceTreeUtil tree = new ResourceTreeUtil(permission);
-//        return tree.buildTree();
-//
-//    }
-
 
     @Override
     public List<ResourceTree> getResourcesAllByRolePermission(Long roleId) {
@@ -204,7 +174,7 @@ public class ResourceServiceImpl extends BaseServiceImpl<ResourceEntity, Long> i
             resourceAllMapper.put(id, resourceEntity);
         }
 
-        // 获取用户菜单
+        // 获取用户菜单,只返回普通用户权限,
         List<ResourceEntity> permission = new ArrayList<>();
 
         for (Map.Entry<Long, ResourceEntity> entry : resourceAllMapper.entrySet()) {
@@ -234,8 +204,15 @@ public class ResourceServiceImpl extends BaseServiceImpl<ResourceEntity, Long> i
      * @return
      */
     private HashMap<Long, ResourceEntity> getAllResourceMapper(){
+
+//        Condition condition = new Condition(ResourceEntity.class);
+//        // 只查询普通角色
+//        condition.and().andNotEqualTo("resourceKey","admin");
+//        List<ResourceEntity> resourceEntityAll = this.findAll(condition);
+
+
         // 查找所有resources
-        List<ResourceEntity> resourceEntityAll = resourceMapper.selectAll();
+        List<ResourceEntity> resourceEntityAll = this.findAll();
         // 资源Mapper
         HashMap<Long, ResourceEntity> resourceMapper = new HashMap<>();
         for (ResourceEntity i : resourceEntityAll) {

+ 4 - 1
xiaoan-service/src/main/java/com/xiaoan/service/backend/util/ResourceTreeUtil.java

@@ -23,7 +23,10 @@ public class ResourceTreeUtil {
             treeGrid.setResourceKey(n.getResourceKey());
             treeGrid.setResourceType(n.getResourceType());
 
-            treeGrid.setAuthority(n.getAuthority());
+            if (n.getAuthority() != null){
+                treeGrid.setAuthority(n.getAuthority());
+            }
+
             if (n.getParentId() != null) {
                 treeGrid.setParentId(n.getParentId());
             }

+ 8 - 12
xiaoan-web/src/main/java/com/xiaoan/web/backend/DepartmentController.java

@@ -10,6 +10,8 @@ import com.xiaoan.service.backend.DepartmentService;
 import com.xiaoan.web.aop.WebControllerLog;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.Data;
+import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.authz.annotation.Logical;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
@@ -28,16 +30,18 @@ import java.util.List;
  *
  * 需要admin权限
  */
+@Log4j2
 @Api(tags = "后台部门管理", value = "DepartmentController")
 @RestController
 @RequestMapping("api/manage/department")
 @Transactional
+@RequiresRoles("admin")
 public class DepartmentController extends BaseController {
 
     @Autowired
     private DepartmentService departmentService;
 
-    @RequiresPermissions("admin:department:list")
+//    @RequiresPermissions("admin:department:list")
     @ApiOperation("分页获取部门列表/搜索")
     @WebControllerLog(description = "部门信息-查询列表")
     @PostMapping("list")
@@ -49,13 +53,14 @@ public class DepartmentController extends BaseController {
         return new ResultJson(MsgCode.SUCCESS_CODE, pageInfo);
     }
 
-    @RequiresPermissions("admin:department:add")
+//    @RequiresPermissions("admin:department:add")
     @ApiOperation("新增部门")
     @WebControllerLog(description = "部门信息-新增/修改部门")
     @PostMapping("save")
     public ResultJson save(@RequestBody DepartmentRequest param){
         if(StringUtils.isEmpty(param.getName())){
-            return new ResultJson(MsgCode.e_COMMON_3001, MsgCode.msg_COMMON_3001);
+            log.error("部门名称不能为空");
+            return new ResultJson(MsgCode.e_COMMON_3001, "部门名称不能为空");
         }
 
         Long id = param.getId();
@@ -73,12 +78,6 @@ public class DepartmentController extends BaseController {
             Integer byMaxNum = departmentService.findByMaxNum();
 
             // 用于第一条数据
-//            if (byMaxNum == null){
-//                byMaxNum = 0;
-//            }
-//
-//            byMaxNum = byMaxNum + 1;
-
             byMaxNum = (byMaxNum == null)? 1:byMaxNum + 1;
 
             entity.setNum(byMaxNum);
@@ -98,9 +97,7 @@ public class DepartmentController extends BaseController {
         return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
     }
 
-    @RequiresPermissions("admin:department:remove")
     @WebControllerLog(description = "部门信息-多部门删除")
-    @RequiresRoles(value = {"admin"}, logical = Logical.OR)
     @ApiOperation("删除多部门")
     @GetMapping("delete/all/{id}")
     public ResultJson deleteAll(@PathVariable String id){
@@ -108,7 +105,6 @@ public class DepartmentController extends BaseController {
         return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
     }
 
-    @RequiresPermissions("admin:department:remove")
     @WebControllerLog(description = "部门信息-删除部门")
     @ApiOperation("部门信息-删除部门")
     @PostMapping("delete/{id}")

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

@@ -12,6 +12,7 @@ import com.xiaoan.web.shiro.JwtUtil2;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.transaction.annotation.Transactional;
@@ -117,6 +118,18 @@ public class IndexController {
     @PostMapping(value = "admin/login")
     public ResultJson login(@RequestBody LoginRequest param) throws Exception {
         log.warn("run login , userName:{}, password:{}", param.getUserName(), param.getPassword());
+
+        if(StringUtils.isEmpty(param.getUserName())){
+            log.error("用户不能为空");
+            return new ResultJson(MsgCode.e_COMMON_3001, "用户不能为空");
+        }
+
+        if(StringUtils.isEmpty(param.getPassword())){
+            log.error("密码不能为空");
+            return new ResultJson(MsgCode.e_COMMON_3001, "密码不能为空");
+        }
+
+
         // 1.获取用户
         UserEntity userEntity = userService.findByUserName(param.getUserName());
         if (userEntity == null){
@@ -125,7 +138,6 @@ public class IndexController {
         }
         // 验证密码,解密出来是明文密码,在跟输入密码比较
         String pwd = PasswordUtils.decrypt(userEntity.getPassword(), userEntity.getUserName(), PasswordUtils.getStaticSalt());
-        log.info("22222222 : {}", pwd);
         if (!pwd.equals(param.getPassword())) {
             log.error("密码错误");
             return new ResultJson(MsgCode.e_ADMIN_4002, MsgCode.msg_ADMIN_4002);

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

@@ -15,6 +15,8 @@ import com.xiaoan.web.aop.WebControllerLog;
 import com.xiaoan.web.shiro.JwtUtil2;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,7 +24,6 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import tk.mybatis.mapper.entity.Condition;
 
-import javax.validation.Valid;
 import java.util.HashMap;
 import java.util.List;
 
@@ -30,6 +31,7 @@ import java.util.List;
 /**
  * Created by owen on 2020/2/18 0018 12:17
  */
+@Log4j2
 @Api(tags = "后台问题反馈", value = "IssueController")
 @RestController
 @RequestMapping("api/manage/issue")
@@ -64,7 +66,18 @@ public class IssueController extends BaseController {
     @WebControllerLog(description = "问题反馈-提交问题")
     @ApiOperation("提交问题")
     @PostMapping("save")
-    public ResultJson save(@Valid @RequestBody IssueRequest param){
+    public ResultJson save(@RequestBody IssueRequest param){
+
+        if(StringUtils.isEmpty(param.getTitle())){
+            log.error("标题不能为空");
+            return new ResultJson(MsgCode.e_COMMON_3001, "标题不能为空");
+        }
+
+        if(StringUtils.isEmpty(param.getContent())){
+            log.error("内容不能为空");
+            return new ResultJson(MsgCode.e_COMMON_3001, "内容不能为空");
+        }
+
         IssueEntity issueEntity = new IssueEntity();
         BeanUtils.copyProperties(param, issueEntity);
         Long userId = JwtUtil2.getUserId(getToken());

+ 3 - 1
xiaoan-web/src/main/java/com/xiaoan/web/backend/LogController.java

@@ -10,6 +10,7 @@ import com.xiaoan.web.aop.WebControllerLog;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.apache.shiro.authz.annotation.RequiresRoles;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
@@ -28,6 +29,7 @@ import java.util.List;
 @RestController
 @RequestMapping("api/manage/log")
 @Transactional
+@RequiresRoles("admin")
 public class LogController extends BaseController {
 
     @Autowired
@@ -37,7 +39,7 @@ public class LogController extends BaseController {
     /**
      * 疑问:搜索是否应该有个起始/结束时间
      */
-    @RequiresPermissions("admin:log:list")
+//    @RequiresPermissions("admin:log:list")
     @WebControllerLog(description = "操作日志-日志搜索/列表")
     @ApiOperation("搜索/列表共用")
     @PostMapping("list")

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

@@ -53,7 +53,6 @@ public class PersonalCenterController extends BaseController {
     public ResultJson findSceneList(@RequestBody SceneProRequest param){
 
         List<SceneResponse> list = null;
-//        List userRole = JWTUtil.getUserRole(getToken());
         List userRole = JwtUtil2.getUserRole(getToken());
         if (userRole.contains("admin")) {
             list = sceneService.findAllBySearchKey(param, null);
@@ -67,7 +66,7 @@ public class PersonalCenterController extends BaseController {
     }
 
     @RequiresPermissions("admin:scene:remove")
-//    @WebControllerLog(description = "个人中心-我的场景/删除")
+    @WebControllerLog(description = "个人中心-我的场景/删除")
     @ApiOperation("删除场景")
     @GetMapping("scene/delete/{id}")
     public ResultJson delete(@PathVariable Long id){
@@ -86,7 +85,7 @@ public class PersonalCenterController extends BaseController {
      * @return
      */
     @RequiresPermissions("admin:scene:edit")
-//    @WebControllerLog(description = "个人中心-我的场景/编辑")
+    @WebControllerLog(description = "个人中心-我的场景/编辑")
     @ApiOperation("编辑场景")
     @GetMapping("scene/edit/{id}")
     public ResultJson edit(@PathVariable Long id){
@@ -150,6 +149,7 @@ public class PersonalCenterController extends BaseController {
             // 1:表示专业八目
             cameraDetailEntity.setType(1);
             cameraDetailEntity.setCameraId(cameraEntity.getId());
+            cameraDetailEntity.setUserId(JwtUtil2.getUserId(getToken()));
             cameraDetailService.save(cameraDetailEntity);
         } else {
             cameraEntity = cameraService.findById(param.getId());

+ 2 - 0
xiaoan-web/src/main/java/com/xiaoan/web/backend/ResourceController.java

@@ -25,6 +25,8 @@ import java.util.List;
  * Created by owen on 2020/2/18 0018 12:17
  *
  * 这一块的数据添加应该给开发者用,而不是给管理人员用
+ *
+ * 这个接口是没有暴露出去的
  */
 @ApiIgnore
 @Api(tags = "后台资源管理", value = "ResourceController")

+ 24 - 36
xiaoan-web/src/main/java/com/xiaoan/web/backend/RoleController.java

@@ -14,10 +14,12 @@ import com.xiaoan.domain.dto.request.RoleRequest;
 import com.xiaoan.service.backend.ResourceService;
 import com.xiaoan.service.backend.RoleService;
 import com.xiaoan.service.backend.dto.ResourceTree;
+import com.xiaoan.service.backend.util.ResourceTreeUtil;
 import com.xiaoan.web.aop.WebControllerLog;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.authz.annotation.Logical;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.apache.shiro.authz.annotation.RequiresRoles;
@@ -54,12 +56,11 @@ public class RoleController extends BaseController {
     @Autowired
     private ResourceService resourceService;
 
-//    @RequiresPermissions(logical = Logical.AND, value = {"view", "edit"})
 
     /**
      * 超级管理员角色只有一个
      */
-    @RequiresPermissions("admin:role:list")
+//    @RequiresPermissions("admin:role:list")
     @WebControllerLog(description = "角色权限-查询列表")
     @ApiOperation("分页获取角色列表/搜索")
     @PostMapping("list")
@@ -87,8 +88,15 @@ public class RoleController extends BaseController {
     @ApiOperation("获取资源")
     @GetMapping("find/resource")
     public ResultJson findResource() throws Exception {
-        List<ResourceTree> listTree = resourceService.getTree();
-        return new ResultJson(MsgCode.SUCCESS_CODE, listTree);
+
+        Condition condition = new Condition(ResourceEntity.class);
+        // 只查询普通角色
+        condition.and().andNotEqualTo("resourceKey","admin");
+        List<ResourceEntity> result = resourceService.findAll(condition, "sort desc");
+        ResourceTreeUtil tree = new ResourceTreeUtil(result);
+        List<ResourceTree> resourceTrees = tree.buildTree();
+
+        return new ResultJson(MsgCode.SUCCESS_CODE, resourceTrees);
     }
 
 
@@ -110,40 +118,22 @@ public class RoleController extends BaseController {
     }
 
 
-    /**
-     * 测试权限用
-     * @return
-     */
-    @ApiIgnore
-    @ApiOperation("adminPer")
-    @GetMapping("adminPer")
-//    @RequiresPermissions(value="admin:role:list")
-    @RequiresPermissions(logical = Logical.AND, value = {"admin:role:list"})
-    public ResultJson adminPer(){
-        return new ResultJson(MsgCode.SUCCESS_CODE, new Date());
-    }
-
-
-    /**
-     * 测试权限用
-     * @return
-     */
-    @ApiIgnore
-    @ApiOperation("rootPer")
-    @GetMapping("rootPer")
-//    @RequiresPermissions(value="admin:role:list0000")
-    @RequiresPermissions(logical = Logical.AND, value = {"admin:role:list0000"})
-    public ResultJson rootPer(){
-        return new ResultJson(MsgCode.SUCCESS_CODE, new Date());
-    }
-
-
 
     @WebControllerLog(description = "角色权限-新增/修改")
-    @RequiresPermissions(value="admin:role:add")
     @ApiOperation("新增或修改角色信息")
     @PostMapping("save")
-    public ResultJson save(@Valid @RequestBody RoleRequest param){
+    public ResultJson save(@RequestBody RoleRequest param){
+
+        if (StringUtils.isBlank(param.getRoleName())){
+            log.error("角色名称不能为空");
+            return new ResultJson(MsgCode.e_COMMON_3001, "角色名称不能为空");
+        }
+
+        if (param.getResources() == null){
+            log.error("权限不能为空");
+            return new ResultJson(MsgCode.e_COMMON_3001, "权限不能为空");
+        }
+
 
         RoleEntity roleEntity = null;
         int n = 0;
@@ -180,7 +170,6 @@ public class RoleController extends BaseController {
     }
 
     @WebControllerLog(description = "角色权限-角色删除")
-    @RequiresPermissions("admin:role:remove")
     @ApiOperation("删除角色")
     @GetMapping("delete/{id}")
     public ResultJson delete(@PathVariable Long id){
@@ -193,7 +182,6 @@ public class RoleController extends BaseController {
     }
 
     @WebControllerLog(description = "角色权限-多角色删除")
-    @RequiresPermissions("admin:role:remove")
     @ApiOperation("多角色删除")
     @GetMapping("delete/all/{ids}")
     public ResultJson delete(@PathVariable String ids){

+ 2 - 0
xiaoan-web/src/main/java/com/xiaoan/web/backend/SceneController.java

@@ -19,6 +19,8 @@ import java.util.List;
 
 /**
  * Created by Hb_zzZ on 2020/3/2.
+ *
+ * 这个好像不使用了
  */
 
 @Api(tags = "后台场景管理", value = "SceneController")

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

@@ -30,6 +30,7 @@ import java.util.HashMap;
 @RestController
 @RequestMapping("api/manage/statistics")
 @Transactional
+@RequiresRoles("admin")
 public class StatisticsController {
 
     @Autowired
@@ -38,7 +39,7 @@ public class StatisticsController {
     @Autowired
     private SceneService sceneService;
 
-    @RequiresPermissions("admin:statistics:list")
+//    @RequiresPermissions("admin:statistics:list")
 //    @RequiresRoles(value = {"admin"}, logical = Logical.OR)
     @WebControllerLog(description = "数据统计-获取数据")
     @ApiOperation("获取数据")

+ 52 - 16
xiaoan-web/src/main/java/com/xiaoan/web/backend/UserController.java

@@ -1,7 +1,10 @@
 package com.xiaoan.web.backend;
 
+import cn.hutool.core.lang.Validator;
+import cn.hutool.core.util.StrUtil;
 import com.github.pagehelper.PageInfo;
 import com.xiaoan.common.constant.MsgCode;
+import com.xiaoan.common.exception.BaseRuntimeException;
 import com.xiaoan.common.model.PageDto;
 import com.xiaoan.common.util.PasswordUtils;
 import com.xiaoan.common.util.RegexpUtils;
@@ -15,6 +18,7 @@ import com.xiaoan.web.aop.WebControllerLog;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.authz.annotation.Logical;
 import org.apache.shiro.authz.annotation.RequiresRoles;
 import org.springframework.beans.BeanUtils;
@@ -30,6 +34,8 @@ import java.util.*;
  * Created by owen on 2020/2/18 0018 12:17
  *
  * 超级管理员账户,需要手动添加
+ *
+ * 这个不能直接在类管理
  */
 @Log4j2
 @Api(tags = "后台用户管理", value = "UserController")
@@ -57,19 +63,52 @@ public class UserController extends BaseController {
     @RequiresRoles(value = {"admin"}, logical = Logical.OR)
     @ApiOperation("新增或修改用户信息")
     @PostMapping("save")
-    public ResultJson save(@Valid @RequestBody UserRequest param){
+    public ResultJson save(@RequestBody UserRequest param){
+
 
-//        System.out.println(param.toString());
 
-        int n = 0;
 
         // 验证表单
+
+        if (StringUtils.isBlank(param.getUserName())){
+            log.error("userName: 用户名不能为空");
+            return new ResultJson(MsgCode.e_COMMON_3001, "用户名不能为空");
+        }
+
+        if (StringUtils.isBlank(param.getRealName())){
+            log.error("真实姓名不能为空");
+            return new ResultJson(MsgCode.e_COMMON_3001, "真实姓名不能为空");
+        }
+
+        if (!Validator.isEmail(param.getEmail())) {
+            log.error("email格式有误");
+            return new ResultJson(MsgCode.e_COMMON_3001, "email格式有误");
+        }
+
+        if (param.getDepartmentId() == null) {
+            log.error("部门不能为空");
+            return new ResultJson(MsgCode.e_COMMON_3001, "部门不能为空");
+        }
+
+        if (param.getRoleId() == null) {
+            log.error("角色不能为空");
+            return new ResultJson(MsgCode.e_COMMON_3001, "角色不能为空");
+        }
+
+        if (!Validator.isMobile(param.getPhone())) {
+            log.error("手机号码有误");
+            return new ResultJson(MsgCode.e_COMMON_3001, "手机号码有误");
+        }
+
         if (RegexpUtils.isContainChinese(param.getUserName())) {
             log.error("userName: 不能包含中文");
             return new ResultJson(MsgCode.e_COMMON_3003, "用户名不能包含中文字符");
-//            throw new BaseRuntimeException(MsgCode.e_COMMON_3003, "用户名不能包含中文字符");
         }
 
+
+
+        int n = 0;
+
         UserEntity entity = null;
         if (param.getId() == null){
             entity = userService.findByUserName(param.getUserName());
@@ -84,10 +123,7 @@ public class UserController extends BaseController {
 
             Integer byMaxNum = userService.findByMaxNum();
             // 用于第一条数据
-//            if (byMaxNum == null){
-//                byMaxNum = 1;
-//            }
-//            byMaxNum  = byMaxNum +  1;
+
             byMaxNum = (byMaxNum == null)? 1:byMaxNum + 1;
 
             entity.setUserNum(byMaxNum);
@@ -172,6 +208,14 @@ public class UserController extends BaseController {
     @ApiOperation("修改密码")
     @PostMapping("updatePwd")
     public ResultJson updatePwd(@RequestParam String oldPassword, @RequestParam String password){
+
+
+        if (StringUtils.isBlank(oldPassword) || StringUtils.isBlank(password)){
+            log.error("密码不能为空");
+            return new ResultJson(MsgCode.e_COMMON_3001, "密码不能为空");
+        }
+
+
         UserEntity userEntity = userService.findByUserName(getTokenUserName());
 
         // 验证原密码
@@ -214,12 +258,4 @@ public class UserController extends BaseController {
         return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
     }
 
-    public static void main(String[] args) {
-
-        String ids = "1111111";
-
-        System.out.println(RegexpUtils.isContainChinese(ids));
-    }
-
-
 }