孔祥富
2021-03-05 890be4f01daefbca6f085bb8314d40de282c1db8
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
131
132
133
134
package cc.mrbird.febs.server.hr.controller;
 
import cc.mrbird.febs.server.hr.annotation.ControllerEndpoint;
import cc.mrbird.febs.server.hr.constant.MyConstant;
import cc.mrbird.febs.server.hr.entity.EmpJobChange;
import cc.mrbird.febs.server.hr.entity.EmpLaborTrouble;
import cc.mrbird.febs.server.hr.service.IEmpLaborTroubleService;
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 cn.hutool.core.util.StrUtil;
import com.wuwenze.poi.ExcelKit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;
 
/**
 * name:EmpLabortrouble
 * package:cc.mrbird.febs.server.hr.controller
 * description:员工劳资案件控制器
 *
 * @author luoyibo
 * @date 2021-01-31 11:26:36
 * @since JDK1.8
 */
@Api(tags = "人员劳资案件信息录入接口")
@Slf4j
@Validated
@RestController
@RequestMapping("empLaborTrouble")
@RequiredArgsConstructor
public class EmpLaborTroubleController {
 
    private final IEmpLaborTroubleService empLabortroubleService;
 
    @GetMapping
    @PreAuthorize("hasAuthority('empLabortrouble:list')")
    public FebsResponse getAllEmpLabortroubles(EmpLaborTrouble empLabortrouble) {
        return new FebsResponse().data(empLabortroubleService.findEmpLabortroubles(empLabortrouble));
    }
 
    @GetMapping("list")
    public FebsResponse empLabortroubleList(QueryRequest request, EmpLaborTrouble empLabortrouble) {
        Map<String, Object> dataTable = FebsUtil.getDataTable(this.empLabortroubleService.findEmpLabortroubles(request, empLabortrouble));
        return new FebsResponse().data(dataTable);
    }
 
    @ApiOperation(value = "导出员工")
    @RequestMapping(value = "export", method = RequestMethod.POST)
    @ControllerEndpoint(operation = "导出用户数据", exceptionMessage = "导出Excel失败")
    public void export(QueryRequest request, EmpLaborTrouble empBaseinfo, HttpServletResponse response) {
        request.setPageSize(this.empLabortroubleService.count());
        List<EmpLaborTrouble> records = this.empLabortroubleService.findEmpLabortroubles(request, empBaseinfo).getRecords();
        ExcelKit.$Export(EmpLaborTrouble.class, response).downXlsx(records, false);
    }
 
    @PostMapping
    @PreAuthorize("hasAuthority('empLabortrouble:add')")
    public void addEmpLabortrouble(@Valid EmpLaborTrouble empLabortrouble) throws FebsException {
        try {
            this.empLabortroubleService.createEmpLabortrouble(empLabortrouble);
        } catch (Exception e) {
            String message = "新增员工劳资案件失败";
            if (StrUtil.equals(e.getMessage(), MyConstant.MESSAGE)){
                message = e.getMessage();
            }
            log.error(message, e);
            throw new FebsException(message);
        }
    }
 
    @DeleteMapping
    @PreAuthorize("hasAuthority('empLabortrouble:delete')")
    public void deleteEmpLabortrouble(EmpLaborTrouble empLabortrouble) throws FebsException {
        try {
            this.empLabortroubleService.deleteEmpLabortrouble(empLabortrouble);
        } catch (Exception e) {
            String message = "删除员工劳资案件失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
 
    @DeleteMapping("{ids}")
    @PreAuthorize("hasAuthority('empLabortrouble:delete')")
    public void logicDeleteEmpLabortrouble(@PathVariable("ids") String ids) throws FebsException {
        try {
            this.empLabortroubleService.logicDelEmpLabortrouble(ids);
        } catch (Exception e) {
            String message = "逻辑删除员工劳资案件失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
 
    @PutMapping
    @PreAuthorize("hasAuthority('empLabortrouble:update')")
    public void updateEmpLabortrouble(EmpLaborTrouble empLabortrouble) throws FebsException {
        try {
            this.empLabortroubleService.updateEmpLabortrouble(empLabortrouble);
        } catch (Exception e) {
            String message = "修改员工劳资案件失败";
            if (StrUtil.equals(e.getMessage(), MyConstant.MESSAGE)){
                message = e.getMessage();
            }
            log.error(message, e);
            throw new FebsException(message);
        }
    }
 
    @ApiOperation(value = "劳资案件信息提交")
    @DeleteMapping("toNormal/{ids}")
    @PreAuthorize("hasAuthority('empLabortrouble:delete')")
    public void momentToNormal(@NotBlank(message = "{required}") @PathVariable("ids") String ids) throws FebsException {
        try {
            this.empLabortroubleService.momentToNormal(ids);
        } catch (Exception e) {
            String message = "劳资信息提交失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
}