value
2024-05-15 862d71a72acc5f7b4f5a2e7b7b7303d73b800691
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
package com.yuanchu.mom.controller;
 
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.mom.annotation.ValueClassify;
import com.yuanchu.mom.dto.PerformanceShiftAddDto;
import com.yuanchu.mom.pojo.PerformanceShift;
import com.yuanchu.mom.service.PerformanceShiftService;
import com.yuanchu.mom.utils.StyleMonthUtils;
import com.yuanchu.mom.utils.StyleYearUtils;
import com.yuanchu.mom.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.Collection;
import java.util.List;
import java.util.Map;
 
 
/**
 * <p>
 * 绩效管理-班次 前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2024-05-08 09:12:04
 */
@Api(tags = "绩效管理-班次")
@RestController
@RequestMapping("/performanceShift")
public class PerformanceShiftController {
 
    @Autowired
    private PerformanceShiftService performanceShiftService;
 
    @ValueClassify("班次")
    @ApiOperation(value = "排班")
    @PostMapping("add")
    public Result<?> performanceShiftAdd(@RequestBody PerformanceShiftAddDto performanceShiftAddDto) {
        performanceShiftService.performanceShiftAdd(performanceShiftAddDto);
        return Result.success();
    }
 
    @ValueClassify("班次")
    @ApiOperation(value = "月份分页查询")
    @PostMapping("page")
    public Result<?> performanceShiftPage(Integer size, Integer current, String time, String userName, String laboratory) {
        return Result.success(performanceShiftService.performanceShiftPage(new Page<>(current, size), time, userName, laboratory));
    }
 
    @ValueClassify("班次")
    @ApiOperation(value = "年份分页查询")
    @PostMapping("pageYear")
    public Result<?> performanceShiftPageYear(Integer size, Integer current, String time, String userName, String laboratory) {
        return Result.success(performanceShiftService.performanceShiftPageYear(new Page<>(current, size), time, userName, laboratory));
    }
 
    @ValueClassify("班次")
    @ApiOperation(value = "班次状态修改")
    @PutMapping("update")
    public Result<?> performanceShiftUpdate(@RequestBody PerformanceShift performanceShift) {
        performanceShiftService.performanceShiftUpdate(performanceShift);
        return Result.success();
    }
 
    @ValueClassify("班次")
    @ApiOperation(value = "导出")
    @GetMapping("export")
    public void exportToExcel(@NotNull(message = "时间不能为空!") String time, String userName, String laboratory, Boolean isMonth, HttpServletResponse response) throws Exception {
        Map<Object, Object> data;
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setHeader("requestType","excel");
        response.setHeader("Access-Control-Expose-Headers", "requestType");
        if (!isMonth) {
            data = performanceShiftService.exportToYearExcel(time, userName, laboratory);
            // 设置单元格样式
            HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(StyleYearUtils.getHeadStyle(), StyleYearUtils.getContentStyle());
            // 保存到第一个sheet中
            EasyExcel.write(response.getOutputStream())
                    .head((List<List<String>>) data.get("header"))
                    .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 自适应列宽
                    .registerWriteHandler(horizontalCellStyleStrategy)
                    .sheet("年度")
                    .doWrite((Collection<?>) data.get("data"));
        } else {
            data = performanceShiftService.exportToMonthExcel(time, userName, laboratory);
            // 设置单元格样式
            HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(StyleMonthUtils.getHeadStyle(), StyleMonthUtils.getContentStyle());
            EasyExcel.write(response.getOutputStream())
                    .head((List<List<String>>) data.get("header"))
                    .registerWriteHandler(horizontalCellStyleStrategy)
                    .sheet("月度")
                    .doWrite((Collection<?>) data.get("data"));
        }
    }
}