管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-02-27 cec8c5738686bd16d17ae37455b85069e6babe29
src/main/java/com/lf/server/controller/sys/UserController.java
@@ -3,6 +3,7 @@
import com.lf.server.annotation.SysLog;
import com.lf.server.controller.all.BaseController;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.RoleEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.entity.ctrl.UserUpdateEntity;
import com.lf.server.helper.StringHelper;
@@ -34,65 +35,30 @@
    TokenService tokenService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uname", value = "用户名", dataType = "String", paramType = "query", required = false, example = "室")
    })
    @GetMapping({"/selectCount"})
    public ResponseMsg<Integer> selectCount(String uname) {
        try {
            int count = userService.selectCount(uname);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uname", value = "用戶名", dataType = "String", paramType = "query", example = "室"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"),
            @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectByPage")
    public ResponseMsg<List<UserEntity>> selectByPage(String uname, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            List<UserEntity> rs = userService.selectByPage(uname, pageSize, pageSize * (pageIndex - 1));
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "分页查询并返回记录数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uname", value = "用户名", dataType = "String", paramType = "query", example = "室"),
            @ApiImplicitParam(name = "depcode", value = "单位编码", dataType = "String", paramType = "query", example = "00"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"),
            @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectByPageAndCount")
    public ResponseMsg<List<UserEntity>> selectByPageAndCount(String uname, Integer pageSize, Integer pageIndex) {
    public ResponseMsg<List<UserEntity>> selectByPageAndCount(String uname, String depcode, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            int count = userService.selectCount(uname);
            int count = userService.selectCount(uname, depcode);
            if (count == 0) {
                return success(0, null);
            }
            List<UserEntity> rs = userService.selectByPage(uname, pageSize, pageSize * (pageIndex - 1));
            List<UserEntity> rs = userService.selectByPage(uname, depcode, pageSize, pageSize * (pageIndex - 1));
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -101,26 +67,26 @@
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uname", value = "用户名", dataType = "String", paramType = "query", example = "室"),
            @ApiImplicitParam(name = "roleid", value = "角色ID", dataType = "Integer", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "depid", value = "单位ID", dataType = "Integer", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "depcode", value = "单位编码", dataType = "String", paramType = "query", example = "00"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"),
            @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectByPageForRole")
    public ResponseMsg<List<UserEntity>> selectByPageForRole(String uname, Integer roleid, Integer depid, Integer pageSize, Integer pageIndex) {
    public ResponseMsg<List<UserEntity>> selectByPageForRole(String uname, Integer roleid, String depcode, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            int count = userService.selectCountForRole(uname, roleid, depid);
            int count = userService.selectCountForRole(uname, roleid, depcode);
            if (count == 0) {
                return success(0, null);
            }
            List<UserEntity> rs = userService.selectByPageForRole(uname, roleid, depid, pageSize, pageSize * (pageIndex - 1));
            List<UserEntity> rs = userService.selectByPageForRole(uname, roleid, depcode, pageSize, pageSize * (pageIndex - 1));
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -136,7 +102,7 @@
            return success(userEntity);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -156,7 +122,7 @@
            return success(userEntity);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -169,7 +135,7 @@
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -187,7 +153,88 @@
            return success("成功", rows > 0);
        } catch (Exception ex) {
            return fail(ex.getMessage(), false);
            return fail(ex, false);
        }
    }
    @SysLog()
    @ApiOperation(value = "查询是/否为管理员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectIsAdmin")
    public ResponseMsg<Boolean> selectIsAdmin(Integer id) {
        try {
            UserEntity ue = userService.selectUser(id);
            if (ue == null) {
                return fail("用户不存在", false);
            }
            Integer rows = userService.selectForIsAdmin(ue.getId());
            return success("成功", rows > 0);
        } catch (Exception ex) {
            return fail(ex, false);
        }
    }
    @SysLog()
    @ApiOperation(value = "查询管理员用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "管理员类别", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectAdminUsers")
    public ResponseMsg<Object> selectAdminUsers(Integer type) {
        try {
            if (null == type || type < 1) {
                return fail("管理员类别不能为空或小于1", false);
            }
            List<UserEntity> rs = userService.selectAdminUsers(type);
            return success(rs);
        } catch (Exception ex) {
            return fail(ex, false);
        }
    }
    @SysLog()
    @ApiOperation(value = "根据用户ID查询角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectRoleByUserId")
    public ResponseMsg<Object> selectRoleByUserId(Integer id) {
        try {
            if (null == id || id < 1) {
                return fail("用户ID不能为空或小于1", false);
            }
            List<RoleEntity> rs = userService.selectRoleByUserId(id);
            return success(rs);
        } catch (Exception ex) {
            return fail(ex, false);
        }
    }
    @SysLog()
    @ApiOperation(value = "根据角色查询用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "角色ID", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectUserByRoleId")
    public ResponseMsg<Object> selectUserByRoleId(Integer id) {
        try {
            if (null == id || id < 1) {
                return fail("用户ID不能为空或小于1", false);
            }
            List<UserEntity> rs = userService.selectUserByRoleId(id);
            return success(rs);
        } catch (Exception ex) {
            return fail(ex, false);
        }
    }
@@ -213,7 +260,7 @@
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
            return fail(ex, -1);
        }
    }
@@ -245,7 +292,7 @@
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
            return fail(ex, -1);
        }
    }
@@ -261,7 +308,7 @@
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
            return fail(ex, -1);
        }
    }
@@ -281,7 +328,7 @@
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
            return fail(ex, -1);
        }
    }
@@ -305,11 +352,11 @@
                entity.setUpdateUser(ue.getId());
            }
            int count = userService.updateUsers(entity);
            int count = userService.updateUser(entity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
            return fail(ex, -1);
        }
    }
@@ -347,7 +394,7 @@
            return success(rows > 0 ? "更新成功" : "更新失败", rows > 0);
        } catch (Exception ex) {
            return fail(ex.getMessage(), false);
            return fail(ex, false);
        }
    }
}