allen 1 年之前
父節點
當前提交
552c0ae736

+ 3 - 3
fms-admin/src/main/java/com/fms/system/controller/FailureController.java

@@ -118,10 +118,10 @@ public class FailureController extends BaseController
 
     @PreAuthorize("@ss.hasPermi('system:failure:export')")
     @Log(title = "故障报告", businessType = BusinessType.EXPORT)
-    @PostMapping("/generateReport")
-    public void generateReport(HttpServletResponse response, String reportMonth, String major){
+    @GetMapping("/generateReport")
+    public AjaxResult generateReport(String reportMonth, String major){
         logger.info("generateReport: reportMonth:{}, major:{}" ,reportMonth, major);
-        failureService.generateReport(reportMonth, major);
+        return AjaxResult.success(failureService.generateReport(reportMonth, major));
     }
     @PreAuthorize("@ss.hasPermi('system:failure:query')")
     @GetMapping("/getMajorOption")

+ 17 - 0
fms-admin/src/main/java/com/fms/system/domain/Failure.java

@@ -1,5 +1,7 @@
 package com.fms.system.domain;
 
+import java.util.Date;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 import com.fms.common.annotation.Excel;
@@ -34,6 +36,11 @@ public class Failure extends BaseEntity
     @Excel(name = "LT")
     private String bdlt;
 
+    /** 故障日期 */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @Excel(name = "故障日期", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date failureDate;
+
     /** 机型 */
     @Excel(name = "机型")
     private String aircraftType;
@@ -143,6 +150,15 @@ public class Failure extends BaseEntity
     {
         return bdlt;
     }
+    public void setFailureDate(Date failureDate) 
+    {
+        this.failureDate = failureDate;
+    }
+
+    public Date getFailureDate() 
+    {
+        return failureDate;
+    }
     public void setAircraftType(String aircraftType) 
     {
         this.aircraftType = aircraftType;
@@ -296,6 +312,7 @@ public class Failure extends BaseEntity
             .append("jJdJxy", getJjdJxy())
             .append("s", getS())
             .append("bdlt", getBdlt())
+            .append("failureDate", getFailureDate())
             .append("aircraftType", getAircraftType())
             .append("discoveryTime", getDiscoveryTime())
             .append("major", getMajor())

+ 6 - 6
fms-admin/src/main/java/com/fms/system/mapper/FailureMapper.java

@@ -62,17 +62,17 @@ public interface FailureMapper
      */
     public int deleteFailureByIds(Long[] ids);
 
-    Integer getMajorCount(String reportMonth);
+    Integer getMajorCount(@Param("reportMonth") String reportMonth, @Param("major") String major);
 
-    List<String> getTop5UnserviceableCompName(String reportMonth);
+    List<String> getTop5UnserviceableCompName(@Param("reportMonth") String reportMonth, @Param("major") String major);
 
-    Integer getFailureCount(@Param("reportMonth") String reportMonth, @Param("compName") String compName);
+    Integer getFailureCount(@Param("reportMonth") String reportMonth, @Param("compName") String compName, @Param("major") String major);
 
-    List<String> getFailureDescription(@Param("reportMonth") String reportMonth, @Param("compName") String compName);
+    List<String> getFailureDescription(@Param("reportMonth") String reportMonth, @Param("compName") String compName, @Param("major") String major);
 
-    List<String> getFailureCause(@Param("reportMonth") String reportMonth, @Param("compName") String compName);
+    List<String> getFailureCause(@Param("reportMonth") String reportMonth, @Param("compName") String compName, @Param("major") String major);
 
-    List<String> getFailureCompType(@Param("reportMonth") String reportMonth, @Param("compName") String compName);
+    List<String> getFailureCompType(@Param("reportMonth") String reportMonth, @Param("compName") String compName, @Param("major") String major);
 
     List<Map> getMajorOption();
 }

+ 1 - 1
fms-admin/src/main/java/com/fms/system/service/IFailureService.java

@@ -63,7 +63,7 @@ public interface IFailureService
 
     String importData(List<Failure> failureList, boolean updateSupport, String operName);
 
-    void generateReport(String reportMonth, String major);
+    String generateReport(String reportMonth, String major);
 
     List<Map> getMajorOption();
 }

+ 27 - 12
fms-admin/src/main/java/com/fms/system/service/impl/FailureServiceImpl.java

@@ -21,9 +21,12 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import javax.validation.Validator;
+import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.math.BigInteger;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.StringJoiner;
@@ -160,7 +163,8 @@ public class FailureServiceImpl implements IFailureService {
     }
 
     @Override
-    public void generateReport(String reportMonth, String major) {
+    public String generateReport(String reportMonth, String major) {
+        String docPath = "";
 
         // 创建一个新的Word文档
         XWPFDocument document = new XWPFDocument();
@@ -168,14 +172,11 @@ public class FailureServiceImpl implements IFailureService {
         // 故障总数根据时间和故障专业获取总数
         // 创建另一个段落
         XWPFRun runParagraph = createPara(document);
-//        XWPFParagraph paragraph = document.createParagraph();
-//        XWPFRun runParagraph = paragraph.createRun();
-        // todo allen
-        Integer count = failureMapper.getMajorCount(reportMonth);
-        runParagraph.setText("XX专业。共统计故障" + count + "起");
+        Integer count = failureMapper.getMajorCount(reportMonth, major);
+        runParagraph.setText(major + "专业。共统计故障" + count + "起");
 
         // 获取top5的故障件名称
-        List<String> top5UnserviceableCompName = failureMapper.getTop5UnserviceableCompName(reportMonth);
+        List<String> top5UnserviceableCompName = failureMapper.getTop5UnserviceableCompName(reportMonth, major);
 
         if (!CollectionUtils.isEmpty(top5UnserviceableCompName)) {
             StringJoiner sj = new StringJoiner("、");
@@ -188,10 +189,10 @@ public class FailureServiceImpl implements IFailureService {
             for (String compName : top5UnserviceableCompName) {
                 XWPFRun runPara = createPara(document);
                 // top n的故障数量
-                Integer failureCount = failureMapper.getFailureCount(reportMonth, compName);
+                Integer failureCount = failureMapper.getFailureCount(reportMonth, compName, major);
                 runPara.setText(compName + "故障" + failureCount + "起");
                 // top n的 top5故障描述
-                List<String> top5FailureDescription = failureMapper.getFailureDescription(reportMonth, compName);
+                List<String> top5FailureDescription = failureMapper.getFailureDescription(reportMonth, compName, major);
                 if (!CollectionUtils.isEmpty(top5FailureDescription)) {
                     StringJoiner descSj = new StringJoiner(";");
                     for (String desc : top5FailureDescription) {
@@ -200,7 +201,7 @@ public class FailureServiceImpl implements IFailureService {
                     runPara.setText(",故障模式主要是" + descSj + "等");
                 }
                 // top n的 top5故障原因
-                List<String> top5FailureCause = failureMapper.getFailureCause(reportMonth, compName);
+                List<String> top5FailureCause = failureMapper.getFailureCause(reportMonth, compName, major);
                 if (!CollectionUtils.isEmpty(top5FailureCause)) {
                     StringJoiner causeSj = new StringJoiner("、");
                     for (String cause : top5FailureCause) {
@@ -209,7 +210,7 @@ public class FailureServiceImpl implements IFailureService {
                     runPara.setText(",原因主要是" + causeSj + "等");
                 }
                 // top n的 top3型别
-                List<String> top3CompType = failureMapper.getFailureCompType(reportMonth, compName);
+                List<String> top3CompType = failureMapper.getFailureCompType(reportMonth, compName, major);
                 if (!CollectionUtils.isEmpty(top3CompType)) {
                     StringJoiner numSj = new StringJoiner("、");
                     for (String num : top3CompType) {
@@ -223,8 +224,21 @@ public class FailureServiceImpl implements IFailureService {
             log.warn("获取top5的故障件名称为null");
         }
 
+        SimpleDateFormat sdf = new SimpleDateFormat("HHmmssSSS");
+
+        // 获取当前时间
+        Date now = new Date();
+
+        // 格式化当前时间为字符串
+        String currentTime = sdf.format(now);
+        String directoryPath = "d:/fms/report/";
+        File directory = new File(directoryPath);
+        if (!directory.exists()) {
+            directory.mkdirs();
+        }
+        docPath = directoryPath+"故障报告-"+ reportMonth + "-" + major + "-" +currentTime + ".docx";
         // 将文档写入文件
-        try (FileOutputStream out = new FileOutputStream("example.docx")) {
+        try (FileOutputStream out = new FileOutputStream(docPath)) {
             document.write(out);
         } catch (IOException e) {
             log.error("文档写入文件异常", e);
@@ -236,6 +250,7 @@ public class FailureServiceImpl implements IFailureService {
         } catch (IOException e) {
             log.error("关闭文档异常", e);
         }
+        return docPath;
     }
 
     @Override

+ 20 - 9
fms-admin/src/main/resources/mapper/system/FailureMapper.xml

@@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="jjdJxy"    column="j_jd_jxy"    />
         <result property="s"    column="s"    />
         <result property="bdlt"    column="bdlt"    />
+        <result property="failureDate"    column="failure_date"    />
         <result property="aircraftType"    column="aircraft_type"    />
         <result property="discoveryTime"    column="discovery_time"    />
         <result property="major"    column="major"    />
@@ -33,7 +34,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectFailureVo">
-        select id, zq, j_jd_jxy, s, bdlt, aircraft_type, discovery_time, major, failure_description, failure_cause, failure_name, unserviceable_comp_name, unserviceable_comp_type, unserviceable_comp_num, unserviceable_comp_system, failure_consequence, failure_duty, replacement_comp_name, replacement_comp_type, replacement_comp_num, elimination_methods, create_by, create_time, update_by, update_time from failure_t
+        select id, zq, j_jd_jxy, s, bdlt, failure_date, aircraft_type, discovery_time, major, failure_description, failure_cause, failure_name, unserviceable_comp_name, unserviceable_comp_type, unserviceable_comp_num, unserviceable_comp_system, failure_consequence, failure_duty, replacement_comp_name, replacement_comp_type, replacement_comp_num, elimination_methods, create_by, create_time, update_by, update_time from failure_t
     </sql>
 
     <select id="selectFailureList" parameterType="Failure" resultMap="FailureResult">
@@ -43,6 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="jjdJxy != null  and jjdJxy != ''"> and j_jd_jxy = #{jjdJxy}</if>
             <if test="s != null  and s != ''"> and s = #{s}</if>
             <if test="bdlt != null  and bdlt != ''"> and bdlt = #{bdlt}</if>
+            <if test="failureDate != null "> and failure_date = #{failureDate}</if>
             <if test="aircraftType != null  and aircraftType != ''"> and aircraft_type = #{aircraftType}</if>
             <if test="discoveryTime != null  and discoveryTime != ''"> and discovery_time = #{discoveryTime}</if>
             <if test="major != null  and major != ''"> and major = #{major}</if>
@@ -74,6 +76,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="jjdJxy != null">j_jd_jxy,</if>
             <if test="s != null">s,</if>
             <if test="bdlt != null">bdlt,</if>
+            <if test="failureDate != null">failure_date,</if>
             <if test="aircraftType != null">aircraft_type,</if>
             <if test="discoveryTime != null">discovery_time,</if>
             <if test="major != null">major,</if>
@@ -100,6 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="jjdJxy != null">#{jjdJxy},</if>
             <if test="s != null">#{s},</if>
             <if test="bdlt != null">#{bdlt},</if>
+            <if test="failureDate != null">#{failure_date},</if>
             <if test="aircraftType != null">#{aircraftType},</if>
             <if test="discoveryTime != null">#{discoveryTime},</if>
             <if test="major != null">#{major},</if>
@@ -130,6 +134,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="jjdJxy != null">j_jd_jxy = #{jjdJxy},</if>
             <if test="s != null">s = #{s},</if>
             <if test="bdlt != null">bdlt = #{bdlt},</if>
+            <if test="failureDate != null">failure_date = #{failureDate},</if>
             <if test="aircraftType != null">aircraft_type = #{aircraftType},</if>
             <if test="discoveryTime != null">discovery_time = #{discoveryTime},</if>
             <if test="major != null">major = #{major},</if>
@@ -164,16 +169,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
-    <select id="getMajor" resultType="Integer">
+    <select id="getMajorCount" resultType="Integer">
         SELECT COUNT(*) AS failure_count
         FROM failure_t
-        <!-- WHERE DATE_FORMAT(故障发生时间, '%Y-%m') = #{reportMonth} -->
+        WHERE DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth}
+            AND major = #{major}
     </select>
     <select id="getTop5UnserviceableCompName" parameterType="String" resultType="String">
         SELECT unserviceable_comp_name FROM
         (SELECT unserviceable_comp_name, COUNT(*) AS failure_count
         FROM failure_t
-        <!--        WHERE DATE_FORMAT(故障发生时间, '%Y-%m') = #{reportMonth}-->
+        WHERE DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth}
+            AND major = #{major}
         GROUP BY unserviceable_comp_name
         ORDER BY failure_count DESC
         LIMIT 5) t
@@ -183,8 +190,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         SELECT COUNT(*) AS failure_count
         FROM failure_t
         WHERE
-<!--         DATE_FORMAT(故障发生时间, '%Y-%m') = #{reportMonth}-->
-        unserviceable_comp_name = #{compName}
+            DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth}
+            AND unserviceable_comp_name = #{compName}
+            AND major = #{major}
     </select>
 
     <select id="getFailureDescription" parameterType="String" resultType="String">
@@ -198,8 +206,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         FROM
             failure_t ft
         WHERE
-<!--            DATE_FORMAT(故障发生时间, '%Y-%m') = #{reportMonth} AND-->
+            DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth} AND
             unserviceable_comp_name = #{compName}
+            AND major = #{major}
         GROUP BY failure_description
         ) t
         ORDER BY failure_count DESC LIMIT 5
@@ -215,8 +224,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         FROM
             failure_t
         WHERE
-<!--        DATE_FORMAT(故障发生时间, '%Y-%m') = #{reportMonth} AND-->
+        DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth} AND
             unserviceable_comp_name = #{compName}
+            AND major = #{major}
         GROUP BY failure_cause
         ) t
         ORDER BY
@@ -234,8 +244,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         FROM
             failure_t
         WHERE
-<!--        DATE_FORMAT(故障发生时间, '%Y-%m') = #{reportMonth} AND-->
+        DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth} AND
             unserviceable_comp_name = #{compName}
+            AND major = #{major}
         GROUP BY unserviceable_comp_type
         ) t
         ORDER BY

+ 11 - 8
fms-ui/src/api/system/failure.js

@@ -43,14 +43,6 @@ export function delFailure(id) {
   });
 }
 
-// 删除故障记录
-export function generateReport(date) {
-  return request({
-    url: "/system/failure/generateReport",
-    method: "post",
-    data: date,
-  });
-}
 // 获取专业
 export function getMajorOption() {
   return request({
@@ -58,3 +50,14 @@ export function getMajorOption() {
     method: "get",
   });
 }
+// 生成报告
+export function generateReport(reportMonth, major) {
+  return request({
+    url: "/system/failure/generateReport",
+    method: "get",
+    params: {
+      reportMonth,
+      major,
+    },
+  });
+}

+ 88 - 25
fms-ui/src/views/system/failure/index.vue

@@ -244,6 +244,16 @@
       <el-table-column label="J/JD/XY" align="center" prop="jjdJxy" />
       <el-table-column label="S" align="center" prop="s" />
       <el-table-column label="LT" align="center" prop="bdlt" />
+      <el-table-column
+        label="故障日期"
+        align="center"
+        prop="failureDate"
+        width="180"
+      >
+        <template slot-scope="scope">
+          <span>{{ parseTime(scope.row.failureDate, "{y}-{m}-{d}") }}</span>
+        </template>
+      </el-table-column>
       <el-table-column label="机型" align="center" prop="aircraftType" />
       <el-table-column label="发现时机" align="center" prop="discoveryTime" />
       <el-table-column label="专业" align="center" prop="major" />
@@ -349,6 +359,16 @@
         <el-form-item label="LT" prop="bdlt">
           <el-input v-model="form.bdlt" placeholder="请输入LT" />
         </el-form-item>
+        <el-form-item label="故障日期" prop="failureDate">
+          <el-date-picker
+            clearable
+            v-model="form.failureDate"
+            type="date"
+            value-format="yyyy-MM-dd"
+            placeholder="请选择故障日期"
+          >
+          </el-date-picker>
+        </el-form-item>
         <el-form-item label="发现时机" prop="discoveryTime">
           <el-input v-model="form.discoveryTime" placeholder="请输入发现时机" />
         </el-form-item>
@@ -466,23 +486,37 @@
       width="400px"
       append-to-body
     >
-      <div>
-        <el-date-picker
-          v-model="report.reportDate"
-          type="month"
-          placeholder="选择月"
-          value-format="yyyy-MM"
-        >
-        </el-date-picker>
-        <el-select v-model="report.major" placeholder="请选择">
-          <el-option
-            v-for="item in report.majorOption"
-            :key="item.major"
-            :label="item.major"
-            :value="item.major"
-          >
-          </el-option>
-        </el-select>
+      <div style="margin: 5px">
+        <el-row>
+          <el-col>
+            <span style="">故障月份</span>
+          </el-col>
+          <el-col>
+            <el-date-picker
+              v-model="report.reportDate"
+              type="month"
+              placeholder="选择故障月份"
+              value-format="yyyy-MM"
+            >
+            </el-date-picker>
+          </el-col>
+        </el-row>
+      </div>
+      <div style="margin: 5px">
+        <el-row>
+          <el-col><span style="">专业</span></el-col>
+          <el-col>
+            <el-select v-model="report.major" placeholder="请选择专业">
+              <el-option
+                v-for="item in report.majorOption"
+                :key="item.major"
+                :label="item.major"
+                :value="item.major"
+              >
+              </el-option>
+            </el-select>
+          </el-col>
+        </el-row>
       </div>
       <div slot="footer" class="dialog-footer">
         <el-button type="primary" @click="submitGenerateReport"
@@ -551,6 +585,7 @@ export default {
         jjdJxy: null,
         s: null,
         bdlt: null,
+        failureDate: null,
         aircraftType: null,
         discoveryTime: null,
         major: null,
@@ -612,6 +647,7 @@ export default {
         jjdJxy: null,
         s: null,
         bdlt: null,
+        failureDate: null,
         aircraftType: null,
         discoveryTime: null,
         major: null,
@@ -759,14 +795,41 @@ export default {
     },
     // 生成报告
     submitGenerateReport() {
-      console.info(this.report);
-      this.download(
-        "system/failure/generateReport",
-        {
-          reportMonth: this.report.reportDate,
-          major: this.report.major,
-        },
-        `failure_${new Date().getTime()}.doc`
+      if (!this.report.reportDate && !this.report.major) {
+        this.$message({
+          showClose: true,
+          message: "需要选择故障月份和专业",
+          type: "error",
+        });
+        return;
+      }
+      if (!this.report.reportDate) {
+        this.$message({
+          showClose: true,
+          message: "需要选择故障月份",
+          type: "error",
+        });
+        return;
+      }
+      if (!this.report.major) {
+        this.$message({
+          showClose: true,
+          message: "需要选择专业",
+          type: "error",
+        });
+        return;
+      }
+
+      console.info("报告生成参数" + this.report);
+      generateReport(this.report.reportDate, this.report.major).then(
+        (response) => {
+          console.info("报告返回结果" + response);
+          this.$message({
+            showClose: true,
+            message: "恭喜你,报告已生成。" + response.msg,
+            type: "success",
+          });
+        }
       );
       this.report.open = false;
     },

+ 1 - 0
sql/biz_sql20240514.sql

@@ -5,6 +5,7 @@ create table failure_t (
   j_jd_jxy         varchar(255)     default ''                 comment 'J/JD/XY',
   s         varchar(255)     default ''                 comment 'S',
   bdlt         varchar(255)     default ''                 comment 'LT',
+  failure_date datetime                                   comment '故障日期',
   aircraft_type         varchar(255)     default ''                 comment '机型',
   discovery_time         varchar(255)     default ''                 comment '发现时机',
   major         varchar(255)     default ''                 comment '专业',