|
@@ -2,7 +2,10 @@ package com.management.platform.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
-import com.management.platform.entity.*;
|
|
|
|
|
|
+import com.management.platform.entity.Project;
|
|
|
|
+import com.management.platform.entity.Report;
|
|
|
|
+import com.management.platform.entity.TimeCalculation;
|
|
|
|
+import com.management.platform.entity.User;
|
|
import com.management.platform.mapper.*;
|
|
import com.management.platform.mapper.*;
|
|
import com.management.platform.service.ReportService;
|
|
import com.management.platform.service.ReportService;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
@@ -74,14 +77,22 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
}
|
|
}
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
map.put("reportTime", df.format(reportTime));
|
|
map.put("reportTime", df.format(reportTime));
|
|
- List<TimeCalculationShow> timeList = timeCalculationShowMapper.selectList(new QueryWrapper<TimeCalculationShow>().eq("user_id", (String) map.get("id")).eq("date", date));
|
|
|
|
- int calculateTime = 0;
|
|
|
|
- for (TimeCalculationShow show : timeList) {
|
|
|
|
- calculateTime += show.getDuration();
|
|
|
|
|
|
+ //顺便再获取一下可分配时间
|
|
|
|
+ Integer calculateTime = 0;
|
|
|
|
+ //以下区间被认为是工作时间
|
|
|
|
+ Integer[] workType = {-1, 0, 1, 2, 3, 4, 5};
|
|
|
|
+ //工作时间筛选
|
|
|
|
+ List<TimeCalculation> timeCalculations = timeCalculationMapper.selectList(new QueryWrapper<TimeCalculation>()
|
|
|
|
+ .eq("date", LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
|
|
|
|
+ .eq("user_id", userId)
|
|
|
|
+ .in("action_type", workType));
|
|
|
|
+ if (timeCalculations != null) {
|
|
|
|
+ for (TimeCalculation timeCalculation : timeCalculations) {
|
|
|
|
+ calculateTime += timeCalculation.getDuration();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- //数据库是秒,时间转换为小时;
|
|
|
|
- double d = calculateTime * 1.0 / 3600;
|
|
|
|
- map.put("calculateTime", df.format(d));
|
|
|
|
|
|
+ //把总秒数转为double后换算为小时并保留两位小数
|
|
|
|
+ map.put("calculateTime", df.format((double) calculateTime / 3600));
|
|
map.put("state", list.get(0).get("state"));
|
|
map.put("state", list.get(0).get("state"));
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -101,17 +112,22 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
}
|
|
}
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
map.put("reportTime", df.format(reportTime));
|
|
map.put("reportTime", df.format(reportTime));
|
|
- List<TimeCalculationShow> timeList = timeCalculationShowMapper.selectList(
|
|
|
|
- new QueryWrapper<TimeCalculationShow>()
|
|
|
|
- .eq("user_id", map.get("id"))
|
|
|
|
- .eq("date", date));
|
|
|
|
- int calculateTime = 0;
|
|
|
|
- for (TimeCalculationShow show : timeList) {
|
|
|
|
- calculateTime += show.getDuration();
|
|
|
|
|
|
+ //顺便再获取一下可分配时间
|
|
|
|
+ Integer calculateTime = 0;
|
|
|
|
+ //以下区间被认为是工作时间
|
|
|
|
+ Integer[] workType = {-1, 0, 1, 2, 3, 4, 5};
|
|
|
|
+ //工作时间筛选
|
|
|
|
+ List<TimeCalculation> timeCalculations = timeCalculationMapper.selectList(new QueryWrapper<TimeCalculation>()
|
|
|
|
+ .eq("date", LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
|
|
|
|
+ .eq("user_id", userId)
|
|
|
|
+ .in("action_type", workType));
|
|
|
|
+ if (timeCalculations != null) {
|
|
|
|
+ for (TimeCalculation timeCalculation : timeCalculations) {
|
|
|
|
+ calculateTime += timeCalculation.getDuration();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- //数据库是秒,时间转换为小时;
|
|
|
|
- double d = calculateTime * 1.0 / 3600;
|
|
|
|
- map.put("calculateTime", df.format(d));
|
|
|
|
|
|
+ //把总秒数转为double后换算为小时并保留两位小数
|
|
|
|
+ map.put("calculateTime", df.format((double) calculateTime / 3600));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
httpRespMsg.data = nameList;
|
|
httpRespMsg.data = nameList;
|
|
@@ -123,85 +139,6 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
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, 10 * 256);
|
|
|
|
- sheet.setColumnWidth(2, 20 * 256);
|
|
|
|
- sheet.setColumnWidth(3, 10 * 256);
|
|
|
|
- sheet.setColumnWidth(4, 50 * 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;
|
|
|
|
- List<Map<String, Object>> allReportByDate = reportMapper.getAllReportByDate(date);
|
|
|
|
- for (Map<String, Object> map : allReportByDate) {
|
|
|
|
- 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(map.get("duration").toString());
|
|
|
|
- row.createCell(4).setCellValue((String) map.get("content"));
|
|
|
|
- HSSFCell cell = row.createCell(5);
|
|
|
|
- cell.setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
|
|
|
- .format((Timestamp) map.get("time")));
|
|
|
|
- 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("验证失败或缺少数据");
|
|
|
|
- return httpRespMsg;
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- httpRespMsg.setError("文件生成错误");
|
|
|
|
- return httpRespMsg;
|
|
|
|
- }
|
|
|
|
- return httpRespMsg;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//获取本人某天工作时间和已提交的报告
|
|
//获取本人某天工作时间和已提交的报告
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg getReport(String date, HttpServletRequest request) {
|
|
public HttpRespMsg getReport(String date, HttpServletRequest request) {
|
|
@@ -337,4 +274,84 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
}
|
|
}
|
|
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, 10 * 256);
|
|
|
|
+ sheet.setColumnWidth(2, 20 * 256);
|
|
|
|
+ sheet.setColumnWidth(3, 10 * 256);
|
|
|
|
+ sheet.setColumnWidth(4, 50 * 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;
|
|
|
|
+ List<Map<String, Object>> allReportByDate = reportMapper.getAllReportByDate(date);
|
|
|
|
+ for (Map<String, Object> map : allReportByDate) {
|
|
|
|
+ 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(map.get("duration").toString());
|
|
|
|
+ row.createCell(4).setCellValue((String) map.get("content"));
|
|
|
|
+ HSSFCell cell = row.createCell(5);
|
|
|
|
+ cell.setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
|
|
|
+ .format((Timestamp) map.get("time")));
|
|
|
|
+ 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("验证失败或缺少数据");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ httpRespMsg.setError("文件生成错误");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
}
|
|
}
|