diff --git a/pqs-event/event-boot/src/main/java/com/njcn/event/controller/majornetwork/AutonomeWaveController.java b/pqs-event/event-boot/src/main/java/com/njcn/event/controller/majornetwork/AutonomeWaveController.java new file mode 100644 index 000000000..3afb7bb35 --- /dev/null +++ b/pqs-event/event-boot/src/main/java/com/njcn/event/controller/majornetwork/AutonomeWaveController.java @@ -0,0 +1,54 @@ +package com.njcn.event.controller.majornetwork; + +import com.njcn.common.pojo.annotation.OperateInfo; +import com.njcn.common.pojo.enums.common.LogEnum; +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.common.utils.HttpResultUtil; +import com.njcn.device.pq.pojo.param.LargeScreenParam; +import com.njcn.device.pq.pojo.vo.*; +import com.njcn.event.pojo.dto.wave.WaveDataDTO; +import com.njcn.event.service.majornetwork.AutonomeWaveService; +import com.njcn.event.service.majornetwork.LargeScreenService; +import com.njcn.web.controller.BaseController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.List; + +/** + * @version 1.0.0 + * @author: zbj + * @date: 2023/04/23 + */ +@Slf4j +@Api(tags = "离线波形查看") +@RestController +@RequestMapping("/autonomeWave") +@RequiredArgsConstructor +public class AutonomeWaveController extends BaseController { + + private final AutonomeWaveService autonomeWaveService; + + /** + * 上传文件并且展示波形 + */ + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/uploadFileAndViewWave") + @ApiOperation("上传文件并且展示波形") + public HttpResult uploadFileAndViewWave(@ApiParam(value = "文件1", required = true) @RequestPart("file1") MultipartFile file1, + @ApiParam(value = "文件2", required = true) @RequestPart("file2") MultipartFile file2) throws IOException { + String methodDescribe = getMethodDescribe("uploadFileAndViewWave"); + WaveDataDTO result = autonomeWaveService.uploadFileAndViewWave(file1, file2); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + +} diff --git a/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/AutonomeWaveService.java b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/AutonomeWaveService.java new file mode 100644 index 000000000..f163f5ca4 --- /dev/null +++ b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/AutonomeWaveService.java @@ -0,0 +1,16 @@ +package com.njcn.event.service.majornetwork; + +import com.njcn.event.pojo.dto.wave.WaveDataDTO; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; + + +/** + * @version 1.0.0 + * @author: zbj + * @date: 2023/04/23 + */ +public interface AutonomeWaveService { + WaveDataDTO uploadFileAndViewWave(MultipartFile file1, MultipartFile file2) throws IOException; +} diff --git a/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/AutonomeWaveServiceImpl.java b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/AutonomeWaveServiceImpl.java new file mode 100644 index 000000000..27097db35 --- /dev/null +++ b/pqs-event/event-boot/src/main/java/com/njcn/event/service/majornetwork/Impl/AutonomeWaveServiceImpl.java @@ -0,0 +1,75 @@ +package com.njcn.event.service.majornetwork.Impl; + +import com.njcn.common.config.GeneralInfo; +import com.njcn.event.pojo.dto.wave.WaveDataDTO; +import com.njcn.event.service.majornetwork.AutonomeWaveService; +import com.njcn.event.utils.WaveUtil; +import com.njcn.oss.constant.GeneralConstant; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Objects; + +/** + * @version 1.0.0 + * @author: zbj + * @date: 2023/043/23 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class AutonomeWaveServiceImpl implements AutonomeWaveService { + + private final GeneralInfo generalInfo; + + private final WaveUtil waveUtil; + + @Override + public WaveDataDTO uploadFileAndViewWave(MultipartFile file1, MultipartFile file2) throws IOException { + //测试路径 + File dir = new File("C:\\Users\\User\\Desktop\\wave"); + //真实路径 + // File dir = new File(generalInfo.getBusinessTempPath() + File.separator + "wave"); + + String cfgPath, datPath; + if (!dir.exists()) { + dir.mkdirs(); + } + String fileName1 = file1.getOriginalFilename(); + String fileName2 = file2.getOriginalFilename(); + //判断文件后缀 + String fileExtension1 = fileName1.substring(fileName1.lastIndexOf(".")).toUpperCase(); + if (Objects.equals(fileExtension1, GeneralConstant.CFG)) { + //使用本地的波形文件进行测试 + File cfg = new File(dir + File.separator + fileName1); + File dat = new File(dir + File.separator + fileName2); + file1.transferTo(cfg); + file2.transferTo(dat); + cfgPath = dir + File.separator + fileName1; + datPath = dir + File.separator + fileName2; + InputStream cfgInputStream = Files.newInputStream(Paths.get(cfgPath)); + InputStream datInputStream = Files.newInputStream(Paths.get(datPath)); + WaveDataDTO comtrade = waveUtil.getComtrade(cfgInputStream, datInputStream, 1); + return waveUtil.getValidData(comtrade); + } else { + //使用本地的波形文件进行测试 + File dat = new File(dir + File.separator + fileName1); + File cfg = new File(dir + File.separator + fileName2); + file1.transferTo(dat); + file2.transferTo(cfg); + cfgPath = dir + File.separator + fileName2; + datPath = dir + File.separator + fileName1; + InputStream cfgInputStream = Files.newInputStream(Paths.get(cfgPath)); + InputStream datInputStream = Files.newInputStream(Paths.get(datPath)); + WaveDataDTO comtrade = waveUtil.getComtrade(cfgInputStream, datInputStream, 1); + return waveUtil.getValidData(comtrade); + } + } +} \ No newline at end of file