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