 package com.huatek.busi.service.impl;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.huatek.busi.entity.IecBreakerParam;
import com.huatek.busi.mapper.IecBreakerParamMapper;
import com.huatek.busi.service.IecBreakerParamService;
@Component
@Service(interfaceClass = IecBreakerParamService.class)
@Transactional(rollbackFor = Exception.class)
public class IecBreakerParamServiceImpl implements IecBreakerParamService {

    @Autowired
    private IecBreakerParamMapper iecBreakerParamMapper;
    @Override
    public List<IecBreakerParam> findIecBreakerParam(String siteId, String mainTreeId) {
        return iecBreakerParamMapper.findIecBreakerParam(siteId, mainTreeId);
    }
    @Override
    public Map<String, Object> findYxdl(String siteId, String eqmCode) {
        Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 
        ca.setTime(new Date()); //设置时间为当前时间 
        ca.add(Calendar.DATE, -1); //日期减1 
        Date lastDay = ca.getTime();
        SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd");
        String dateString = format.format(lastDay);
        String sTime = dateString + " 00:00:00";
        String eTime = dateString + " 23:59:59";
        return iecBreakerParamMapper.findYxdl(siteId,eqmCode,sTime,eTime);
    }
    
	@Override
	public List<Map<String, Object>> findIecBreakerParamByDay(LocalDate day) {
		String sTime = day + " 00:00:00";
        String eTime = day + " 23:59:59";
        return iecBreakerParamMapper.findIecBreakerParamByDay(sTime,eTime);
	}
	@Override
	public List<IecBreakerParam> findIecBreakerParamNow(String siteId, String mainTreeId, LocalDate day) {
		String sTime = day + " 00:00:00";
        String eTime = day + " 23:59:59";
		return iecBreakerParamMapper.findIecBreakerParamNow(siteId, mainTreeId,sTime,eTime);
	}
}
