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

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.jpsoft.shinestar.modules.sys.dao.SysLogDAO;
import com.jpsoft.shinestar.modules.sys.entity.SysLog;
import com.jpsoft.shinestar.modules.sys.service.SysLogService;
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="sysLogService")
public class SysLogServiceImpl implements SysLogService {
	@Resource(name="sysLogDAO")
	private SysLogDAO sysLogDAO;

	@Override
	public SysLog get(Long id) {
		// TODO Auto-generated method stub
		return sysLogDAO.get(id);
	}

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

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

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

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