Prechádzať zdrojové kódy

feat:故障记录功能修改

Eureka 10 mesiacov pred
rodič
commit
62747edc0f

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

@@ -6,6 +6,7 @@ import com.fms.common.core.controller.BaseController;
 import com.fms.common.core.domain.AjaxResult;
 import com.fms.common.core.page.TableDataInfo;
 import com.fms.common.enums.BusinessType;
+import com.fms.common.utils.StringUtils;
 import com.fms.common.utils.poi.ExcelUtil;
 import com.fms.system.domain.AircraftType;
 import com.fms.system.domain.Failure;
@@ -19,7 +20,9 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 故障记录Controller
@@ -34,9 +37,6 @@ public class FailureController extends BaseController
     @Autowired
     private IFailureService failureService;
 
-    @Resource
-    IAircraftTypeService aircraftTypeService;
-
     /**
      * 查询故障记录列表
      */
@@ -127,19 +127,21 @@ public class FailureController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:failure:export')")
     @Log(title = "故障报告", businessType = BusinessType.EXPORT)
     @GetMapping("/generateReport")
-    public AjaxResult generateReport(String reportMonth, String major, Long brandId) {
-        logger.info("generateReport: reportMonth:{}, major:{}, brandId:{}", reportMonth, major, brandId);
-        AircraftType aircraftType = new AircraftType();
-        aircraftType.setBrandId(brandId);
+    public AjaxResult generateReport(String reportMonth, String major, String brandIds) {
+        logger.info("generateReport: reportMonth:{}, major:{}, brandIds:{}", reportMonth, major, brandIds);
+        if (StringUtils.isEmpty(brandIds)) {
+            return AjaxResult.success("请选择机型系列");
+        }
+
+        List<String> brandIdsList = Arrays.asList(brandIds.split(","));
         String directoryPath = FmsConfig.getProfile();
-        List<AircraftType> aircraftTypeList = aircraftTypeService.selectAircraftTypeList(aircraftType);
-        if (!aircraftTypeList.isEmpty()) {
-            aircraftTypeList.forEach(aircraftTypeInfo -> {
-                failureService.generateReport(reportMonth, major, aircraftTypeInfo.getAircraftTypeName());
+        if (!brandIdsList.isEmpty()) {
+            brandIdsList.forEach(info -> {
+                failureService.generateReport(reportMonth, major, info);
             });
             return AjaxResult.success("恭喜你,报告已生成。相关报告已放置" + directoryPath + "目录下");
         }
-        return AjaxResult.success("当前机型系列下没有任何机型,请检查后重新选择");
+        return AjaxResult.success("请选择机型系列");
     }
     @PreAuthorize("@ss.hasPermi('system:failure:query')")
     @GetMapping("/getMajorOption")

+ 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(@Param("reportMonth") String reportMonth, @Param("major") String major);
+    Integer getMajorCount(@Param("reportMonth") String reportMonth, @Param("major") String major, @Param("aircraftTypes") List<String> aircraftTypes);
 
-    List<String> getTop5UnserviceableCompName(@Param("reportMonth") String reportMonth, @Param("major") String major);
+    List<String> getTop5UnserviceableCompName(@Param("reportMonth") String reportMonth, @Param("major") String major, @Param("aircraftTypes") List<String> aircraftTypes);
 
-    Integer getFailureCount(@Param("reportMonth") String reportMonth, @Param("compName") String compName, @Param("major") String major);
+    Integer getFailureCount(@Param("reportMonth") String reportMonth, @Param("compName") String compName, @Param("major") String major, @Param("aircraftTypes") List<String> aircraftTypes);
 
-    List<String> getFailureDescription(@Param("reportMonth") String reportMonth, @Param("compName") String compName, @Param("major") String major);
+    List<String> getFailureDescription(@Param("reportMonth") String reportMonth, @Param("compName") String compName, @Param("major") String major, @Param("aircraftTypes") List<String> aircraftTypes);
 
-    List<String> getFailureCause(@Param("reportMonth") String reportMonth, @Param("compName") String compName, @Param("major") String major);
+    List<String> getFailureCause(@Param("reportMonth") String reportMonth, @Param("compName") String compName, @Param("major") String major, @Param("aircraftTypes") List<String> aircraftTypes);
 
-    List<String> getFailureCompType(@Param("reportMonth") String reportMonth, @Param("compName") String compName, @Param("major") String major);
+    List<String> getFailureCompType(@Param("reportMonth") String reportMonth, @Param("compName") String compName, @Param("major") String major, @Param("aircraftTypes") List<String> aircraftTypes);
 
     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);
 
-    String generateReport(String reportMonth, String major, String aircraftTypeName);
+    String generateReport(String reportMonth, String major, String brandId);
 
     List<Map> getMajorOption();
 }

+ 39 - 13
fms-admin/src/main/java/com/fms/system/service/impl/FailureServiceImpl.java

@@ -1,11 +1,16 @@
 package com.fms.system.service.impl;
 
+import com.fms.common.config.FmsConfig;
 import com.fms.common.exception.ServiceException;
 import com.fms.common.utils.DateUtils;
 import com.fms.common.utils.StringUtils;
 import com.fms.common.utils.bean.BeanValidators;
+import com.fms.system.domain.AircraftType;
+import com.fms.system.domain.Brand;
 import com.fms.system.domain.Failure;
 import com.fms.system.mapper.FailureMapper;
+import com.fms.system.service.IAircraftTypeService;
+import com.fms.system.service.IBrandService;
 import com.fms.system.service.IFailureService;
 import com.fms.system.service.ISysConfigService;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
@@ -20,16 +25,15 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import javax.annotation.Resource;
 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;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 故障记录Service业务层处理
@@ -49,6 +53,12 @@ public class FailureServiceImpl implements IFailureService {
     @Autowired
     protected Validator validator;
 
+    @Resource
+    IAircraftTypeService aircraftTypeService;
+
+    @Resource
+    IBrandService brandService;
+
     /**
      * 查询故障记录
      *
@@ -163,20 +173,36 @@ public class FailureServiceImpl implements IFailureService {
     }
 
     @Override
-    public String generateReport(String reportMonth, String major, String aircraftTypeName) {
+    public String generateReport(String reportMonth, String major, String brandId) {
         String docPath = "";
 
+        AircraftType aircraftType = new AircraftType();
+        aircraftType.setBrandId(Long.parseLong(brandId));
+        List<AircraftType> aircraftTypeList = aircraftTypeService.selectAircraftTypeList(aircraftType);
+
+        if (aircraftTypeList.isEmpty()) {
+            return null;
+        }
+
+        Brand brand = brandService.selectBrandByBrandId(Long.parseLong(brandId));
+        String brandName = "";
+        if (brand != null) {
+            brandName = brand.getBrandName();
+        }
+
+        List<String> aircraftTypes = aircraftTypeList.stream().map(AircraftType::getAircraftTypeName).collect(Collectors.toList());
+
         // 创建一个新的Word文档
         XWPFDocument document = new XWPFDocument();
 
         // 故障总数根据时间和故障专业获取总数
         // 创建另一个段落
         XWPFRun runParagraph = createPara(document);
-        Integer count = failureMapper.getMajorCount(reportMonth, major);
+        Integer count = failureMapper.getMajorCount(reportMonth, major, aircraftTypes);
         runParagraph.setText(major + "专业。共统计故障" + count + "起");
 
         // 获取top5的故障件名称
-        List<String> top5UnserviceableCompName = failureMapper.getTop5UnserviceableCompName(reportMonth, major);
+        List<String> top5UnserviceableCompName = failureMapper.getTop5UnserviceableCompName(reportMonth, major, aircraftTypes);
 
         if (!CollectionUtils.isEmpty(top5UnserviceableCompName)) {
             StringJoiner sj = new StringJoiner("、");
@@ -189,10 +215,10 @@ public class FailureServiceImpl implements IFailureService {
             for (String compName : top5UnserviceableCompName) {
                 XWPFRun runPara = createPara(document);
                 // top n的故障数量
-                Integer failureCount = failureMapper.getFailureCount(reportMonth, compName, major);
+                Integer failureCount = failureMapper.getFailureCount(reportMonth, compName, major, aircraftTypes);
                 runPara.setText(compName + "故障" + failureCount + "起");
                 // top n的 top5故障描述
-                List<String> top5FailureDescription = failureMapper.getFailureDescription(reportMonth, compName, major);
+                List<String> top5FailureDescription = failureMapper.getFailureDescription(reportMonth, compName, major, aircraftTypes);
                 if (!CollectionUtils.isEmpty(top5FailureDescription)) {
                     StringJoiner descSj = new StringJoiner(";");
                     for (String desc : top5FailureDescription) {
@@ -201,7 +227,7 @@ public class FailureServiceImpl implements IFailureService {
                     runPara.setText(",故障模式主要是" + descSj + "等");
                 }
                 // top n的 top5故障原因
-                List<String> top5FailureCause = failureMapper.getFailureCause(reportMonth, compName, major);
+                List<String> top5FailureCause = failureMapper.getFailureCause(reportMonth, compName, major, aircraftTypes);
                 if (!CollectionUtils.isEmpty(top5FailureCause)) {
                     StringJoiner causeSj = new StringJoiner("、");
                     for (String cause : top5FailureCause) {
@@ -210,7 +236,7 @@ public class FailureServiceImpl implements IFailureService {
                     runPara.setText(",原因主要是" + causeSj + "等");
                 }
                 // top n的 top3型别
-                List<String> top3CompType = failureMapper.getFailureCompType(reportMonth, compName, major);
+                List<String> top3CompType = failureMapper.getFailureCompType(reportMonth, compName, major, aircraftTypes);
                 if (!CollectionUtils.isEmpty(top3CompType)) {
                     StringJoiner numSj = new StringJoiner("、");
                     for (String num : top3CompType) {
@@ -231,12 +257,12 @@ public class FailureServiceImpl implements IFailureService {
 
         // 格式化当前时间为字符串
         String currentTime = sdf.format(now);
-        String directoryPath = "d:/fms/report/";
+        String directoryPath = FmsConfig.getProfile();
         File directory = new File(directoryPath);
         if (!directory.exists()) {
             directory.mkdirs();
         }
-        docPath = directoryPath+"故障报告-"+ reportMonth + "-" + major + "-" +currentTime + ".docx";
+        docPath = directoryPath + "/故障报告-" + reportMonth + "-" + major + "-" + brandName + "-" + currentTime + ".docx";
         // 将文档写入文件
         try (FileOutputStream out = new FileOutputStream(docPath)) {
             document.write(out);

+ 45 - 28
fms-admin/src/main/resources/mapper/system/FailureMapper.xml

@@ -173,26 +173,39 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         SELECT COUNT(*) AS failure_count
         FROM failure_t
         WHERE DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth}
-            AND major = #{major}
+        AND major = #{major}
+        AND aircraft_type in
+        <foreach item="item" index="index" collection="aircraftTypes" open="(" separator="," close=")">
+            #{item}
+        </foreach>
     </select>
-    <select id="getTop5UnserviceableCompName" parameterType="String" resultType="String">
-        SELECT unserviceable_comp_name FROM
-        (SELECT unserviceable_comp_name, COUNT(*) AS failure_count
+    <select id="getTop5UnserviceableCompName" resultType="String">
+        SELECT unserviceable_comp_name
         FROM failure_t
-        WHERE DATE_FORMAT(failure_date, '%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
+            AND aircraft_type in
+            <foreach item="item" index="index" collection="aircraftTypes" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+            GROUP BY unserviceable_comp_name
+            ORDER BY COUNT(*) DESC
+            LIMIT 5;
+        </where>
     </select>
 
     <select id="getFailureCount" parameterType="String" resultType="Integer">
         SELECT COUNT(*) AS failure_count
         FROM failure_t
         WHERE
-            DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth}
-            AND unserviceable_comp_name = #{compName}
-            AND major = #{major}
+        DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth}
+        AND unserviceable_comp_name = #{compName}
+        AND major = #{major}
+        AND aircraft_type in
+        <foreach item="item" index="index" collection="aircraftTypes" open="(" separator="," close=")">
+            #{item}
+        </foreach>
     </select>
 
     <select id="getFailureDescription" parameterType="String" resultType="String">
@@ -209,6 +222,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth} AND
             unserviceable_comp_name = #{compName}
             AND major = #{major}
+        AND aircraft_type in
+        <foreach item="item" index="index" collection="aircraftTypes" open="(" separator="," close=")">
+            #{item}
+        </foreach>
         GROUP BY failure_description
         ) t
         ORDER BY failure_count DESC LIMIT 5
@@ -227,6 +244,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth} AND
             unserviceable_comp_name = #{compName}
             AND major = #{major}
+        AND aircraft_type in
+        <foreach item="item" index="index" collection="aircraftTypes" open="(" separator="," close=")">
+            #{item}
+        </foreach>
         GROUP BY failure_cause
         ) t
         ORDER BY
@@ -234,23 +255,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LIMIT 5
     </select>
     <select id="getFailureCompType" parameterType="String" resultType="String">
-        SELECT
-            unserviceable_comp_type
-        FROM
-        (
-        SELECT
-            unserviceable_comp_type,
-            COUNT(*) AS failure_count
-        FROM
-            failure_t
-        WHERE
-        DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth} AND
-            unserviceable_comp_name = #{compName}
-            AND major = #{major}
-        GROUP BY unserviceable_comp_type
-        ) t
-        ORDER BY
-        failure_count DESC
+        SELECT unserviceable_comp_type
+        FROM (SELECT unserviceable_comp_type,
+        COUNT(*) AS failure_count
+        FROM failure_t
+        WHERE DATE_FORMAT(failure_date, '%Y-%m') = #{reportMonth}
+        AND unserviceable_comp_name = #{compName}
+        AND major = #{major}
+        AND aircraft_type in
+        <foreach item="item" index="index" collection="aircraftTypes" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        GROUP BY unserviceable_comp_type) t
+        ORDER BY failure_count DESC
         LIMIT 5
     </select>
     <select id="getMajorOption" resultType="Map">

+ 2 - 2
fms-ui/src/api/system/failure.js

@@ -51,14 +51,14 @@ export function getMajorOption() {
   });
 }
 // 生成报告
-export function generateReport(reportMonth, major,brandId) {
+export function generateReport(reportMonth, major,brandIds) {
   return request({
     url: "/system/failure/generateReport",
     method: "get",
     params: {
       reportMonth,
       major,
-      brandId,
+      brandIds,
     },
   });
 }

+ 12 - 7
fms-ui/src/views/system/failure/index.vue

@@ -252,7 +252,7 @@
         <el-row>
           <el-col><span style="">机型系列</span></el-col>
           <el-col>
-            <el-select v-model="report.brandId" placeholder="请选择机型系列">
+            <el-select v-model="selectedBrandIds" placeholder="请选择机型系列" multiple @change="handleBrandChange">
               <el-option v-for="option in brandOptions" :key="option.brandId" :label="option.brandName"
                 :value="option.brandId"></el-option>
             </el-select>
@@ -299,6 +299,7 @@ export default {
       total: 0,
       // 故障记录表格数据
       failureList: [],
+      selectedBrandIds: [],
       brandOptions: [],  // 机型系列选项列表
       // 弹出层标题
       title: "",
@@ -359,7 +360,7 @@ export default {
         reportDate: null,
         // 专业
         major: null,
-        brandId: null,
+        brandIds: null,
         majorOption: [],
       },
     };
@@ -446,6 +447,9 @@ export default {
         this.title = "修改故障记录";
       });
     },
+    handleBrandChange() {
+      this.report.brandIds = this.selectedBrandIds.join(',');
+    },
     /** 提交按钮 */
     submitForm() {
       this.$refs["form"].validate((valid) => {
@@ -535,11 +539,12 @@ export default {
     /** 生成报告按钮操作 */
     handleGenerateReport() {
       this.report.title = "生成报告";
-      
+
       this.report.open = true;
       this.report.reportDate = null;
       this.report.major = null;
-      this.report.brandId = null;
+      this.report.brandIds = null;
+      this.selectedBrandIds = []; // 清空已选择的机型系列ID
       this.getBrandOptions();  // 在打开弹框时获取机型系列选项
       this.report.majorOption = getMajorOption();
       getMajorOption().then((response) => {
@@ -548,7 +553,7 @@ export default {
     },
     // 生成报告
     submitGenerateReport() {
-      if (!this.report.reportDate && !this.report.major && !this.report.brandId) {
+      if (!this.report.reportDate && !this.report.major && !this.report.brandIds) {
         this.$message({
           showClose: true,
           message: "需要选择故障月份和专业和机型系列",
@@ -573,7 +578,7 @@ export default {
         return;
       }
 
-      if (!this.report.brandId) {
+      if (!this.report.brandIds) {
         this.$message({
           showClose: true,
           message: "需要选择机型系列",
@@ -582,7 +587,7 @@ export default {
         return;
       }
 
-      generateReport(this.report.reportDate, this.report.major, this.report.brandId).then(
+      generateReport(this.report.reportDate, this.report.major, this.report.brandIds).then(
         (response) => {
           console.info("报告返回结果" + response);
           this.$message({