| | |
| | | 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.ParamContants; |
| | | 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); |
| | | //设置过期日期 |
| | | pkgNode.setExpireDate(calculateExpireDate()); |
| | | nodeService.updateById(pkgNode); |
| | | |
| | | List<NcNode> historyNodes = nodeService.getNodeHistorys(pkgNode); |
| | | List<NcNode> historyNodes = nodeService.getNodeHistory(pkgNode); |
| | | moveNodeToCuredTree(pkgNode,historyNodes,flowCommonService.getProgramProperties(processInstanceId)); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param historyNodes |
| | | */ |
| | | void moveNodeToCuredTree(NcNode pkgNode,List<NcNode> historyNodes, FlowProgramProperties programProperties) { |
| | | NcNode node = historyNodes.get(0); |
| | | //创建节点到机床级别.(固化树) |
| | | NcNode machineNode = ncNodeAutoCreateService.createNodeTreeToMachine(programProperties); |
| | | |
| | | //移动到固化树下的机床节点下层 |
| | | 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(); |
| | | |
| | | for(NcNode hisNode : historyNodes){ |
| | | if(!hisNode.getId().equals(pkgNode.getId())){ |
| | | hisNode.setIsLastEdition(0); |
| | |
| | | } |
| | | nodeService.updateBatchById(historyNodes); |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 计算有效期 |
| | | * @return |
| | | */ |
| | | private Date calculateExpireDate() { |
| | | R<String> validMonResult = sysClient.getParamValue(ParamContants.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)); |
| | | } |
| | | |
| | | } |