From 789b5b823440d174a198a35fd033ca975cb54f4a Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期三, 27 三月 2024 19:23:13 +0800
Subject: [PATCH] 部门端基础数据导入、得分计算接口

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbDeptController.java |   59 +++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbDeptController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbDeptController.java
index af3f223..deade72 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbDeptController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbDeptController.java
@@ -3,9 +3,9 @@
 
 import com.ruoyi.common.basic.PageDTO;
 import com.ruoyi.common.core.domain.R;
-import com.ruoyi.common.exception.GlobalException;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.BeanUtils;
 import com.ruoyi.common.utils.ExcelUtil;
-import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.system.domain.TbDept;
 import com.ruoyi.system.dto.update.DeptFocusDTO;
 import com.ruoyi.system.dto.update.DeptUpdateDTO;
@@ -51,7 +51,7 @@
             ExcelUtil.exportExcel(list, "部门导入模板", "部门导入模板", TbDept.class, "部门导入模板", response);
         } catch (Exception e) {
             log.error("模板下载异常",e);
-            throw new GlobalException("模板下载失败,请联系管理员!");
+            throw new ServiceException("模板下载失败,请联系管理员!");
         }
     }
 
@@ -62,10 +62,13 @@
      */
     @PostMapping("/import")
     @ApiOperation("导入")
-    public R<Object> importExcel(@RequestPart("file")MultipartFile file) {
+    public R<Void> importExcel(@RequestPart("file")MultipartFile file) {
         try {
             tbDeptService.importExcel(file);
         } catch (Exception e) {
+            if (e instanceof ServiceException) {
+                return R.fail(e.getMessage());
+            }
             log.error("导入失败", e);
             throw new RuntimeException(e.getMessage());
         }
@@ -80,7 +83,15 @@
     @PostMapping("/page")
     @ApiOperation("分页条件查询")
     public R<PageDTO<DeptVO>> page(@RequestBody DeptQuery query) {
-        return R.ok(tbDeptService.queryPage(query));
+        try {
+            return R.ok(tbDeptService.queryPage(query));
+        } catch (Exception e) {
+            if (e instanceof ServiceException) {
+                return R.fail(e.getMessage());
+            }
+            log.error("分页条件查询异常", e);
+            return R.fail();
+        }
     }
 
     /**
@@ -88,13 +99,19 @@
      * @param id 部门id
      * @return DeptVO
      */
-    @GetMapping("/getById")
+    @GetMapping("/get-details")
     @ApiOperation("根据id查询部门详情")
-    public R<DeptVO> getById(@RequestParam Integer id) {
-        TbDept dept = tbDeptService.getById(id);
-        DeptVO deptVO = new DeptVO();
-        BeanUtils.copyBeanProp(deptVO, dept);
-        return R.ok(deptVO);
+    public R<DeptVO> getDetails(@RequestParam Integer id) {
+        try {
+            TbDept dept = tbDeptService.getById(id);
+            return R.ok(BeanUtils.copyBean(dept,DeptVO.class));
+        } catch (Exception e) {
+            if (e instanceof ServiceException) {
+                return R.fail(e.getMessage());
+            }
+            log.error("根据id查询部门详情异常", e);
+            return R.fail();
+        }
     }
 
     /**
@@ -105,9 +122,16 @@
     @PostMapping("/edit")
     @ApiOperation("编辑")
     public R<Object> edit(@RequestBody DeptUpdateDTO dto){
-        TbDept tbDept = new TbDept();
-        BeanUtils.copyBeanProp(tbDept,dto);
-        tbDeptService.updateById(tbDept);
+        try {
+            TbDept tbDept = BeanUtils.copyBean(dto, TbDept.class);
+            tbDeptService.updateById(tbDept);
+        } catch (Exception e) {
+            if (e instanceof ServiceException) {
+                return R.fail(e.getMessage());
+            }
+            log.error("编辑异常", e);
+            return R.fail();
+        }
         return R.ok();
     }
 
@@ -119,12 +143,7 @@
     @PostMapping("/focus")
     @ApiOperation("重点关注")
     public R<Object> focus(@RequestBody DeptFocusDTO dto){
-        TbDept tbDept = new TbDept();
-        BeanUtils.copyBeanProp(tbDept,dto);
-        tbDeptService.lambdaUpdate()
-                .eq(TbDept::getId, dto.getId())
-                .set(TbDept::getFocussed, dto.getFocussed())
-                .update();
+       tbDeptService.focus(dto);
         return R.ok();
     }
 }

--
Gitblit v1.7.1