|
@@ -1,31 +1,37 @@
|
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
-import com.management.platform.entity.Project;
|
|
|
-import com.management.platform.entity.Task;
|
|
|
-import com.management.platform.entity.TimeTask;
|
|
|
-import com.management.platform.entity.User;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.management.platform.entity.*;
|
|
|
import com.management.platform.mapper.ProjectMapper;
|
|
|
+import com.management.platform.mapper.StagesMapper;
|
|
|
import com.management.platform.mapper.TaskMapper;
|
|
|
+import com.management.platform.mapper.UserMapper;
|
|
|
import com.management.platform.service.TaskService;
|
|
|
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.*;
|
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
|
+import org.apache.poi.ss.usermodel.CellType;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.*;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
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.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -36,6 +42,7 @@ import java.util.Map;
|
|
|
* @since 2021-04-19
|
|
|
*/
|
|
|
@Service
|
|
|
+@Transactional
|
|
|
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService {
|
|
|
@Value(value = "${upload.path}")
|
|
|
private String path;
|
|
@@ -43,6 +50,10 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
private TaskMapper taskMapper;
|
|
|
@Resource
|
|
|
private ProjectMapper projectMapper;
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ private StagesMapper stagesMapper;
|
|
|
@Override
|
|
|
public HttpRespMsg getExecutorPanel(Integer projectId) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
@@ -264,4 +275,138 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
}
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg importTask(Integer projectId, Integer groupId, Integer stagesId, MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+
|
|
|
+ //首先先搞到公司id
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
+ List<User> allUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
+ //获取当前导入的任务列表
|
|
|
+ Stages stages = stagesMapper.selectById(stagesId);
|
|
|
+ List<Task> maxList = taskMapper.selectList(new QueryWrapper<Task>().eq("stages_id", stagesId).orderByDesc("seq").last("limit 1"));
|
|
|
+ int seq = 1;
|
|
|
+ if (maxList.size() > 0) {
|
|
|
+ seq = maxList.get(0).getSeq() + 1;
|
|
|
+ }
|
|
|
+ HashMap<String, Integer> taskTypeMap = new HashMap<>();
|
|
|
+ taskTypeMap.put("任务", 0);
|
|
|
+ taskTypeMap.put("里程碑", 1);
|
|
|
+ taskTypeMap.put("风险", 2);
|
|
|
+ HashMap<String, Integer> taskLevelMap = new HashMap<>();
|
|
|
+ taskTypeMap.put("一般", 0);
|
|
|
+ taskTypeMap.put("重要", 1);
|
|
|
+ taskTypeMap.put("紧急", 2);
|
|
|
+ //然后处理文件
|
|
|
+ String fileName = multipartFile.getOriginalFilename();
|
|
|
+ File file = new File(fileName == null ? "file" : fileName);
|
|
|
+ InputStream inputStream = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = multipartFile.getInputStream();
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int temp = 0;
|
|
|
+ while ((temp = inputStream.read(buffer, 0, 4096)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, temp);
|
|
|
+ }
|
|
|
+ inputStream.close();
|
|
|
+ outputStream.close();
|
|
|
+ //然后解析表格
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(file);
|
|
|
+ //我们只需要第一个sheet
|
|
|
+ XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
+ //查重检验的手机号列表
|
|
|
+ List<String> phoneList = new ArrayList<>();
|
|
|
+ //要插入的账号列表
|
|
|
+ List<Task> taskList = new ArrayList<>();
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
+ for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //此处新建账号 默认密码为000000 默认 姓名第一列 手机号第二列 月薪第三列
|
|
|
+ XSSFCell nameCell = row.getCell(0);
|
|
|
+ if (nameCell == null) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ XSSFCell typeCell = row.getCell(1);
|
|
|
+ XSSFCell executorCell = row.getCell(2);
|
|
|
+ XSSFCell levelCell = row.getCell(3);
|
|
|
+ XSSFCell endDateCell = row.getCell(4);
|
|
|
+ XSSFCell planHoursCell = row.getCell(5);
|
|
|
+ nameCell.setCellType(CellType.STRING);
|
|
|
+ typeCell.setCellType(CellType.STRING);
|
|
|
+ endDateCell.setCellType(CellType.NUMERIC);
|
|
|
+ planHoursCell.setCellType(CellType.STRING);
|
|
|
+ String name = nameCell.getStringCellValue();
|
|
|
+ String type = typeCell.getStringCellValue();
|
|
|
+ //忽略表头
|
|
|
+ if (name.equals("标题") && type.equals("类型") && rowIndex == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Task task = new Task();
|
|
|
+ task.setProjectId(projectId);
|
|
|
+ task.setGroupId(groupId);
|
|
|
+ String executorName = executorCell.getStringCellValue();
|
|
|
+ System.out.println("姓名=="+executorCell.getStringCellValue());
|
|
|
+ Optional<User> first = allUserList.stream().filter(u -> u.getName().equals(executorName)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ User find = first.get();
|
|
|
+ task.setExecutorId(find.getId());
|
|
|
+ task.setExecutorName(find.getName());
|
|
|
+ task.setExecutorColor(find.getColor());
|
|
|
+ }
|
|
|
+ task.setStagesId(stagesId);
|
|
|
+ task.setStagesName(stages.getStagesName());
|
|
|
+ task.setSeq(seq++);
|
|
|
+ task.setName(name);
|
|
|
+ task.setTaskType(taskTypeMap.get(typeCell.getStringCellValue()));
|
|
|
+ task.setTaskLevel(taskLevelMap.get(levelCell.getStringCellValue()));
|
|
|
+ Date dateCellValue = endDateCell.getDateCellValue();
|
|
|
+ System.out.println("日期=="+dateCellValue.toString());
|
|
|
+ String formatValue = new SimpleDateFormat("yyyy-MM-dd").format(dateCellValue);
|
|
|
+ LocalDate endDate = LocalDate.parse(formatValue, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ task.setEndDate(endDate);
|
|
|
+ task.setPlanHours(Integer.parseInt(planHoursCell.getStringCellValue()));
|
|
|
+
|
|
|
+ task.setCreateDate(LocalDate.now());
|
|
|
+ taskList.add(task);
|
|
|
+ }
|
|
|
+ saveBatch(taskList);
|
|
|
+ //最后删掉这个文件
|
|
|
+// if (!file.delete()) {
|
|
|
+// System.out.println("临时文件" + file.getName() + "删除失败");
|
|
|
+// }
|
|
|
+ //校验是否有重复账号
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ httpRespMsg.setError("文件处理出错");
|
|
|
+ return httpRespMsg;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ httpRespMsg.setError("数据格式有误或存在空数据 导入失败");
|
|
|
+ return httpRespMsg;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ httpRespMsg.setError("发生其他错误");
|
|
|
+ return httpRespMsg;
|
|
|
+ } finally {
|
|
|
+ //关闭流
|
|
|
+ try {
|
|
|
+ if (outputStream != null && inputStream != null) {
|
|
|
+ outputStream.close();
|
|
|
+ inputStream.close();
|
|
|
+ System.out.println("流已关闭");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(file.delete());
|
|
|
+ }
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
}
|