| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.checkerframework.checker.units.qual.N; |
| | | import org.flowable.engine.delegate.DelegateExecution; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.mdm.basesetting.machine.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.commons.contants.ParamConstants; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.service.NcNodeAutoCreateService; |
| | | import org.springblade.mdm.program.service.NcNodeService; |
| | | import org.springblade.mdm.program.service.ProgramAnnotationService; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.system.feign.ISysClient; |
| | | import org.springblade.system.pojo.entity.Dict; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.time.LocalDate; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | |
| | | private final FlowCommonService flowCommonService; |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final ISysClient sysClient; |
| | | private final OssTemplate ossTemplate; |
| | | private final ProgramAnnotationService programAnnotationService; |
| | | private final MachineService machineService; |
| | | |
| | | public static final String GH = "GH"; |
| | | |
| | | |
| | | /** |
| | | * 默认有效期间(月数),2年 |
| | | */ |
| | |
| | | * 固化审批通过处理任务, |
| | | * @param execution 流程execution |
| | | */ |
| | | public void execute(DelegateExecution execution) { |
| | | @Transactional |
| | | public void execute(DelegateExecution execution) throws IOException { |
| | | log.info("执行固化程序任务服务,流程实例id={}", execution.getProcessInstanceId()); |
| | | //固化程序检查有效期, |
| | | //1.将流程设置 |
| | | dealWithNode(execution.getProcessInstanceId()); |
| | | } |
| | | |
| | |
| | | * 处理node状态。 |
| | | * @param processInstanceId 流程实例id |
| | | */ |
| | | void dealWithNode(String processInstanceId) { |
| | | void dealWithNode(String processInstanceId) throws IOException { |
| | | //程序包节点和下属程序节点(包括历史节点非最新版本的)从试切挪到固化下面 |
| | | //程序包节点 设置未已固化 |
| | | NcNode pkgNode = nodeService.lambdaQuery().eq(NcNode::getProcessInstanceId, processInstanceId).one(); |
| | |
| | | * @param pkgNode 要挪动的节点 |
| | | * @param historyProgramPackageNodes 程序包名 历史节点 |
| | | */ |
| | | void moveNodeToCuredTree(NcNode pkgNode,List<NcNode> historyProgramPackageNodes, FlowProgramProperties programProperties) { |
| | | void moveNodeToCuredTree(NcNode pkgNode,List<NcNode> historyProgramPackageNodes, FlowProgramProperties programProperties) throws IOException { |
| | | //创建节点到机床级别.(固化树) |
| | | NcNode machineNode = ncNodeAutoCreateService.createNodeTreeToMachine(programProperties); |
| | | |
| | |
| | | } |
| | | nodeService.updateBatchById(historyProgramPackageNodes); |
| | | |
| | | Machine machine = machineService.getByCode(pkgNode.getMachineCode()); |
| | | List<Dict> annoDicts = programAnnotationService.getAnnotionList(); |
| | | //新的流程文件,需要在包节点下新建,不能用老的 |
| | | List<FlowProgramFile> files = flowProgramFileService.lambdaQuery().eq(FlowProgramFile::getProcessInstanceId,pkgNode.getProcessInstanceId()).list(); |
| | | for(FlowProgramFile flowProgramFile : files){ |
| | |
| | | newProgNode.setFlowProgramFileId(flowProgramFile.getId()); |
| | | newProgNode.setIsCured(1); |
| | | ncNodeService.save(newProgNode); |
| | | |
| | | //修改文件内容更新注释,并更新文件数据的地址 |
| | | ///替换注释后总是不行啊 |
| | | setGhAnnotation(flowProgramFile,machine.getMachineGroupCode(),annoDicts); |
| | | |
| | | flowProgramFileService.updateById(flowProgramFile); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置固化注释,实现方式,获取文件字节下,修改后替换文件 |
| | | * @param flowProgramFile oss 文件 |
| | | * |
| | | */ |
| | | void setGhAnnotation(FlowProgramFile flowProgramFile,String machineGroup,List<Dict> annoDicts) throws IOException { |
| | | String ossName = flowProgramFile.getOssName(); |
| | | // |
| | | try(InputStream ins = ossTemplate.statFileStream(ossName);){ |
| | | String annoTxt = programAnnotationService.generateAnnotation("GH",machineGroup,annoDicts); |
| | | int statusLineIndex = 2; |
| | | String line2 = FileContentUtil.readLineAt(ins,statusLineIndex);//第三行应该是状态注释 |
| | | InputStream finishedStream; |
| | | if(programAnnotationService.isAnnotation(line2,machineGroup,annoDicts)){ |
| | | finishedStream = FileContentUtil.replaceAtLine(ins,statusLineIndex,annoTxt); |
| | | }else{ |
| | | finishedStream = FileContentUtil.insertLine(ins,statusLineIndex,annoTxt); |
| | | } |
| | | try(finishedStream) { |
| | | finishedStream.reset(); |
| | | BladeFile bfile = ossTemplate.putFile(flowProgramFile.getName(), finishedStream); |
| | | //替换原有的文件地址 |
| | | flowProgramFile.setOssName(bfile.getName()); |
| | | } |
| | | } |
| | | } |
| | | |