allen 1 year ago
parent
commit
e4d9d194c7

+ 18 - 13
fms-admin/pom.xml

@@ -66,24 +66,29 @@
             <artifactId>hutool-all</artifactId>
             <version>5.8.28</version>
         </dependency>
-
         <dependency>
             <groupId>org.apache.poi</groupId>
-            <artifactId>poi-ooxml</artifactId>
-            <version>5.2.5</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.poi</groupId>
-            <artifactId>poi-ooxml-schemas</artifactId>
+            <artifactId>poi</artifactId>
             <version>4.1.2</version>
         </dependency>
 
-        <dependency>
-            <groupId>org.apache.xmlbeans</groupId>
-            <artifactId>xmlbeans</artifactId>
-            <version>5.2.1</version>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.apache.poi</groupId>-->
+<!--            <artifactId>poi-ooxml</artifactId>-->
+<!--            <version>5.2.5</version>-->
+<!--        </dependency>-->
+
+<!--        <dependency>-->
+<!--            <groupId>org.apache.poi</groupId>-->
+<!--            <artifactId>poi-ooxml-schemas</artifactId>-->
+<!--            <version>4.1.2</version>-->
+<!--        </dependency>-->
+
+<!--        <dependency>-->
+<!--            <groupId>org.apache.xmlbeans</groupId>-->
+<!--            <artifactId>xmlbeans</artifactId>-->
+<!--            <version>5.2.1</version>-->
+<!--        </dependency>-->
 
     </dependencies>
 

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

@@ -1,35 +1,26 @@
 package com.fms.system.controller;
 
-import java.util.Date;
-import java.util.List;
-import javax.servlet.http.HttpServletResponse;
-
-import com.fms.common.core.domain.entity.SysUser;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
 import com.fms.common.annotation.Log;
 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.poi.ExcelUtil;
 import com.fms.system.domain.Failure;
 import com.fms.system.service.IFailureService;
-import com.fms.common.utils.poi.ExcelUtil;
-import com.fms.common.core.page.TableDataInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
 /**
  * 故障记录Controller
  * 
  * @author Allen
- * @date 2024-05-14
+ * @date 2024-06-10
  */
 @RestController
 @RequestMapping("/system/failure")
@@ -106,15 +97,15 @@ public class FailureController extends BaseController
         return toAjax(failureService.deleteFailureByIds(ids));
     }
 
-    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
-    @PreAuthorize("@ss.hasPermi('system:user:import')")
+    @Log(title = "故障记录", businessType = BusinessType.IMPORT)
+    @PreAuthorize("@ss.hasPermi('system:failure:import')")
     @PostMapping("/importData")
     public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
     {
         ExcelUtil<Failure> util = new ExcelUtil<>(Failure.class);
         List<Failure> failureList = util.importExcel(file.getInputStream());
         String operName = getUsername();
-        String message = failureService.importUser(failureList, updateSupport, operName);
+        String message = failureService.importData(failureList, updateSupport, operName);
         return success(message);
     }
 
@@ -128,8 +119,13 @@ 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){
-        logger.info(String.valueOf(reportMonth));
-        failureService.generateReport(reportMonth);
+    public void generateReport(HttpServletResponse response, String reportMonth, String major){
+        logger.info("generateReport: reportMonth:{}, major:{}" ,reportMonth, major);
+        failureService.generateReport(reportMonth, major);
+    }
+    @PreAuthorize("@ss.hasPermi('system:failure:query')")
+    @GetMapping("/getMajorOption")
+    public AjaxResult getMajorOption(){
+        return AjaxResult.success(failureService.getMajorOption());
     }
 }

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

@@ -58,6 +58,10 @@ public class Failure extends BaseEntity
     @Excel(name = "故障名称")
     private String failureName;
 
+    /** 故障件名称 */
+    @Excel(name = "故障件名称")
+    private String unserviceableCompName;
+
     /** 故障件型别 */
     @Excel(name = "故障件型别")
     private String unserviceableCompType;
@@ -193,6 +197,15 @@ public class Failure extends BaseEntity
     {
         return failureName;
     }
+    public void setUnserviceableCompName(String unserviceableCompName) 
+    {
+        this.unserviceableCompName = unserviceableCompName;
+    }
+
+    public String getUnserviceableCompName() 
+    {
+        return unserviceableCompName;
+    }
     public void setUnserviceableCompType(String unserviceableCompType) 
     {
         this.unserviceableCompType = unserviceableCompType;
@@ -289,6 +302,7 @@ public class Failure extends BaseEntity
             .append("failureDescription", getFailureDescription())
             .append("failureCause", getFailureCause())
             .append("failureName", getFailureName())
+            .append("unserviceableCompName", getUnserviceableCompName())
             .append("unserviceableCompType", getUnserviceableCompType())
             .append("unserviceableCompNum", getUnserviceableCompNum())
             .append("unserviceableCompSystem", getUnserviceableCompSystem())

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

@@ -1,7 +1,10 @@
 package com.fms.system.mapper;
 
 import java.util.List;
+import java.util.Map;
+
 import com.fms.system.domain.Failure;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 故障记录Mapper接口
@@ -59,5 +62,17 @@ public interface FailureMapper
      */
     public int deleteFailureByIds(Long[] ids);
 
-    Integer getMajor(String reportMonth);
+    Integer getMajorCount(String reportMonth);
+
+    List<String> getTop5UnserviceableCompName(String reportMonth);
+
+    Integer getFailureCount(@Param("reportMonth") String reportMonth, @Param("compName") String compName);
+
+    List<String> getFailureDescription(@Param("reportMonth") String reportMonth, @Param("compName") String compName);
+
+    List<String> getFailureCause(@Param("reportMonth") String reportMonth, @Param("compName") String compName);
+
+    List<String> getFailureCompType(@Param("reportMonth") String reportMonth, @Param("compName") String compName);
+
+    List<Map> getMajorOption();
 }

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

@@ -1,6 +1,8 @@
 package com.fms.system.service;
 
 import java.util.List;
+import java.util.Map;
+
 import com.fms.system.domain.Failure;
 
 /**
@@ -59,7 +61,9 @@ public interface IFailureService
      */
     public int deleteFailureById(Long id);
 
-    String importUser(List<Failure> failureList, boolean updateSupport, String operName);
+    String importData(List<Failure> failureList, boolean updateSupport, String operName);
+
+    void generateReport(String reportMonth, String major);
 
-    void generateReport(String reportMonth);
+    List<Map> getMajorOption();
 }

+ 140 - 63
fms-admin/src/main/java/com/fms/system/service/impl/FailureServiceImpl.java

@@ -1,24 +1,32 @@
 package com.fms.system.service.impl;
 
-import java.util.List;
-import java.util.Map;
-
-import com.fms.common.core.domain.entity.SysUser;
 import com.fms.common.exception.ServiceException;
 import com.fms.common.utils.DateUtils;
-import com.fms.common.utils.SecurityUtils;
 import com.fms.common.utils.StringUtils;
 import com.fms.common.utils.bean.BeanValidators;
+import com.fms.system.domain.Failure;
+import com.fms.system.mapper.FailureMapper;
+import com.fms.system.service.IFailureService;
 import com.fms.system.service.ISysConfigService;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
+import org.apache.poi.xwpf.usermodel.XWPFRun;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import com.fms.system.mapper.FailureMapper;
-import com.fms.system.domain.Failure;
-import com.fms.system.service.IFailureService;
+import org.springframework.util.CollectionUtils;
 
 import javax.validation.Validator;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.List;
+import java.util.Map;
+import java.util.StringJoiner;
 
 /**
  * 故障记录Service业务层处理
@@ -27,8 +35,7 @@ import javax.validation.Validator;
  * @date 2024-05-14
  */
 @Service
-public class FailureServiceImpl implements IFailureService 
-{
+public class FailureServiceImpl implements IFailureService {
     private static final Logger log = LoggerFactory.getLogger(FailureServiceImpl.class);
     @Autowired
     private FailureMapper failureMapper;
@@ -41,159 +48,229 @@ public class FailureServiceImpl implements IFailureService
 
     /**
      * 查询故障记录
-     * 
+     *
      * @param id 故障记录主键
      * @return 故障记录
      */
     @Override
-    public Failure selectFailureById(Long id)
-    {
+    public Failure selectFailureById(Long id) {
         return failureMapper.selectFailureById(id);
     }
 
     /**
      * 查询故障记录列表
-     * 
+     *
      * @param failure 故障记录
      * @return 故障记录
      */
     @Override
-    public List<Failure> selectFailureList(Failure failure)
-    {
+    public List<Failure> selectFailureList(Failure failure) {
         return failureMapper.selectFailureList(failure);
     }
 
     /**
      * 新增故障记录
-     * 
+     *
      * @param failure 故障记录
      * @return 结果
      */
     @Override
-    public int insertFailure(Failure failure)
-    {
+    public int insertFailure(Failure failure) {
         failure.setCreateTime(DateUtils.getNowDate());
         return failureMapper.insertFailure(failure);
     }
 
     /**
      * 修改故障记录
-     * 
+     *
      * @param failure 故障记录
      * @return 结果
      */
     @Override
-    public int updateFailure(Failure failure)
-    {
+    public int updateFailure(Failure failure) {
         failure.setUpdateTime(DateUtils.getNowDate());
         return failureMapper.updateFailure(failure);
     }
 
     /**
      * 批量删除故障记录
-     * 
+     *
      * @param ids 需要删除的故障记录主键
      * @return 结果
      */
     @Override
-    public int deleteFailureByIds(Long[] ids)
-    {
+    public int deleteFailureByIds(Long[] ids) {
         return failureMapper.deleteFailureByIds(ids);
     }
 
     /**
      * 删除故障记录信息
-     * 
+     *
      * @param id 故障记录主键
      * @return 结果
      */
     @Override
-    public int deleteFailureById(Long id)
-    {
+    public int deleteFailureById(Long id) {
         return failureMapper.deleteFailureById(id);
     }
 
     @Override
-    public String importUser(List<Failure> failureList, boolean isUpdateSupport, String operName)
-    {
-        if (StringUtils.isNull(failureList) || failureList.size() == 0)
-        {
+    public String importData(List<Failure> failureList, boolean isUpdateSupport, String operName) {
+        if (StringUtils.isNull(failureList) || failureList.size() == 0) {
             throw new ServiceException("导入数据不能为空!");
         }
         int successNum = 0;
         int failureNum = 0;
         StringBuilder successMsg = new StringBuilder();
         StringBuilder failureMsg = new StringBuilder();
-        for (Failure failure : failureList)
-        {
-            try
-            {
+        for (Failure failure : failureList) {
+            try {
                 // 验证是否存在这个用户
                 Failure f = failureMapper.selectFailureById(failure.getId());
-                if (StringUtils.isNull(f))
-                {
+                if (StringUtils.isNull(f)) {
                     BeanValidators.validateWithException(validator, failure);
                     failure.setCreateBy(operName);
                     failureMapper.insertFailure(failure);
                     successNum++;
                     successMsg.append("<br/>" + successNum + "、id " + failure.getId() + " 导入成功");
-                }
-                else if (isUpdateSupport)
-                {
+                } else if (isUpdateSupport) {
                     BeanValidators.validateWithException(validator, failure);
                     failure.setUpdateBy(operName);
                     failureMapper.updateFailure(failure);
                     successNum++;
                     successMsg.append("<br/>" + successNum + "、id " + failure.getId() + " 更新成功");
-                }
-                else
-                {
+                } else {
                     failureNum++;
                     failureMsg.append("<br/>" + failureNum + "、id " + failure.getId() + " 已存在");
                 }
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 failureNum++;
                 String msg = "<br/>" + failureNum + "、账号 " + failure.getId() + " 导入失败:";
                 failureMsg.append(msg + e.getMessage());
                 log.error(msg, e);
             }
         }
-        if (failureNum > 0)
-        {
+        if (failureNum > 0) {
             failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
             throw new ServiceException(failureMsg.toString());
-        }
-        else
-        {
+        } else {
             successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
         }
         return successMsg.toString();
     }
 
     @Override
-    public void generateReport(String reportMonth) {
-        // 故障总数根据时间和故障专业获取总数
+    public void generateReport(String reportMonth, String major) {
 
-        Integer count = failureMapper.getMajor(reportMonth);
+        // 创建一个新的Word文档
+        XWPFDocument document = new XWPFDocument();
+
+        // 故障总数根据时间和故障专业获取总数
+        // 创建另一个段落
+        XWPFRun runParagraph = createPara(document);
+//        XWPFParagraph paragraph = document.createParagraph();
+//        XWPFRun runParagraph = paragraph.createRun();
+        // todo allen
+        Integer count = failureMapper.getMajorCount(reportMonth);
+        runParagraph.setText("XX专业。共统计故障" + count + "起");
 
         // 获取top5的故障件名称
+        List<String> top5UnserviceableCompName = failureMapper.getTop5UnserviceableCompName(reportMonth);
+
+        if (!CollectionUtils.isEmpty(top5UnserviceableCompName)) {
+            StringJoiner sj = new StringJoiner("、");
+            for (String compName : top5UnserviceableCompName) {
+                sj.add(compName);
+            }
+            runParagraph.setText(",故障主要集中在" + sj + "等。");
+            // loop top5 的故障信息
+            // loop start
+            for (String compName : top5UnserviceableCompName) {
+                XWPFRun runPara = createPara(document);
+                // top n的故障数量
+                Integer failureCount = failureMapper.getFailureCount(reportMonth, compName);
+                runPara.setText(compName + "故障" + failureCount + "起");
+                // top n的 top5故障描述
+                List<String> top5FailureDescription = failureMapper.getFailureDescription(reportMonth, compName);
+                if (!CollectionUtils.isEmpty(top5FailureDescription)) {
+                    StringJoiner descSj = new StringJoiner(";");
+                    for (String desc : top5FailureDescription) {
+                        descSj.add(desc);
+                    }
+                    runPara.setText(",故障模式主要是" + descSj + "等");
+                }
+                // top n的 top5故障原因
+                List<String> top5FailureCause = failureMapper.getFailureCause(reportMonth, compName);
+                if (!CollectionUtils.isEmpty(top5FailureCause)) {
+                    StringJoiner causeSj = new StringJoiner("、");
+                    for (String cause : top5FailureCause) {
+                        causeSj.add(cause);
+                    }
+                    runPara.setText(",原因主要是" + causeSj + "等");
+                }
+                // top n的 top3型别
+                List<String> top3CompType = failureMapper.getFailureCompType(reportMonth, compName);
+                if (!CollectionUtils.isEmpty(top3CompType)) {
+                    StringJoiner numSj = new StringJoiner("、");
+                    for (String num : top3CompType) {
+                        numSj.add(num);
+                    }
+                    runPara.setText(",主要集中在" + numSj + "等。");
+                }
+            }
+            // loop end
+        } else {
+            log.warn("获取top5的故障件名称为null");
+        }
 
-        List<String>
+        // 将文档写入文件
+        try (FileOutputStream out = new FileOutputStream("example.docx")) {
+            document.write(out);
+        } catch (IOException e) {
+            log.error("文档写入文件异常", e);
+        }
+
+        // 关闭文档
+        try {
+            document.close();
+        } catch (IOException e) {
+            log.error("关闭文档异常", e);
+        }
+    }
 
-        // loop top5 的故障信息
+    @Override
+    public List<Map> getMajorOption() {
+        return failureMapper.getMajorOption();
+    }
 
-        // loop start
+    private XWPFRun createPara(XWPFDocument document){
+        // 创建一个段落
+        XWPFParagraph paragraph = document.createParagraph();
 
-        // top n的故障数量
+        // 设置段落缩进:2个字符
+        paragraph.setIndentationFirstLine(3 * 240); // 1字符约等于240 twip
 
-        // top n的 top5故障描述
+        // 设置段前段后间距为0行
+        paragraph.setSpacingBefore(0);
+        paragraph.setSpacingAfter(0);
+
+        // 设置行距为固定值28.5磅
+        CTPPr ppr = paragraph.getCTP().getPPr();
+        if (ppr == null) {
+            ppr = paragraph.getCTP().addNewPPr();
+        }
+        CTSpacing spacing = ppr.getSpacing() == null ? ppr.addNewSpacing() : ppr.getSpacing();
+        spacing.setLineRule(STLineSpacingRule.EXACT);
+        spacing.setLine(new BigInteger(String.valueOf(570))); // 28.5磅,单位是twips 28.5 * 20
 
-        // top n的 top5故障原因
+        // 创建一个运行来包含文本
+        XWPFRun run = paragraph.createRun();
 
-        // top n的 top3 型号
+        // 设置字体大小为三号(16磅)
+        run.setFontSize(16);
 
-        // loop end
+        // 设置字体样式为仿宋GB
+        run.setFontFamily("仿宋_GB2312");
+        return run;
     }
 }

+ 90 - 1
fms-admin/src/main/resources/mapper/system/FailureMapper.xml

@@ -16,6 +16,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="failureDescription"    column="failure_description"    />
         <result property="failureCause"    column="failure_cause"    />
         <result property="failureName"    column="failure_name"    />
+        <result property="unserviceableCompName"    column="unserviceable_comp_name"    />
         <result property="unserviceableCompType"    column="unserviceable_comp_type"    />
         <result property="unserviceableCompNum"    column="unserviceable_comp_num"    />
         <result property="unserviceableCompSystem"    column="unserviceable_comp_system"    />
@@ -32,7 +33,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_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, 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">
@@ -48,6 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="failureDescription != null  and failureDescription != ''"> and failure_description = #{failureDescription}</if>
             <if test="failureCause != null  and failureCause != ''"> and failure_cause = #{failureCause}</if>
             <if test="failureName != null  and failureName != ''"> and failure_name like concat('%', #{failureName}, '%')</if>
+            <if test="unserviceableCompName != null  and unserviceableCompName != ''"> and unserviceable_comp_name like concat('%', #{unserviceableCompName}, '%')</if>
             <if test="unserviceableCompType != null  and unserviceableCompType != ''"> and unserviceable_comp_type = #{unserviceableCompType}</if>
             <if test="unserviceableCompNum != null  and unserviceableCompNum != ''"> and unserviceable_comp_num = #{unserviceableCompNum}</if>
             <if test="unserviceableCompSystem != null  and unserviceableCompSystem != ''"> and unserviceable_comp_system = #{unserviceableCompSystem}</if>
@@ -78,6 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="failureDescription != null">failure_description,</if>
             <if test="failureCause != null">failure_cause,</if>
             <if test="failureName != null">failure_name,</if>
+            <if test="unserviceableCompName != null">unserviceable_comp_name,</if>
             <if test="unserviceableCompType != null">unserviceable_comp_type,</if>
             <if test="unserviceableCompNum != null">unserviceable_comp_num,</if>
             <if test="unserviceableCompSystem != null">unserviceable_comp_system,</if>
@@ -103,6 +106,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="failureDescription != null">#{failureDescription},</if>
             <if test="failureCause != null">#{failureCause},</if>
             <if test="failureName != null">#{failureName},</if>
+            <if test="unserviceableCompName != null">#{unserviceableCompName},</if>
             <if test="unserviceableCompType != null">#{unserviceableCompType},</if>
             <if test="unserviceableCompNum != null">#{unserviceableCompNum},</if>
             <if test="unserviceableCompSystem != null">#{unserviceableCompSystem},</if>
@@ -132,6 +136,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="failureDescription != null">failure_description = #{failureDescription},</if>
             <if test="failureCause != null">failure_cause = #{failureCause},</if>
             <if test="failureName != null">failure_name = #{failureName},</if>
+            <if test="unserviceableCompName != null">unserviceable_comp_name = #{unserviceableCompName},</if>
             <if test="unserviceableCompType != null">unserviceable_comp_type = #{unserviceableCompType},</if>
             <if test="unserviceableCompNum != null">unserviceable_comp_num = #{unserviceableCompNum},</if>
             <if test="unserviceableCompSystem != null">unserviceable_comp_system = #{unserviceableCompSystem},</if>
@@ -159,4 +164,88 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+    <select id="getMajor" resultType="Integer">
+        SELECT COUNT(*) AS failure_count
+        FROM failure_t
+        <!-- WHERE DATE_FORMAT(故障发生时间, '%Y-%m') = #{reportMonth} -->
+    </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}-->
+        GROUP BY unserviceable_comp_name
+        ORDER BY failure_count DESC
+        LIMIT 5) t
+    </select>
+
+    <select id="getFailureCount" parameterType="String" resultType="Integer">
+        SELECT COUNT(*) AS failure_count
+        FROM failure_t
+        WHERE
+<!--         DATE_FORMAT(故障发生时间, '%Y-%m') = #{reportMonth}-->
+        unserviceable_comp_name = #{compName}
+    </select>
+
+    <select id="getFailureDescription" parameterType="String" resultType="String">
+        SELECT
+            failure_description
+        FROM
+        (
+        SELECT
+            failure_description,
+            COUNT(*) AS failure_count
+        FROM
+            failure_t ft
+        WHERE
+<!--            DATE_FORMAT(故障发生时间, '%Y-%m') = #{reportMonth} AND-->
+            unserviceable_comp_name = #{compName}
+        GROUP BY failure_description
+        ) t
+        ORDER BY failure_count DESC LIMIT 5
+    </select>
+    <select id="getFailureCause" parameterType="String" resultType="String">
+        SELECT
+            failure_cause
+        FROM
+        (
+        SELECT
+            failure_cause,
+            COUNT(*) AS failure_count
+        FROM
+            failure_t
+        WHERE
+<!--        DATE_FORMAT(故障发生时间, '%Y-%m') = #{reportMonth} AND-->
+            unserviceable_comp_name = #{compName}
+        GROUP BY failure_cause
+        ) t
+        ORDER BY
+        failure_count DESC
+        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(故障发生时间, '%Y-%m') = #{reportMonth} AND-->
+            unserviceable_comp_name = #{compName}
+        GROUP BY unserviceable_comp_type
+        ) t
+        ORDER BY
+        failure_count DESC
+        LIMIT 5
+    </select>
+    <select id="getMajorOption" resultType="Map">
+        SELECT
+            distinct major
+        FROM
+            failure_t
+    </select>
 </mapper>

+ 7 - 0
fms-ui/src/api/system/failure.js

@@ -51,3 +51,10 @@ export function generateReport(date) {
     data: date,
   });
 }
+// 获取专业
+export function getMajorOption() {
+  return request({
+    url: "/system/failure/getMajorOption",
+    method: "get",
+  });
+}

+ 41 - 1
fms-ui/src/views/system/failure/index.vue

@@ -80,6 +80,14 @@
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
+      <el-form-item label="故障件名称" prop="unserviceableCompName">
+        <el-input
+          v-model="queryParams.unserviceableCompName"
+          placeholder="请输入故障件名称"
+          clearable
+          @keyup.enter.native="handleQuery"
+        />
+      </el-form-item>
       <el-form-item label="故障件号码" prop="unserviceableCompNum">
         <el-input
           v-model="queryParams.unserviceableCompNum"
@@ -246,6 +254,11 @@
       />
       <el-table-column label="故障原因" align="center" prop="failureCause" />
       <el-table-column label="故障名称" align="center" prop="failureName" />
+      <el-table-column
+        label="故障件名称"
+        align="center"
+        prop="unserviceableCompName"
+      />
       <el-table-column
         label="故障件型别"
         align="center"
@@ -354,6 +367,12 @@
         <el-form-item label="故障名称" prop="failureName">
           <el-input v-model="form.failureName" placeholder="请输入故障名称" />
         </el-form-item>
+        <el-form-item label="故障件名称" prop="unserviceableCompName">
+          <el-input
+            v-model="form.unserviceableCompName"
+            placeholder="请输入故障件名称"
+          />
+        </el-form-item>
         <el-form-item label="故障件号码" prop="unserviceableCompNum">
           <el-input
             v-model="form.unserviceableCompNum"
@@ -455,6 +474,15 @@
           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>
       <div slot="footer" class="dialog-footer">
         <el-button type="primary" @click="submitGenerateReport"
@@ -474,6 +502,7 @@ import {
   addFailure,
   updateFailure,
   generateReport,
+  getMajorOption,
 } from "@/api/system/failure";
 import { getToken } from "@/utils/auth";
 
@@ -528,6 +557,7 @@ export default {
         failureDescription: null,
         failureCause: null,
         failureName: null,
+        unserviceableCompName: null,
         unserviceableCompType: null,
         unserviceableCompNum: null,
         unserviceableCompSystem: null,
@@ -550,6 +580,9 @@ export default {
         title: "生成报告",
         // 报告日期
         reportDate: null,
+        // 专业
+        major: null,
+        majorOption: [],
       },
     };
   },
@@ -585,6 +618,7 @@ export default {
         failureDescription: null,
         failureCause: null,
         failureName: null,
+        unserviceableCompName: null,
         unserviceableCompType: null,
         unserviceableCompNum: null,
         unserviceableCompSystem: null,
@@ -717,6 +751,11 @@ export default {
       this.report.title = "生成报告";
       this.report.open = true;
       this.report.reportDate = null;
+      this.report.major = null;
+      this.report.majorOption = getMajorOption();
+      getMajorOption().then((response) => {
+        this.report.majorOption = response.data;
+      });
     },
     // 生成报告
     submitGenerateReport() {
@@ -725,8 +764,9 @@ export default {
         "system/failure/generateReport",
         {
           reportMonth: this.report.reportDate,
+          major: this.report.major,
         },
-        `failure_${new Date().getTime()}.xlsx`
+        `failure_${new Date().getTime()}.doc`
       );
       this.report.open = false;
     },