package com.huatek.busi.service.impl.gis;

import java.time.LocalDate;
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.RptGisMonitor;
import com.huatek.busi.mapper.RptGisMonitorMapper;
import com.huatek.busi.service.IecBreakerParamService;
import com.huatek.busi.service.arrester.RptGisMonitorService;

/**
 *  GIS开关--断路器(机械特性)信息--每天汇总信息
 * @author buck_guo
 * @date 2019/09/04
 */
@Component
@Service(interfaceClass = RptGisMonitorService.class)
@Transactional(rollbackFor = Exception.class)
public class RptGisMonitorServiceImpl implements RptGisMonitorService {
    
    @Autowired
    private RptGisMonitorMapper rptGisMonitorMapper;
    
    @Autowired
    private IecBreakerParamService iecBreakerParamService;

    @Override
    public RptGisMonitor findRptGisMonitor(String mainTreeId,String siteId) {
        return rptGisMonitorMapper.findRptGisMonitor(mainTreeId,siteId);
    }

	@Override
	public void updaeGisMonitorByDay(LocalDate day) {
		List<Map<String, Object>> list = iecBreakerParamService.findIecBreakerParamByDay(day);
		for(Map<String, Object> map:list)
		{
			//断开次数累加
			RptGisMonitor monitor = findRptGisMonitor(map.get("eqmCode").toString(),map.get("siteId").toString());
			if(monitor != null)
			{
				rptGisMonitorMapper.updaeGisMonitorByDay(monitor.getMainTreeId(), monitor.getSiteId(),monitor.getTurnoffCount()+Long.parseLong(map.get("breakCount")+""));   
			}	
		}
	}
}
