|
|
@@ -1,27 +1,30 @@
|
|
|
package com.ctsi.user.controller;
|
|
|
|
|
|
-import cn.dev33.satoken.annotation.SaCheckLogin;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ctsi.entity.FramePage;
|
|
|
+import com.ctsi.utils.ApiResult;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import com.ctsi.user.entity.SysUser;
|
|
|
import com.ctsi.user.service.SysUserService;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
/**
|
|
|
* 用户表;(sys_user)表控制层
|
|
|
- * @author : http://www.chiner.pro
|
|
|
- * @date : 2024-1-9
|
|
|
+ * @author : machaoyi
|
|
|
+ * @date : 2024-1-10
|
|
|
*/
|
|
|
@Api(tags = "用户表对象功能接口")
|
|
|
@RestController
|
|
|
@RequestMapping("/sysUser")
|
|
|
public class SysUserController{
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private SysUserService sysUserService;
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(SysUserController.class);
|
|
|
|
|
|
/**
|
|
|
* 通过ID查询单条数据
|
|
|
@@ -31,8 +34,13 @@ public class SysUserController{
|
|
|
*/
|
|
|
@ApiOperation("通过ID查询单条数据")
|
|
|
@GetMapping("{id}")
|
|
|
- public ResponseEntity<SysUser> queryById(Long id){
|
|
|
- return ResponseEntity.ok(sysUserService.queryById(id));
|
|
|
+ public ApiResult<SysUser> queryById(Long id){
|
|
|
+ try {
|
|
|
+ return ApiResult.success(sysUserService.queryById(id));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return ApiResult.failure("查询失败",null);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -43,8 +51,13 @@ public class SysUserController{
|
|
|
*/
|
|
|
@ApiOperation("分页查询")
|
|
|
@GetMapping
|
|
|
- public ResponseEntity<Page<SysUser>> paginQuery(SysUser sysUser, FramePage framePage){
|
|
|
- return ResponseEntity.ok(sysUserService.paginQuery(sysUser, framePage.getPageNum(), framePage.getPageSize()));
|
|
|
+ public ApiResult<Page<SysUser>> paginQuery(SysUser sysUser, FramePage framePage){
|
|
|
+ try {
|
|
|
+ return ApiResult.success(sysUserService.paginQuery(sysUser, framePage.getPageNum(), framePage.getPageSize()));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return ApiResult.failure("分页查询失败",null);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -55,8 +68,13 @@ public class SysUserController{
|
|
|
*/
|
|
|
@ApiOperation("新增数据")
|
|
|
@PostMapping
|
|
|
- public ResponseEntity<SysUser> add(@RequestBody SysUser sysUser){
|
|
|
- return ResponseEntity.ok(sysUserService.insert(sysUser));
|
|
|
+ public ApiResult<SysUser> add(@RequestBody SysUser sysUser){
|
|
|
+ try {
|
|
|
+ return ApiResult.success(sysUserService.insert(sysUser));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return ApiResult.failure("新增数据失败",null);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -67,8 +85,13 @@ public class SysUserController{
|
|
|
*/
|
|
|
@ApiOperation("更新数据")
|
|
|
@PutMapping
|
|
|
- public ResponseEntity<SysUser> edit(@RequestBody SysUser sysUser){
|
|
|
- return ResponseEntity.ok(sysUserService.update(sysUser));
|
|
|
+ public ApiResult<SysUser> edit(@RequestBody SysUser sysUser){
|
|
|
+ try {
|
|
|
+ return ApiResult.success(sysUserService.update(sysUser));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return ApiResult.failure("更新数据失败",null);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -79,7 +102,12 @@ public class SysUserController{
|
|
|
*/
|
|
|
@ApiOperation("通过主键删除数据")
|
|
|
@DeleteMapping
|
|
|
- public ResponseEntity<Boolean> deleteById(Long id){
|
|
|
- return ResponseEntity.ok(sysUserService.deleteById(id));
|
|
|
+ public ApiResult<Boolean> deleteById(Long id){
|
|
|
+ try {
|
|
|
+ return ApiResult.success(sysUserService.deleteById(id));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return ApiResult.failure("删除数据失败",null);
|
|
|
+ }
|
|
|
}
|
|
|
}
|