From 083df8d788c95c009a94378e620684eb5de2bd21 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期六, 13 九月 2025 13:08:09 +0800
Subject: [PATCH] 注释问题修复
---
blade-service/blade-mdm/src/main/java/org/springblade/mdm/test/OssTestController.java | 106 ++++++++++++++++++++++++++++++-----------------------
1 files changed, 60 insertions(+), 46 deletions(-)
diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/test/OssTestController.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/test/OssTestController.java
index bd77b7a..d786e24 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/test/OssTestController.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/test/OssTestController.java
@@ -7,10 +7,16 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.IOUtils;
import org.springblade.core.oss.OssTemplate;
+import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.FileUtil;
+import org.springblade.mdm.program.service.ProgramAnnotationService;
+import org.springblade.mdm.utils.FileContentUtil;
+import org.springblade.system.pojo.entity.Dict;
+import org.springblade.system.pojo.entity.DictBiz;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -36,6 +42,7 @@
@Slf4j
public class OssTestController {
private final OssTemplate ossTemplate;
+ private final ProgramAnnotationService programAnnotationService;
@GetMapping("/readzip")
@ApiOperationSupport(order = 2)
@Operation(summary = "璇粃ip")
@@ -68,54 +75,61 @@
System.out.println(entryNameList);
- /*
- try (ZipFile zipFile = new ZipFile(tempFile.toFile())) {
- ZipEntry entry = zipFile.getEntry(entryn);
- InputStream ins = zipFile.getInputStream(entry);
- Path outputPath = Paths.get("d:/downtest.txt");
- Files.copy(ins, outputPath, StandardCopyOption.REPLACE_EXISTING);
- }
-
- List<String> entryNameList = new ArrayList<>();
- try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(bytes);
- ZipFile zipFile = new ZipFile(channel)) {
-
- ZipArchiveEntry entry;
- Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
- String entryn = "CP1-13-1/CP1-13-1-1-1-1.txt";
- while (entries.hasMoreElements()) {
- entry = entries.nextElement();
- entryNameList.add(entry.getName());
- }
- }*/
- /*
- try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(bytes);
- ZipFile zipFile = new ZipFile(channel)) {
- List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList();
- for(String dir : dirList) {
- entryNameList.stream().filter(s -> s.startsWith(dir)).forEach(entryName -> {
- ZipArchiveEntry fileEntry = zipFile.getEntry(entryName);
- //ZipArchiveEntry fileEntry = entryMap.get(entryName);
- String fileName = StringUtils.removeStart(entryName,dir);//鍘婚櫎鏂囦欢鍚嶈矾寰勯儴鍒�
- try {
- InputStream ins = zipFile.getInputStream(fileEntry);
- ByteArrayInputStream byteS = new ByteArrayInputStream(ins.readAllBytes());
-
- Path outputPath = Paths.get("d:/downtest.txt");
- Files.copy(byteS, outputPath, StandardCopyOption.REPLACE_EXISTING);
- byteS.reset();
-
- BladeFile newOssFile = ossTemplate.putFile("mdm", fileName, byteS);
- r.setData(newOssFile.getName());
- System.out.println(newOssFile.getName());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- });
- }
- }*/
return r;
}
+ @GetMapping("/replace")
+ @ApiOperationSupport(order = 2)
+ @Operation(summary = "鏇挎崲鍐呭")
+ public R<String> replace(String filepath) throws IOException {
+ File file = new File(filepath);
+ FileInputStream fis = new FileInputStream(file);
+ InputStream newins = FileContentUtil.replaceAtLine(fis,2,"GHTEST");
+
+ BladeFile bfile = ossTemplate.putFile("replaceok.txt",newins);
+ return R.data(bfile.getLink()+","+bfile.getName());
+ }
+ /*
+ @GetMapping("/replace2")
+ @ApiOperationSupport(order = 2)
+ @Operation(summary = "鏇挎崲鍐呭2")
+ public R<String> replace() throws IOException {
+ String ossName = "upload/20250816/fb971fa2186b5572443687e9fa425123.txt";//杩欐槸閲岄潰宸叉湁鐨勬枃浠�
+
+ String filename = "CP3-1-1-1.txt";
+ String machineGroup = "FANUC";
+ List<DictBiz> annoDicts = programAnnotationService.getAnnotionList();
+ BladeFile bfile = null;
+ try(InputStream ins = ossTemplate.statFileStream(ossName);){
+ byte[] bytes = IOUtils.toByteArray(ins);
+ ByteArrayInputStream byteins = new ByteArrayInputStream(bytes);
+ String annoTxt = programAnnotationService.generateAnnotation("GH",machineGroup,annoDicts);
+ int statusLineIndex = 2;
+ String line2 = FileContentUtil.readLineAt(byteins,statusLineIndex);//绗笁琛屽簲璇ユ槸鐘舵�佹敞閲�
+ byteins.reset();
+ InputStream finishedStream;
+ if(programAnnotationService.isAnnotation(line2,machineGroup,annoDicts)){
+ finishedStream = FileContentUtil.replaceAtLine(byteins,statusLineIndex,annoTxt);
+ }else{
+ finishedStream = FileContentUtil.insertLine(byteins,statusLineIndex,annoTxt);
+ }
+
+ try(finishedStream) {
+ finishedStream.reset();
+ bfile = ossTemplate.putFile(filename, finishedStream);
+ //鏇挎崲鍘熸湁鐨勬枃浠跺湴鍧�
+ //flowProgramFile.setOssName(bfile.getName());
+ }
+ }
+
+ InputStream ins = ossTemplate.statFileStream(ossName);
+ InputStream newins = FileContentUtil.replaceAtLine(fis,2,"GHTEST");
+
+ BladeFile bfile = ossTemplate.putFile("replaceok.txt",newins);
+
+
+ return R.data(bfile.getLink()+","+bfile.getName());
+ }
+*/
}
--
Gitblit v1.9.3