|
@@ -1,16 +1,14 @@
|
|
|
package com.jiayue.biz.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.db.handler.StringHandler;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
-import com.jiayue.biz.domain.ProjectMenusOne;
|
|
|
-import com.jiayue.biz.domain.ProjectMenusThree;
|
|
|
-import com.jiayue.biz.domain.ProjectMenusTow;
|
|
|
-import com.jiayue.biz.domain.ProjectProgress;
|
|
|
+import com.jiayue.biz.domain.*;
|
|
|
+import com.jiayue.biz.service.ProjectInfoService;
|
|
|
import com.jiayue.biz.service.ProjectProgressService;
|
|
|
import com.jiayue.biz.util.CalculationUtil;
|
|
|
+import com.jiayue.biz.util.FileUtil;
|
|
|
import com.jiayue.common.utils.DateUtil;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
@@ -25,7 +23,10 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -44,6 +45,9 @@ public class ProjectProgressServiceImpl implements ProjectProgressService {
|
|
|
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
|
+
|
|
|
+ private ProjectInfoService projectInfoService;
|
|
|
+
|
|
|
//查询项目进展
|
|
|
public List<ProjectProgress> selectProProjectInfo() {
|
|
|
return mongoTemplate.find(new Query(), ProjectProgress.class, "project_progress");
|
|
@@ -66,7 +70,7 @@ public class ProjectProgressServiceImpl implements ProjectProgressService {
|
|
|
* 保存附件
|
|
|
*
|
|
|
* @param multipartFile 文件
|
|
|
- * @param id 文件夹名
|
|
|
+ * @param id 文件夹名
|
|
|
*/
|
|
|
@SneakyThrows
|
|
|
public void saveAttachment(MultipartFile multipartFile, String id) {
|
|
@@ -81,14 +85,12 @@ public class ProjectProgressServiceImpl implements ProjectProgressService {
|
|
|
|
|
|
//项目进展解析
|
|
|
public void projectProgressParse(MultipartFile multipartFile, String id) {
|
|
|
- String fileName = multipartFile.getOriginalFilename();
|
|
|
- File filed = new File(fileName);
|
|
|
+ ProjectInfo oneProjectInfoById = projectInfoService.getOneProjectInfoById(id);
|
|
|
try {
|
|
|
- ExcelReader reader = ExcelUtil.getReader(filed);
|
|
|
- List<List<Object>> read = reader.read();
|
|
|
- //解析文件入库
|
|
|
- saveProjectProgress(read, id);
|
|
|
-
|
|
|
+ //创建临时文件
|
|
|
+ File tempFile = File.createTempFile(oneProjectInfoById.getProjectBasicInfo().getProjectName(), ".xls");
|
|
|
+ multipartFile.transferTo(tempFile);
|
|
|
+ //新文件目录
|
|
|
File projectProgressDirFileNew = new File(projectProgressDir + id + File.separator + projectProgressBackNew);
|
|
|
if (!projectProgressDirFileNew.exists()) {
|
|
|
projectProgressDirFileNew.mkdirs();
|
|
@@ -98,13 +100,20 @@ public class ProjectProgressServiceImpl implements ProjectProgressService {
|
|
|
//删除旧文件
|
|
|
if (files != null && files.length > 0) {
|
|
|
for (File file1 : files) {
|
|
|
- FileUtil.del(file1);
|
|
|
+ Files.delete(Paths.get(file1.getPath()));
|
|
|
}
|
|
|
}
|
|
|
- //项目进展文件移动
|
|
|
- multipartFile.transferTo(new File(projectProgressDirFileNew.getPath() + File.separator + fileName));
|
|
|
|
|
|
- } catch (IOException e) {
|
|
|
+ ExcelReader reader = ExcelUtil.getReader(tempFile);
|
|
|
+ List<List<Object>> read = reader.read();
|
|
|
+ //解析文件入库
|
|
|
+ saveProjectProgress(read, id);
|
|
|
+ if (tempFile.exists()) {
|
|
|
+ //将临时文件复制到需要保存的目录
|
|
|
+ cn.hutool.core.io.FileUtil.copy(tempFile, projectProgressDirFileNew, true);
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
@@ -115,20 +124,27 @@ public class ProjectProgressServiceImpl implements ProjectProgressService {
|
|
|
//项目进展解析文件入库
|
|
|
public void saveProjectProgress(List<List<Object>> read, String id) {
|
|
|
ArrayList<ProjectMenusOne> projectMenusOneList = new ArrayList<>();
|
|
|
-
|
|
|
+ int total = 0;
|
|
|
String s1 = "";
|
|
|
//创建一级菜单
|
|
|
ProjectMenusOne projectMenusOne = new ProjectMenusOne();
|
|
|
ProjectMenusTow projectMenusTow = new ProjectMenusTow();
|
|
|
//循环每行数据
|
|
|
for (List<Object> objects : read) {
|
|
|
+ total++;
|
|
|
if (indexStr.contains(objects.get(0).toString())) {
|
|
|
//每次进入新的一级菜单都需要新的对象
|
|
|
projectMenusOne = new ProjectMenusOne();
|
|
|
projectMenusOne.setId(UUID.randomUUID().toString());
|
|
|
projectMenusOne.setIndex(objects.get(0).toString());
|
|
|
projectMenusOne.setWorkContent(objects.get(1).toString());
|
|
|
- projectMenusOne.setPlanTime(objects.get(2).toString());
|
|
|
+ if (objects.get(2) != null) {
|
|
|
+ if (objects.get(2).toString().contains("00:00:00")) {
|
|
|
+ projectMenusOne.setPlanTime(objects.get(2).toString().replace("00:00:00", ""));
|
|
|
+ }
|
|
|
+ projectMenusOne.setPlanTime(objects.get(2).toString());
|
|
|
+ }
|
|
|
+
|
|
|
projectMenusOne.setProjectMenusTows(new ArrayList<ProjectMenusTow>());
|
|
|
projectMenusOneList.add(projectMenusOne);
|
|
|
if ((objects.get(0).toString().equals("一") && objects.get(4) != null && !objects.get(4).toString().equals("")) ||
|
|
@@ -164,11 +180,13 @@ public class ProjectProgressServiceImpl implements ProjectProgressService {
|
|
|
|
|
|
}
|
|
|
//最终List
|
|
|
- ProjectProgress projectProgress = new ProjectProgress();
|
|
|
- projectProgress.setId(id);
|
|
|
+ List<ProjectProgress> projectProgresses = this.selectProProjectInfo();
|
|
|
+ List<ProjectProgress> progressList = projectProgresses.stream().filter(p -> p.getProjectId().equals(id)).collect(Collectors.toList());
|
|
|
+ ProjectProgress projectProgress = progressList.get(0);
|
|
|
+// ProjectProgress projectProgress = new ProjectProgress();
|
|
|
projectProgress.setProjectMenusOneList(projectMenusOneList);
|
|
|
|
|
|
-// mongoTemplate.save(projectProgress,"project_progress");
|
|
|
+ mongoTemplate.save(projectProgress, "project_progress");
|
|
|
|
|
|
}
|
|
|
|
|
@@ -179,7 +197,13 @@ public class ProjectProgressServiceImpl implements ProjectProgressService {
|
|
|
projectMenusTow.setId(UUID.randomUUID().toString());
|
|
|
projectMenusTow.setIndex(objects.get(0) == null ? "" : objects.get(0).toString());
|
|
|
projectMenusTow.setWorkContent(objects.get(1) == null ? "" : objects.get(1).toString());
|
|
|
- projectMenusTow.setPlanTime(objects.get(2) == null ? "" : objects.get(2).toString());
|
|
|
+ if (objects.get(2) != null) {
|
|
|
+ if (objects.get(2).toString().contains("00:00:00")) {
|
|
|
+ projectMenusTow.setPlanTime(objects.get(2).toString().replace("00:00:00", ""));
|
|
|
+ }
|
|
|
+ projectMenusTow.setPlanTime(objects.get(2) == null ? "" : objects.get(2).toString());
|
|
|
+ }
|
|
|
+
|
|
|
return projectMenusTow;
|
|
|
}
|
|
|
|
|
@@ -192,7 +216,11 @@ public class ProjectProgressServiceImpl implements ProjectProgressService {
|
|
|
projectMenusThree.setIndex(splitStr(objects.get(3).toString()));
|
|
|
projectMenusThree.setWorkContent(splitStr22(objects.get(3).toString()));
|
|
|
}
|
|
|
- projectMenusThree.setRealTime(objects.get(4) == null ? "" : objects.get(4).toString());
|
|
|
+ if (objects.get(4) != null) {
|
|
|
+ projectMenusThree.setRealTime(objects.get(4).toString().length() <= 6 ? objects.get(4).toString() : objects.get(4).toString().substring(0, objects.get(4).toString().indexOf(" ")));
|
|
|
+ } else {
|
|
|
+ projectMenusThree.setRealTime("");
|
|
|
+ }
|
|
|
projectMenusThree.setRemark(objects.get(5) == null ? "" : objects.get(5).toString());
|
|
|
return projectMenusThree;
|
|
|
|