|
@@ -12,17 +12,18 @@ import com.management.platform.mapper.UserMapper;
|
|
import com.management.platform.service.ReportService;
|
|
import com.management.platform.service.ReportService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeParseException;
|
|
import java.time.format.DateTimeParseException;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -47,6 +48,9 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
@Resource
|
|
@Resource
|
|
private ProjectMapper projectMapper;
|
|
private ProjectMapper projectMapper;
|
|
|
|
|
|
|
|
+ @Value(value = "${upload.path}")
|
|
|
|
+ private String path;
|
|
|
|
+
|
|
//获取报告列表
|
|
//获取报告列表
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg getReportList(String date, HttpServletRequest request) {
|
|
public HttpRespMsg getReportList(String date, HttpServletRequest request) {
|
|
@@ -62,6 +66,85 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
httpRespMsg.data = nameList;
|
|
httpRespMsg.data = nameList;
|
|
} catch (NullPointerException e) {
|
|
} catch (NullPointerException e) {
|
|
httpRespMsg.setError("验证失败");
|
|
httpRespMsg.setError("验证失败");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg exportReport(String date, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ try {
|
|
|
|
+ //准备导出
|
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
|
+ HSSFSheet sheet = workbook.createSheet(date + "日报");
|
|
|
|
+ //创建表头
|
|
|
|
+ HSSFRow headRow = sheet.createRow(0);
|
|
|
|
+ //设置列宽 setColumnWidth的第二个参数要乘以256,这个参数的单位是1/256个字符宽度
|
|
|
|
+ sheet.setColumnWidth(0, 5 * 256);
|
|
|
|
+ sheet.setColumnWidth(1, 18 * 256);
|
|
|
|
+ sheet.setColumnWidth(2, 18 * 256);
|
|
|
|
+ sheet.setColumnWidth(3, 18 * 256);
|
|
|
|
+ sheet.setColumnWidth(4, 30 * 256);
|
|
|
|
+ sheet.setColumnWidth(5, 18 * 256);
|
|
|
|
+ //设置为居中加粗
|
|
|
|
+ HSSFCellStyle headStyle = workbook.createCellStyle();
|
|
|
|
+ HSSFFont font = workbook.createFont();
|
|
|
|
+ font.setBold(true);
|
|
|
|
+ headStyle.setFont(font);
|
|
|
|
+
|
|
|
|
+ HSSFCell headCell;
|
|
|
|
+ headCell = headRow.createCell(0);
|
|
|
|
+ headCell.setCellValue("序号");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+ headCell = headRow.createCell(1);
|
|
|
|
+ headCell.setCellValue("上传者");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+ headCell = headRow.createCell(2);
|
|
|
|
+ headCell.setCellValue("项目名称");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+ headCell = headRow.createCell(3);
|
|
|
|
+ headCell.setCellValue("工作时间");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+ headCell = headRow.createCell(4);
|
|
|
|
+ headCell.setCellValue("工作内容");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+ headCell = headRow.createCell(5);
|
|
|
|
+ headCell.setCellValue("提交时间");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+
|
|
|
|
+ //设置日期格式
|
|
|
|
+ HSSFCellStyle style = workbook.createCellStyle();
|
|
|
|
+ style.setDataFormat(HSSFDataFormat.getBuiltinFormat("yy/mm/dd hh:mm"));
|
|
|
|
+ //新增数据行,并且设置单元格数据
|
|
|
|
+ int rowNum = 1;
|
|
|
|
+ for (Map<String, Object> map : reportMapper.getAllReportByDate(date)) {
|
|
|
|
+ HSSFRow row = sheet.createRow(rowNum);
|
|
|
|
+ row.createCell(0).setCellValue(rowNum);
|
|
|
|
+ row.createCell(1).setCellValue((String) map.get("name"));
|
|
|
|
+ row.createCell(2).setCellValue((String) map.get("project"));
|
|
|
|
+ row.createCell(3).setCellValue((String) map.get("duration"));
|
|
|
|
+ row.createCell(4).setCellValue((String) map.get("content"));
|
|
|
|
+ HSSFCell cell = row.createCell(5);
|
|
|
|
+ cell.setCellValue((String) map.get("time"));
|
|
|
|
+ cell.setCellStyle(style);
|
|
|
|
+ rowNum++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //生成Excel文件
|
|
|
|
+ String fileUrlSuffix = date + "日报" + new SimpleDateFormat("hh-mm-ss").format(new Date()) + ".xls";
|
|
|
|
+ try {
|
|
|
|
+ FileOutputStream fos = new FileOutputStream(path + fileUrlSuffix);
|
|
|
|
+ workbook.write(fos);
|
|
|
|
+ fos.flush();
|
|
|
|
+ fos.close();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ httpRespMsg.data = "/upload/" + fileUrlSuffix;
|
|
|
|
+ } catch (NullPointerException e) {
|
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
|
|
+ return httpRespMsg;
|
|
}
|
|
}
|
|
return httpRespMsg;
|
|
return httpRespMsg;
|
|
}
|
|
}
|
|
@@ -92,8 +175,10 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
httpRespMsg.data = resultMap;
|
|
httpRespMsg.data = resultMap;
|
|
} catch (NullPointerException e) {
|
|
} catch (NullPointerException e) {
|
|
httpRespMsg.setError("验证失败");
|
|
httpRespMsg.setError("验证失败");
|
|
|
|
+ return httpRespMsg;
|
|
} catch (DateTimeParseException e) {
|
|
} catch (DateTimeParseException e) {
|
|
httpRespMsg.setError("日期格式有误");
|
|
httpRespMsg.setError("日期格式有误");
|
|
|
|
+ return httpRespMsg;
|
|
}
|
|
}
|
|
return httpRespMsg;
|
|
return httpRespMsg;
|
|
}
|
|
}
|