package com.lf.server.controller.data;
|
|
import com.lf.server.controller.BaseController;
|
import com.lf.server.entity.all.ResponseMsg;
|
import com.lf.server.entity.data.UsersEntity;
|
import com.lf.server.service.data.UsersService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.List;
|
|
/**
|
* 用户表
|
* @author sws
|
* @date 2022-09-27
|
*/
|
@Api(tags = "用户管理")
|
@RestController
|
@RequestMapping("/user")
|
public class UsersController extends BaseController {
|
@Autowired
|
UsersService userService;
|
|
@ApiOperation(value = "查询记录数")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "uname", value = "用户名", dataType = "String", paramType = "query", required = false, example = "sys_user")
|
})
|
@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);
|
}
|
}
|
|
@ApiOperation(value = "分页查询")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "uname", value = "用戶名", dataType = "String", paramType = "query", example = "sys_user"),
|
@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<UsersEntity>> selectByPage(String uname, Integer pageSize, Integer pageIndex) {
|
try {
|
if (pageSize < 1 || pageIndex < 1) {
|
return fail("每页页数或分页数小于1", null);
|
}
|
|
List<UsersEntity> rs = userService.selectByPage(uname, pageSize, pageSize * (pageIndex - 1));
|
|
return success(rs);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@ApiOperation(value = "分页查询并返回记录数")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "uname", value = "用户名", dataType = "String", paramType = "query", example = "sys_dict"),
|
@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<UsersEntity>> selectByPageAndCount(String uname, Integer pageSize, Integer pageIndex) {
|
try {
|
if (pageSize < 1 || pageIndex < 1) {
|
return fail("每页页数或分页数小于1", null);
|
}
|
int count = userService.selectCount(uname);
|
if (count == 0) {
|
return success(0, null);
|
}
|
List<UsersEntity> rs = userService.selectByPage(uname, pageSize, pageSize * (pageIndex - 1));
|
|
return success(count, rs);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@ApiOperation(value = "插入字典")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "userEntity", value = "字典实体类", dataType = "com.lf.server.entity.data.UserEntity", paramType = "body", example = "")
|
})
|
@PostMapping(value = "/insertUser", produces = "application/json; charset=UTF-8")
|
public ResponseMsg<Integer> insertUser(@RequestBody UsersEntity usersEntity) {
|
try {
|
int count = userService.insertUser(usersEntity);
|
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), -1);
|
}
|
}
|
|
@ApiOperation(value = "插入多条字典")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "userEntity", value = "字典实体类集合", dataType = "List<UserEntity>", paramType = "body", example = "")
|
})
|
@PostMapping(value = "/insertUsers", produces = "application/json; charset=UTF-8")
|
public ResponseMsg<Integer> insertUsers(@RequestBody List<UsersEntity> usersEntity) {
|
try {
|
int count = userService.insertUsers(usersEntity);
|
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), -1);
|
}
|
}
|
|
@ApiOperation(value = "删除一条字典")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "字典ID", dataType = "Integer", paramType = "query", example = "1")
|
})
|
@GetMapping(value = "/deleteUser")
|
public ResponseMsg<Integer> deleteUser(int id) {
|
try {
|
int count = userService.deleteUser(id);
|
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), -1);
|
}
|
}
|
|
@ApiOperation(value = "删除多条字典")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "ids", value = "字典ID集合", dataType = "List<Integer>", paramType = "query", example = "1,2")
|
})
|
@GetMapping(value = "/deleteUsers")
|
public ResponseMsg<Integer> deleteUsers(@RequestParam List<Integer> ids) {
|
try {
|
if (ids == null || ids.isEmpty()) {
|
return fail("id数组不能为空", -1);
|
}
|
|
int count = userService.deleteUsers(ids);
|
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), -1);
|
}
|
}
|
|
@ApiOperation(value = "更新一条字典")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "userEntity", value = "字典ID集合", dataType = "UserEntity", paramType = "body", example = "")
|
})
|
@ResponseBody
|
@PostMapping(value = "/updateUsers", produces = "application/json; charset=UTF-8")
|
public ResponseMsg<Integer> updateUsers(@RequestBody UsersEntity usersEntity) {
|
try {
|
int count = userService.updateUsers(usersEntity);
|
|
return success(count);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), -1);
|
}
|
}
|
|
@ApiOperation(value = "根据ID查询字典")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "字典ID", dataType = "Integer", paramType = "query", example = "1")
|
})
|
@GetMapping(value = "/selectUser")
|
public ResponseMsg<UsersEntity> selectUser(int id) {
|
try {
|
UsersEntity usersEntity = userService.selectUser(id);
|
|
return success(usersEntity);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
|
@ApiOperation(value = "查询所有字典")
|
@GetMapping(value = "/selectUserAll")
|
public ResponseMsg<List<UsersEntity>> selectUserAll() {
|
try {
|
List<UsersEntity> list = userService.selectUserAll();
|
|
return success(list);
|
} catch (Exception ex) {
|
return fail(ex.getMessage(), null);
|
}
|
}
|
}
|