package com.zhiwei.manage.service;

import java.util.List;

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

import com.zhiwei.manage.bean.Channel;
import com.zhiwei.manage.bean.PageEty;
import com.zhiwei.manage.bean.ServerBean;
import com.zhiwei.manage.dao.ServerDao;

@Service
public class ServerServiceImpl implements ServerService {

	@Autowired
	private ServerDao sd;

	@Override
	public void insert(ServerBean serverBean) {
		sd.insert(serverBean);
	}

	@Override
	public PageEty findDb(int pageNo, int pageSize, String dbName) {
		List<ServerBean> list = sd.findDb(pageNo, pageSize, dbName);
		PageEty page = new PageEty();
		page.setData(list);
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);
		int count = sd.findServerCount(dbName);
		page.setDataCount(count);
		if (count % pageSize == 0) {
			page.setPageCount(count / pageSize);
		} else {
			page.setPageCount(count / pageSize + 1);
		}
		System.out.println(page);
		return page;
	}

	@Override
	public boolean update(ServerBean serverBean) {
		return sd.update(serverBean);
	}

	@Override
	public boolean delete(List<String> id) {
		return sd.delete(id);
	}


	@Override
	public void insertChannels(Channel channels) {
		sd.insertChannels(channels);
	}

	@Override
	public void findPt(String pt) {
		sd.findPt(pt);
	}

	@Override
	public boolean updateChannel(Channel channel) {
		return sd.updateChannel(channel);
	}

	@Override
	public boolean deleteChannel(List<String> id) {
		return sd.deleteChannel(id);
	}

	@Override
	public PageEty findChannel(int pageNo,int pageSize) {
		List<Channel> list= sd.findAllChannels(pageNo,pageSize);
		PageEty page = new PageEty();
		page.setData(list);
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);
		int count = sd.findChannelsCount();
		page.setDataCount(count);
		if (count % pageSize == 0) {
			page.setPageCount(count / pageSize);
		} else {
			page.setPageCount(count / pageSize + 1);
		}
		return page;
	}

	@Override
	public List<Channel> findDisChannel() {
		return sd.findDisChannels();
	}

	@Override
	public List<String> findDisChan() {
		return sd.findDisChan();
	}

	@Override
	public List<Channel> findChannels() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ServerBean findServer(String pt) {
		return sd.findServerBean(pt);
	}

}
