Alan
2021-02-21 c294865250a10b3b0f5661e1e2e7b127917552c7
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
package cc.mrbird.febs.server.hr.controller;
 
import cc.mrbird.febs.common.core.entity.FebsResponse;
import cc.mrbird.febs.common.core.entity.QueryRequest;
import cc.mrbird.febs.common.core.exception.FebsException;
import cc.mrbird.febs.common.core.utils.FebsUtil;
import cc.mrbird.febs.server.hr.entity.EmpAccessory;
import cc.mrbird.febs.server.hr.service.IEmpAccessoryService;
import cc.mrbird.febs.server.hr.vo.EmpAccessoryVO;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Map;
 
/**
 * 附件管理 Controller
 *
 * @author yz
 * @date 2021-02-15 17:07:19
 */
@Slf4j
@Validated
@RestController
@RequestMapping("empAccessory")
@RequiredArgsConstructor
public class EmpAccessoryController {
 
    private final IEmpAccessoryService empAccessoryService;
 
    @GetMapping
    @PreAuthorize("hasAuthority('empAccessory:list')")
    public FebsResponse getAllEmpAccessorys(EmpAccessory empAccessory) {
        return new FebsResponse().data(empAccessoryService.findEmpAccessorys(empAccessory));
    }
 
    @GetMapping("list")
    @PreAuthorize("hasAuthority('empAccessory:list')")
    public FebsResponse empAccessoryList(QueryRequest request, EmpAccessoryVO vo) {
        Map<String, Object> dataTable = FebsUtil.getDataTable(this.empAccessoryService.findEmpAccessorys(request, vo));
        return new FebsResponse().data(dataTable);
    }
 
    @PostMapping
    @PreAuthorize("hasAuthority('empAccessory:add')")
    public void addEmpAccessory(@NotNull(message = "{required}") Long labelid,@NotNull(message = "{required}") Long empId, MultipartFile file) throws FebsException {
        try {
            this.empAccessoryService.createEmpAccessory(labelid,file,empId);
        } catch (Exception e) {
            String message = "新增EmpAccessory失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
 
    @DeleteMapping
    @PreAuthorize("hasAuthority('empAccessory:delete')")
    public void deleteEmpAccessory(@NotBlank(message = "{required}")  String accessoryids) throws FebsException {
        try {
            this.empAccessoryService.deleteEmpAccessory(accessoryids);
        } catch (Exception e) {
            String message = "删除EmpAccessory失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
 
    @PutMapping
    @PreAuthorize("hasAuthority('empAccessory:update')")
    public void updateEmpAccessory(EmpAccessory empAccessory) throws FebsException {
        try {
            this.empAccessoryService.updateEmpAccessory(empAccessory);
        } catch (Exception e) {
            String message = "修改EmpAccessory失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
 
    @PostMapping("/download")
    @PreAuthorize("hasAuthority('empAccessory:download')")
    public void download(@NotBlank(message = "{required}")  String accessoryids, HttpServletRequest request, HttpServletResponse response) throws FebsException {
        try {
            this.empAccessoryService.download(accessoryids,request,response);
        } catch (Exception e) {
            String message = "下载文件失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
 
    @PostMapping("/mvFiles")
    @PreAuthorize("hasAuthority('empAccessory:mv')")
    public void mvFiles(@NotBlank(message = "{required}")  String accessoryids,@NotNull(message = "{required}") Long labelid,@NotNull(message = "{required}")  Long empId) throws FebsException {
        try {
            this.empAccessoryService.mvFiles(accessoryids,labelid,empId);
        } catch (Exception e) {
            String message = "移动文件失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
    @PostMapping("/singledownload")
    @PreAuthorize("hasAuthority('empAccessory:singledownload')")
    public void singledownload(@NotBlank(message = "{required}")  String empIds, @NotNull(message = "{required}")  Long labelid, HttpServletRequest request, HttpServletResponse response) throws FebsException {
        try {
            this.empAccessoryService.singledownload(empIds,labelid,request,response);
        } catch (Exception e) {
            String message = "下载文件失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
}