diff --git a/das/src/main/java/com/das/modules/cache/service/impl/EquipmentCacheImpl.java b/das/src/main/java/com/das/modules/cache/service/impl/EquipmentCacheImpl.java index 5f50a77d..6426fa40 100644 --- a/das/src/main/java/com/das/modules/cache/service/impl/EquipmentCacheImpl.java +++ b/das/src/main/java/com/das/modules/cache/service/impl/EquipmentCacheImpl.java @@ -19,13 +19,12 @@ public class EquipmentCacheImpl implements EquipmentCache { @Autowired SysEquipmentMapper sysEquipmentMapper; - private final List deviceInfoCaches = Collections.synchronizedList(new ArrayList<>()); /** * 设备CODE索引,用于通过设备CODE访问设备缓存信息 */ - private final ConcurrentHashMap deviceCodeIndex = new ConcurrentHashMap<>(); - private final ConcurrentHashMap deviceIdIndex = new ConcurrentHashMap<>(); + private final ConcurrentHashMap deviceCodeIndex = new ConcurrentHashMap<>(); + private final ConcurrentHashMap deviceIdIndex = new ConcurrentHashMap<>(); /** * 初始化设备缓存 @@ -44,11 +43,10 @@ public class EquipmentCacheImpl implements EquipmentCache { deviceInfoCache.setMadeinFactory(equipment.getMadeinFactory()); deviceInfoCache.setParentDeviceId(equipment.getParentEquipmentId()); deviceInfoCache.setIotModelId(equipment.getIotModelId()); - deviceInfoCaches.add(deviceInfoCache); //创建Code索引 - deviceCodeIndex.put(deviceInfoCache.getDeviceCode(),i); + deviceCodeIndex.put(deviceInfoCache.getDeviceCode(),deviceInfoCache); //创建Id索引 - deviceIdIndex.put(equipment.getId(),i); + deviceIdIndex.put(equipment.getId(),deviceInfoCache); } } @@ -57,8 +55,8 @@ public class EquipmentCacheImpl implements EquipmentCache { */ @PreDestroy private void freeDeviceInfoCaches() { - deviceInfoCaches.clear(); deviceCodeIndex.clear(); + deviceIdIndex.clear(); } @@ -68,7 +66,7 @@ public class EquipmentCacheImpl implements EquipmentCache { */ @Override public List getDevicesCache() { - return Collections.unmodifiableList(deviceInfoCaches); + return deviceIdIndex.values().stream().toList(); } @Override @@ -84,43 +82,29 @@ public class EquipmentCacheImpl implements EquipmentCache { deviceInfoCache.setObjectType(equipment.getObjectType()); deviceInfoCache.setParentDeviceId(equipment.getParentEquipmentId()); deviceInfoCache.setIotModelId(equipment.getIotModelId()); - //如果是已经缓存过的设备直接缓存 - Integer index = deviceIdIndex.get(deviceId); - if (index != null) { - deviceInfoCaches.set(index, deviceInfoCache); - } - else{ - deviceInfoCaches.add(deviceInfoCache); - index = deviceInfoCaches.size() - 1; - deviceCodeIndex.put(deviceInfoCache.getDeviceCode(),index); - deviceIdIndex.put(equipment.getId(),index); - } + + deviceIdIndex.put(deviceId,deviceInfoCache); + deviceCodeIndex.put(deviceInfoCache.getDeviceCode(),deviceInfoCache); } } @Override public DeviceInfoCache getDeviceInfoCacheByCode(String deviceCode) { - Integer index = deviceCodeIndex.get(deviceCode); - if (index != null) { - return deviceInfoCaches.get(index); - } - return null; + return deviceCodeIndex.get(deviceCode); } @Override public DeviceInfoCache getDeviceInfoCacheById(Long deviceId) { - Integer index = deviceIdIndex.get(deviceId); - if (index != null) { - return deviceInfoCaches.get(index); - } - return null; + return deviceIdIndex.get(deviceId); } @Override public void removeDeviceCache(Long deviceId) { - Integer index = deviceIdIndex.get(deviceId); - if (index != null) { - deviceInfoCaches.remove(index); + + DeviceInfoCache cache = deviceIdIndex.get(deviceId); + if (cache != null) { + deviceIdIndex.remove(deviceId); + deviceCodeIndex.remove(cache.getDeviceCode()); } } diff --git a/das/src/main/java/com/das/modules/data/service/impl/DataServiceImpl.java b/das/src/main/java/com/das/modules/data/service/impl/DataServiceImpl.java index 8bb1b9e2..e88d9d07 100644 --- a/das/src/main/java/com/das/modules/data/service/impl/DataServiceImpl.java +++ b/das/src/main/java/com/das/modules/data/service/impl/DataServiceImpl.java @@ -353,7 +353,7 @@ public class DataServiceImpl implements DataService { /** * 获取指定时间区间内的最早的数据 - * @param devcieId + * @param deviceId * @param attr * @param startTime * @param endTime @@ -417,8 +417,12 @@ public class DataServiceImpl implements DataService { // 解析interval的数值和单位 long intervalInMilliseconds = parseIntervalToMilliseconds(interval); + //8小时时区 + long i = 8 * 3600 * 1000L; + long timeChina = startTime + i; + // 计算不能被整除的部分 - return startTime % intervalInMilliseconds; + return timeChina % intervalInMilliseconds; } public long parseIntervalToMilliseconds(String interval) { diff --git a/das/src/main/java/com/das/modules/equipment/controller/EquipmentController.java b/das/src/main/java/com/das/modules/equipment/controller/EquipmentController.java index 7fa6a9f7..e35f05c6 100644 --- a/das/src/main/java/com/das/modules/equipment/controller/EquipmentController.java +++ b/das/src/main/java/com/das/modules/equipment/controller/EquipmentController.java @@ -13,6 +13,7 @@ import com.das.modules.equipment.domain.vo.SysEquipmentVo; import com.das.modules.equipment.entity.SysEquipmentDocs; import com.das.modules.equipment.entity.SysGenExtProps; import com.das.modules.equipment.service.SysEquipmentService; +import io.micrometer.common.util.StringUtils; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -196,8 +197,34 @@ public class EquipmentController { } @RequestMapping(value = "/file/upload", method = RequestMethod.POST) - public R addFile(Long deviceId, String folderName, MultipartFile file) { - SysEquipmentDocs upload = sysEquipmentService.upload(deviceId, folderName, file); + public R> addFile(Long deviceId, String component,String folderName, List fileList) throws Exception { + List upload = sysEquipmentService.upload(deviceId, component,folderName, fileList); return R.success(upload); } + + @RequestMapping(value = "/file/getList", method = RequestMethod.POST) + public R> getFileList(Long deviceId, String component) { + List fileList = sysEquipmentService.getFileList(deviceId, component); + return R.success(fileList); + } + + @RequestMapping(value = "/file/read", method = RequestMethod.POST) + public void readFile(String path, HttpServletResponse response) throws IOException { + if (StringUtils.isBlank(path)){ + throw new ServiceException("请输入浏览的文件路径"); + } + response.setContentType("application/octet-stream"); + sysEquipmentService.readFileToSteam(path, response.getOutputStream()); + + } + + @RequestMapping(value = "/file/delete", method = RequestMethod.GET) + public void deleteFile(String path, HttpServletResponse response) throws IOException { + if (StringUtils.isBlank(path)){ + throw new ServiceException("请输入浏览的文件路径"); + } + response.setContentType("application/octet-stream"); + sysEquipmentService.readFileToSteam(path, response.getOutputStream()); + + } } diff --git a/das/src/main/java/com/das/modules/equipment/domain/dto/SysEquipmentDto.java b/das/src/main/java/com/das/modules/equipment/domain/dto/SysEquipmentDto.java index 89b30c73..f19fbcf1 100644 --- a/das/src/main/java/com/das/modules/equipment/domain/dto/SysEquipmentDto.java +++ b/das/src/main/java/com/das/modules/equipment/domain/dto/SysEquipmentDto.java @@ -1,5 +1,6 @@ package com.das.modules.equipment.domain.dto; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import lombok.Data; @@ -62,6 +63,7 @@ public class SysEquipmentDto implements Serializable { /** * 安装日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") private Date installDate; /** diff --git a/das/src/main/java/com/das/modules/equipment/domain/dto/SysGenExtPropsDto.java b/das/src/main/java/com/das/modules/equipment/domain/dto/SysGenExtPropsDto.java index 6f4201c1..93887550 100644 --- a/das/src/main/java/com/das/modules/equipment/domain/dto/SysGenExtPropsDto.java +++ b/das/src/main/java/com/das/modules/equipment/domain/dto/SysGenExtPropsDto.java @@ -18,89 +18,53 @@ public class SysGenExtPropsDto { @JsonSerialize(using = ToStringSerializer.class) private Long id; - private String fanName; - - private String fanNumber; - - private String fanType; - - private String fanTypeDetails; - private String pitchSystemModel; private String pitchSystemManufacturer; - private String pitchSystemDetails; - private String blade1Model; private String blade1Manufacturer; - private String blade1Details; - private String blade1BearingModel; private String blade1BearingManufacturer; - private String blade1BearingDetails; - private String blade2Model; private String blade2Manufacturer; - private String blade2Details; - private String blade2BearingModel; private String blade2BearingManufacturer; - private String blade2BearingDetails; - private String blade3Model; private String blade3Manufacturer; - private String blade3Details; - private String blade3BearingModel; private String blade3BearingManufacturer; - private String blade3BearingDetails; - private String mainBearingModel; private String mainBearingManufacturer; - private String mainBearingDetails; - private String gearboxModel; private String gearboxManufacturer; - private String gearboxDetails; - private String generatorModel; private String generatorManufacturer; - private String generatorDetails; - private String converterModel; private String converterManufacturer; - private String converterDetails; - private String mainControlSystemModel; private String mainControlSystemManufacturer; private String mainControlSystemSoftwareVersion; - - private String mainControlSystemSoftwareVersionDetails; - - private String towerBaseCabinetDetails; - - private String nacelleCabinetDetails; } diff --git a/das/src/main/java/com/das/modules/equipment/entity/SysEquipmentDocs.java b/das/src/main/java/com/das/modules/equipment/entity/SysEquipmentDocs.java index e4f3096f..ced4545c 100644 --- a/das/src/main/java/com/das/modules/equipment/entity/SysEquipmentDocs.java +++ b/das/src/main/java/com/das/modules/equipment/entity/SysEquipmentDocs.java @@ -17,12 +17,18 @@ import java.util.Date; @AllArgsConstructor public class SysEquipmentDocs { - @TableId(value = "deviceid") + @TableId(value = "id") + private Long id; + + @TableField(value = "deviceid") private Long deviceId; @TableField(value = "name") private String name; + @TableField(value = "component") + private String component; + @TableField(value = "url") private String url; /** diff --git a/das/src/main/java/com/das/modules/equipment/entity/SysGenExtProps.java b/das/src/main/java/com/das/modules/equipment/entity/SysGenExtProps.java index 5fa833fc..ab5de0fc 100644 --- a/das/src/main/java/com/das/modules/equipment/entity/SysGenExtProps.java +++ b/das/src/main/java/com/das/modules/equipment/entity/SysGenExtProps.java @@ -20,18 +20,6 @@ public class SysGenExtProps { @JsonSerialize(using = ToStringSerializer.class) private Long id; - @TableField(value = "fan_name") - private String fanName; - - @TableField(value = "fan_Number") - private String fanNumber; - - @TableField(value = "fan_type") - private String fanType; - - @TableField(value = "fan_type_details") - private String fanTypeDetails; - // Pitch System @TableField(value = "pitch_system_model") private String pitchSystemModel; @@ -39,9 +27,6 @@ public class SysGenExtProps { @TableField(value = "pitch_system_manufacturer") private String pitchSystemManufacturer; - @TableField(value = "pitch_system_details") - private String pitchSystemDetails; - // Blade 1 @TableField(value = "blade1_model") private String blade1Model; @@ -49,18 +34,12 @@ public class SysGenExtProps { @TableField(value = "blade1_manufacturer") private String blade1Manufacturer; - @TableField(value = "blade1_details") - private String blade1Details; - @TableField(value = "blade1_bearing_model") private String blade1BearingModel; @TableField(value = "blade1_bearing_manufacturer") private String blade1BearingManufacturer; - @TableField(value = "blade1_bearing_details") - private String blade1BearingDetails; - // Blade 2 @TableField(value = "blade2_model") private String blade2Model; @@ -68,18 +47,12 @@ public class SysGenExtProps { @TableField(value = "blade2_manufacturer") private String blade2Manufacturer; - @TableField(value = "blade2_details") - private String blade2Details; - @TableField(value = "blade2_bearing_model") private String blade2BearingModel; @TableField(value = "blade2_bearing_manufacturer") private String blade2BearingManufacturer; - @TableField(value = "blade2_bearing_details") - private String blade2BearingDetails; - // Blade 3 @TableField(value = "blade3_model") private String blade3Model; @@ -87,18 +60,12 @@ public class SysGenExtProps { @TableField(value = "blade3_manufacturer") private String blade3Manufacturer; - @TableField(value = "blade3_details") - private String blade3Details; - @TableField(value = "blade3_bearing_model") private String blade3BearingModel; @TableField(value = "blade3_bearing_manufacturer") private String blade3BearingManufacturer; - @TableField(value = "blade3_bearing_details") - private String blade3BearingDetails; - // Main Bearing @TableField(value = "main_bearing_model") private String mainBearingModel; @@ -106,9 +73,6 @@ public class SysGenExtProps { @TableField(value = "main_bearing_manufacturer") private String mainBearingManufacturer; - @TableField(value = "main_bearing_details") - private String mainBearingDetails; - // Gearbox @TableField(value = "gearbox_model") private String gearboxModel; @@ -116,9 +80,6 @@ public class SysGenExtProps { @TableField(value = "gearbox_manufacturer") private String gearboxManufacturer; - @TableField(value = "gearbox_details") - private String gearboxDetails; - // Generator @TableField(value = "generator_model") private String generatorModel; @@ -126,9 +87,6 @@ public class SysGenExtProps { @TableField(value = "generator_manufacturer") private String generatorManufacturer; - @TableField(value = "generator_details") - private String generatorDetails; - // Converter @TableField(value = "converter_model") private String converterModel; @@ -136,9 +94,6 @@ public class SysGenExtProps { @TableField(value = "converter_manufacturer") private String converterManufacturer; - @TableField(value = "converter_details") - private String converterDetails; - // Main Control System @TableField(value = "main_control_system_model") private String mainControlSystemModel; @@ -148,15 +103,4 @@ public class SysGenExtProps { @TableField(value = "main_control_system_software_version") private String mainControlSystemSoftwareVersion; - - @TableField(value = "main_control_system_software_version_details") - private String mainControlSystemSoftwareVersionDetails; - - // Cabinet Details - - @TableField(value = "tower_base_cabinet_details") - private String towerBaseCabinetDetails; - - @TableField(value = "nacelle_cabinet_details") - private String nacelleCabinetDetails; } diff --git a/das/src/main/java/com/das/modules/equipment/service/SysEquipmentService.java b/das/src/main/java/com/das/modules/equipment/service/SysEquipmentService.java index b85657e9..90ba395f 100644 --- a/das/src/main/java/com/das/modules/equipment/service/SysEquipmentService.java +++ b/das/src/main/java/com/das/modules/equipment/service/SysEquipmentService.java @@ -11,6 +11,7 @@ import jakarta.servlet.http.HttpServletResponse; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.io.OutputStream; import java.text.ParseException; import java.util.List; @@ -39,5 +40,11 @@ public interface SysEquipmentService { SysGenExtProps querySysEquipmentExtProps(Long id); - SysEquipmentDocs upload(Long deviceId, String folderName, MultipartFile file); + List upload(Long deviceId, String component,String folderName, List fileList) throws Exception; + + List getFileList(Long deviceId, String component); + + void readFileToSteam(String path, OutputStream stream); + + void deleteFile(String path); } diff --git a/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java b/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java index 2474085f..0524103c 100644 --- a/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java +++ b/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java @@ -1,6 +1,7 @@ package com.das.modules.equipment.service.impl; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.img.ImgUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.poi.excel.ExcelReader; @@ -41,6 +42,7 @@ import jakarta.annotation.Resource; import jakarta.servlet.ServletOutputStream; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.VerticalAlignment; @@ -50,10 +52,12 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; -import java.io.IOException; -import java.io.InputStream; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.*; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import java.rmi.ServerException; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -64,6 +68,7 @@ import java.util.List; @Transactional(rollbackFor = Exception.class) @Service +@Slf4j public class SysEquipmentServiceImpl implements SysEquipmentService { @Autowired @@ -98,6 +103,10 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { @Autowired private SysEquipmentDocsMapper sysEquipmentDocsMapper; + // 7厘米转换为像素(以300 DPI为基准) + private static final int TARGET_WIDTH = 826; // 7厘米 * 300 DPI / 2.54 + private static final int TARGET_HEIGHT = 826; // 7厘米 * 300 DPI / 2.54 + @Override public SysEquipmentVo creatSysEquipment(SysEquipmentDto sysEquipmentDto) { @@ -118,8 +127,8 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { sysEquipment.setRevision(1); sysEquipmentMapper.insert(sysEquipment); //物模型不为空 增加设备物模型mapping缓存 - if (sysEquipment.getIotModelId() != null){ - dataService.deviceModelMap.put(sysEquipment.getId().toString(),dataService.iotModelMap.get(sysEquipment.getIotModelId().toString())); + if (sysEquipment.getIotModelId() != null) { + dataService.deviceModelMap.put(sysEquipment.getId().toString(), dataService.iotModelMap.get(sysEquipment.getIotModelId().toString())); } //更新设备缓存 cacheService.getEquipmentCache().refreshDeviceCache(sysEquipment.getId()); @@ -147,14 +156,14 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { sysEquipment.setUpdatedBy(sysUserVo.getAccount()); sysEquipmentMapper.updateById(sysEquipment); - if (oldModelSysEquipInfo.getIotModelId() == null && sysEquipment.getIotModelId() != null){ - dataService.deviceModelMap.put(sysEquipment.getId().toString(),dataService.iotModelMap.get(sysEquipment.getIotModelId().toString())); + if (oldModelSysEquipInfo.getIotModelId() == null && sysEquipment.getIotModelId() != null) { + dataService.deviceModelMap.put(sysEquipment.getId().toString(), dataService.iotModelMap.get(sysEquipment.getIotModelId().toString())); } //更新设备缓存 cacheService.getEquipmentCache().refreshDeviceCache(sysEquipment.getId()); - if (tdEngineService.checkTableExist("e_"+sysEquipment.getId())){ - tdEngineService.updateTagDeviceCode("e_"+sysEquipment.getId(),sysEquipment.getCode()); - tdEngineService.updateTagDeviceName("e_"+sysEquipment.getId(),sysEquipment.getName()); + if (tdEngineService.checkTableExist("e_" + sysEquipment.getId())) { + tdEngineService.updateTagDeviceCode("e_" + sysEquipment.getId(), sysEquipment.getCode()); + tdEngineService.updateTagDeviceName("e_" + sysEquipment.getId(), sysEquipment.getName()); } SysEquipmentVo sysEquipmentVo = new SysEquipmentVo(); BeanCopyUtils.copy(sysEquipment, sysEquipmentVo); @@ -170,7 +179,7 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { sysEquipmentMapper.deleteById(sysEquipmentDto.getId()); //删除缓存 //更新设备缓存 - cacheService.getEquipmentCache().refreshDeviceCache(sysEquipmentDto.getId()); + cacheService.getEquipmentCache().removeDeviceCache(sysEquipmentDto.getId()); dataService.deviceModelMap.remove(sysEquipmentDto.getId().toString()); } @@ -187,10 +196,10 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { public List queryAllSysEquipmentList(SysEquipmentDto sysEquipmentDto) { // 查询当前账号机构下的子机构和子设备 QueryWrapper queryWrapper = new QueryWrapper<>(); - if (sysEquipmentDto.getOrgId() !=null){ + if (sysEquipmentDto.getOrgId() != null) { queryWrapper.eq("org_id", sysEquipmentDto.getOrgId()); } - if (sysEquipmentDto.getParentEquipmentId() !=null){ + if (sysEquipmentDto.getParentEquipmentId() != null) { queryWrapper.eq("parent_equipment_id", sysEquipmentDto.getParentEquipmentId()); } queryWrapper.eq("object_type", sysEquipmentDto.getObjectType()); @@ -209,9 +218,10 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { /** * 设备台账导出Excel + * * @param sysEquipmentDto 查询参数 - * @param request HttpServletRequest - * @param response HttpServletResponse + * @param request HttpServletRequest + * @param response HttpServletResponse */ @Override public void exportSysEquipment(SysEquipmentDto sysEquipmentDto, HttpServletRequest request, HttpServletResponse response) { @@ -278,18 +288,18 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { List delSysEquipmentList = new ArrayList<>(); // 遍历 for (List row : list) { - if (ObjectUtil.isAllNotEmpty(row.get(4),row.get(1),row.get(5))){ - throw new ServerException("请检查必填参数:"+row); + if (ObjectUtil.isAllNotEmpty(row.get(4), row.get(1), row.get(5))) { + throw new ServerException("请检查必填参数:" + row); } - if (!Integer.valueOf(row.get(1).toString()).equals(EquipmentTypeIds.EQUIPMENT_TYPE_STATION_WTG) && !Integer.valueOf(row.get(1).toString()).equals(EquipmentTypeIds.EQUIPMENT_TYPE_WIND_FARM)){ - throw new ServerException("设备类型编码错误"+ row.get(1)); + if (!Integer.valueOf(row.get(1).toString()).equals(EquipmentTypeIds.EQUIPMENT_TYPE_STATION_WTG) && !Integer.valueOf(row.get(1).toString()).equals(EquipmentTypeIds.EQUIPMENT_TYPE_WIND_FARM)) { + throw new ServerException("设备类型编码错误" + row.get(1)); } SysEquipment field = new SysEquipment(); // 根据编码获取物模型id if (StringUtils.hasText(row.get(2).toString())) { Long iotModelId = sysIotModelMapper.queryIotModelIdByCode(row.get(2).toString()); - if (iotModelId == null){ - throw new ServerException("物模型编码错误,错误编码:"+ row.get(2).toString()); + if (iotModelId == null) { + throw new ServerException("物模型编码错误,错误编码:" + row.get(2).toString()); } field.setIotModelId(iotModelId); } @@ -323,7 +333,7 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { field.setParentEquipmentId(Long.valueOf(parentEquipmentId)); SysEquipmentVo info = sysEquipmentMapper.queryEquipmentInfoByCode(field.getCode()); - if(info == null) { + if (info == null) { if ("I".equals(row.get(0))) { //加入集合 // 遍历完一个添加一个 @@ -348,35 +358,35 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { } } sysEquipmentMapper.insertBatch(addSysEquipmentList); - for (SysEquipment item : addSysEquipmentList){ - if (item.getIotModelId() != null){ + for (SysEquipment item : addSysEquipmentList) { + if (item.getIotModelId() != null) { String modelCode = dataService.iotModelMap.get(item.getIotModelId().toString()); - dataService.deviceModelMap.put(item.getId().toString(),modelCode); + dataService.deviceModelMap.put(item.getId().toString(), modelCode); } //更新设备缓存 cacheService.getEquipmentCache().refreshDeviceCache(item.getId()); } if (CollectionUtils.isNotEmpty(updateSysEquipmentList)) { sysEquipmentMapper.updateBatchById(updateSysEquipmentList); - for (SysEquipment item : updateSysEquipmentList){ - if (item.getIotModelId() != null){ + for (SysEquipment item : updateSysEquipmentList) { + if (item.getIotModelId() != null) { String modelCode = dataService.iotModelMap.get(item.getIotModelId().toString()); - dataService.deviceModelMap.put(item.getId().toString(),modelCode); + dataService.deviceModelMap.put(item.getId().toString(), modelCode); } //更新设备缓存 cacheService.getEquipmentCache().refreshDeviceCache(item.getId()); //更新td表TAG - if (tdEngineService.checkTableExist("e_"+item.getId())){ - tdEngineService.updateTagDeviceCode("e_"+item.getId(),item.getCode()); - tdEngineService.updateTagDeviceName("e_"+item.getId(),item.getName()); + if (tdEngineService.checkTableExist("e_" + item.getId())) { + tdEngineService.updateTagDeviceCode("e_" + item.getId(), item.getCode()); + tdEngineService.updateTagDeviceName("e_" + item.getId(), item.getName()); } } } if (CollectionUtils.isNotEmpty(delSysEquipmentList)) { // 删除设备 sysEquipmentMapper.deleteBatchIds(delSysEquipmentList); - for (SysEquipment item : delSysEquipmentList){ + for (SysEquipment item : delSysEquipmentList) { dataService.deviceModelMap.remove(item.getId().toString()); //更新设备缓存 cacheService.getEquipmentCache().removeDeviceCache(item.getId()); @@ -387,7 +397,7 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { @Override public SysGenExtProps creatSysEquipmentExtProps(SysGenExtPropsDto sysGenExtPropsDto) { - if (sysGenExtPropsDto.getId() == null){ + if (sysGenExtPropsDto.getId() == null) { throw new ServiceException("设备id不能为空"); } SysGenExtProps sysEquipmentExtProps = new SysGenExtProps(); @@ -398,7 +408,7 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { @Override public SysGenExtProps updateSysEquipmentExtProps(SysGenExtPropsDto sysGenExtPropsDto) { - if (sysGenExtPropsDto.getId() == null){ + if (sysGenExtPropsDto.getId() == null) { throw new ServiceException("设备id不能为空"); } SysGenExtProps sysEquipmentExtProps = new SysGenExtProps(); @@ -410,6 +420,17 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { @Override public void deleteSysEquipmentExtProps(Long id) { sysGenExtPropsMapper.deleteById(id); + //查询设备下的所有图片 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("deviceid",id); + List sysEquipmentDocsList = sysEquipmentDocsMapper.selectList(queryWrapper); + if (CollectionUtils.isNotEmpty(sysEquipmentDocsList)){ + for (SysEquipmentDocs item : sysEquipmentDocsList){ + deleteFile(item.getUrl()); + sysEquipmentDocsMapper.deleteById(item.getId()); + } + + } } @Override @@ -418,22 +439,108 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { } @Override - public SysEquipmentDocs upload(Long deviceId, String folderName, MultipartFile file) { - DeviceInfoCache deviceInfoCache = equipmentCache.getDeviceInfoCacheById(deviceId); - String parent = FileConstants.FILE_SEPARATOR +"风机图片"+ FileConstants.FILE_SEPARATOR + deviceInfoCache.getDeviceCode(); - String url = minioViewsServcie.upload(minioAutoProperties.getPublicBucket(), parent, folderName, file); - String fileName = url.substring(url.lastIndexOf("/")); + public List upload(Long deviceId, String component, String folderName, List fileList) throws Exception { + List result = new ArrayList<>(); + for (MultipartFile file : fileList) { + DeviceInfoCache deviceInfoCache = equipmentCache.getDeviceInfoCacheById(deviceId); + String parent = FileConstants.FILE_SEPARATOR + "WindTurbine" + FileConstants.FILE_SEPARATOR + deviceInfoCache.getDeviceCode() + FileConstants.FILE_SEPARATOR + "pic"; + File scale = null; + try { + String url = minioViewsServcie.upload(minioAutoProperties.getPublicBucket(), parent, folderName, file); + scale = scale(file); + String scaleFileName = scale.getName(); + String scaleName = scaleFileName.substring(scaleFileName.lastIndexOf("_") + 1); + String scaleParent = FileConstants.FILE_SEPARATOR + "WindTurbine" + FileConstants.FILE_SEPARATOR + deviceInfoCache.getDeviceCode() + FileConstants.FILE_SEPARATOR + "thumbnailPic" + FileConstants.FILE_SEPARATOR + scaleName; + minioViewsServcie.uploadTemFile(minioAutoProperties.getPublicBucket(), scale, scaleParent); + String fileName = url.substring(url.lastIndexOf("/") + 1); + SysEquipmentDocs sysEquipmentDocs = saveDocs(deviceId, component, fileName, url); + SysEquipmentDocs sysEquipmentDocsScale = saveDocs(deviceId, component, scaleName, scaleParent); + result.add(sysEquipmentDocs); + result.add(sysEquipmentDocsScale); + } catch (Exception e) { + log.error("图片上传失败{}", e); + } finally { + if (scale != null && scale.exists()){ + scale.delete(); + } + } + + } + return result; + } + + @Override + public List getFileList(Long deviceId, String component) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("DEVICEID",deviceId); + queryWrapper.eq("COMPONENT",component); + return sysEquipmentDocsMapper.selectList(queryWrapper); + } + + @Override + public void readFileToSteam(String path, OutputStream stream) { + minioViewsServcie.readFileToStream(path, stream); + } + + @Override + public void deleteFile(String path) { + try { + minioViewsServcie.removeFile(minioAutoProperties.getPublicBucket(), path,false); + //删除缩略图 + String thumbnailPath = path.replace("pic", "thumbnailPic"); + minioViewsServcie.removeFile(minioAutoProperties.getPublicBucket(), thumbnailPath,false); + }catch (Exception e){ + log.error("文件删除失败"); + } + + } + + public File scale(MultipartFile file) throws IOException { + // 获取原始文件名和文件类型 + String originalFileName = file.getOriginalFilename(); + String originalContentType = file.getContentType(); + + if (originalFileName == null || originalFileName.isEmpty()) { + throw new IllegalArgumentException("文件名不能为空"); + } + + if (originalContentType == null || originalContentType.isEmpty()) { + throw new IllegalArgumentException("文件类型不能为空"); + } + // 创建临时文件,名称基于原始文件名 + File tempFile = File.createTempFile("thumbnail_", "_" + originalFileName); + InputStream inputStream = file.getInputStream(); + try { + File mulFile = new File(System.getProperty("java.io.tmpdir") + "/" + file.getOriginalFilename()); + // 将MultipartFile写入临时文件 + file.transferTo(mulFile); + // 生成缩略图 + ImgUtil.scale(mulFile, tempFile, 700, 700, null); + } finally { + IoUtil.close(inputStream); + + } + return tempFile; + } + + public SysEquipmentDocs saveDocs(Long deviceId, String component,String fileName,String url){ SysEquipmentDocs sysEquipmentDocs = new SysEquipmentDocs(); sysEquipmentDocs.setDeviceId(deviceId); sysEquipmentDocs.setName(fileName); sysEquipmentDocs.setUrl(url); + sysEquipmentDocs.setComponent(component); sysEquipmentDocs.setUpdateTime(new Date()); - SysEquipmentDocs sysEquipmentDocsInfo = sysEquipmentDocsMapper.selectById(deviceId); - if (sysEquipmentDocsInfo == null){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("url",url); + SysEquipmentDocs sysEquipmentDocsInfo = sysEquipmentDocsMapper.selectOne(queryWrapper); + if (sysEquipmentDocsInfo == null) { sysEquipmentDocsMapper.insert(sysEquipmentDocs); - }else { + } else { + sysEquipmentDocs.setId(sysEquipmentDocsInfo.getId()); sysEquipmentDocsMapper.updateById(sysEquipmentDocs); } return sysEquipmentDocs; } + + } diff --git a/das/src/main/java/com/das/modules/fdr/service/MinioViewsServcie.java b/das/src/main/java/com/das/modules/fdr/service/MinioViewsServcie.java index ac85e1b8..2bcf8a21 100644 --- a/das/src/main/java/com/das/modules/fdr/service/MinioViewsServcie.java +++ b/das/src/main/java/com/das/modules/fdr/service/MinioViewsServcie.java @@ -78,11 +78,11 @@ public class MinioViewsServcie { } - public String upload(String bucketName, String path, String folderName,MultipartFile file) { + public String upload(String bucketName, String path, String folderName, MultipartFile file) { String targetFile = null; try { - // 上传一个空对象来模拟文件夹 - if (!StringUtils.isBlank(folderName)){ + // 上传一个空对象来模拟文件夹 + if (!StringUtils.isBlank(folderName)) { targetFile = path + folderName + FileConstants.FILE_SEPARATOR; ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); minioClient.putObject( @@ -91,9 +91,8 @@ public class MinioViewsServcie { .object(targetFile) .stream(bais, 0, -1) .build()); - } - else { - targetFile= path +"/" + file.getOriginalFilename(); + } else { + targetFile = path + "/" + file.getOriginalFilename(); uploadFile(bucketName, file, targetFile, "application/octet-stream"); } } catch (Exception e) { @@ -114,7 +113,7 @@ public class MinioViewsServcie { */ public void uploadFile(String bucketName, MultipartFile file, String objectName, String contentType) throws Exception { InputStream inputStream = file.getInputStream(); - try{ + try { minioClient.putObject( PutObjectArgs.builder() .bucket(bucketName) @@ -122,12 +121,35 @@ public class MinioViewsServcie { .contentType(contentType) .stream(inputStream, inputStream.available(), -1) .build()); - }catch (Exception e){ + } catch (Exception e) { log.error("minio文件上传失败", e); } } + public void uploadTemFile(String bucketName, File file, String objectName) throws Exception { + + try (FileInputStream fileInputStream = new FileInputStream(file)) { + minioClient.putObject( + PutObjectArgs.builder() + .bucket(bucketName) + .object(objectName) + .contentType("application/octet-stream") + .stream(fileInputStream, file.length(), -1) + .build() + ); + + + // 删除临时文件 + if (!file.delete()) { + System.err.println("临时文件删除失败:" + file.getAbsolutePath()); + } + } catch (Exception e) { + log.error("生成缩略图或上传到 MinIO 失败", e); + } + + } + //获取路径下的文件夹文件列表 public List getFileTree(String directoryName) { List fileNodes = new ArrayList<>(); @@ -137,7 +159,7 @@ public class MinioViewsServcie { if (StringUtils.isBlank(directoryName)) { build = ListObjectsArgs.builder().bucket(minioProperties.getBucket()).recursive(true).build(); } else { - build = ListObjectsArgs.builder().bucket(minioProperties.getBucket()).prefix(directoryName+"/").recursive(true).build(); + build = ListObjectsArgs.builder().bucket(minioProperties.getBucket()).prefix(directoryName + "/").recursive(true).build(); } Iterable> results = minioClient.listObjects(build); for (Result result : results) { @@ -147,24 +169,23 @@ public class MinioViewsServcie { String size = FileUtil.readableFileSize(item.size()); String relativePath = null; String[] parts = null; - if (!StringUtils.isBlank(directoryName)){ + if (!StringUtils.isBlank(directoryName)) { relativePath = itemName.substring(directoryName.length()); parts = relativePath.split("/"); - } - else { + } else { parts = itemName.split("/"); } String lastModifyTime = null; - DateTimeFormatter dateFormat =DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"); - if (!isDir){ + DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"); + if (!isDir) { ZonedDateTime zonedDateTime = item.lastModified(); lastModifyTime = zonedDateTime.format(dateFormat); } if (parts.length > 0) { String nodeName = parts[1]; int type = isDir ? 0 : 1; - itemName= isDir ? itemName.substring(0,itemName.lastIndexOf("/")) : itemName; - FileNode node = new FileNode(nodeName, type,size,lastModifyTime,"/"+itemName); + itemName = isDir ? itemName.substring(0, itemName.lastIndexOf("/")) : itemName; + FileNode node = new FileNode(nodeName, type, size, lastModifyTime, "/" + itemName); if (!fileNodes.contains(node)) { fileNodes.add(node); } @@ -178,15 +199,15 @@ public class MinioViewsServcie { public void readFileToStream(String path, OutputStream stream) { - try ( GetObjectResponse res = minioClient.getObject( - GetObjectArgs.builder().bucket(minioProperties.getBucket()).object(path).build())){ + try (GetObjectResponse res = minioClient.getObject( + GetObjectArgs.builder().bucket(minioProperties.getBucket()).object(path).build())) { res.transferTo(stream); } catch (Exception e) { log.error("minio读取文件失败", e); } } - public void download(String path, Path tempDir,HttpServletResponse httpServletResponse) { + public void download(String path, Path tempDir, HttpServletResponse httpServletResponse) { File tempFile = null; try (InputStream inputStream = minioClient.getObject(GetObjectArgs.builder() @@ -202,7 +223,7 @@ public class MinioViewsServcie { } finally { assert tempFile != null; - if (tempFile.exists()){ + if (tempFile.exists()) { tempFile.delete(); } } @@ -257,7 +278,7 @@ public class MinioViewsServcie { return total; } - public InputStream getFileStream(String url){ + public InputStream getFileStream(String url) { InputStream inputStream = null; try { diff --git a/das/src/main/resources/application.yml b/das/src/main/resources/application.yml index ed5945e9..2d60c655 100644 --- a/das/src/main/resources/application.yml +++ b/das/src/main/resources/application.yml @@ -109,6 +109,6 @@ tdengine: minio: url: http://192.168.109.187:9000 bucket: das - publicBucket: das-public + publicBucket: das-dock accessKey: das secretKey: zaq12WSX \ No newline at end of file diff --git a/document/风电场数据采集系统使用手册.docx b/document/风电场数据采集系统使用手册v1.0.docx similarity index 79% rename from document/风电场数据采集系统使用手册.docx rename to document/风电场数据采集系统使用手册v1.0.docx index 1b93911a..ff652d4b 100644 Binary files a/document/风电场数据采集系统使用手册.docx and b/document/风电场数据采集系统使用手册v1.0.docx differ diff --git a/document/风电场数据采集系统使用手册v1.1.docx b/document/风电场数据采集系统使用手册v1.1.docx new file mode 100644 index 00000000..a9659390 Binary files /dev/null and b/document/风电场数据采集系统使用手册v1.1.docx differ diff --git a/ui/dasadmin/src/views/backend/home/home.vue b/ui/dasadmin/src/views/backend/home/home.vue index 1c9f11ff..fa2637e1 100644 --- a/ui/dasadmin/src/views/backend/home/home.vue +++ b/ui/dasadmin/src/views/backend/home/home.vue @@ -363,36 +363,6 @@ const StatusListData = () => { } }) } -// 添加响应式属性以存储故障代码字典 -/*const malFunctionEnums = ref<{ [key: string]: { [code: string]: string } }>({}); - -const requestedParams = new Set(); -const failedRequests = new Set(); - -const fetchData = async (item: any) => { - const key = `${item.madeinFactory}-${item.model}`; - - if (requestedParams.has(key)) { - return; - } - requestedParams.add(key); - - try { - const response = await queryfaultCodeDict({ madeinfactory: item.madeinFactory, model: item.model }); - if (response.code === 200) { - const data: any = {}; - response.data.forEach((item: any) => { - data[item.code] = item.description; - }); - malFunctionEnums.value[key] = data; - } else { - console.warn('查询故障代码字典失败:', response.message); - failedRequests.add(key); - } - } catch (error) { - failedRequests.add(key); - } -};*/ let autoUpdateForSecondTimer: any = null diff --git a/ui/dasadmin/src/views/backend/home/windMatrixpage.vue b/ui/dasadmin/src/views/backend/home/windMatrixpage.vue index 700c92b4..52da39b3 100644 --- a/ui/dasadmin/src/views/backend/home/windMatrixpage.vue +++ b/ui/dasadmin/src/views/backend/home/windMatrixpage.vue @@ -411,57 +411,6 @@ const getSafeImagePath = (item, type) => { }; -/*const getFaultDescription=(item)=>{ - const key = `${item.madeinFactory}-${item.model}`; - if (failedRequests.has(key)) { - return ''; - } - - if (!malFunctionEnums[key]) { - fetchData(item); // 如果还没有请求过,则发起请求 - // return item.attributeMap.firsttriggeredcode; - } - - let firsttriggeredcode = item.attributeMap.firsttriggeredcode; - if (malFunctionKeys.includes('FirstTriggeredCode') && malFunctionEnums[key]) { - if(firsttriggeredcode==0){ - return '' - }else{ - firsttriggeredcode = malFunctionEnums[key][firsttriggeredcode] ?? ''; - } - } - return firsttriggeredcode; -} - -let malFunctionEnums: { [key: string]: { [code: string]: string } } = {}; -const requestedParams = new Set(); -const failedRequests = new Set(); - -const fetchData = async (item: any) => { - const key = `${item.madeinFactory}-${item.model}`; - - if (requestedParams.has(key)) { - return; - } - requestedParams.add(key); - - try { - const response = await queryfaultCodeDict({ madeinfactory: item.madeinFactory, model: item.model }); - if (response.code === 200) { - const data: any = {}; - response.data.forEach((item: any) => { - data[item.code] = item.description; - }); - malFunctionEnums[key] = data; - } else { - console.warn('查询故障代码字典失败:', response.message); - failedRequests.add(key); - } - } catch (error) { - failedRequests.add(key); - } -};*/ -