| | |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.checkerframework.checker.units.qual.N; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.flowable.engine.delegate.DelegateExecution; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.system.feign.ISysClient; |
| | | import org.springblade.system.pojo.entity.Dict; |
| | | import org.springblade.system.pojo.entity.DictBiz; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.time.LocalDate; |
| | |
| | | private final OssTemplate ossTemplate; |
| | | private final ProgramAnnotationService programAnnotationService; |
| | | private final MachineService machineService; |
| | | |
| | | public static final String GH = "GH"; |
| | | |
| | | |
| | | /** |
| | | * 默认有效期间(月数),2年 |
| | |
| | | NcNode pkgNode = nodeService.lambdaQuery().eq(NcNode::getProcessInstanceId, processInstanceId).one(); |
| | | if(pkgNode.isDeviationProgram()){ |
| | | //偏离的程序直接锁定 |
| | | pkgNode.setIsLocked(1); |
| | | //pkgNode.setIsLocked(1); |
| | | pkgNode.lock(); |
| | | nodeService.updateById(pkgNode); |
| | | }else { |
| | | //试切的 |
| | | pkgNode.setIsCured(1); |
| | | pkgNode.setIsLocked(NcNode.UNLOCK); |
| | | //设置过期日期 |
| | | pkgNode.upgradeVersionNUmber(); |
| | | pkgNode.upgradeVersionNumber(); |
| | | pkgNode.setExpireDate(calculateExpireDate()); |
| | | nodeService.updateById(pkgNode); |
| | | |
| | |
| | | //创建节点到机床级别.(固化树) |
| | | NcNode machineNode = ncNodeAutoCreateService.createNodeTreeToMachine(programProperties); |
| | | |
| | | pkgNode.setParentId(machineNode.getParentId()); |
| | | pkgNode.setParentIds(machineNode.getParentIds());//更新上级节点,下面还要用应为在historyProgramPackageNodes中的和这个不是一个实例 |
| | | //机床下现在没有文件了,程序包名升级与机床同级了,改为找到机床同级程序包名更新了 |
| | | //TODO 这个parentIds是不是不够?,不够,一个机床下多个程序包的情况不行吧,但是按照树,多个程序包不太现实 |
| | | this.nodeService.lambdaUpdate().likeRight(NcNode::getParentIds, machineNode.getParentIds()) |
| | | .in(NcNode::getNodeType, Arrays.asList(NcNode.TYPE_PROGRAM_PACKAGE,NcNode.TYPE_PROGRAM_FILE)) |
| | | .ne(NcNode::getId,pkgNode.getId())//不要更新新固化的节点new |
| | | .set(NcNode::getIsLastEdition,0).set(NcNode::getIsLocked,1).update(); |
| | | |
| | | for(NcNode hisPackageNode : historyProgramPackageNodes){ |
| | |
| | | hisPackageNode.setParentId(machineNode.getParentId()); |
| | | hisPackageNode.setParentIds(machineNode.getParentIds());//程序包与机床节点同级 |
| | | |
| | | //处理程序包下层的程序节点 |
| | | //处理程序包下层的程序节点111 |
| | | List<NcNode> programNodes = nodeService.lambdaQuery().eq(NcNode::getParentId,hisPackageNode.getId()).list(); |
| | | FlowProgramFile pfile; |
| | | for(NcNode programNode : programNodes){ |
| | | programNode.setIsLastEdition(0); |
| | | programNode.setParentIds(hisPackageNode.getParentIds()+","+hisPackageNode.getId()); |
| | | programNode.setIsLastEdition(0); |
| | | |
| | | pfile = flowProgramFileService.getById(programNode.getFlowProgramFileId()); |
| | | if(programNode.getParentId().equals(pkgNode.getId()) && !pfile.isProgram()){ |
| | | //当前固化程序包名下的“其他文件”非程序文件。不设置为老版本,直接挪到固化树下,两个网络之间只交换程序文件,其他文件只能保留 |
| | | programNode.setIsLastEdition(1); |
| | | } |
| | | |
| | | } |
| | | nodeService.updateBatchById(programNodes); |
| | | } |
| | | nodeService.updateBatchById(historyProgramPackageNodes); |
| | | |
| | | Machine machine = machineService.getByCode(pkgNode.getMachineCode()); |
| | | List<Dict> annoDicts = programAnnotationService.getAnnotionList(); |
| | | List<DictBiz> annoDicts = programAnnotationService.getAnnotionList(); |
| | | //新的流程文件,需要在包节点下新建,不能用老的 |
| | | List<FlowProgramFile> files = flowProgramFileService.lambdaQuery().eq(FlowProgramFile::getProcessInstanceId,pkgNode.getProcessInstanceId()).list(); |
| | | for(FlowProgramFile flowProgramFile : files){ |
| | |
| | | newProgNode.setName(flowProgramFile.getName()); |
| | | newProgNode.setNodeType(NcNode.TYPE_PROGRAM_FILE); |
| | | newProgNode.setParentId(pkgNode.getId()); |
| | | newProgNode.setDrawingNo(pkgNode.getDrawingNo()); |
| | | newProgNode.setDrawingNoEdition(pkgNode.getDrawingNoEdition()); |
| | | newProgNode.setMachineCode(pkgNode.getMachineCode()); |
| | | newProgNode.setProcessEdition(pkgNode.getProcessEdition()); |
| | | newProgNode.setProcessName(pkgNode.getProcessName()); |
| | | newProgNode.setProcessNo(pkgNode.getProcessNo()); |
| | | newProgNode.setParentIds(pkgNode.getParentIds()+","+pkgNode.getId()); |
| | | newProgNode.setIsLastEdition(1); |
| | | newProgNode.setVersionNumber(pkgNode.getVersionNumber()); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置固化注释,实现方式,获取文件字节下,修改后替换文件 |
| | | * @param flowProgramFile oss 文件 |
| | | * |
| | | */ |
| | | void setGhAnnotation(FlowProgramFile flowProgramFile,String machineGroup,List<Dict> annoDicts) throws IOException { |
| | | void setGhAnnotation(FlowProgramFile flowProgramFile,String machineGroup,List<DictBiz> annoDicts) throws IOException { |
| | | String ossName = flowProgramFile.getOssName(); |
| | | // |
| | | try(InputStream ins = ossTemplate.statFileStream(ossName);){ |
| | | byte[] bytes = IOUtils.toByteArray(ins); |
| | | ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes); |
| | | |
| | | InputStream finishedStream = programAnnotationService.setGHAnnotation(byteInputStream,machineGroup,annoDicts); |
| | | /* |
| | | String annoTxt = programAnnotationService.generateAnnotation("GH",machineGroup,annoDicts); |
| | | int statusLineIndex = 2; |
| | | String line2 = FileContentUtil.readLineAt(ins,statusLineIndex);//第三行应该是状态注释 |
| | | //int statusLineIndex = 2; |
| | | String line2 = FileContentUtil.readLineAt(byteInputStream,ProgramAnnotationService.STATUS_LINE_INDEX);//第三行应该是状态注释 |
| | | byteInputStream.reset(); |
| | | InputStream finishedStream; |
| | | if(programAnnotationService.isAnnotation(line2,machineGroup,annoDicts)){ |
| | | finishedStream = FileContentUtil.replaceAtLine(ins,statusLineIndex,annoTxt); |
| | | finishedStream = FileContentUtil.replaceAtLine(byteInputStream,ProgramAnnotationService.STATUS_LINE_INDEX,annoTxt); |
| | | }else{ |
| | | finishedStream = FileContentUtil.insertLine(ins,statusLineIndex,annoTxt); |
| | | } |
| | | finishedStream = FileContentUtil.insertLine(byteInputStream,ProgramAnnotationService.STATUS_LINE_INDEX,annoTxt); |
| | | }*/ |
| | | try(finishedStream) { |
| | | finishedStream.reset(); |
| | | BladeFile bfile = ossTemplate.putFile(flowProgramFile.getName(), finishedStream); |