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
package com.ruoyi.staff.controller;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.staff.pojo.StaffJoinLeaveRecord;
import com.ruoyi.staff.pojo.StaffOnJob;
import com.ruoyi.staff.service.IStaffJoinLeaveRecordService;
import com.ruoyi.staff.service.IStaffOnJobService;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
 
/**
 * 员工台账/合同管理
 */
@RestController
@RequestMapping("/staff/staffOnJob")
public class StaffOnJobController {
 
    @Resource
    private IStaffOnJobService staffOnJobService;
 
 
    /**
     * 在职员工台账分页查询
     * @param page
     * @param staffOnJob
     * @return
     */
    @GetMapping("/listPage")
    public AjaxResult staffOnJobListPage(Page page, StaffOnJob staffOnJob) {
        return AjaxResult.success(staffOnJobService.staffOnJobListPage(page, staffOnJob));
    }
 
    /**
     * 在职员工下拉(新增离职用)
     * @return
     */
    @GetMapping("/list")
    public AjaxResult staffOnJobList() {
        return AjaxResult.success(staffOnJobService.staffOnJobList());
    }
 
    /**
     * 在职员工详情
     * @param staffNo
     * @return
     */
    @GetMapping("/staffNo")
    public AjaxResult staffOnJobDetail(String staffNo) {
        return AjaxResult.success(staffOnJobService.staffOnJobDetail(staffNo));
    }
    /**
     * 在职员工导入
     */
    @PostMapping("/import")
    @Log(title = "在职员工导入", businessType = BusinessType.IMPORT)
    public AjaxResult importData(@RequestPart("file") MultipartFile file) {
        Boolean b = staffOnJobService.importData(file);
        if (b) {
            return AjaxResult.success("导入成功");
        }
        return AjaxResult.error("导入失败");
    }
 
    /**
     * 在职员工导出
     * @param response
     * @param staffOnJob
     */
    @PostMapping("/export")
    public void staffOnJobExport(HttpServletResponse response,StaffOnJob staffOnJob) {
        staffOnJobService.staffOnJobExport(response, staffOnJob);
    }
 
    /**
     * 新增在职员工
     */
    @PostMapping
    public AjaxResult add(@RequestBody StaffOnJob staffOnJob) {
        if (staffOnJob.getStaffState() == null) {
            staffOnJob.setStaffState(1);
        }
        return staffOnJobService.save(staffOnJob) ? AjaxResult.success() : AjaxResult.error("新增失败");
    }
 
    /**
     * 修改在职员工
     */
    @PutMapping("/{id}")
    public AjaxResult update(@PathVariable Long id, @RequestBody StaffOnJob staffOnJob) {
        staffOnJob.setId(id);
        return staffOnJobService.updateById(staffOnJob) ? AjaxResult.success() : AjaxResult.error("修改失败");
    }
 
    /**
     * 删除在职员工
     */
    @DeleteMapping("/del")
    public AjaxResult del(@RequestBody List<Long> ids) {
        return staffOnJobService.removeByIds(ids) ? AjaxResult.success() : AjaxResult.error("删除失败");
    }
 
    /**
     * 在职员工统计(在职人数 / 薪资合计)
     */
    @GetMapping("/statistics")
    public AjaxResult statistics() {
        List<StaffOnJob> list = staffOnJobService.list();
        long onJobCount = list.stream()
                .filter(s -> s.getStaffState() != null && s.getStaffState() == 1).count();
        java.math.BigDecimal salaryTotal = list.stream()
                .filter(s -> s.getStaffState() != null && s.getStaffState() == 1 && s.getSalary() != null)
                .map(StaffOnJob::getSalary)
                .reduce(java.math.BigDecimal.ZERO, java.math.BigDecimal::add);
        java.util.Map<String, Object> map = new java.util.HashMap<>();
        map.put("onJobCount", onJobCount);
        map.put("salaryTotal", salaryTotal);
        return AjaxResult.success(map);
    }
 
 
}