package com.wx.application.core.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wx.application.base.BaseService;
import com.wx.application.core.entity.GraphCase;
import com.wx.application.core.mapper.GraphCaseMapper;
import com.wx.application.nebula.graph.bean.NebulaSpace;
import com.wx.application.nebula.graph.service.NebulaOperateService;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author zj
 * @since 2022-09-23
 */
/*@Slf4j*/
@Service("coreGraphCaseService")
@Transactional
public class GraphCaseService extends BaseService<GraphCase, GraphCaseMapper> {

	@Autowired
	GraphCaseMapper baseMapper;
	
	@Autowired
	NebulaOperateService nebulaOperateService;
	
	/**
	 * 创建工作空间
	 */
	public NebulaSpace createGraphCase(GraphCase graphCase) {
		
		create(graphCase);
		
		NebulaSpace e = new NebulaSpace();
		e.setName(graphCase.getName());
		e.setComment(graphCase.getComment());
		
		nebulaOperateService.createSpace(e);
		
		return e;
	}
	
	public void removeGraphCase(Long id) {
		GraphCase graphCase = getOne(id);
		if(graphCase != null) {
			nebulaOperateService.dropSpace(graphCase.getName());
			baseMapper.deleteById(id);
		}
	}

}
