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.CanteenDiningDAO;
import com.jpsoft.shinestar.modules.base.entity.CanteenDining;
import com.jpsoft.shinestar.modules.base.service.CanteenDiningService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="canteenDiningService")
public class CanteenDiningServiceImpl implements CanteenDiningService {
	@Resource(name="canteenDiningDAO")
	private CanteenDiningDAO canteenDiningDAO;

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

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

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

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

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

	@Override
	public List<CanteenDining> findByCanteenId(String CanteenId){
		return canteenDiningDAO.findByCanteenId(CanteenId);
	}
		
	@Override
	public Page<CanteenDining> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
        Page<CanteenDining> page = PageHelper.startPage(1,10).doSelectPage(()->{
            canteenDiningDAO.search(searchParams,sortList);
        });
        
        return page;
	}
}