主设备上传文件逻辑

This commit is contained in:
weitang 2025-06-05 10:36:14 +08:00
parent acbd0eae9e
commit e056f1931f
15 changed files with 111 additions and 22 deletions

View File

@ -128,9 +128,9 @@ public class IEC61850Service {
if (ObjUtil.isNotEmpty(deviceSignal)) {
//查找设备
MeterDevice meterDevice = meterDeviceService.getById(deviceSignal.getMeterDeviceId());
QueryWrapper<GatewayDevice> queryWrapper = new QueryWrapper<>();
LambdaQueryWrapper<GatewayDevice> queryWrapper = new LambdaQueryWrapper<>();
//通讯网关机的IP地址
queryWrapper.eq("ip_addr", meterDevice.getNetdeviceIp());
queryWrapper.eq(GatewayDevice::getIpAddr, meterDevice.getNetdeviceIp());
//查找网关机
GatewayDevice gatewayDevice = gatewayDeviceService.getOne(queryWrapper);
String convalue = value;

View File

@ -111,6 +111,10 @@ public class HttpServerConfig {
@Value("${httpserver.patrolserver.documentpath}")
private String documentPath;
@Value("${httpserver.patrolserver.maindevicefilepath}")
private String mainDeviceFilepath;
@Value("${httpserver.patrolserver.tempfilepath}")
private String tempFilePath;
@ -255,6 +259,10 @@ public class HttpServerConfig {
return documentPath;
}
public String getMainDeviceFilepath() {
return mainDeviceFilepath;
}
public String getTempFilePath() {
return tempFilePath;
}

View File

@ -34,6 +34,10 @@ public class WebConfig implements WebMvcConfigurer {
@Value("${httpserver.patrolserver.alarmfilepath}")
private String alarmFilePath;
@Value("${httpserver.patrolserver.maindevicefilepath}")
private String mainDeviceFilepath;
@Resource
private ISubstationDeviceService substationDeviceService;
@ -94,6 +98,10 @@ public class WebConfig implements WebMvcConfigurer {
// 告警图片
String alarmUrl = "file:" + alarmFilePath;
registry.addResourceHandler("/alarm/**").addResourceLocations(alarmUrl).setCachePeriod(0);
// 告警图片
String mainDeviceUrl = "file:" + mainDeviceFilepath;
registry.addResourceHandler("/mainDevice/**").addResourceLocations(mainDeviceUrl).setCachePeriod(0);
}
}

View File

@ -36,10 +36,11 @@ public class AlgorithmLogsController {
@GetMapping("/getAlgorithmLogsPage")
@ApiOperation("分页查询算法分析日志")
public ResponseResult getAlgorithmLogsPage(String stationCode, String algorithmId, String areaId, String bayId,
String mainDeviceId, String componentId, String componentName,
String mainDeviceId, String componentId, String componentName,String startDate,
String endDate,
Page<AlgorithmLogs> page) {
Page<Map<String, Object>> pageMaps = algorithmLogsService.getAlgorithmLogsPage(stationCode, algorithmId, areaId,
bayId, mainDeviceId, componentId, componentName, page);
bayId, mainDeviceId, componentId, componentName,startDate,endDate, page);
return ResponseResult.successData(pageMaps);
}

View File

@ -27,5 +27,6 @@ public interface AlgorithmLogsMapper extends BaseMapper<AlgorithmLogs> {
* 参数说明 page 分页参数
* 返回值说明: com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.yfd.platform.modules.algorithm.domain.AlgorithmLogs>
***********************************/
Page<Map<String,Object>> getAlgorithmLogsPage(String stationCode, String algorithmId, String areaId, String bayId, String mainDeviceId, String componentId, String componentName, Page<AlgorithmLogs> page);
Page<Map<String,Object>> getAlgorithmLogsPage(String stationCode, String algorithmId, String areaId, String bayId, String mainDeviceId, String componentId, String componentName,String startDate,
String endDate, Page<AlgorithmLogs> page);
}

View File

@ -27,6 +27,7 @@ public interface IAlgorithmLogsService extends IService<AlgorithmLogs> {
* 参数说明 page 分页参数
* 返回值说明: com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.yfd.platform.modules.algorithm.domain.AlgorithmLogs>
***********************************/
Page<Map<String,Object>> getAlgorithmLogsPage(String stationCode, String algorithmId, String areaId, String bayId, String mainDeviceId, String componentId, String componentName, Page<AlgorithmLogs> page);
Page<Map<String,Object>> getAlgorithmLogsPage(String stationCode, String algorithmId, String areaId, String bayId, String mainDeviceId, String componentId, String componentName,String startDate,
String endDate, Page<AlgorithmLogs> page);
}

View File

@ -37,8 +37,9 @@ public class AlgorithmLogsServiceImpl extends ServiceImpl<AlgorithmLogsMapper, A
***********************************/
@Override
public Page<Map<String,Object>> getAlgorithmLogsPage(String stationCode, String algorithmId, String areaId, String bayId,
String mainDeviceId, String componentId, String componentName, Page<AlgorithmLogs> page) {
String mainDeviceId, String componentId, String componentName,String startDate,
String endDate, Page<AlgorithmLogs> page) {
return algorithmLogsMapper.getAlgorithmLogsPage(stationCode,algorithmId, areaId, bayId,
mainDeviceId, componentId,componentName, page);
mainDeviceId, componentId,componentName,startDate,endDate, page);
}
}

View File

@ -68,7 +68,8 @@ public class SubstationMaindeviceController {
@PostMapping("/addMainDevice")
@ApiOperation("新增主设备")
@PreAuthorize("@el.check('add:maindevice')")
public ResponseResult addMainDevice(SubstationMaindevice substationMaindevice) {
public ResponseResult addMainDevice(SubstationMaindevice substationMaindevice,
MultipartFile file) {
String mainDeviceName = substationMaindevice.getMainDeviceName();
String bayId = substationMaindevice.getBayId();
int count =
@ -82,6 +83,16 @@ public class SubstationMaindeviceController {
substationMaindevice.setDatastatus("1");
substationMaindevice.setLastmodifier(SecurityUtils.getCurrentUsername());
substationMaindevice.setLastmodifydate(LocalDateTime.now());
// 文件上传逻辑
if (file != null && !file.isEmpty()) {
try {
// 调用服务层方法
String fileUrl = substationMaindeviceService.uploadImage(file);
substationMaindevice.setFileUrl(fileUrl);
} catch (Exception e) {
return ResponseResult.error("文件上传失败:" + e.getMessage());
}
}
boolean ok = substationMaindeviceService.save(substationMaindevice);
if (ok) {
return ResponseResult.success();
@ -282,7 +293,8 @@ public class SubstationMaindeviceController {
@PostMapping("/updateMainDevice")
@ApiOperation("修改主设备")
@PreAuthorize("@el.check('update:maindevice')")
public ResponseResult updateMainDevice(SubstationMaindevice substationMaindevice) {
public ResponseResult updateMainDevice(SubstationMaindevice substationMaindevice,
MultipartFile file) {
if (substationMaindevice == null) {
return ResponseResult.error("参数为空");
}
@ -303,6 +315,16 @@ public class SubstationMaindeviceController {
}
substationMaindevice.setLastmodifier(SecurityUtils.getCurrentUsername());
substationMaindevice.setLastmodifydate(LocalDateTime.now());
// 文件上传逻辑
if (file != null && !file.isEmpty()) {
try {
String fileUrl = substationMaindeviceService.uploadImage(file); // 调用服务层方法
substationMaindevice.setFileUrl(fileUrl);
} catch (Exception e) {
return ResponseResult.error("文件上传失败:" + e.getMessage());
}
}
boolean ok = substationMaindeviceService.updateById(substationMaindevice);
if (ok) {
return ResponseResult.success();

View File

@ -72,6 +72,21 @@ public class SubstationMaindevice implements Serializable {
*/
private String areaName;
/**
* 出厂寿命
*/
private String factoryLifespan;
/**
* 初始运行时间设备第一次运行的时间
*/
private LocalDateTime runTime;
/**
* 主设备效果图地址
*/
private String fileUrl;
/**
* 数据状态
*/
@ -108,4 +123,5 @@ public class SubstationMaindevice implements Serializable {
*/
@TableField("material_id")
private String materialId;
}

View File

@ -146,4 +146,5 @@ public interface ISubstationMaindeviceService extends IService<SubstationMaindev
***********************************/
List<TreeNode> getComponentTree(String stationCode, String componentName);
String uploadImage(MultipartFile file);
}

View File

@ -1,9 +1,11 @@
package com.yfd.platform.modules.basedata.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfd.platform.config.HttpServerConfig;
import com.yfd.platform.modules.auxcontrol.domain.DeviceSignal;
import com.yfd.platform.modules.auxcontrol.service.IDeviceSignalService;
import com.yfd.platform.modules.basedata.domain.*;
@ -13,6 +15,7 @@ import com.yfd.platform.system.domain.SysDictionary;
import com.yfd.platform.system.domain.SysDictionaryItems;
import com.yfd.platform.system.service.ISysDictionaryItemsService;
import com.yfd.platform.system.service.ISysDictionaryService;
import com.yfd.platform.utils.FileUtil;
import com.yfd.platform.utils.SecurityUtils;
import freemarker.template.utility.NullArgumentException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@ -26,13 +29,11 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -40,7 +41,6 @@ import java.util.stream.Collectors;
* 变电站_主设备 服务实现类
* </p>
*
*
* @since 2023-03-28
*/
@Transactional
@ -68,6 +68,9 @@ public class SubstationMaindeviceServiceImpl extends ServiceImpl<SubstationMaind
@Resource
private IDeviceSignalService deviceSignalService;
@Resource
private HttpServerConfig httpServerConfig;
/**********************************
* 用途说明: 获取主设备及部件树
* 参数说明 name 参数名称
@ -737,6 +740,18 @@ public class SubstationMaindeviceServiceImpl extends ServiceImpl<SubstationMaind
return treeNodes.get(0).getChildren();
}
@Override
public String uploadImage(MultipartFile file) {
// 文件存储地址
String fileName =
IdUtil.fastSimpleUUID() + "." + FileUtil.getExtensionName(file.getOriginalFilename());
// 上传文件
String name =
Objects.requireNonNull(FileUtil.upload(file, httpServerConfig.getMainDeviceFilepath(), fileName)).getName();
return name;
}
/**********************************
* 用途说明: 构造树
* 参数说明 dataList 名称

View File

@ -233,13 +233,18 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
*/
public static File upload(MultipartFile file, String filePath,String tofilename) {
if (file == null || file.isEmpty()) {
log.warn("上传文件为空");
return null;
}
try {
String filename = filePath + File.separator + tofilename;
File dest = new File(filename).getCanonicalFile();
// 检测是否存在目录
if (!dest.getParentFile().exists()) {
if (!dest.getParentFile().mkdirs()) {
}
File parentDir = dest.getParentFile();
if (parentDir != null && !parentDir.exists() && !parentDir.mkdirs()) {
log.warn("无法创建父目录: {}", parentDir.getAbsolutePath());
return null;
}
// 文件写入
file.transferTo(dest);

View File

@ -148,6 +148,7 @@ httpserver: #配置http请求访问的地址
dotask: true #是否执行定期任务
snapfilepath: d:\riis\video\ #视频截图文件路径
alarmfilepath: d:\riis\alarm\ #报警图片存储路径
maindevicefilepath: d:\riis\maindevice\ #主设备文件存储地址
tempfilepath: d:\riis\temp\ #模板图片路径
ffmpegpath: E:\ffmpeg\bin\ #ffmpeg截图命名路径
modelpath: d:\riis\model\

View File

@ -148,6 +148,7 @@ httpserver: #配置http请求访问的地址
dotask: true #是否执行定期任务
snapfilepath: d:\riis\video\ #视频截图文件路径
alarmfilepath: d:\riis\alarm\ #报警图片存储路径
maindevicefilepath: d:\riis\maindevice\ #主设备文件存储地址
tempfilepath: d:\riis\temp\ #模板图片路径
ffmpegpath: E:\ffmpeg\bin\ #ffmpeg截图命名路径
modelpath: d:\riis\model\

View File

@ -4,7 +4,8 @@
<!--分页查询算法分析日志-->
<select id="getAlgorithmLogsPage" resultType="java.util.Map">
SELECT
SELECT COALESCE
( al.analysis_result ->> '$.description', '' ) description,
ac.algorithm_class_name,
al.*
FROM
@ -32,5 +33,12 @@
<if test="componentName != null and componentName != ''">
AND al.component_name = #{componentName}
</if>
<if test="startDate != null and startDate != ''">
AND str_to_date(al.analysis_time, '%Y-%m-%d %H:%i:%s') &gt;= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
AND str_to_date(al.analysis_time, '%Y-%m-%d %H:%i:%s') &lt;= #{endDate}
</if>
ORDER BY al.analysis_time DESC
</select>
</mapper>