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.InformationInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.InformationInfo;
import com.jpsoft.shinestar.modules.base.service.InformationInfoService;
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="informationInfoService")
public class InformationInfoServiceImpl implements InformationInfoService {
	@Resource(name="informationInfoDAO")
	private InformationInfoDAO informationInfoDAO;

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

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

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

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

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = informationInfoDAO.exist(id);
		
		return count > 0 ? true : false;
	}
	
	@Override
	public List<InformationInfo> list() {
		// TODO Auto-generated method stub
		return informationInfoDAO.list();
	}
		
	@Override
	public Page<InformationInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
        Page<InformationInfo> page = PageHelper.startPage(pageNumber,pageSize).doSelectPage(()->{
            informationInfoDAO.search(searchParams,sortList);
        });
        
        return page;
	}

	@Override
	public List<InformationInfo> findByOwnerIdAndType(String ownerId, String type) {
		return informationInfoDAO.findByOwnerIdAndType(ownerId,type);
	}
}