Commit 9be28960 by 谢春璐

fix

parent 2d0f5649
...@@ -8,6 +8,8 @@ import lombok.extern.slf4j.Slf4j; ...@@ -8,6 +8,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
...@@ -43,24 +45,36 @@ public class ExcelWrite { ...@@ -43,24 +45,36 @@ public class ExcelWrite {
Sheet sheet = null; Sheet sheet = null;
if (null != template) { if (null != template) {
try { try {
if (template.getName().contains(".")&&template.getName().substring(template.getName().lastIndexOf(".")+1, template.getName().length()).toLowerCase().equals("xls")) { if (template.getName().contains(".") && template.getName()
.substring(template.getName().lastIndexOf(".") + 1, template.getName().length()).toLowerCase()
.equals("xls")) {
workbook = new HSSFWorkbook(new POIFSFileSystem(new FileInputStream(template))); workbook = new HSSFWorkbook(new POIFSFileSystem(new FileInputStream(template)));
}else{ } else {
workbook=new XSSFWorkbook(new FileInputStream(template)); workbook = new XSSFWorkbook(new FileInputStream(template));
} }
sheet = workbook.getSheetAt(0); sheet = workbook.getSheetAt(0);
sheet.setColumnWidth(0, 3766);
} catch (Exception e) { } catch (Exception e) {
} }
} else { } else {
if (out.getName().contains(".")&&out.getName().substring(out.getName().lastIndexOf(".")+1, out.getName().length()).toLowerCase().equals("xls")) { if (out.getName().contains(".") && out.getName()
.substring(out.getName().lastIndexOf(".") + 1, out.getName().length()).toLowerCase().equals("xls")) {
workbook = new HSSFWorkbook(); workbook = new HSSFWorkbook();
}else{ } else {
workbook=new XSSFWorkbook(); workbook = new XSSFWorkbook();
} }
sheet = workbook.createSheet(sheetName); sheet = workbook.createSheet(sheetName);
} }
if (null != data.getTitles() && data.getTitles().length > 0) { if (null != data.getTitles() && data.getTitles().length > 0) {
Row titleRow = sheet.createRow(0); Row titleRow = sheet.createRow(0);
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFillForegroundColor((short) 13);
cellStyle.setFillPattern(CellStyle.ALIGN_JUSTIFY);
Font font = workbook.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
font.setFontHeightInPoints((short) 16);
cellStyle.setFont(font);
titleRow.setRowStyle(cellStyle);
for (int j = 0; j < data.getTitles().length; j++) { for (int j = 0; j < data.getTitles().length; j++) {
Cell busiDataCell = titleRow.createCell(j); Cell busiDataCell = titleRow.createCell(j);
busiDataCell.setCellValue(data.getTitles()[j]); busiDataCell.setCellValue(data.getTitles()[j]);
......
...@@ -245,10 +245,12 @@ public class FileServiceImpl implements FileService { ...@@ -245,10 +245,12 @@ public class FileServiceImpl implements FileService {
newWorkCheckList.add(w); newWorkCheckList.add(w);
}); });
newWorkCheckList.sort(Comparator.comparing(WorkCheck::getDate));
staff.setWorkCheckList(newWorkCheckList); staff.setWorkCheckList(newWorkCheckList);
newStaffList.add(staff); newStaffList.add(staff);
}); });
newStaffList.sort(Comparator.comparing(Staff::getName));
return newStaffList; return newStaffList;
} }
...@@ -261,15 +263,18 @@ public class FileServiceImpl implements FileService { ...@@ -261,15 +263,18 @@ public class FileServiceImpl implements FileService {
titleList.add("姓名"); titleList.add("姓名");
// 取打卡记录中最早日期和最晚日期为标题的开始日期和结束日期 // 取打卡记录中最早日期和最晚日期为标题的开始日期和结束日期
String start = staffList.stream().min(Comparator.comparing(staff -> staff.getWorkCheckList().get(0).getDate())) String start = staffList.stream().min(
Comparator.comparing(staff -> DateUtils.parseDate(staff.getWorkCheckList().stream()
.min(Comparator.comparing(w -> DateUtils.parseDate(w.getDate()).getTime())).get().getDate())
.getTime()))
.get() .get()
.getWorkCheckList().get(0).getDate(); .getWorkCheckList().get(0).getDate();
List<WorkCheck> workCheckList = staffList.stream() List<WorkCheck> workCheckList = staffList.stream().max(
.max(Comparator Comparator.comparing(staff -> DateUtils.parseDate(staff.getWorkCheckList().stream()
.comparing(staff -> staff.getWorkCheckList().get(staff.getWorkCheckList().size() - 1).getDate())) .max(Comparator.comparing(w -> DateUtils.parseDate(w.getDate()).getTime())).get().getDate())
.get() .getTime()))
.getWorkCheckList(); .get().getWorkCheckList();
String end = workCheckList.get(workCheckList.size() - 1).getDate(); String end = workCheckList.get(workCheckList.size() - 1).getDate();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment