资源管理微调

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

1
.gitignore vendored
View File

@@ -52,3 +52,4 @@ rebel.xml
# 个人工作文档,不与团队共享
CLAUDE.md
docs/
data/

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);

View File

@@ -64,32 +64,32 @@ webSocket:
#源参数下发,暂态数据默认值
Dip:
#暂态前时间s
fPreTime: 2f
# 暂态前时间s
# fPreTime: 2f
#写入时间s
fRampIn: 0.001f
#写出时间s
fRampOut: 0.001f
#暂态后时间s
fAfterTime: 3f
# 暂态后时间s
# fAfterTime: 3f
Flicker:
waveFluType: CPM
waveType: SQU
fDutyCycle: 50f
#Flicker:
# waveFluType: CPM
# waveType: SQU
# fDutyCycle: 50f
log:
homeDir: D:\logs
commonLevel: info
#log:
# homeDir: D:\logs
# commonLevel: info
report:
template: D:\template
reportDir: D:\report
# template: D:\template
# reportDir: D:\report
dateFormat: yyyy年MM月dd日
data:
homeDir: D:\data
resource:
videoDir: ${data.homeDir}\resources\videos
#data:
# homeDir: D:\data
#resource:
# videoDir: ${data.homeDir}\resources\videos
qr:
cloud: http://pqmcc.com:18082/api/file
dev:

View File

@@ -0,0 +1,50 @@
package com.njcn.gather.system.config;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.File;
/**
* @author caozehui
* @data 2026-05-28
*/
@Component
public class PathConfig {
private String appPath;
@PostConstruct
public void init() {
// 获取程序运行目录
appPath = System.getProperty("user.dir");
// 或者获取jar包所在目录
// appPath = new File(getClass().getProtectionDomain()
// .getCodeSource().getLocation().getPath()).getParent();
}
public String getAppPath() {
return appPath;
}
public String getLogPath() {
return appPath + File.separator + "logs";
}
public String getDataPath() {
return appPath + File.separator + "data";
}
public String getReportTemplatePath() {
return this.getDataPath() + File.separator + "template";
}
public String getReportPath() {
return this.getDataPath() + File.separator + "report";
}
public String getResourcePath() {
return this.getDataPath() + File.separator + "resource";
}
}

View File

@@ -65,6 +65,20 @@ public class ResourceManageController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
@PostMapping("/update")
@ApiOperation("编辑资源信息")
@ApiImplicitParam(name = "updateParam", value = "资源参数", required = true)
public HttpResult<Boolean> update(@RequestBody @Validated ResourceManageParam.UpdateParam updateParam) {
String methodDescribe = getMethodDescribe("update");
LogUtil.njcnDebug(log, "{},编辑资源参数为:{}", methodDescribe, updateParam);
boolean result = resourceManageService.update(updateParam);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
}
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@GetMapping("/play")
@ApiOperation("获取视频播放地址")

View File

@@ -19,7 +19,8 @@ public enum ResourceManageResponseEnum {
PLAY_TOKEN_INVALID("A013009", "播放授权无效"),
PLAY_TOKEN_EXPIRED("A013010", "播放授权已过期"),
RANGE_INVALID("A013011", "视频请求范围非法"),
DISK_SPACE_NOT_ENOUGH("A013012", "磁盘空间不足");
DISK_SPACE_NOT_ENOUGH("A013012", "磁盘空间不足"),
ID_NOT_BLANK("A013013", "资源id不能为空");
private final String code;
private final String message;

View File

@@ -21,6 +21,18 @@ public class ResourceManageParam {
@ApiModelProperty(value = "视频文件", required = true)
private MultipartFile file;
@Data
public static class UpdateParam {
@ApiModelProperty(value = "资源id", required = true)
private String id;
@ApiModelProperty(value = "资源名称", required = true)
private String name;
@ApiModelProperty(value = "备注", required = true)
private String remark;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class QueryParam extends BaseParam {

View File

@@ -18,6 +18,8 @@ public interface IResourceManageService extends IService<ResourceManage> {
boolean add(ResourceManageParam resourceManageParam);
boolean update(ResourceManageParam.UpdateParam updateParam);
PlayVO play(String id);
void stream(String id, String token, String rangeHeader, HttpServletResponse response);

View File

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.gather.system.config.PathConfig;
import com.njcn.gather.system.resource.mapper.ResourceManageMapper;
import com.njcn.gather.system.resource.pojo.enums.ResourceManageResponseEnum;
import com.njcn.gather.system.resource.pojo.param.ResourceManageParam;
@@ -19,7 +20,6 @@ import com.njcn.web.utils.RequestUtil;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@@ -53,8 +53,9 @@ public class ResourceManageServiceImpl extends ServiceImpl<ResourceManageMapper,
private static final ConcurrentHashMap<String, PlayToken> PLAY_TOKEN_CACHE = new ConcurrentHashMap<>();
@Value("${resource.videoDir:D:/data/resources/videos}")
private String videoDir;
// @Value("${resource.videoDir:D:/data/resources/videos}")
// private String videoDir;
private final PathConfig pathConfig;
@Override
public Page<ResourceManageVO> list(ResourceManageParam.QueryParam queryParam) {
@@ -93,7 +94,7 @@ public class ResourceManageServiceImpl extends ServiceImpl<ResourceManageMapper,
String originalFilename = file.getOriginalFilename();
String dateDir = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
String savedFileName = UUID.randomUUID().toString().replace("-", "") + MP4_SUFFIX;
Path rootPath = Paths.get(videoDir).toAbsolutePath().normalize();
Path rootPath = Paths.get(pathConfig.getResourcePath()).toAbsolutePath().normalize();
Path targetDir = rootPath.resolve(dateDir).normalize();
Path targetFile = targetDir.resolve(savedFileName).normalize();
ensurePathInRoot(rootPath, targetFile);
@@ -134,6 +135,19 @@ public class ResourceManageServiceImpl extends ServiceImpl<ResourceManageMapper,
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean update(ResourceManageParam.UpdateParam updateParam) {
validateUpdateParam(updateParam);
getEnabledResource(updateParam.getId());
return this.lambdaUpdate()
.set(ResourceManage::getName, updateParam.getName().trim())
.set(ResourceManage::getRemark, updateParam.getRemark().trim())
.eq(ResourceManage::getId, updateParam.getId())
.eq(ResourceManage::getState, DataStateEnum.ENABLE.getCode())
.update();
}
@Override
public PlayVO play(String id) {
ResourceManage resourceManage = getEnabledResource(id);
@@ -217,6 +231,18 @@ public class ResourceManageServiceImpl extends ServiceImpl<ResourceManageMapper,
}
}
private void validateUpdateParam(ResourceManageParam.UpdateParam param) {
if (param == null || StrUtil.isBlank(param.getId())) {
throw new BusinessException(ResourceManageResponseEnum.ID_NOT_BLANK);
}
if (StrUtil.isBlank(param.getName())) {
throw new BusinessException(ResourceManageResponseEnum.NAME_NOT_BLANK);
}
if (StrUtil.isBlank(param.getRemark())) {
throw new BusinessException(ResourceManageResponseEnum.REMARK_NOT_BLANK);
}
}
private ResourceManage getEnabledResource(String id) {
ResourceManage resourceManage = this.lambdaQuery()
.eq(ResourceManage::getId, id)
@@ -229,7 +255,7 @@ public class ResourceManageServiceImpl extends ServiceImpl<ResourceManageMapper,
}
private Path resolveResourcePath(ResourceManage resourceManage) {
Path rootPath = Paths.get(videoDir).toAbsolutePath().normalize();
Path rootPath = Paths.get(pathConfig.getResourcePath()).toAbsolutePath().normalize();
String relativePath = resourceManage.getRelativePath().replace("\\", "/");
String prefix = RELATIVE_VIDEO_ROOT + "/";
if (!relativePath.startsWith(prefix)) {