| | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.flowable.engine.delegate.DelegateExecution; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.mdm.commons.contants.ParamConstants; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | | import org.springblade.mdm.flow.service.FlowProgramProperties; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.entity.NcProgram; |
| | | import org.springblade.mdm.program.service.NcNodeAutoCreateService; |
| | | import org.springblade.mdm.program.service.NcNodeService; |
| | | import org.springblade.system.feign.ISysClient; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | |
| | | private final NcNodeService nodeService; |
| | | private final NcNodeAutoCreateService ncNodeAutoCreateService; |
| | | private final FlowCommonService flowCommonService; |
| | | private final ISysClient sysClient; |
| | | /** |
| | | * 默认有效期间(月数),2年 |
| | | */ |
| | | private static final int DEFAULT_VALID_MONTH = 24; |
| | | /** |
| | | * 固化审批通过处理任务, |
| | | * @param execution 流程execution |
| | |
| | | //固化程序检查有效期, |
| | | //1.将流程设置 |
| | | dealWithNode(execution.getProcessInstanceId()); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | //程序包节点和下属程序节点(包括历史节点非最新版本的)从试切挪到固化下面 |
| | | //程序包节点 设置未已固化 |
| | | NcNode pkgNode = nodeService.lambdaQuery().eq(NcNode::getProcessInstanceId, processInstanceId).one(); |
| | | pkgNode.setIsCured(1); |
| | | if(pkgNode.isDeviationProgram()){ |
| | | //偏离的程序直接锁定 |
| | | pkgNode.setIsLocked(1); |
| | | nodeService.updateById(pkgNode); |
| | | }else { |
| | | pkgNode.setIsCured(1); |
| | | //设置过期日期 |
| | | pkgNode.setExpireDate(calculateExpireDate()); |
| | | nodeService.updateById(pkgNode); |
| | | |
| | | List<NcNode> historyNodes = nodeService.getNodeHistorys(pkgNode); |
| | | moveNodeToCuredTree(pkgNode,historyNodes,flowCommonService.getProgramProperties(processInstanceId)); |
| | | |
| | | List<NcNode> historyProgramPackageNodes = nodeService.getNodeHistory(pkgNode); |
| | | moveNodeToCuredTree(pkgNode, historyProgramPackageNodes, flowCommonService.getProgramProperties(processInstanceId)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 将节点和历史节点挪动到固化的同级节点下 |
| | | * @param historyNodes |
| | | * @param historyProgramPackageNodes 程序包名 历史节点 |
| | | */ |
| | | void moveNodeToCuredTree(NcNode pkgNode,List<NcNode> historyNodes, FlowProgramProperties programProperties) { |
| | | NcNode node = historyNodes.get(0); |
| | | void moveNodeToCuredTree(NcNode pkgNode,List<NcNode> historyProgramPackageNodes, FlowProgramProperties programProperties) { |
| | | //创建节点到机床级别.(固化树) |
| | | NcNode machineNode = ncNodeAutoCreateService.createNodeTreeToMachine(programProperties); |
| | | |
| | | //移动到固化树下的机床节点下层 |
| | | String newParentIds = machineNode.getParentIds()+","+machineNode.getId(); |
| | | for(NcNode hisNode : historyNodes){ |
| | | if(!hisNode.getId().equals(pkgNode.getId())){ |
| | | hisNode.setIsLastEdition(0); |
| | | //String newParentIds = machineNode.getParentIds()+","+machineNode.getId(); |
| | | |
| | | //更新机床 下属节点的数据 为旧版本,锁定(最新版本=0,lock=1). |
| | | /* |
| | | this.nodeService.lambdaUpdate().likeRight(NcNode::getParentIds, newParentIds) |
| | | .in(NcNode::getNodeType, Arrays.asList(NcNode.TYPE_PROGRAM_PACKAGE,NcNode.TYPE_PROGRAM_FILE)) |
| | | .set(NcNode::getIsLastEdition,0).set(NcNode::getIsLocked,1).update(); |
| | | */ |
| | | //机床下现在没有文件了,程序包名升级与机床同级了,改为找到机床同级程序包名更新了 |
| | | this.nodeService.lambdaUpdate().likeRight(NcNode::getParentIds, machineNode.getParentIds()) |
| | | .in(NcNode::getNodeType, Arrays.asList(NcNode.TYPE_PROGRAM_PACKAGE,NcNode.TYPE_PROGRAM_FILE)) |
| | | .set(NcNode::getIsLastEdition,0).set(NcNode::getIsLocked,1).update(); |
| | | |
| | | for(NcNode hisPackageNode : historyProgramPackageNodes){ |
| | | if(!hisPackageNode.getId().equals(pkgNode.getId())){ |
| | | hisPackageNode.setIsLastEdition(0); |
| | | } |
| | | hisNode.setParentId(machineNode.getId()); |
| | | hisNode.setParentIds(newParentIds); |
| | | hisPackageNode.setParentId(machineNode.getId()); |
| | | hisPackageNode.setParentIds(machineNode.getParentIds());//程序包与机床节点同级 |
| | | |
| | | //处理程序包下层的程序节点 |
| | | List<NcNode> programNodes = nodeService.lambdaQuery().eq(NcNode::getParentId,hisNode.getId()).list(); |
| | | List<NcNode> programNodes = nodeService.lambdaQuery().eq(NcNode::getParentId,hisPackageNode.getId()).list(); |
| | | for(NcNode programNode : programNodes){ |
| | | programNode.setParentIds(hisNode.getParentIds()+","+hisNode.getId()); |
| | | programNode.setParentIds(hisPackageNode.getParentIds()+","+hisPackageNode.getId()); |
| | | } |
| | | nodeService.updateBatchById(programNodes); |
| | | } |
| | | nodeService.updateBatchById(historyNodes); |
| | | |
| | | |
| | | nodeService.updateBatchById(historyProgramPackageNodes); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 计算有效期 |
| | | * @return |
| | | */ |
| | | private Date calculateExpireDate() { |
| | | R<String> validMonResult = sysClient.getParamValue(ParamConstants.CURE_VALID_MONTH_KEY); |
| | | |
| | | int month = DEFAULT_VALID_MONTH; |
| | | if(validMonResult.isSuccess() && validMonResult.getData()!=null){ |
| | | month = Integer.parseInt(validMonResult.getData()); |
| | | } |
| | | |
| | | LocalDate now = LocalDate.now(); |
| | | return DateUtil.toDate(now.plusMonths(month)); |
| | | } |
| | | |
| | | } |