| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.AuxiliaryOriginalHoursDto; |
| | | import com.yuanchu.mom.pojo.Evaluate; |
| | | import com.yuanchu.mom.mapper.EvaluateMapper; |
| | | import com.yuanchu.mom.service.EvaluateService; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(Evaluate.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("getPage"); |
| | | if(map1.get("look")==1) evaluate.setCreateUser(map1.get("userId")); |
| | | //map.put("body", evaluateMapper.getPage(page, QueryWrappers.queryWrappers(evaluate))); |
| | | if (map1.get("look") == 1) evaluate.setCreateUser(map1.get("userId")); |
| | | map.put("body", evaluateMapper.getPage(page, QueryWrappers.queryWrappers(evaluate))); |
| | | return map; |
| | | } |
| | | |
| | | //导出考评 |
| | | @Override |
| | | public void export(String month, String name, String departLims, HttpServletResponse response) throws IOException { |
| | | List<Evaluate> evaluates = new ArrayList<Evaluate>(); |
| | | //查询原始工时(使用分页查询) |
| | | Evaluate evaluate = new Evaluate(); |
| | | if (ObjectUtils.isNotEmpty(month)) { |
| | | evaluate.setMonth(month); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(name)) { |
| | | evaluate.setName(name); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(departLims)) { |
| | | evaluate.setDepartLims(departLims); |
| | | } |
| | | IPage<Evaluate> body = (IPage<Evaluate>) getPage(new Page(-1, -1), evaluate).get("body"); |
| | | evaluates = body.getRecords(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName = URLEncoder.encode("考评导出", "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | try { |
| | | // 新建ExcelWriter |
| | | ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build(); |
| | | WriteSheet mainSheet = EasyExcel.writerSheet(0, "考评导出").head(Evaluate.class).build(); |
| | | excelWriter.write(evaluates, mainSheet); |
| | | // 关闭流 |
| | | excelWriter.finish(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("导出失败"); |
| | | } |
| | | } |
| | | } |