From 5980a5fed8092f9866cb2f6a8b74abb7d631c018 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期日, 07 四月 2024 18:26:47 +0800
Subject: [PATCH] 平台端 当前季度数据接口

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbFieldController.java |   95 ++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 77 insertions(+), 18 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbFieldController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbFieldController.java
index 405cbc6..f927e35 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbFieldController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbFieldController.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.TbField;
 import com.ruoyi.system.dto.FieldDTO;
@@ -21,7 +22,6 @@
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
-import java.util.Objects;
 
 /**
  * <p>
@@ -48,8 +48,16 @@
      */
     @GetMapping("/categories")
     @ApiOperation(value = "获取分类列表",notes = "一级分类id传0,二级分类传一级分类id,三级分类同理")
-    public R<List<FieldCategoryVO>> queryFieldCategories(@RequestParam Integer id) {
-        return R.ok(tbFieldCategoryService.queryFieldCategories(id));
+    public R<List<FieldCategoryVO>> queryFieldCategories(@RequestParam Long id) {
+        try {
+            return R.ok(tbFieldCategoryService.queryFieldCategories(id));
+        } catch (Exception e) {
+            if (e instanceof ServiceException) {
+                return R.fail(e.getMessage());
+            }
+            log.error("获取分类列表异常", e);
+            return R.fail();
+        }
     }
 
     /**
@@ -60,14 +68,30 @@
     @PostMapping("/add")
     @ApiOperation("添加字段")
     public R<Void> add(@RequestBody @Validated FieldDTO dto){
-        tbFieldService.add(dto);
+        try {
+            tbFieldService.add(dto);
+        } catch (Exception e) {
+            if (e instanceof ServiceException) {
+                return R.fail(e.getMessage());
+            }
+            log.error("添加字段异常", e);
+            return R.fail();
+        }
         return R.ok();
     }
 
     @GetMapping("/influenced-data")
     @ApiOperation("隐藏字段,获取同步隐藏的基础数据")
-    public R<List<String>> influencedData(@RequestParam Integer id) {
-        return R.ok(tbFieldService.influencedData(id));
+    public R<String> influencedData(@RequestParam Long id) {
+        try {
+            return R.ok(tbFieldService.influencedData(id));
+        } catch (Exception e) {
+            if (e instanceof ServiceException) {
+                return R.fail(e.getMessage());
+            }
+            log.error("获取同步隐藏的基础数据异常", e);
+            return R.fail();
+        }
     }
     /**
      * 隐藏显示操作
@@ -77,7 +101,15 @@
     @PostMapping("/show-hide")
     @ApiOperation("隐藏显示操作")
     public R<Void> showHide(@RequestBody ShowHideDTO dto) {
-        tbFieldService.showHide(dto);
+        try {
+            tbFieldService.showHide(dto);
+        } catch (Exception e) {
+            if (e instanceof ServiceException) {
+                return R.fail(e.getMessage());
+            }
+            log.error("隐藏显示操作异常", e);
+            return R.fail();
+        }
         return R.ok();
     }
 
@@ -89,12 +121,15 @@
     @PostMapping("/edit")
     @ApiOperation("编辑字段")
     public R<Void> add(@RequestBody @Validated FieldUpdateDTO dto){
-        TbField field = tbFieldService.getById(dto.getId());
-        if (Objects.isNull(field)) {
-            throw new RuntimeException("参数异常");
+        try {
+            tbFieldService.update(dto);
+        } catch (Exception e) {
+            if (e instanceof ServiceException) {
+                return R.fail(e.getMessage());
+            }
+            log.error("编辑字段异常", e);
+            return R.fail();
         }
-        TbField tbField = BeanUtils.copyBean(dto, TbField.class);
-        tbFieldService.updateById(tbField);
         return R.ok();
     }
 
@@ -106,7 +141,15 @@
     @PostMapping("/page")
     @ApiOperation("分页条件查询")
     public R<PageDTO<FieldVO>> page(@RequestBody FieldQuery query) {
-        return R.ok(tbFieldService.queryPage(query));
+        try {
+            return R.ok(tbFieldService.queryPage(query));
+        } catch (Exception e) {
+            if (e instanceof ServiceException) {
+                return R.fail(e.getMessage());
+            }
+            log.error("分页条件查询异常", e);
+            return R.fail();
+        }
     }
 
     /**
@@ -116,9 +159,17 @@
      */
     @GetMapping("/get-details")
     @ApiOperation("获取详情")
-    public R<FieldVO> getDetails(@RequestParam Integer id){
-        TbField field = tbFieldService.getById(id);
-        return R.ok(BeanUtils.copyBean(field, FieldVO.class));
+    public R<FieldVO> getDetails(@RequestParam Long id){
+        try {
+            TbField field = tbFieldService.getById(id);
+            return R.ok(BeanUtils.copyBean(field, FieldVO.class));
+        } catch (Exception e) {
+            if (e instanceof ServiceException) {
+                return R.fail(e.getMessage());
+            }
+            log.error("获取详情", e);
+            return R.fail();
+        }
     }
 
     /**
@@ -128,8 +179,16 @@
      */
     @DeleteMapping("/delete")
     @ApiOperation("删除")
-    public R<Void> delete(@RequestParam Integer id){
-        tbFieldService.removeById(id);
+    public R<Void> delete(@RequestParam Long id){
+        try {
+            tbFieldService.removeById(id);
+        } catch (Exception e) {
+            if (e instanceof ServiceException) {
+                return R.fail(e.getMessage());
+            }
+            log.error("获取详情", e);
+            return R.fail();
+        }
         return R.ok();
     }
 }

--
Gitblit v1.7.1