package com.yingxin.prms.service.dao;

import com.yingxin.prms.domain.FlowLine;
import com.yingxin.prms.domain.FlowNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Description:
 * Datetime:    2021/1/12   9:53
 * Author:   gaozhentao
 */
@Repository
public class FlowDaoImpl {

    private final CassandraTemplate template;

    @Autowired
    public FlowDaoImpl(CassandraTemplate template) {
            this.template = template;
        }


    public void insertNode(FlowNode flowNode) {
        String cql ="INSERT INTO ctid_prof.flownode(cluster_name, server_path)" +
                "VALUES('"+flowNode.getCluster_name()+"', '"+flowNode.getServerPath()+"');";
        template.getCqlOperations().execute(cql);
    }
    public boolean updateNode(String clusterName,String coordinate,String mark) {
        String cql ="UPDATE ctid_prof.flownode set coordinate='"+coordinate+"', mark='"+mark+
                "' WHERE  cluster_name='"+clusterName+"'";
        return template.getCqlOperations().execute(cql);
    }


    public List<FlowNode> findNodeAll() {
        String cql ="SELECT * FROM ctid_prof.flownode";
        return template.select(cql,FlowNode.class);
    }
    public List<FlowLine> findLineAll() {
        String cql ="SELECT * FROM ctid_prof.flowline";
        return template.select(cql,FlowLine.class);
    }

    public void insertLine(FlowLine flowLine) {
        String cql ="update INTO ctid_prof.flowline ( cluster_name_left, cluster_name_right, coordinate_left, coordinate_right)"+
                "VALUES( '"+flowLine.getCluster_name_left()+"', '"+flowLine.getClusterNameRight()+"', '"+flowLine.getCoordinateLeft()+"', '"+flowLine.getCoordinateRight()+"');";
        template.getCqlOperations().execute(cql);
    }

    public void updateLine(String clusterNameLeft, String clusterNameRight, String points, String color) {
        String cql ="UPDATE ctid_prof.flowline SET points='"+points+"',color ='"+color+"' " +
                "where cluster_name_left='"+clusterNameLeft+"' and cluster_name_right='"+clusterNameRight+"'";
         template.getCqlOperations().execute(cql);
    }
}
