mitao
2024-03-14 717811c825b998c3001ad0145bd1fd8f46d1a796
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
package com.ruoyi.web.controller.api;
 
 
import com.ruoyi.common.basic.PageVO;
import com.ruoyi.common.core.domain.AjaxResult;
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
 */
@Api(tags = "部门管理相关接口")
@Slf4j
@RestController
@RequestMapping("/dept")
@RequiredArgsConstructor
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 AjaxResult
     */
    @PostMapping("/import")
    @ApiOperation("导入")
    public AjaxResult importExcel(@RequestPart("file")MultipartFile file) {
        try {
            tbDeptService.importExcel(file);
        } catch (Exception e) {
            log.error("导入失败", e);
            throw new RuntimeException(e.getMessage());
        }
        return AjaxResult.success();
    }
 
    /**
     * 分页条件查询
     * @param query 查询条件
     * @return AjaxResult<PageVO<DeptVO>>
     */
    @PostMapping("/page")
    @ApiOperation("分页条件查询")
    public AjaxResult<PageVO<DeptVO>> page(@RequestBody DeptQuery query) {
        return AjaxResult.success(tbDeptService.queryPage(query));
    }
 
    @GetMapping("/{id}")
    @ApiOperation("根据id查询部门详情")
    public AjaxResult<DeptVO> getById(@PathVariable Integer id) {
        TbDept dept = tbDeptService.getById(id);
        DeptVO deptVO = new DeptVO();
        BeanUtils.copyBeanProp(deptVO, dept);
        return AjaxResult.success(deptVO);
    }
    /**
     * 编辑
     * @param dto
     * @return
     */
    @PostMapping("/edit")
    @ApiOperation("编辑")
    public AjaxResult edit(@RequestBody DeptUpdateDTO dto){
        TbDept tbDept = new TbDept();
        BeanUtils.copyBeanProp(tbDept,dto);
        tbDeptService.updateById(tbDept);
        return AjaxResult.success();
    }
 
    /**
     * 重点关注
     * @param dto
     * @return
     */
    @PostMapping("/focus")
    @ApiOperation("重点关注")
    public AjaxResult 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 AjaxResult.success();
    }
}