mitao
2024-03-15 92b586e7d47167421f6500be641734acebeacd79
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.ruoyi.web.controller.api;
 
 
import com.ruoyi.common.basic.PageDTO;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.exception.GlobalException;
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;
import com.ruoyi.system.query.DeptQuery;
import com.ruoyi.system.service.TbDeptService;
import com.ruoyi.system.vo.DeptVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
 
/**
 * <p>
 * 部门管理表 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2024-03-13
 */
@Slf4j
@RestController
@RequestMapping("/dept")
@RequiredArgsConstructor
@Api(tags = "部门管理相关接口")
public class TbDeptController {
 
    private final HttpServletResponse response;
    private final TbDeptService tbDeptService;
 
    /**
     * 导入模板下载
     */
    @GetMapping("/download")
    @ApiOperation("模板下载")
    public void download() {
        try {
            ArrayList<TbDept> list = new ArrayList<>();
            ExcelUtil.exportExcel(list, "部门导入模板", "部门导入模板", TbDept.class, "部门导入模板", response);
        } catch (Exception e) {
            log.error("模板下载异常",e);
            throw new GlobalException("模板下载失败,请联系管理员!");
        }
    }
 
    /**
     * 导入
     * @param file 文件
     * @return R
     */
    @PostMapping("/import")
    @ApiOperation("导入")
    public R<Object> importExcel(@RequestPart("file")MultipartFile file) {
        try {
            tbDeptService.importExcel(file);
        } catch (Exception e) {
            log.error("导入失败", e);
            throw new RuntimeException(e.getMessage());
        }
        return R.ok();
    }
 
    /**
     * 分页条件查询
     * @param query 查询条件
     * @return R<PageVO<DeptVO>>
     */
    @PostMapping("/page")
    @ApiOperation("分页条件查询")
    public R<PageDTO<DeptVO>> page(@RequestBody DeptQuery query) {
        return R.ok(tbDeptService.queryPage(query));
    }
 
    /**
     * 根据id查询部门详情
     * @param id 部门id
     * @return DeptVO
     */
    @GetMapping("/getById")
    @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);
    }
 
    /**
     * 编辑
     * @param dto 部门更新实体
     * @return 响应成功
     */
    @PostMapping("/edit")
    @ApiOperation("编辑")
    public R<Object> edit(@RequestBody DeptUpdateDTO dto){
        TbDept tbDept = new TbDept();
        BeanUtils.copyBeanProp(tbDept,dto);
        tbDeptService.updateById(tbDept);
        return R.ok();
    }
 
    /**
     * 重点关注
     * @param dto 部门更新实体
     * @return 响应成功
     */
    @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();
        return R.ok();
    }
}