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

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jpsoft.shinestar.modules.base.dao.MobileBannerInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.MobileBannerInfo;
import com.jpsoft.shinestar.modules.base.service.MobileBannerInfoService;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Transactional
@Component(value="mobileBannerInfoService")
public class MobileBannerInfoServiceImpl implements MobileBannerInfoService {
	@Resource(name="mobileBannerInfoDAO")
	private MobileBannerInfoDAO mobileBannerInfoDAO;

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

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

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

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

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

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