| | |
| | | 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; |
| | |
| | | @Slf4j |
| | | public class OssTestController { |
| | | private final OssTemplate ossTemplate; |
| | | private final ProgramAnnotationService programAnnotationService; |
| | | @GetMapping("/readzip") |
| | | @ApiOperationSupport(order = 2) |
| | | @Operation(summary = "读zip") |
| | |
| | | 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()); |
| | | } |
| | | */ |
| | | } |