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.PersonHealthLedgerDAO;
import com.jpsoft.shinestar.modules.base.dto.PersonHealthLedgerDTO;
import com.jpsoft.shinestar.modules.base.entity.PersonHealthLedger;
import com.jpsoft.shinestar.modules.base.entity.PersonInfo;
import com.jpsoft.shinestar.modules.base.service.PersonHealthLedgerService;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import org.joda.time.DateTime;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Transactional
@Component(value="personHealthLedgerService")
public class PersonHealthLedgerServiceImpl implements PersonHealthLedgerService {
	@Resource(name="personHealthLedgerDAO")
	private PersonHealthLedgerDAO personHealthLedgerDAO;

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

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

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

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

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

	@Override
	public PersonHealthLedger lastByPersonId(Long personId){
		return personHealthLedgerDAO.lastByPersonId(personId);
	}
	
	@Override
	public List<PersonHealthLedger> list() {
		// TODO Auto-generated method stub
		return personHealthLedgerDAO.list();
	}
	@Override
	public List<PersonHealthLedger> findByTimeAndPersonId(String queryTime,Long personId,String addressOut,String addressIn,String temperature){
		return personHealthLedgerDAO.findByTimeAndPersonId(queryTime,personId,addressOut,addressIn,temperature);
	}

//	@Override
//	public List<PersonHealthLedger> findByCreateTime(Date startTime, Date endTime){
//		return personHealthLedgerDAO.findByCreateTime(startTime,endTime);
//	}
	@Override
	public PersonHealthLedger existByCreateTimeAndPersonId(long personId,Date startTime, Date endTime){
		return personHealthLedgerDAO.existByCreateTimeAndPersonId(personId,startTime,endTime);
	}
		
	@Override
	public Page<PersonHealthLedger> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
        Page<PersonHealthLedger> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            personHealthLedgerDAO.search(searchParams,sortList);
        });
        
        return page;
	}

	@Override
	public Page<PersonHealthLedgerDTO> workerPageList(Map<String, Object> searchParams, int pageNumber, int pageSize, boolean count, List<Sort> sortList) {

		Page<PersonHealthLedgerDTO> page = PageHelper.startPage(pageNumber, pageSize, count).doSelectPage(() -> {
			personHealthLedgerDAO.workerSearch(searchParams, sortList);
		});

		return page;
	}

//	@Override
//	public Page<PersonInfo> teacherPageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize, boolean count, List<Sort> sortList) {
//		Page<PersonInfo> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
//			personHealthLedgerDAO.teacherSearch(searchParams,sortList);
//		});
//
//		return page;
//	}

	@Override
	public int replace(Long srcPersonId, Long destPersonId) {
		return personHealthLedgerDAO.replace(srcPersonId,destPersonId);
	}

	@Override
	public List<PersonHealthLedger> findByCreateTimeAndPersonId(long personId,Date startTime, Date endTime){
		return personHealthLedgerDAO.findByCreateTimeAndPersonId(personId,startTime,endTime);
	}

	@Override
	public List<Map> query(Map<String, Object> searchParams) {
		return personHealthLedgerDAO.query(searchParams);
	}
}