package com.ruoyi.ems.service.impl;

import com.ruoyi.ems.domain.ElecStoreH;
import com.ruoyi.ems.mapper.EmsElecStoreHMapper;
import com.ruoyi.ems.model.ElecStoreAnalyze;
import com.ruoyi.ems.model.ElecStoreSta;
import com.ruoyi.ems.model.QueryMeter;
import com.ruoyi.ems.service.IElecStoreService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 储能计量-小时Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-09
 */
@Service
public class ElecStoreServiceImpl implements IElecStoreService {
    @Autowired
    private EmsElecStoreHMapper elecStoreHMapper;

    /**
     * 查询储能计量-小时
     *
     * @param id 储能计量-小时主键
     * @return 储能计量-小时
     */
    @Override
    public ElecStoreH selectHourById(Long id) {
        return elecStoreHMapper.selectStoreHById(id);
    }

    @Override
    public ElecStoreAnalyze getDayStatistics(String date) {
        ElecStoreSta daySum = elecStoreHMapper.selectStoreHSumDate(date);
        List<ElecStoreSta> hourSum = elecStoreHMapper.selectStoreHSumHour(date);

        ElecStoreAnalyze analyze = new ElecStoreAnalyze();
        analyze.setDaySum(daySum);
        analyze.setHourSum(hourSum);

        return analyze;
    }

    /**
     * 查询储能计量-小时列表
     *
     * @param elecStoreH 储能计量-小时
     * @return 储能计量-小时
     */
    @Override
    public List<ElecStoreH> selectHourList(ElecStoreH elecStoreH) {
        if (StringUtils.equals("-1", elecStoreH.getAreaCode())) {
            return elecStoreHMapper.selectStoreHAllArea(elecStoreH);
        } else {
            return elecStoreHMapper.selectStoreHList(elecStoreH);
        }
    }

    @Override
    public ElecStoreH selectStoreHByDataRange(ElecStoreH elecStoreH) {
        return elecStoreHMapper.selectStoreHByDataRange(elecStoreH);
    }

    @Override
    public List<ElecStoreH> selectDayList(QueryMeter param) {
        return elecStoreHMapper.selectStoreDayList(param);
    }

    /**
     * 新增储能计量-小时
     *
     * @param elecStoreH 储能计量-小时
     * @return 结果
     */
    @Override
    public int insertHour(ElecStoreH elecStoreH) {
        return elecStoreHMapper.insertStoreH(elecStoreH);
    }

    /**
     * 修改储能计量-小时
     *
     * @param elecStoreH 储能计量-小时
     * @return 结果
     */
    @Override
    public int updateHour(ElecStoreH elecStoreH) {
        return elecStoreHMapper.updateStoreH(elecStoreH);
    }

    /**
     * 批量删除储能计量-小时
     *
     * @param ids 需要删除的储能计量-小时主键
     * @return 结果
     */
    @Override
    public int deleteHourByIds(Long[] ids) {
        return elecStoreHMapper.deleteStoreHByIds(ids);
    }

    /**
     * 删除储能计量-小时信息
     *
     * @param id 储能计量-小时主键
     * @return 结果
     */
    @Override
    public int deleteHourById(Long id) {
        return elecStoreHMapper.deleteStoreHById(id);
    }
}
