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.PunchRecordDAO;
import com.jpsoft.shinestar.modules.base.entity.PunchRecord;
import com.jpsoft.shinestar.modules.base.service.PunchRecordService;
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="punchRecordService")
public class PunchRecordServiceImpl implements PunchRecordService {
	@Resource(name="punchRecordDAO")
	private PunchRecordDAO punchRecordDAO;

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

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

		return punchRecordDAO.insert(model);
	}

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

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

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = punchRecordDAO.exist(id);

		return count > 0 ? true : false;
	}

	@Override
	public List<PunchRecord> list() {
		// TODO Auto-generated method stub
		return punchRecordDAO.list();
	}

	@Override
	public Page<PunchRecord> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize, boolean count, List<Sort> sortList) {
        Page<PunchRecord> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            punchRecordDAO.search(searchParams,sortList);
        });

        return page;
	}

	@Override
	public List<PunchRecord> findByPersonAndDate(Long personId, String startDate, String endDate) {
		return punchRecordDAO.findByPersonAndDate(personId,startDate,endDate);
	}
}