浏览代码

项目日志上链开发

anderx 1 年之前
父节点
当前提交
4d8d0cab98

+ 7 - 0
ruoyi-common/pom.xml

@@ -146,6 +146,13 @@
             <version>5.8.15</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>${poi.version}</version>
+        </dependency>
+
+
     </dependencies>
 
 </project>

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/project/mapper/ProjectStaffRecordMapper.java

@@ -53,5 +53,5 @@ public interface ProjectStaffRecordMapper {
 
     void mateUserRecord(@Param("collect") List<Long> collect);
 
-    void updateTianheType(List<ProjectStaffRecord> newList);
+    void updateTianheType(@Param("collect")List<ProjectStaffRecord> newList);
 }

+ 41 - 2
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectTaskServiceImpl.java

@@ -24,9 +24,13 @@ import com.ruoyi.project.mapper.ProjectTaskMapper;
 import com.ruoyi.project.service.ProjectTaskService;
 import com.ruoyi.system.mapper.SysUserMapper;
 import com.ruoyi.system.service.ISysDeptService;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
+import org.apache.poi.xwpf.usermodel.XWPFRun;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -34,6 +38,9 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Validator;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
 import java.util.*;
 import java.util.zip.ZipOutputStream;
 
@@ -57,6 +64,8 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
     private ProjectStaffRecordMapper projectStaffRecordMapper;
     @Autowired
     private TianheService tianheService;
+    @Value("${ruoyi.profile}")
+    private  String profile=null;
 
     @Override
     public AjaxResult addProjectTask(ProjectTask projectTask) {
@@ -385,7 +394,11 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
         String json = JSONObject.toJSONString(map);
         String address = getAddress();
         String  operateId = "yfdk_"+DateUtils.dateTimeNow();
-        String s = tianheService.seveText(address, json, operateId);
+        String docx = createDocx(json, operateId);
+        File file = new File(docx);
+        String s = tianheService.seveFile(address,operateId,file);
+        //文字导入
+//        String s = tianheService.seveText(address, json, operateId);
         JSONObject res = JSONObject.parseObject(s);
         Integer code = (Integer) res.get("code");
         String tianheCloudUrl=null;
@@ -424,6 +437,31 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
         }
     }
 
+    private String  createDocx(String json, String operateId) {
+        String url=profile+"/"+ operateId +".docx";
+        XWPFDocument document = new XWPFDocument();
+        XWPFParagraph paragraph = document.createParagraph();
+        XWPFRun run = paragraph.createRun();
+        run.setText(json);
+        try {
+            // 保存文档到指定路径
+            FileOutputStream out = new FileOutputStream(url);
+            document.write(out);
+            out.close();
+            System.out.println("Word文档已成功创建!");
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            // 关闭文档对象
+            try {
+                document.close();
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return url;
+    }
+
     /**
      * 处理日志跟随项目上链
      */
@@ -432,8 +470,9 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
         int i=0;
         List<ProjectStaffRecord> newList=new ArrayList<>();
         for (ProjectStaffRecord projectStaffRecord : projectStaffRecords) {
+            i++;
             newList.add(projectStaffRecord);
-            if (newList.size()==count||i==projectStaffRecords.size()-1){
+            if (newList.size()==count||i==projectStaffRecords.size()){
                 projectStaffRecordMapper.updateTianheType(newList);
                 newList.clear();
             }