From d68c61517a3a6d4ec4d47844c21bdc143f99cbab Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期三, 17 四月 2024 22:58:05 +0800
Subject: [PATCH] 大屏接口
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbBasicDataCategoryController.java | 94 +++++++++++++++++++++++++++++++++++++---------
1 files changed, 75 insertions(+), 19 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbBasicDataCategoryController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbBasicDataCategoryController.java
index 75d5212..9af6b8c 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbBasicDataCategoryController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbBasicDataCategoryController.java
@@ -3,6 +3,7 @@
import com.ruoyi.common.basic.PageDTO;
import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.BeanUtils;
import com.ruoyi.system.domain.TbBasicDataCategory;
import com.ruoyi.system.dto.BasicDataCategoryDTO;
@@ -16,9 +17,13 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.Objects;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+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.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
/**
* <p>
@@ -39,79 +44,130 @@
/**
* 添加
+ *
* @param dto 基础数据分类传输对象
* @return R<Void>
*/
@PostMapping("/add")
@ApiOperation("添加")
public R<Void> add(@RequestBody @Validated BasicDataCategoryDTO dto) {
- tbBasicDataCategoryService.add(dto);
+ try {
+ tbBasicDataCategoryService.add(dto);
+ } catch (Exception e) {
+ if (e instanceof ServiceException) {
+ return R.fail(e.getMessage());
+ }
+ log.error("添加异常", e);
+ return R.fail();
+ }
return R.ok();
}
/**
* 编辑
+ *
* @param dto 基础数据分类更新传输对象
* @return R<Void>
*/
@PostMapping("/edit")
@ApiOperation("编辑")
public R<Void> add(@RequestBody @Validated BasicDataCategoryUpdateDTO dto) {
- tbBasicDataCategoryService.update(dto);
+ try {
+ tbBasicDataCategoryService.update(dto);
+ } catch (Exception e) {
+ if (e instanceof ServiceException) {
+ return R.fail(e.getMessage());
+ }
+ log.error("编辑异常", e);
+ return R.fail();
+ }
return R.ok();
}
/**
* 删除
+ *
* @param id id
* @return R<Void>
*/
@DeleteMapping("/delete")
@ApiOperation("删除")
- public R<Void> delete(@RequestParam(value = "id") Integer id){
- tbBasicDataCategoryService.removeById(id);
+ public R<Void> delete(@RequestParam(value = "id") Long id) {
+ try {
+ tbBasicDataCategoryService.removeById(id);
+ } catch (Exception e) {
+ if (e instanceof ServiceException) {
+ return R.fail(e.getMessage());
+ }
+ log.error("删除异常", e);
+ return R.fail();
+ }
return R.ok();
}
/**
* 根据id获取详情
+ *
* @param id id
* @return R<BasicDataCategoryVO>
*/
@GetMapping("/get-details")
@ApiOperation("根据id获取详情")
- public R<BasicDataCategoryVO> getDetails(@RequestParam(value = "id") Integer id){
- TbBasicDataCategory basicDataCategory = tbBasicDataCategoryService.getById(id);
- BasicDataCategoryVO vo = BeanUtils.copyBean(basicDataCategory, BasicDataCategoryVO.class);
- return R.ok(vo);
+ public R<BasicDataCategoryVO> getDetails(@RequestParam(value = "id") Long id) {
+ try {
+ TbBasicDataCategory basicDataCategory = tbBasicDataCategoryService.getById(id);
+ BasicDataCategoryVO vo = BeanUtils.copyBean(basicDataCategory,
+ BasicDataCategoryVO.class);
+ return R.ok(vo);
+ } catch (Exception e) {
+ if (e instanceof ServiceException) {
+ return R.fail(e.getMessage());
+ }
+ log.error("根据id获取详情异常", e);
+ return R.fail();
+ }
}
/**
* 隐藏显示操作
+ *
* @param dto 显示隐藏操作数据传输对象
* @return R<Void>
*/
@PostMapping("/show-hide")
@ApiOperation("隐藏显示操作")
public R<Void> showHide(@RequestBody ShowHideDTO dto) {
- TbBasicDataCategory basicDataCategory = tbBasicDataCategoryService.getById(dto.getId());
- if (Objects.isNull(basicDataCategory)) {
- throw new RuntimeException("非法参数");
+ try {
+ tbBasicDataCategoryService.showHide(dto);
+ } catch (Exception e) {
+ if (e instanceof ServiceException) {
+ return R.fail(e.getMessage());
+ }
+ log.error("隐藏显示操作异常", e);
+ return R.fail();
}
- tbBasicDataCategoryService.lambdaUpdate().set( TbBasicDataCategory::getStatus, dto.getStatus()).eq(TbBasicDataCategory::getId, dto.getId()).update();
return R.ok();
}
/**
* 分页条件查询
+ *
* @param query 基础数据分类条件查询对象
- * @return R<PageDTO<BasicDataCategoryVO>>
+ * @return R<PageDTO < BasicDataCategoryVO>>
*/
@PostMapping("/page")
@ApiOperation("分页条件查询")
- public R<PageDTO<BasicDataCategoryVO>> page(@RequestBody BasicDataCategoryQuery query) {
- return R.ok(tbBasicDataCategoryService.queryPage(query));
+ public R<PageDTO<BasicDataCategoryVO>> page(
+ @Validated @RequestBody BasicDataCategoryQuery query) {
+ try {
+ return R.ok(tbBasicDataCategoryService.queryPage(query));
+ } catch (Exception e) {
+ if (e instanceof ServiceException) {
+ return R.fail(e.getMessage());
+ }
+ log.error("分页条件查询异常", e);
+ return R.fail();
+ }
}
-
}
--
Gitblit v1.7.1