Browse Source

修改下载报告代码

liujiejie 3 months ago
parent
commit
cb2706d2cf
1 changed files with 14 additions and 272 deletions
  1. 14 272
      src/views/performance/assetssMag.vue

+ 14 - 272
src/views/performance/assetssMag.vue

@@ -1,13 +1,12 @@
 <template>
   <div class="global-variable">
     <div class="condition">
-      <el-alert
+      <!-- <el-alert
         title="分析前请核对数据是否导入,点击查看是否导入即可查看"
         type="warning"
         show-icon
-        v-hasPermi="['home:offlinedata']"
       >
-      </el-alert>
+      </el-alert> -->
       <el-form
         :inline="true"
         ref="ruleForm"
@@ -68,13 +67,13 @@
           <!-- <el-button @click="handleDownLoadChart" size="small">下载</el-button> -->
         </el-form-item>
       </el-form>
-      <!-- <div class="progress" v-if="downloadDisabled">
+      <div class="progress" v-if="downloadDisabled">
         <div class="progressText">文档生成进度:</div>
         <el-progress
           :percentage="progressPercent"
           :color="colors"
         ></el-progress>
-      </div> -->
+      </div>
     </div>
     <div class="list-page">
       <el-table
@@ -252,7 +251,6 @@
           align="center"
           label="报告"
           min-width="120"
-          v-hasPermi="['home:performance:uploadReport']"
         >
           <template slot-scope="scope">
             <el-dropdown v-if="scope.row.reportVos.length > 0" trigger="click">
@@ -311,18 +309,6 @@
           min-width="300"
         >
           <template slot-scope="scope">
-            <!-- <el-button
-              @click="handleDownLoadChartImage(scope.row)"
-              type="text"
-              size="small"
-              :disabled="downloadDisabled"
-              v-if="
-                (scope.row.errState == 1 && scope.row.analysisState == 30) ||
-                scope.row.analysisState == 30
-              "
-            >
-              下载图表
-            </el-button> -->
             <el-button
               @click="handleDownLoadChart(scope.row)"
               type="text"
@@ -335,13 +321,12 @@
             >
               下载报告
             </el-button>
-            <el-button
-              v-hasPermi="['home:performance:uploadReport']"
+            <!-- <el-button
               @click="abnormalDialog(scope.row, '上传报告')"
               type="text"
               size="small"
               >上传报告</el-button
-            >
+            > -->
             <el-button
               @click="handleAssetss(scope.row)"
               type="text"
@@ -627,7 +612,6 @@ export default {
 
         const res = await axios.post(
           `/downLoadChart/chartServer/charts/${urlType}`,
-          // "/downLoadChart/chartServer/charts/line",
           {
             fieldEngineCode: itemField.fieldEngineCode,
             bucketName: "bucket-zhzn",
@@ -637,13 +621,10 @@ export default {
               objectname,
             fieldInfo: this.fieldInfo,
             fileAddr: itemField.fileAddr,
-            // fileAddr:
-            //   "http://192.168.50.234:6900/wof053500048/WOF053500048-WOB000005/temperature_large_components/manual/generatordrive_end_bearing_temperature/A9.json",
             chartType:
               filterAnalysis.typeDocxName === "production_indicator_unit"
                 ? "radar"
                 : urlType,
-            // chartType: "line",
           },
         );
         // 每完成 10% 提示一次(可调)
@@ -691,251 +672,19 @@ export default {
           if (!this.fileDataList[key]) {
             this.$set(this.fileDataList, key, []); // Vue 2 中响应式设置对象属性
           }
-          (res?.data?.data?.imageUrls || [])
-            .filter((imgval) => typeof imgval === "string" && imgval.trim())
-            .forEach((imgval) => {
-              this.fileDataList[key].push(imgval);
-            });
+          res?.data?.data?.imageUrls.map((imgval) => {
+            this.fileDataList[key].push(imgval);
+          });
         } else {
           if (!this.fileDataList[key]) {
             this.$set(this.fileDataList, key, []); // Vue 2 中响应式设置对象属性
           }
-          if (
-            typeof res?.data?.data?.imageUrl === "string" &&
-            res.data.data.imageUrl.trim()
-          ) {
-            this.fileDataList[key].push(res.data.data.imageUrl);
-          }
+          this.fileDataList[key].push(res?.data?.data?.imageUrl);
         }
       } catch (err) {
         console.error("生成失败:", err);
       }
     },
-    async handleDownLoadChartImage(row) {
-      this.progress.current = 0;
-      this.progress.total = 0;
-      this.fileDataList = {};
-      this.setDownloadDisabled(true);
-      try {
-        await this.getAllAnalysis(row.batchCode);
-        await this.getFieldDetail(row.batchCode);
-        this.$message.info("开始下载图片");
-        const limit = pLimit(1); // 限制同时并发的请求数量为 5
-        const tasks = [];
-        for (const itemAnalysis of this.allAnalysis) {
-          const filterAnalysis = allAnalysisType.filter(
-            (itemType) => itemType.typeName === itemAnalysis.analysisTypeName,
-          )[0];
-          console.log(filterAnalysis, "filterAnalysis");
-          if (itemAnalysis.generalFiles) {
-            //这里过滤的是发电机温度的类型 在url 中是否能找到filterFileAddr
-            for (const itemField of filterAnalysis.filterFileAddr
-              ? itemAnalysis.generalFiles
-                  .filter((item) => item.fileAddr.endsWith(".json"))
-                  .filter((item) =>
-                    item.fileAddr.includes(filterAnalysis.filterFileAddr),
-                  ) || []
-              : itemAnalysis.generalFiles) {
-              //静态偏航误差 --通过allAnalysisType.js文件配置实现需求
-              if (Array.isArray(filterAnalysis.generalFiles.urlType)) {
-                filterAnalysis.generalFiles.urlType.map(
-                  (itemUrlType, indUrlType) => {
-                    tasks.push(
-                      limit(async () => {
-                        await this.postChartData(
-                          itemUrlType,
-                          row,
-                          itemAnalysis,
-                          itemField,
-                          filterAnalysis,
-                          "generalFiles",
-                        );
-                        this.progress.current++;
-                      }),
-                    );
-                  },
-                );
-              } else if (filterAnalysis.typeCode === "fault") {
-                if (itemField.fileAddr.includes("turbine_fault_result")) {
-                  if (itemField.engineTypeCode === "turbine_fault_result") {
-                    tasks.push(
-                      limit(async () => {
-                        await this.postChartData(
-                          "faultUnitChart",
-                          row,
-                          itemAnalysis,
-                          itemField,
-                          filterAnalysis,
-                          "generalFiles",
-                        );
-                        this.progress.current++;
-                      }),
-                    );
-                  }
-                } else {
-                  if (itemField.engineTypeCode === "total_fault_result") {
-                    tasks.push(
-                      limit(async () => {
-                        await this.postChartData(
-                          "faultAllChart",
-                          row,
-                          itemAnalysis,
-                          itemField,
-                          filterAnalysis,
-                          "generalFiles",
-                        );
-                        this.progress.current++;
-                      }),
-                    );
-                  }
-                }
-              } else if (filterAnalysis.typeCode === "production_indicator") {
-                //总图全场
-                if (
-                  itemField.fileAddr.includes(
-                    filterAnalysis.generalFiles.FileTypeFromUrl,
-                  )
-                ) {
-                  tasks.push(
-                    limit(async () => {
-                      await this.postChartData(
-                        filterAnalysis.generalFiles.urlType,
-                        row,
-                        itemAnalysis,
-                        itemField,
-                        filterAnalysis,
-                        "generalFiles",
-                      );
-                      this.progress.current++;
-                      // 每完成 10% 提示一次(可调)
-                    }),
-                  );
-                } else {
-                  tasks.push(
-                    limit(async () => {
-                      await this.postChartData(
-                        "radarChart",
-                        row,
-                        itemAnalysis,
-                        itemField,
-                        filterAnalysis,
-                        "generalFiles",
-                      );
-                      this.progress.current++;
-                    }),
-                  );
-                }
-              } else {
-                tasks.push(
-                  limit(async () => {
-                    await this.postChartData(
-                      filterAnalysis.generalFiles.urlType,
-                      row,
-                      itemAnalysis,
-                      itemField,
-                      filterAnalysis,
-                      "generalFiles",
-                    );
-                    this.progress.current++;
-                  }),
-                );
-              }
-            }
-          }
-          if (itemAnalysis.diagramRelations) {
-            for (const itemField of filterAnalysis.filterFileAddr
-              ? itemAnalysis.diagramRelations
-                  .filter((item) => item.fileAddr.endsWith(".json"))
-                  .filter((item) =>
-                    item.fileAddr.includes(filterAnalysis.filterFileAddr),
-                  ) || []
-              : itemAnalysis.diagramRelations) {
-              const urlType = Array.isArray(
-                filterAnalysis.diagramRelations.urlType,
-              )
-                ? this.getFileTypeFromUrl(
-                    itemField.fileAddr,
-                    filterAnalysis.diagramRelations.FileTypeFromUrl,
-                  ) === filterAnalysis.diagramRelations.FileTypeFromUrl
-                  ? filterAnalysis.diagramRelations.urlType[0]
-                  : filterAnalysis.diagramRelations.urlType[1]
-                : filterAnalysis.diagramRelations.urlType;
-              tasks.push(
-                limit(async () => {
-                  await this.postChartData(
-                    urlType,
-                    row,
-                    itemAnalysis,
-                    itemField,
-                    filterAnalysis,
-                    "diagramRelations",
-                  );
-                  this.progress.current++;
-                }),
-              );
-            }
-          }
-        }
-        this.progress.total = tasks.length;
-        await Promise.all(tasks);
-
-        const engineTypeList = await this.getEngineTypeList(
-          this.fieldInfo.engineMillTypes,
-          row.batchCode,
-        );
-        this.$notify.success("✅ 图表全部生成完成,开始下载图片...");
-        const wordFilePath = await axios.post(
-          "/downLoadChart/chartServer/charts/CopyFileImage",
-          {
-            fieldInfo: this.fieldInfo,
-            dataTime: `${this.analysisInfo.dataStartTime}-${this.analysisInfo.dataEndTime}`,
-            bucketName: "bucket-zhzn",
-            objectName: `charts/${row.fieldCode}/${row.batchCode}`,
-            engineTypeList: engineTypeList,
-            chartsImages: {
-              ...this.fileDataList,
-              // "zn-techcn-replace-tags-data_integrity_minute-generalFiles": [
-              //   "http://106.120.102.238:26900/bucket-zhzn/charts/WOF039800012/WOF039800012-WOB000002/temperature_environment/bartotal_Mid.jpg",
-              // ],
-
-              // "zn-techcn-replace-tags-data_integrity_second-generalFiles": [
-              //   "http://106.120.102.238:26900/bucket-zhzn/charts/WOF039800012/WOF039800012-WOB000002/temperature_large_components/gearbox_low_speed_shaft_bearing_temperature/%2302.jpg",
-              //   "http://106.120.102.238:26900/bucket-zhzn/charts/WOF039800012/WOF039800012-WOB000002/temperature_environment/bartotal_Mid.jpg",
-              // ],
-            },
-          },
-        );
-
-        // //下载minio 文件
-        this.downloadZip(wordFilePath.data.data.url);
-        // downloadDocx(
-        //   wordFilePath.data.data.url,
-        //   wordFilePath.data.data.fileName,
-        // );
-        this.$notify.success("🎉 图片已下载!");
-        this.setDownloadDisabled(false);
-      } catch (error) {
-        console.log(error, "error");
-        this.$notify.error("🎉 图片下载失败!");
-        this.setDownloadDisabled(false);
-      }
-    },
-    async downloadZip(url) {
-      const res = await axios.get(url, {
-        responseType: "blob",
-      });
-      const blob = new Blob([res.data], {
-        type: "application/zip",
-      });
-
-      const link = document.createElement("a");
-      link.href = URL.createObjectURL(blob);
-      link.download = "charts_images.zip";
-
-      document.body.appendChild(link);
-      link.click();
-      link.remove();
-    },
     async handleDownLoadChart(row) {
       this.progress.current = 0;
       this.progress.total = 0;
@@ -946,13 +695,13 @@ export default {
         await this.getAllAnalysis(row.batchCode);
         await this.getFieldDetail(row.batchCode);
         this.$message.info("开始生成word文档");
-        const limit = pLimit(1); // 限制同时并发的请求数量为 5
+        const limit = pLimit(5); // 限制同时并发的请求数量为 5
         const tasks = [];
-        let minioUrl = "";
         for (const itemAnalysis of this.allAnalysis) {
           const filterAnalysis = allAnalysisType.filter(
             (itemType) => itemType.typeName === itemAnalysis.analysisTypeName,
           )[0];
+
           if (itemAnalysis.generalFiles) {
             //这里过滤的是发电机温度的类型 在url 中是否能找到filterFileAddr
             for (const itemField of filterAnalysis.filterFileAddr
@@ -962,7 +711,6 @@ export default {
                     item.fileAddr.includes(filterAnalysis.filterFileAddr),
                   ) || []
               : itemAnalysis.generalFiles) {
-              minioUrl = new URL(itemField.fileAddr);
               //静态偏航误差 --通过allAnalysisType.js文件配置实现需求
               if (Array.isArray(filterAnalysis.generalFiles.urlType)) {
                 filterAnalysis.generalFiles.urlType.map(
@@ -1077,7 +825,6 @@ export default {
                     item.fileAddr.includes(filterAnalysis.filterFileAddr),
                   ) || []
               : itemAnalysis.diagramRelations) {
-              minioUrl = new URL(itemField.fileAddr);
               const urlType = Array.isArray(
                 filterAnalysis.diagramRelations.urlType,
               )
@@ -1123,15 +870,9 @@ export default {
             ...this.fileDataList,
           },
         );
-        const path = wordFilePath.data.data.url.replace(
-          /^https?:\/\/[^/]+/,
-          "",
-        );
-
         // //下载minio 文件
         downloadDocx(
-          `${minioUrl.origin}${path}`,
-          // wordFilePath.data.data.url,
+          wordFilePath.data.data.url,
           wordFilePath.data.data.fileName,
         );
         this.$notify.success("🎉 Word 文档生成并已下载!");
@@ -1142,6 +883,7 @@ export default {
         this.setDownloadDisabled(false);
       }
     },
+
     async getEngineTypeList(typeList, batchCode) {
       return await Promise.all(
         typeList.map((item) => this.getEngineMillList(item, batchCode)),