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

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;

import com.jpsoft.shinestar.modules.base.dto.WatchMeasureCurve;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.base.dao.WatchMeasureDAO;
import com.jpsoft.shinestar.modules.base.entity.WatchMeasure;
import com.jpsoft.shinestar.modules.base.service.WatchMeasureService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="watchMeasureService")
public class WatchMeasureServiceImpl implements WatchMeasureService {
	@Resource(name="watchMeasureDAO")
	private WatchMeasureDAO watchMeasureDAO;

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

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

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

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

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

	@Override
	public String getWatchNewData(String deviceNo, String name) {
		// TODO Auto-generated method stub

		return watchMeasureDAO.getWatchNewData(deviceNo, name);
	}

	@Override
	public List<WatchMeasureCurve> getCurveData(String deviceNo, String name,int limit) {
		// TODO Auto-generated method stub

		return watchMeasureDAO.getCurveData(deviceNo, name, limit);
	}

	@Override
	public List<WatchMeasureCurve> getLbsData(String deviceNo, String startTime, String endTime) {
		// TODO Auto-generated method stub

		return watchMeasureDAO.getLbsData(deviceNo, startTime, endTime);
	}

	@Override
	public WatchMeasure getLastDataByDay(String deviceNo, String name, String date) {
		return watchMeasureDAO.getLastDataByDay(deviceNo,name, date);
	}
}