| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.system.feign.IDictBizClient; |
| | |
| | | * 状态行索引(第三行) 0 based |
| | | */ |
| | | public static final int STATUS_LINE_INDEX = 2; |
| | | |
| | | /** |
| | | * 偏离单注释行索引号 0 based |
| | | */ |
| | | public static final int STATUS_DEVIATION_INDEX = 3; |
| | | |
| | | public static final String SQ = "SQ"; |
| | | public static final String GH = "GH"; |
| | |
| | | * 设置固化注释行 |
| | | * @param inputStream |
| | | * @param machineGroup |
| | | * @param annoDicts |
| | | * @param annoDictList |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | public InputStream setGHAnnotation(InputStream inputStream, String machineGroup,List<DictBiz> annoDicts) throws IOException { |
| | | public InputStream setGHAnnotation(InputStream inputStream, String machineGroup,List<DictBiz> annoDictList) throws IOException { |
| | | |
| | | return setAnnotationAndGetInputStream(inputStream, machineGroup, annoDictList, GH, STATUS_LINE_INDEX); |
| | | } |
| | | |
| | | /** |
| | | * 设置偏离单注释 |
| | | * @param inputStream |
| | | * @param machineGroup |
| | | * @param annoDictList |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | public InputStream setPldAnnotation(String deviation,InputStream inputStream,String machineGroup,List<DictBiz> annoDictList) throws IOException { |
| | | // |
| | | return setAnnotationAndGetInputStream(inputStream, machineGroup, annoDictList, deviation, STATUS_DEVIATION_INDEX); |
| | | } |
| | | |
| | | @NotNull |
| | | private InputStream setAnnotationAndGetInputStream(InputStream inputStream, String machineGroup, List<DictBiz> annoDictList, String text, int lineIndex) throws IOException { |
| | | InputStream finishedStream; |
| | | try(inputStream){ |
| | | ByteArrayInputStream byteInputStream = new ByteArrayInputStream(IOUtils.toByteArray(inputStream)); |
| | | |
| | | String annoTxt = generateAnnotation(GH,machineGroup,annoDicts);//加了注释之后的文本 |
| | | String annoTxt = generateAnnotation(text,machineGroup,annoDictList);//加了注释之后的文本 |
| | | |
| | | String lineText = FileContentUtil.readLineAt(byteInputStream,STATUS_LINE_INDEX);//第三行应该是状态注释 |
| | | String lineText = FileContentUtil.readLineAt(byteInputStream, lineIndex); |
| | | byteInputStream.reset(); |
| | | |
| | | if(isAnnotation(lineText,machineGroup,annoDicts)){ |
| | | finishedStream = FileContentUtil.replaceAtLine(byteInputStream,STATUS_LINE_INDEX,annoTxt); |
| | | if(isAnnotation(lineText,machineGroup,annoDictList)){ |
| | | finishedStream = FileContentUtil.replaceAtLine(byteInputStream, lineIndex,annoTxt); |
| | | }else{ |
| | | finishedStream = FileContentUtil.insertLine(byteInputStream,STATUS_LINE_INDEX,annoTxt); |
| | | finishedStream = FileContentUtil.insertLine(byteInputStream, lineIndex,annoTxt); |
| | | } |
| | | finishedStream.reset(); |
| | | |
| | | } |
| | | |
| | | return finishedStream; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 为输入流设置发送目录(第二行)和状态(第三行) |
| | | * @param sendPath 发送路径 |