package com.ps.visualization.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.ps.base.dao.impl.BaseDaoImpl;
import com.ps.visualization.dao.CountryProgressDao;
import com.ps.visualization.vo.CountryProgress;

@Repository(value = "countryProgressDao")
public class CountryProgressDaoImpl extends
		BaseDaoImpl<CountryProgress, Integer> implements CountryProgressDao {

	@Override
	public List getScanProgress(String countryName, String[] protocolGroup) {
		// TODO Auto-generated method stub
		String sql = "";
		if (countryName.equalsIgnoreCase("all")) {
			sql = "select country_code,ip_num_done/ip_num_total b from country_progress where rounds='"
					+ getScanRounds() + "' order by b desc";
		} else {
			sql = "select country_code,ip_num_done/ip_num_total b from country_progress where country =\""
					+ countryName
					+ "\" and rounds='"
					+ getScanRounds()
					+ "' order by b desc";
		}
		List<Object[]> spList = new ArrayList<Object[]>();
		spList = findNativeSqlQuery(sql);
		return spList;
	}

	@Override
	public List getScanTopKey(String countryName, String[] protocolGroup) {
		// TODO Auto-generated method stub
		Integer num = 10;
		String sql = "";
		if (countryName.equalsIgnoreCase("all")) {
			sql = "SELECT pf.country_code, COUNT(pf.country) cc FROM portsinfo pf WHERE pf.rounds = '"
					+ getScanRounds()
					+ "' AND pf.service <> '"
					+ protocolGroup[0]
					+ "' AND pf.service <> '"
					+ protocolGroup[1]
					+ "' AND pf.country <> '' GROUP BY pf.country order by cc desc LIMIT "
					+ num;
		} else {
			// sql =
			// "select country_code,ip_num_exist b from country_progress where country = \""
			// + countryName
			// + "\" and rounds='4' order by b desc limit "
			// + num;
		}
		List<Object[]> stList = new ArrayList<Object[]>();
		stList = findNativeSqlQuery(sql);
		return stList;

	}

}
