package com.jpsoft.shinestar.modules.base.service.impl;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.base.dao.MeetingPersonDAO;
import com.jpsoft.shinestar.modules.base.entity.MeetingPerson;
import com.jpsoft.shinestar.modules.base.service.MeetingPersonService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="meetingPersonService")
public class MeetingPersonServiceImpl implements MeetingPersonService {
	@Resource(name="meetingPersonDAO")
	private MeetingPersonDAO meetingPersonDAO;

	@Override
	public MeetingPerson get(String id) {
		// TODO Auto-generated method stub
		return meetingPersonDAO.get(id);
	}

	@Override
	public int insert(MeetingPerson model) {
		// TODO Auto-generated method stub
		//model.setId(UUID.randomUUID().toString());
		
		return meetingPersonDAO.insert(model);
	}

	@Override
	public int update(MeetingPerson model) {
		// TODO Auto-generated method stub
		return meetingPersonDAO.update(model);		
	}

	@Override
	public int delete(String id) {
		// TODO Auto-generated method stub
		return meetingPersonDAO.delete(id);
	}

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = meetingPersonDAO.exist(id);
		
		return count > 0 ? true : false;
	}
	
	@Override
	public List<MeetingPerson> list() {
		// TODO Auto-generated method stub
		return meetingPersonDAO.list();
	}

	@Override
	public List<MeetingPerson> findByMeetingId(String meetingId){
		return meetingPersonDAO.findByMeetingId(meetingId);
	}

	@Override
	public Page<MeetingPerson> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
        Page<MeetingPerson> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            meetingPersonDAO.search(searchParams,sortList);
        });
        
        return page;
	}


	@Override
	public Page<Map> realToSearch(Map<String, Object> searchParams, int pageIndex, int pageSize, boolean count, List<Sort> sortList) {
		Page<Map> page = PageHelper.startPage(pageIndex,pageSize,count).doSelectPage(()->{
			meetingPersonDAO.realToSearch(searchParams,sortList);
		});

		return page;
	}

	@Override
	public Page<MeetingPerson> absentSearch(Map<String, Object> searchParams, int pageIndex, int pageSize, boolean count, List<Sort> sortList) {
		Page<MeetingPerson> page = PageHelper.startPage(pageIndex,pageSize,count).doSelectPage(()->{
			meetingPersonDAO.absentSearch(searchParams,sortList);
		});

		return page;
	}

	@Override
	public Page<Map> lateSearch(Map<String, Object> searchParams, int pageIndex, int pageSize, boolean count, List<Sort> sortList) {
		Page<Map> page = PageHelper.startPage(pageIndex,pageSize,count).doSelectPage(()->{
			meetingPersonDAO.lateSearch(searchParams,sortList);
		});

		return page;
	}
}