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 com.jpsoft.shinestar.modules.base.dao.CanteenDeviceDAO;
import com.jpsoft.shinestar.modules.base.entity.CanteenDevice;
import com.jpsoft.shinestar.modules.base.service.CanteenDeviceService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="canteenDeviceService")
public class CanteenDeviceServiceImpl implements CanteenDeviceService {
	@Resource(name="canteenDeviceDAO")
	private CanteenDeviceDAO canteenDeviceDAO;

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

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

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

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

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

	@Override
	public CanteenDevice findByDeviceIdAndCanteenId(String deviceId,String canteenId){
		return canteenDeviceDAO.findByDeviceIdAndCanteenId(deviceId,canteenId);
	}

	@Override
	public CanteenDevice findByDeviceId(String deviceId){
		return canteenDeviceDAO.findByDeviceId(deviceId);
	}

	@Override
	public List<CanteenDevice> list() {
		// TODO Auto-generated method stub
		return canteenDeviceDAO.list();
	}
		
	@Override
	public Page<CanteenDevice> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
        Page<CanteenDevice> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            canteenDeviceDAO.search(searchParams,sortList);
        });
        
        return page;
	}
}