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.PunchLocationDAO;
import com.jpsoft.shinestar.modules.base.entity.PunchLocation;
import com.jpsoft.shinestar.modules.base.service.PunchLocationService;
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="punchLocationService")
public class PunchLocationServiceImpl implements PunchLocationService {
	@Resource(name="punchLocationDAO")
	private PunchLocationDAO punchLocationDAO;

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

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

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

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

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