package com.ruoyi.staff.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.ruoyi.framework.web.domain.R; import com.ruoyi.staff.dto.PerformanceShiftAddDto; import com.ruoyi.staff.pojo.PersonalAttendanceLocationConfig; import com.ruoyi.staff.pojo.PersonalShift; import com.ruoyi.staff.service.PersonalAttendanceLocationConfigService; import com.ruoyi.staff.service.PersonalShiftService; import com.ruoyi.staff.utils.StyleMonthUtils; import com.ruoyi.staff.utils.StyleYearUtils; 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; /** *

* 前端控制器 *

* * @author 芯导软件(江苏)有限公司 * @since 2026-03-05 03:52:19 */ @RestController @RequestMapping("/personalShift") @Api(tags = "人员排班") public class PersonalShiftController { @Autowired private PersonalShiftService personalShiftService; @ApiOperation("人员排班") @PostMapping("/add") public R add(@RequestBody PerformanceShiftAddDto performanceShiftAddDto){ return R.ok(personalShiftService.performanceShiftAdd(performanceShiftAddDto)); } @ApiOperation(value = "月份分页查询") @GetMapping("page") public R performanceShiftPage(Integer size, Integer current, String time, String userName, Integer sysDeptId) { return R.ok(personalShiftService.performanceShiftPage(new Page<>(current, size), time, userName, sysDeptId)); } @ApiOperation(value = "年份分页查询") @GetMapping("pageYear") public R performanceShiftPageYear(Integer size, Integer current, String time, String userName, Integer sysDeptId) { return R.ok(personalShiftService.performanceShiftPageYear(new Page<>(current, size), time, userName, sysDeptId)); } @ApiOperation(value = "班次状态修改") @PostMapping("update") public R performanceShiftUpdate(@RequestBody PersonalShift personalShift) { personalShiftService.performanceShiftUpdate(personalShift); return R.ok(); } @ApiOperation(value = "导出") @GetMapping("export") public void exportToExcel(@NotNull(message = "时间不能为空!") String time, String userName, Integer sysDeptId, Boolean isMonth, HttpServletResponse response) throws Exception { Map data; response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("requestType","excel"); response.setHeader("Access-Control-Expose-Headers", "requestType"); if (!isMonth) { data = personalShiftService.exportToYearExcel(time, userName, sysDeptId); // 设置单元格样式 HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(StyleYearUtils.getHeadStyle(), StyleYearUtils.getContentStyle()); // 保存到第一个sheet中 EasyExcel.write(response.getOutputStream()) .head((List>) data.get("header")) .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 自适应列宽 .registerWriteHandler(horizontalCellStyleStrategy) .sheet("年度") .doWrite((Collection) data.get("data")); } else { data = personalShiftService.exportToMonthExcel(time, userName, sysDeptId); // 设置单元格样式 HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(StyleMonthUtils.getHeadStyle(), StyleMonthUtils.getContentStyle()); EasyExcel.write(response.getOutputStream()) .head((List>) data.get("header")) .registerWriteHandler(horizontalCellStyleStrategy) .sheet("月度") .doWrite((Collection) data.get("data")); } } }