package com.ruoyi.ems.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.core.utils.DateTimeUtil;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.ems.domain.ElecPgSupplyH;
import com.ruoyi.ems.domain.vo.QueryIndex;
import com.ruoyi.ems.mapper.ElecPgSupplyHMapper;
import com.ruoyi.ems.mapper.PvSupplyHMapper;
import com.ruoyi.ems.service.IElecPgSupplyHService;

/**
 * 电网供应计量-小时Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-09
 */
@Service
public class EmsPgSupplyHServiceImpl implements IElecPgSupplyHService {
    @Autowired
    private ElecPgSupplyHMapper emsPgSupplyHMapper;

    @Autowired
    private PvSupplyHMapper pvSupplyHMapper;

    /**
     * 查询电网供应计量-小时
     *
     * @param id 电网供应计量-小时主键
     * @return 电网供应计量-小时
     */
    @Override
    public ElecPgSupplyH selectPgSupplyHById(Long id) {
        return emsPgSupplyHMapper.selectPgSupplyHById(id);
    }

    /**
     * 查询电网供应计量-小时列表
     *
     * @param elecPgSupplyH 电网供应计量-小时
     * @return 电网供应计量-小时
     */
    @Override
    public List<ElecPgSupplyH> selectPgSupplyHList(ElecPgSupplyH elecPgSupplyH) {
        if (StringUtils.isNotEmpty(elecPgSupplyH.getAreaCode())) {
            return emsPgSupplyHMapper.selectPgSupplyHList(elecPgSupplyH);
        }
        return emsPgSupplyHMapper.selectPgSupplyHAllArea(elecPgSupplyH);
    }

    @Override
    public List<ElecPgSupplyH> selectPgSupplyH(QueryIndex queryIndex) {
        return emsPgSupplyHMapper.selectPgSupplyH(queryIndex);
    }

    @Override
    public Map<String, Object> selectSupplyPvByH() {
        String thisDay = DateTimeUtil.currentDateTime(DateTimeUtil.DateFormatter.yyyy_MM_dd);
        Map<String, Map<String, Object>> supplyByHMap = emsPgSupplyHMapper.calThisDaySupplyByH(thisDay);
        Map<String, Map<String, Object>> pvByHMap = pvSupplyHMapper.calThisDayPvByH(thisDay);
        return new HashMap<String, Object>() {{
            put("supply", supplyByHMap);
            put("pv", pvByHMap);
        }};
    }

    @Override
    public Map<String, Object> selectSupplyPvByDay() {
        String thisDay = DateTimeUtil.currentDateTime(DateTimeUtil.DateFormatter.yyyy_MM_dd);
        Map<String, Object> thisDaySupply = emsPgSupplyHMapper.calThisDaySupply(thisDay);
        Map<String, Object> thisDayPv = pvSupplyHMapper.calThisDayPv(thisDay);
        return new HashMap<String, Object>() {{
            put("supply", thisDaySupply);
            put("pv", thisDayPv);
        }};
    }

    /**
     * 新增电网供应计量-小时
     *
     * @param elecPgSupplyH 电网供应计量-小时
     * @return 结果
     */
    @Override
    public int insertPgSupplyH(ElecPgSupplyH elecPgSupplyH) {
        return emsPgSupplyHMapper.insertPgSupplyH(elecPgSupplyH);
    }

    /**
     * 修改电网供应计量-小时
     *
     * @param elecPgSupplyH 电网供应计量-小时
     * @return 结果
     */
    @Override
    public int updatePgSupplyH(ElecPgSupplyH elecPgSupplyH) {
        return emsPgSupplyHMapper.updatePgSupplyH(elecPgSupplyH);
    }

    /**
     * 批量删除电网供应计量-小时
     *
     * @param ids 需要删除的电网供应计量-小时主键
     * @return 结果
     */
    @Override
    public int deletePgSupplyHByIds(Long[] ids) {
        return emsPgSupplyHMapper.deletePgSupplyHByIds(ids);
    }

    /**
     * 删除电网供应计量-小时信息
     *
     * @param id 电网供应计量-小时主键
     * @return 结果
     */
    @Override
    public int deletePgSupplyHById(Long id) {
        return emsPgSupplyHMapper.deletePgSupplyHById(id);
    }
}
