package cn.cecep.talroad.data.analyse.task.transfer.rate;

import cn.cecep.talroad.common.core.utils.DateUtils;
import cn.cecep.talroad.data.analyse.task.entity.SimpleSRaFactoryTransferRateAnalysis;
import cn.cecep.talroad.enums.LabelFactoryEnum;
import cn.cecep.talroad.enums.TimeTypeEnum;
import cn.cecep.talroad.mapper.analysis.SRaFactoryTransferRateAnalysisMapper;
import cn.cecep.talroad.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.List;

/**
 * @author hehongyu
 * @description: 关联分析系统-数据质量分析-企业传输率分析-无组织
 * @date 2023/6/27 23:06
 */
@Slf4j
@Service
public class InorganizationAnalyseService extends TransferRateAbstractService{

    @Autowired
    private SRaFactoryTransferRateAnalysisMapper mapper;

    @Override
    protected String getLabelCode() {
        return LabelFactoryEnum.JG053.getEnumId();
    }

    @Override
    protected BigDecimal getAnalyseValue(SimpleSRaFactoryTransferRateAnalysis entity) {
        return entity.getElecTransmissionRate();
    }

    @Override
    protected List<SimpleSRaFactoryTransferRateAnalysis> getDataList() {
        //利用mysql 函数 查询本年的 日平均传输率
        Calendar instance = Calendar.getInstance();
        instance.set(Calendar.YEAR,instance.get(Calendar.YEAR) - 1);
        return mapper.selectAvgRateByDateTimeGroupFactoryId(DateUtil.format(instance.getTime(), DateUtils.YYYY_MM_DD),TimeTypeEnum.DAY.getCode());
    }
}
