mitao
2024-03-27 789b5b823440d174a198a35fd033ca975cb54f4a
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();
    }
}