资源管理微调

This commit is contained in:
caozehui
2026-05-28 16:27:04 +08:00
parent 7f21049d0f
commit d2388576a9
14 changed files with 200 additions and 86 deletions

View File

@@ -46,6 +46,7 @@ import com.njcn.gather.storage.pojo.po.ContrastNonHarmonicResult;
import com.njcn.gather.storage.service.DetectionDataDealService;
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.config.PathConfig;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
@@ -57,7 +58,6 @@ import com.njcn.gather.tools.comtrade.comparewave.service.ICompareWaveService;
import com.njcn.gather.util.StorageUtil;
import com.njcn.web.utils.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.FileInputStream;
@@ -127,8 +127,9 @@ public class SocketContrastResponseService {
// private SysRegRes contrastRegRes = null;
@Value("${report.reportDir}")
private String alignDataFilePath;
// @Value("${report.reportDir}")
// private String alignDataFilePath;
private final PathConfig pathConfig;
public static final Map<String, List<String>> testItemCodeMap = new HashMap() {{
put("FREQ", Arrays.asList(DetectionCodeEnum.FREQ.getCode()));
@@ -2314,7 +2315,7 @@ public class SocketContrastResponseService {
});
});
ExcelUtil.saveExcel(alignDataFilePath, "对齐数据.xlsx", sheetsList);
ExcelUtil.saveExcel(pathConfig.getDataPath(), "对齐数据.xlsx", sheetsList);
}
/**

View File

@@ -41,6 +41,7 @@ import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.source.pojo.po.SourceInitialize;
import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.config.PathConfig;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.dictionary.service.IDictDataService;
import com.njcn.web.utils.HttpServletUtil;
@@ -53,6 +54,7 @@ import org.springframework.stereotype.Service;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -81,8 +83,9 @@ public class PreDetectionServiceImpl implements PreDetectionService {
private final ISysTestConfigService sysTestConfigService;
@Value("${report.reportDir}")
private String alignDataFilePath;
// @Value("${report.reportDir}")
// private String alignDataFilePath;
private final PathConfig pathConfig;
@Override
@@ -353,7 +356,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.setContentType("application/octet-stream;charset=UTF-8");
try {
InputStream inputStream = new FileInputStream(alignDataFilePath + "\\" + fileName);
InputStream inputStream = new FileInputStream(pathConfig.getDataPath() + File.separator + fileName);
byte[] buffer = new byte[1024];
int len = 0;
ServletOutputStream outputStream = response.getOutputStream();

View File

@@ -23,6 +23,7 @@ import com.njcn.gather.monitor.service.IPqMonitorService;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.vo.AdPlanCheckDataVO;
import com.njcn.gather.plan.service.util.BatchFileReader;
import com.njcn.gather.system.config.PathConfig;
import com.njcn.gather.system.config.handler.NonWebAutoFillValueHandler;
import com.njcn.gather.tools.report.model.constant.ReportConstant;
import com.njcn.gather.type.pojo.po.DevType;
@@ -64,11 +65,11 @@ public class AsyncPlanHandler {
private final JdbcTemplate jdbcTemplate;
@Value("${report.reportDir}")
private String reportPath;
@Value("${data.homeDir}")
private String dataPath;
private final PathConfig pathConfig;
// @Value("${report.reportDir}")
// private String reportPath;
// @Value("${data.homeDir}")
// private String dataPath;
private static final int BATCH_SIZE = 10000;
private static final int FINAL_STEP = 85;
@@ -199,13 +200,13 @@ public class AsyncPlanHandler {
// 创建 ZIP 文件
String zipFileName = plan.getName() + "_检测数据包.zip";
File zipFile = FileUtil.file(dataPath + File.separator + TEST_DATA_DIR + File.separator, zipFileName);
File zipFile = FileUtil.file(pathConfig.getDataPath() + File.separator + TEST_DATA_DIR + File.separator, zipFileName);
// 添加检测报告文件
if (ObjectUtil.isNotNull(report) && report.equals(1)) {
for (PqDev dev : devList) {
DevType devType = devTypeService.getById(dev.getDevType());
String dirPath = reportPath.concat(File.separator).concat(devType.getName());
String dirPath = pathConfig.getReportPath().concat(File.separator).concat(devType.getName());
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
// 如果reportFile存在则将reportFile中的文件添加到已有的zip文件中
if (FileUtil.exist(reportFile)) {
@@ -344,7 +345,7 @@ public class AsyncPlanHandler {
for (File docx : docxFiles) {
for (PqDev dev : devList) {
DevType devType = devTypeService.getById(dev.getDevType());
String dirPath = reportPath.concat(File.separator).concat(devType.getName());
String dirPath = pathConfig.getReportPath().concat(File.separator).concat(devType.getName());
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
// 文件名匹配,复制到对应目录下
if (docx.getName().equals(reportFile.getName())) {

View File

@@ -77,6 +77,7 @@ import com.njcn.gather.storage.service.TableGenService;
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.config.PathConfig;
import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.pojo.po.DictType;
@@ -154,8 +155,9 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
private final IPqDevCheckHistoryService pqDevCheckHistoryService;
private final JdbcTemplate jdbcTemplate;
@Value("${report.reportDir}")
private String reportPath;
// @Value("${report.reportDir}")
// private String reportPath;
private final PathConfig pathConfig;
@Override
public List<AdPlanVO> listAdPlan(AdPlanParam.QueryParam queryParam) {
@@ -2333,7 +2335,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
if (ObjectUtil.isNotNull(report) && report.equals(1)) {
for (PqDev dev : devList) {
DevType devType = devTypeService.getById(dev.getDevType());
String dirPath = reportPath.concat(File.separator).concat(devType.getName());
String dirPath = pathConfig.getReportPath().concat(File.separator).concat(devType.getName());
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
// 如果reportFile存在则将reportFile中的文件添加到已有的zip文件中
if (FileUtil.exist(reportFile)) {

View File

@@ -68,16 +68,13 @@ import com.njcn.gather.storage.service.SimAndDigHarmonicService;
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.config.PathConfig;
import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.service.IDictDataService;
import com.njcn.gather.system.pojo.enums.SystemResponseEnum;
import com.njcn.gather.tools.report.model.constant.ReportConstant;
import com.njcn.gather.tools.report.service.IWordReportService;
import com.njcn.gather.tools.report.util.BookmarkUtil;
import com.njcn.gather.tools.report.util.Docx4jUtil;
import com.njcn.gather.tools.report.util.DocxMergeUtil;
import com.njcn.gather.tools.report.util.FilePathSanitizer;
import com.njcn.gather.tools.report.util.WordDocumentUtil;
import com.njcn.gather.tools.report.util.*;
import com.njcn.gather.type.pojo.po.DevType;
import com.njcn.gather.type.service.IDevTypeService;
import com.njcn.gather.user.user.pojo.po.SysUser;
@@ -145,13 +142,13 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
*/
private static final String RESULT_MAP_NO_DATA_FLAG = "__internal_no_data__";
@Value("${report.template:D:\\template}")
private String templatePath;
@Value("${report.reportDir:D:\\report}")
private String reportPath;
// @Value("${report.template:D:\\template}")
// private String templatePath;
//
// @Value("${report.reportDir:D:\\report}")
// private String reportPath;
private final PathConfig pathConfig;
@Value("${qr.cloud}")
private String cloudUrl;
@@ -328,7 +325,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
MultipartFile baseFile = reportParam.getBaseFile();
MultipartFile detailFile = reportParam.getDetailFile();
String relativePath = reportParam.getName() + File.separator + reportParam.getVersion() + File.separator;
String newDir = templatePath + File.separator + relativePath;
String newDir = pathConfig.getReportTemplatePath() + File.separator + relativePath;
long FILE_SIZE_LIMIT = 5 * 1024 * 1024;
if (isAdd) {
@@ -405,13 +402,13 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
// 文件夹重命名
String oldBasePathStr = oldPqReport.getBasePath();
String baseName = oldBasePathStr.substring(oldBasePathStr.lastIndexOf(File.separator) + 1);
Path oldBasePath = Paths.get(templatePath + File.separator + oldBasePathStr);
Path oldBasePath = Paths.get(pathConfig.getReportTemplatePath() + File.separator + oldBasePathStr);
Path newBasePath = Paths.get(newDir + baseName);
pqReport.setBasePath(relativePath + baseName);
String oldDetailPathStr = oldPqReport.getDetailPath();
String detailName = oldDetailPathStr.substring(oldDetailPathStr.lastIndexOf(File.separator) + 1);
Path oldDetailPath = Paths.get(templatePath + File.separator + oldDetailPathStr);
Path oldDetailPath = Paths.get(pathConfig.getReportTemplatePath() + File.separator + oldDetailPathStr);
Path newDetailPath = Paths.get(newDir + detailName);
pqReport.setDetailPath(relativePath + detailName);
@@ -422,13 +419,13 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
Files.move(oldBasePath, newBasePath);
Files.move(oldDetailPath, newDetailPath);
if (!oldPqReport.getName().equals(reportParam.getName()) && !this.existSameName(pqReport.getId(), oldPqReport.getName())) {
this.recursionDeleteDirectory(templatePath + File.separator + oldPqReport.getName());
this.recursionDeleteDirectory(pathConfig.getReportTemplatePath() + File.separator + oldPqReport.getName());
} else {
Paths.get(templatePath + oldDir).toFile().delete();
Paths.get(pathConfig.getReportTemplatePath() + oldDir).toFile().delete();
}
} else {
// 文件夹重命名
Paths.get(templatePath + oldDir).toFile().renameTo(Paths.get(newDir).toFile());
Paths.get(pathConfig.getReportTemplatePath() + oldDir).toFile().renameTo(Paths.get(newDir).toFile());
}
} catch (IOException e) {
throw new BusinessException(ReportResponseEnum.FILE_RENAME_FAILED);
@@ -437,13 +434,13 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
if (!baseFileOriginalFilename.isEmpty()) {
pqReport.setBasePath(relativePath + baseFileOriginalFilename);
Paths.get(templatePath + File.separator + oldPqReport.getBasePath()).toFile().delete();
Paths.get(pathConfig.getReportTemplatePath() + File.separator + oldPqReport.getBasePath()).toFile().delete();
Paths.get(newDir + oldPqReport.getBasePath().substring(oldPqReport.getBasePath().lastIndexOf(File.separator) + 1)).toFile().delete();
this.uploadFile(baseFile, newDir + baseFileOriginalFilename);
}
if (!detailFileOriginalFilename.isEmpty()) {
pqReport.setDetailPath(relativePath + detailFileOriginalFilename);
Paths.get(templatePath + File.separator + oldPqReport.getDetailPath()).toFile().delete();
Paths.get(pathConfig.getReportTemplatePath() + File.separator + oldPqReport.getDetailPath()).toFile().delete();
Paths.get(newDir + oldPqReport.getDetailPath().substring(oldPqReport.getDetailPath().lastIndexOf(File.separator) + 1)).toFile().delete();
this.uploadFile(detailFile, newDir + detailFileOriginalFilename);
}
@@ -528,7 +525,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
private void deleteFile(List<String> ids) {
List<PqReport> pqReports = this.listByIds(ids);
for (PqReport pqReport : pqReports) {
String uploadDir = templatePath + File.separator + pqReport.getName() + File.separator + pqReport.getVersion() + File.separator;
String uploadDir = pathConfig.getReportTemplatePath() + File.separator + pqReport.getName() + File.separator + pqReport.getVersion() + File.separator;
Path uploadPath = Paths.get(uploadDir);
if (Files.exists(uploadPath)) {
//清空目录下的文件
@@ -540,7 +537,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
}
}
file1.delete();
String dir = templatePath + File.separator + pqReport.getName() + File.separator;
String dir = pathConfig.getReportTemplatePath() + File.separator + pqReport.getName() + File.separator;
Path dirPath = Paths.get(dir);
File dirFile = dirPath.toFile();
File[] fileArr2 = dirFile.listFiles();
@@ -634,8 +631,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
InputStream finalWordStream = DocxMergeUtil.mergeDocuments(wordFileInputStreams);
// 处理需要输出的目录地址 基础路径+设备类型+装置编号.docx
// 最终文件输出的路径
// String dirPath = reportPath.concat(File.separator).concat(devType.getName());
String dirPath = reportPath;
// String dirPath = pathConfig.getReportPath().concat(File.separator).concat(devType.getName());
String dirPath = pathConfig.getReportPath();
// 确保目录存在
ensureDirectoryExists(dirPath);
String reportFullPath = dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
@@ -828,8 +825,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
if (Objects.isNull(report)) {
throw new BusinessException(ReportResponseEnum.REPORT_TEMPLATE_NOT_EXIST);
}
Path basePath = Paths.get(templatePath + File.separator + report.getBasePath());
Path detailPath = Paths.get(templatePath + File.separator + report.getDetailPath());
Path basePath = Paths.get(pathConfig.getReportTemplatePath() + File.separator + report.getBasePath());
Path detailPath = Paths.get(pathConfig.getReportTemplatePath() + File.separator + report.getDetailPath());
try (InputStream baseInputStream = Files.newInputStream(basePath);
InputStream detailInputStream = Files.newInputStream(detailPath)) {
WordprocessingMLPackage detailModelDocument = WordprocessingMLPackage.load(detailInputStream);
@@ -843,7 +840,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
MainDocumentPart detailDocumentPart = detailModelDocument.getMainDocumentPart();
dealDataModelScatteredByBookmarkByPlanContrast(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO);
// 保存新的文档
String dirPath = reportPath.concat(File.separator).concat(FilePathSanitizer.toSafeFileName(plan.getName()));
String dirPath = pathConfig.getReportPath().concat(File.separator).concat(FilePathSanitizer.toSafeFileName(plan.getName()));
// 确保目录存在
ensureDirectoryExists(dirPath);
// 构建文件名cityName_gdName_subName_name.docx
@@ -910,8 +907,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
if (Objects.isNull(report)) {
throw new BusinessException(ReportResponseEnum.REPORT_TEMPLATE_NOT_EXIST);
}
Path basePath = Paths.get(templatePath + File.separator + report.getBasePath());
Path detailPath = Paths.get(templatePath + File.separator + report.getDetailPath());
Path basePath = Paths.get(pathConfig.getReportTemplatePath() + File.separator + report.getBasePath());
Path detailPath = Paths.get(pathConfig.getReportTemplatePath() + File.separator + report.getDetailPath());
try (InputStream baseInputStream = Files.newInputStream(basePath);
InputStream detailInputStream = Files.newInputStream(detailPath)) {
WordprocessingMLPackage detailModelDocument = WordprocessingMLPackage.load(detailInputStream);
@@ -926,7 +923,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
dealDataModelScatteredByBookmark(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO);
// 保存新的文档
String dirPath = reportPath.concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName()));
String dirPath = pathConfig.getReportPath().concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName()));
// 确保目录存在
ensureDirectoryExists(dirPath);
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX)));
@@ -1937,7 +1934,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
if (SceneEnum.LEAVE_FACTORY_TEST.getValue().equals(currrentScene)) {
// 出厂测试场景
filePath = reportPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
filePath = pathConfig.getReportPath().concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX;
} else if (plan != null) {
// 根据计划模式确定路径结构
@@ -1949,16 +1946,16 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
pqDevVO.getGdName() != null ? pqDevVO.getGdName() : "未知供电公司",
pqDevVO.getSubName() != null ? pqDevVO.getSubName() : "未知电站",
pqDevVO.getName() != null ? pqDevVO.getName() : "未知设备");
filePath = reportPath.concat(File.separator).concat(FilePathSanitizer.toSafeFileName(plan.getName())).concat(File.separator).concat(fileName);
filePath = pathConfig.getReportPath().concat(File.separator).concat(FilePathSanitizer.toSafeFileName(plan.getName())).concat(File.separator).concat(fileName);
downloadFileName = fileName;
} else {
// 数字/模拟模式:使用原来的路径结构
filePath = reportPath.concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName())).concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
filePath = pathConfig.getReportPath().concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName())).concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX;
}
} else {
// 兜底:使用旧的路径结构
filePath = reportPath.concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName())).concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
filePath = pathConfig.getReportPath().concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName())).concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX;
}
@@ -2486,7 +2483,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
return;
}
log.info("找到{}台设备需要上传报告", devices.size());
String dirPath = reportPath;
String dirPath = pathConfig.getReportPath();
// 确保目录存在
ensureDirectoryExists(dirPath);
// 异步批量上传每台设备的报告

View File

@@ -75,14 +75,11 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
private Double fRampIn;
@Value("${Dip.fRampOut}")
private Double fRampOut;
// @Value("${Dip.fAfterTime}")
// @Value("${Dip.fAfterTime}")
// private Double fAfterTime;
@Value("${Flicker.waveFluType}")
private String waveFluType;
@Value("${Flicker.waveType}")
private String waveType;
@Value("${Flicker.fDutyCycle}")
private Double fDutyCycle;
private static final String waveFluType = "SQU";
private static final String waveType = "CPM";
private static final Double fDutyCycle = 50.0;
private final IPqDevService pqDevService;
@@ -1067,9 +1064,16 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
channelListDTO.setDipData(dipDataDTO);
//闪变数据
SourceIssue.ChannelListDTO.FlickerDataDTO flickerDataDTO = new SourceIssue.ChannelListDTO.FlickerDataDTO();
flickerDataDTO.setWaveFluType(waveFluType);
flickerDataDTO.setWaveType(waveType);
flickerDataDTO.setFDutyCycle(fDutyCycle);
SourceIssue.ChannelListDTO.FlickerDataDTO flickerData = channelListDTO.getFlickerData();
if (ObjectUtil.isNotNull(flickerData)) {
flickerDataDTO.setWaveFluType(flickerData.getWaveFluType());
flickerDataDTO.setWaveType(flickerData.getWaveType());
flickerDataDTO.setFDutyCycle(flickerData.getFDutyCycle());
} else {
flickerDataDTO.setWaveFluType(waveFluType);
flickerDataDTO.setWaveType(waveType);
flickerDataDTO.setFDutyCycle(fDutyCycle);
}
flickerDataDTO.setFChagFre(0.0);
flickerDataDTO.setFChagValue(0.0);