package com.huatek.busi.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.huatek.busi.entity.EquipmentSumNumber;
import com.huatek.busi.mapper.*;
import com.huatek.busi.service.SumEquipmentNumberService;
import com.huatek.busi.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;


@Slf4j
@Component
@Service(interfaceClass = SumEquipmentNumberService.class)
@Transactional(rollbackFor = Exception.class)
public class SumEquipmentNumberServiceImpl implements SumEquipmentNumberService {
    @Autowired
    private TransformerNumberMapper transformerNumberMapper;
    @Autowired
    private GisNumberMapper gisNumberMapper;
    @Autowired
    private CableNumberMapper cableNumberMapper;
    @Autowired
    private CubicleNumberMapper cubicleNumberMapper;
    @Autowired
    private GeneratorNumberMapper generatorNumberMapper;
    @Autowired
    private ArresterNumberMapper arresterNumberMapper;

    public static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    @Override
    public EquipmentSumNumber findSumEquipmentNumber() {
        EquipmentSumNumber findAllSum = new EquipmentSumNumber();
        //各个设备总数
//        int countSumTransformer = transformerNumberMapper.finSumNumber(siteId);
//        int countSumGis = gisNumberMapper.findSumNumber();
//        int countSumCable = cableNumberMapper.findSumNumber();
//        int countSumCubicle = cubicleNumberMapper.findSumNumber();
//        int countSumGenerator = generatorNumberMapper.findSumNumber();
//        int countSumArrester = arresterNumberMapper.findSumNumber();
        //各个设备故障数
        Date dNow = new Date();
        Date dB = DateUtil.getDateByType(dNow, -1, "day");
        String dTime = sdf.format(dB);
        int countFaultTransformer = transformerNumberMapper.finFaultNumber(dTime);
        int countFaultGis = gisNumberMapper.findFaultNumber(dTime);
        int countFaultCable = cableNumberMapper.findFaultNumber(dTime);
        int countFaultCubicle = cubicleNumberMapper.findFaultNumber(dTime);
        int countFaultGenerator = generatorNumberMapper.findFaultNumber(dTime);
        int countFaultArrester = arresterNumberMapper.findFaultNumber(dTime);

        //统计六大类外挂设备总数
//        int countAllSum= countSumTransformer+countSumGis+countSumCable+countSumCubicle+countSumGenerator+countSumArrester;
        //统计六大类外挂设备故障数
        int countAllFault = countFaultTransformer+countFaultGis+countFaultCable+countFaultCubicle+countFaultGenerator+countFaultArrester;

//        findAllSum.setAllSumNumber(countAllSum);
        findAllSum.setAllSumFaultNumber(countAllFault);
        findAllSum.setAllSumNormalNumber(0);//在线数目前不确定

        return findAllSum;
    }


}
