|
@@ -1,16 +1,31 @@
|
|
package com.management.platform.service.impl;
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
|
+import com.management.platform.entity.Project;
|
|
import com.management.platform.entity.Task;
|
|
import com.management.platform.entity.Task;
|
|
|
|
+import com.management.platform.entity.TimeTask;
|
|
|
|
+import com.management.platform.entity.User;
|
|
|
|
+import com.management.platform.mapper.ProjectMapper;
|
|
import com.management.platform.mapper.TaskMapper;
|
|
import com.management.platform.mapper.TaskMapper;
|
|
import com.management.platform.service.TaskService;
|
|
import com.management.platform.service.TaskService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.management.platform.util.ExcelUtil;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.sql.Timestamp;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -22,8 +37,12 @@ import java.util.List;
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService {
|
|
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService {
|
|
|
|
+ @Value(value = "${upload.path}")
|
|
|
|
+ private String path;
|
|
@Resource
|
|
@Resource
|
|
private TaskMapper taskMapper;
|
|
private TaskMapper taskMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private ProjectMapper projectMapper;
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg getExecutorPanel(Integer projectId) {
|
|
public HttpRespMsg getExecutorPanel(Integer projectId) {
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
@@ -49,4 +68,199 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
public List<Task> simpleList(Wrapper<Task> queryWrapper) {
|
|
public List<Task> simpleList(Wrapper<Task> queryWrapper) {
|
|
return taskMapper.simpleList(queryWrapper);
|
|
return taskMapper.simpleList(queryWrapper);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getTaskTimeCompare(Integer projectId) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ msg.data = taskMapper.getTaskTimeCompare(projectId);
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg exportTaskTimeCompare(Integer projectId) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ List<Map> list= taskMapper.getTaskTimeCompare(projectId);
|
|
|
|
+ Project project = projectMapper.selectById(projectId);
|
|
|
|
+ try {
|
|
|
|
+ //准备导出
|
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
|
+ HSSFSheet sheet = workbook.createSheet("实际工时VS计划工时");
|
|
|
|
+ //创建表头
|
|
|
|
+ HSSFRow headRow = sheet.createRow(0);
|
|
|
|
+ //设置列宽 setColumnWidth的第二个参数要乘以256 这个参数的单位是1/256个字符宽度
|
|
|
|
+ sheet.setColumnWidth(0, 5 * 256);
|
|
|
|
+ sheet.setColumnWidth(1, 50 * 256);
|
|
|
|
+ sheet.setColumnWidth(2, 20 * 256);
|
|
|
|
+ sheet.setColumnWidth(3, 20 * 256);
|
|
|
|
+ sheet.setColumnWidth(4, 10 * 256);
|
|
|
|
+ //设置为居中加粗
|
|
|
|
+ HSSFCellStyle headStyle = workbook.createCellStyle();
|
|
|
|
+ HSSFFont font = workbook.createFont();
|
|
|
|
+ font.setBold(true);
|
|
|
|
+ headStyle.setFont(font);
|
|
|
|
+ HSSFFont redFont = workbook.createFont();
|
|
|
|
+ redFont.setColor(HSSFFont.COLOR_RED);
|
|
|
|
+ HSSFCellStyle redStyle = workbook.createCellStyle();
|
|
|
|
+ redStyle.setFont(redFont);
|
|
|
|
+ //表头
|
|
|
|
+ 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("实际工时(h)");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+ headCell = headRow.createCell(3);
|
|
|
|
+ headCell.setCellValue("计划工时(h)");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+ headCell = headRow.createCell(4);
|
|
|
|
+ headCell.setCellValue("偏差");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+ int rowNum = 1;
|
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
|
+ HSSFRow row = sheet.createRow(rowNum);
|
|
|
|
+ row.createCell(0).setCellValue(rowNum);
|
|
|
|
+ row.createCell(1).setCellValue((String) map.get("name"));
|
|
|
|
+ row.createCell(2).setCellValue((Double) map.get("workHours"));
|
|
|
|
+ row.createCell(3).setCellValue((Integer) map.get("planHours"));
|
|
|
|
+ HSSFCell percentCell = row.createCell(4);
|
|
|
|
+ if ((Integer) map.get("planHours") != null) {
|
|
|
|
+ double percent = (Double) map.get("workHours")*100/(Integer) map.get("planHours");
|
|
|
|
+ percent = (percent - 100);
|
|
|
|
+ String sign = "";
|
|
|
|
+ if (percent > 0) {
|
|
|
|
+ percentCell.setCellStyle(redStyle);
|
|
|
|
+ sign = "+";
|
|
|
|
+ } else if (percent < 0) {
|
|
|
|
+ sign = "-";
|
|
|
|
+ }
|
|
|
|
+ percentCell.setCellValue(sign+percent+"%");
|
|
|
|
+ } else {
|
|
|
|
+ percentCell.setCellValue(" ");
|
|
|
|
+ }
|
|
|
|
+ rowNum++;
|
|
|
|
+ }
|
|
|
|
+ //生成Excel文件
|
|
|
|
+ String fileUrlSuffix = project.getProjectName()+"工时对比" + System.currentTimeMillis() + ".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
|
|
|
|
+ public HttpRespMsg exportTask(Integer projectId) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ List<TimeTask> list= taskMapper.getTaskWithWorktime(projectId);
|
|
|
|
+ Project project = projectMapper.selectById(projectId);
|
|
|
|
+ try {
|
|
|
|
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
+ //准备导出
|
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
|
+ HSSFSheet sheet = workbook.createSheet("任务数据");
|
|
|
|
+ //创建表头
|
|
|
|
+ HSSFRow headRow = sheet.createRow(0);
|
|
|
|
+ //设置列宽 setColumnWidth的第二个参数要乘以256 这个参数的单位是1/256个字符宽度
|
|
|
|
+ sheet.setColumnWidth(0, 50 * 256);
|
|
|
|
+ sheet.setColumnWidth(1, 20 * 256);
|
|
|
|
+ sheet.setColumnWidth(2, 20 * 256);
|
|
|
|
+ sheet.setColumnWidth(3, 20 * 256);
|
|
|
|
+ sheet.setColumnWidth(4, 20 * 256);
|
|
|
|
+ sheet.setColumnWidth(5, 20 * 256);
|
|
|
|
+ sheet.setColumnWidth(6, 20 * 256);
|
|
|
|
+ sheet.setColumnWidth(7, 20 * 256);
|
|
|
|
+ sheet.setColumnWidth(8, 20 * 256);
|
|
|
|
+ sheet.setColumnWidth(9, 20 * 256);
|
|
|
|
+ sheet.setColumnWidth(10, 20 * 256);
|
|
|
|
+ //设置为居中加粗
|
|
|
|
+ HSSFCellStyle headStyle = workbook.createCellStyle();
|
|
|
|
+ HSSFFont font = workbook.createFont();
|
|
|
|
+ font.setBold(true);
|
|
|
|
+ headStyle.setFont(font);
|
|
|
|
+ HSSFFont redFont = workbook.createFont();
|
|
|
|
+ redFont.setColor(HSSFFont.COLOR_RED);
|
|
|
|
+ HSSFCellStyle redStyle = workbook.createCellStyle();
|
|
|
|
+ redStyle.setFont(redFont);
|
|
|
|
+ //表头
|
|
|
|
+ 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);
|
|
|
|
+ headCell = headRow.createCell(6);
|
|
|
|
+ headCell.setCellValue("是否完成");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+ headCell = headRow.createCell(7);
|
|
|
|
+ headCell.setCellValue("是否逾期");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+ headCell = headRow.createCell(8);
|
|
|
|
+ headCell.setCellValue("计划工时");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+ headCell = headRow.createCell(10);
|
|
|
|
+ headCell.setCellValue("实际工时");
|
|
|
|
+ headCell.setCellStyle(headStyle);
|
|
|
|
+ int rowNum = 1;
|
|
|
|
+ for (TimeTask task : list) {
|
|
|
|
+ HSSFRow row = sheet.createRow(rowNum);
|
|
|
|
+ row.createCell(0).setCellValue(task.getName());
|
|
|
|
+ row.createCell(1).setCellValue(project.getProjectName());
|
|
|
|
+ row.createCell(2).setCellValue(task.getExecutorName());
|
|
|
|
+ row.createCell(3).setCellValue(dateTimeFormatter.format(task.getCreateDate()));
|
|
|
|
+ row.createCell(4).setCellValue(dateTimeFormatter.format(task.getEndDate()));
|
|
|
|
+ row.createCell(5).setCellValue(dateTimeFormatter.format(task.getFinishDate()));
|
|
|
|
+ row.createCell(6).setCellValue(task.getTaskStatus() == 1?"Y":"N");
|
|
|
|
+ boolean isExpired = false;
|
|
|
|
+ if (task.getTaskStatus() == 0 && !task.getEndDate().isAfter(LocalDate.now())) {
|
|
|
|
+ isExpired = true;
|
|
|
|
+ }
|
|
|
|
+ row.createCell(7).setCellValue(isExpired?"Y":"N");
|
|
|
|
+ row.createCell(8).setCellValue(task.getPlanHours());
|
|
|
|
+ row.createCell(9).setCellValue(task.getWorkHours());
|
|
|
|
+ rowNum++;
|
|
|
|
+ }
|
|
|
|
+ //生成Excel文件
|
|
|
|
+ String fileUrlSuffix = "【"+project.getProjectName()+"】任务数据" + System.currentTimeMillis() + ".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;
|
|
|
|
+ }
|
|
}
|
|
}
|