| | |
| | | package org.springblade.mdm.program.service; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.system.feign.IDictClient; |
| | | import org.springblade.system.pojo.entity.Dict; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | |
| | | String temp = StringUtils.removeEnd(StringUtils.removeStart(text,begin),end); |
| | | return temp; |
| | | } |
| | | |
| | | /** |
| | | * 为程序文件增加注释 |
| | | * @param oriText 原始文本 |
| | | * @param lineIndex 行索引 0 based |
| | | * @param inputStream 文件的输入流 |
| | | * @param machineGroup 机床组 生成注释用 |
| | | * @return 加注释后的流 |
| | | * @throws IOException |
| | | */ |
| | | public InputStream setAnnotation(String oriText,int lineIndex,InputStream inputStream, String machineGroup) throws IOException { |
| | | List<Dict> annoDicts = getAnnotionList(); |
| | | // |
| | | InputStream finishedStream; |
| | | try(inputStream){ |
| | | ByteArrayInputStream byteInputStream = new ByteArrayInputStream(IOUtils.toByteArray(inputStream)); |
| | | |
| | | String annoTxt = generateAnnotation(oriText,machineGroup,annoDicts);//加了注释之后的文本 |
| | | |
| | | String lineText = FileContentUtil.readLineAt(byteInputStream,lineIndex);//第三行应该是状态注释 |
| | | byteInputStream.reset(); |
| | | |
| | | if(isAnnotation(lineText,machineGroup,annoDicts)){ |
| | | finishedStream = FileContentUtil.replaceAtLine(byteInputStream,lineIndex,annoTxt); |
| | | }else{ |
| | | finishedStream = FileContentUtil.insertLine(byteInputStream,lineIndex,annoTxt); |
| | | } |
| | | finishedStream.reset(); |
| | | |
| | | } |
| | | |
| | | return finishedStream; |
| | | } |
| | | } |
| | | |