Browse Source

上传一下代码

master
HY 1 month ago
parent
commit
36499b42c0
1 changed files with 66 additions and 26 deletions
  1. +66
    -26
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/modules/clockinlog/controller/ClockinLogController.java

+ 66
- 26
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/modules/clockinlog/controller/ClockinLogController.java View File

@ -1,12 +1,11 @@
package org.jeecg.modules.clockinlog.controller;
import java.io.*;
import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.util.*;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@ -16,19 +15,16 @@ import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapp
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.http.HttpHeaders;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbookFactory;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.DateUtils2;
import org.jeecg.common.util.ExcelStyleUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.clockInproject.entity.ClockInProject;
import org.jeecg.modules.clockInproject.service.IClockInProjectService;
import org.jeecg.modules.clockinauth.entity.ClockinAuth;
@ -52,6 +48,7 @@ import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
@ -59,6 +56,8 @@ import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecgframework.poi.excel.view.JeecgMapExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
@ -200,7 +199,7 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
@RequestMapping(value = "/exportXls2")
public ModelAndView exportXls3(HttpServletRequest request, ClockinLog clockinLog) {
public ModelAndView exportXls3(HttpServletRequest request, ClockinLog clockinLog) throws IOException {
return this.exportXls2(request,ClockInLogExportResp.class, "打卡");
}
@ -350,7 +349,8 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
protected ModelAndView exportXls3(HttpServletRequest request, Class<ClockInLogExportResp> clazz, String title) {
protected Object exportXls3(HttpServletRequest request, Class<ClockInLogExportResp> clazz, String title) throws IOException {
// Step.1 组装查询条件
Map<String, String[]> parameterMap = request.getParameterMap();
String[] clockStartTimes = parameterMap.get("clockStartTime");
@ -390,10 +390,25 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
}
// 创建工作簿
XSSFWorkbookFactory xssfWorkbookFactory = new XSSFWorkbookFactory();
Workbook workbook = new XSSFWorkbook();
// 创建工作表
Sheet sheet = workbook.createSheet("考勤");
// 创建表头行
Row headerRow = sheet.createRow(0);
headerRow.createCell(0).setCellValue("日期");
headerRow.createCell(1).setCellValue("打卡时间");
List<Map<String, Object>> maps = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
// XSSFWorkbook workbook = new XSSFWorkbook();
// XSSFSheet sheet = workbook.createSheet("打卡数据");
// XSSFRow headRow = sheet.createRow(0);
// headRow.createCell(0).setCellValue("姓名");
// headRow.createCell(1).setCellValue("性别");
// headRow.createCell(2).setCellValue("数据");
List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
ExcelExportEntity excelExportEntity = new ExcelExportEntity("姓名", "name");
excelExportEntity.setNeedMerge(true);
@ -465,7 +480,8 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
if(DayOfWeek.SATURDAY.equals(localDateTime.getDayOfWeek()) || DayOfWeek.SUNDAY.equals(localDateTime.getDayOfWeek())){
type = 1;
}
Row row = sheet.createRow(n);
row.createCell(0).setCellValue(yearMonthDay);
List<ClockInLogResp> clockInLogExpeort = clockinLogMapper.getClockInLogExpeort(yearMonthDay, clockInProject.getId(), clockinTeamLog.getUserId(),type);
String clockInTime = "";
for (ClockInLogResp clockInLogResp:clockInLogExpeort) {
@ -476,6 +492,12 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
clockInTime = clockInTime+"\n"+clockInLogResp.getClockStartTime();
// strings.add(clockInLogResp.getClockStartTime());
}
// 创建一个单元格样式用于自动换行
CellStyle wrapStyle = workbook.createCellStyle();
wrapStyle.setWrapText(true);
Cell cell = row.createCell(1);
cell.setCellValue(clockInTime);
cell.setCellStyle(wrapStyle);
Map<String, Object> map1 = new HashMap<>();
map1.put(n+"",clockInTime);
maps1.add(map1);
@ -489,6 +511,24 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
exportList.add(clockInLogExportResp);
}
// 调整列宽以适应内容
sheet.autoSizeColumn(0);
sheet.autoSizeColumn(1);
// 将工作簿写入字节数组输出流
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
byte[] bytes = bos.toByteArray();
// 构建响应头
org.springframework.http.HttpHeaders headers = new org.springframework.http.HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", "attendance_data.xlsx");
// 返回响应实体
return ResponseEntity.ok()
.headers(headers)
.body(bytes);
// 过滤选中数据
// String selections = request.getParameter("selections");
@ -500,21 +540,21 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
// }
// Step.3 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
//此处设置的filename无效 ,前端会重更新设置一下
mv.addObject(NormalExcelConstants.FILE_NAME, title);
mv.addObject(NormalExcelConstants.CLASS, entity.getClass());
//update-begin--Author:liusq Date:20210126 for图片导出报错ImageBasePath未设置--------------------
ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
// exportParams.setType(ExcelType.XSSF);
exportParams.setImageBasePath(upLoadPath);
//update-end--Author:liusq Date:20210126 for图片导出报错ImageBasePath未设置----------------------
mv.addObject(NormalExcelConstants.PARAMS,exportParams);
mv.addObject(NormalExcelConstants.DATA_LIST, maps);
return mv;
// ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
// //此处设置的filename无效 ,前端会重更新设置一下
//
// mv.addObject(NormalExcelConstants.FILE_NAME, title);
// mv.addObject(NormalExcelConstants.CLASS, entity.getClass());
// //update-begin--Author:liusq Date:20210126 for图片导出报错ImageBasePath未设置--------------------
// ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
//
//// exportParams.setType(ExcelType.XSSF);
// exportParams.setImageBasePath(upLoadPath);
//
// //update-end--Author:liusq Date:20210126 for图片导出报错ImageBasePath未设置----------------------
// mv.addObject(NormalExcelConstants.PARAMS,exportParams);
// mv.addObject(NormalExcelConstants.DATA_LIST, maps);
// return mv;
}


Loading…
Cancel
Save