|
@@ -73,6 +73,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
+ //导出报告
|
|
|
@Override
|
|
|
public HttpRespMsg exportReport(String date, HttpServletRequest request) {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
@@ -82,7 +83,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
HSSFSheet sheet = workbook.createSheet(date + "日报");
|
|
|
//创建表头
|
|
|
HSSFRow headRow = sheet.createRow(0);
|
|
|
- //设置列宽 setColumnWidth的第二个参数要乘以256,这个参数的单位是1/256个字符宽度
|
|
|
+ //设置列宽 setColumnWidth的第二个参数要乘以256 这个参数的单位是1/256个字符宽度
|
|
|
sheet.setColumnWidth(0, 5 * 256);
|
|
|
sheet.setColumnWidth(1, 10 * 256);
|
|
|
sheet.setColumnWidth(2, 20 * 256);
|
|
@@ -94,7 +95,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
HSSFFont font = workbook.createFont();
|
|
|
font.setBold(true);
|
|
|
headStyle.setFont(font);
|
|
|
-
|
|
|
+ //表头
|
|
|
HSSFCell headCell;
|
|
|
headCell = headRow.createCell(0);
|
|
|
headCell.setCellValue("序号");
|
|
@@ -114,11 +115,10 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
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);
|
|
@@ -133,13 +133,13 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
cell.setCellStyle(style);
|
|
|
rowNum++;
|
|
|
}
|
|
|
-
|
|
|
//生成Excel文件
|
|
|
String fileUrlSuffix = date + "日报" + new SimpleDateFormat("hh-mm-ss").format(new Date()) + ".xls";
|
|
|
FileOutputStream fos = new FileOutputStream(path + fileUrlSuffix);
|
|
|
workbook.write(fos);
|
|
|
fos.flush();
|
|
|
fos.close();
|
|
|
+ //返回生成的文件地址/upload文件夹下
|
|
|
httpRespMsg.data = "/upload/" + fileUrlSuffix;
|
|
|
} catch (NullPointerException e) {
|
|
|
httpRespMsg.setError("验证失败或缺少数据");
|
|
@@ -163,15 +163,19 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
.eq("creator_id", userId)
|
|
|
.eq("create_date", LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")))));
|
|
|
//顺便再获取一下可分配时间
|
|
|
- Double totalWorkingTime = 0.0;
|
|
|
- //此处认为0是工作时间
|
|
|
+ Integer totalWorkingTime = 0;
|
|
|
+ //以下区间被认为是工作时间
|
|
|
+ Integer[] workType = {0, 1, 2, 3, 4, 5};
|
|
|
+ //工作时间筛选
|
|
|
for (TimeCalculation timeCalculation : timeCalculationMapper.selectList(new QueryWrapper<TimeCalculation>()
|
|
|
.eq("date", LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
|
|
|
.eq("user_id", userId)
|
|
|
- .eq("action_type", 0))) {
|
|
|
+ .in("action_type", workType))) {
|
|
|
totalWorkingTime += timeCalculation.getDuration();
|
|
|
}
|
|
|
- resultMap.put("time", new DecimalFormat("#.00").format(totalWorkingTime / 3600));
|
|
|
+ //把总秒数转为double后换算为小时并保留两位小数
|
|
|
+ resultMap.put("time", new DecimalFormat("#.00").format((double) totalWorkingTime / 3600));
|
|
|
+ //顺便返回该公司全部的计划
|
|
|
resultMap.put("project", projectMapper.selectList(new QueryWrapper<Project>()
|
|
|
.eq("company_id", userMapper.selectById(userId).getCompanyId())));
|
|
|
httpRespMsg.data = resultMap;
|