RosteringController.java
3.19 KB
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
package com.pipihelper.project.controller;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.core.Result;
import com.pipihelper.project.core.ResultGenerator;
import com.pipihelper.project.rostering.model.DateRuleModel;
import com.pipihelper.project.rostering.model.RosteringExportModel;
import com.pipihelper.project.rostering.model.RosteringModel;
import com.pipihelper.project.rostering.model.ShiftRuleModel;
import com.pipihelper.project.rostering.model.StaffRuleModel;
import com.pipihelper.project.rostering.service.RosteringService;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
/**
* @description:
* @author: zsw
* @create: 2022-10-15 20:01
**/
@RestController
@RequestMapping("/api/v1/rostering")
public class RosteringController {
@Autowired
private RosteringService rosteringService;
@PostMapping(value = "list-staff")
public Result listStaff() {
return ResultGenerator.genSuccessResult(rosteringService.findAllStaff());
}
@RequestMapping(value = "export")
public void listStaff(String datas, String date, HttpServletResponse response) {
List<RosteringExportModel> rosteringModels = JSONObject.parseArray(datas, RosteringExportModel.class);
Workbook workbook = rosteringService.export(rosteringModels);
try {
String fileName = DateUtil.format(DateUtil.parse(date), "yyyy-MM") + "rostering.xls";
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
workbook.write(response.getOutputStream());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
}
@PostMapping(value = "gen")
public Result genRostering(@RequestParam("date") Date date,
@RequestParam("shiftRuleModel") String shiftRuleModelStr,
@RequestParam("staffRuleModel") String staffRuleModelStr,
@RequestParam("dateRuleModel") String dateRuleModelStr) {
List<ShiftRuleModel> shiftRuleModels = JSONObject.parseArray(shiftRuleModelStr, ShiftRuleModel.class);
List<StaffRuleModel> staffRuleModels = JSONObject.parseArray(staffRuleModelStr, StaffRuleModel.class);
List<DateRuleModel> dateRuleModels = JSONObject.parseArray(dateRuleModelStr, DateRuleModel.class);
return ResultGenerator.genSuccessResult(rosteringService.gen(date, shiftRuleModels, staffRuleModels, dateRuleModels));
}
}