| | |
| | | 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.dto.PerformanceShiftAddDto; |
| | | import com.yuanchu.mom.pojo.PerformanceShift; |
| | | import com.yuanchu.mom.service.PerformanceShiftService; |
| | | import com.yuanchu.mom.utils.StyleUtils; |
| | | 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; |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | @ApiOperation(value = "绩效管理-班次-导出") |
| | | @GetMapping("update") |
| | | public Result<?> exportToExcel(String time, String userName, String laboratory) { |
| | | performanceShiftService.exportToExcel(time, userName, laboratory); |
| | | return Result.success(); |
| | | public void exportToExcel(@NotNull(message = "时间不能为空!") String time, String userName, String laboratory, HttpServletResponse response) throws Exception { |
| | | Map<Object, Object> data = performanceShiftService.exportToExcel(time, userName, laboratory); |
| | | // 设置单元格样式 |
| | | HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(StyleUtils.getHeadStyle(), StyleUtils.getContentStyle()); |
| | | // 保存到第一个sheet中 |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setHeader("requestType","excel"); |
| | | response.setHeader("Access-Control-Expose-Headers", "requestType"); |
| | | EasyExcel.write(response.getOutputStream()) |
| | | .head((List<List<String>>) data.get("header")) |
| | | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 自适应列宽 |
| | | .registerWriteHandler(horizontalCellStyleStrategy) |
| | | .sheet("模板") |
| | | .doWrite((Collection<?>) data.get("data")); |
| | | } |
| | | } |