package com.ruoyi.ems.service.impl;

import com.ruoyi.common.core.utils.DateTimeUtil;
import com.ruoyi.ems.domain.ElecPgSupplyH;
import com.ruoyi.ems.mapper.ElecPgSupplyHMapper;
import com.ruoyi.ems.mapper.ElecPvSupplyHMapper;
import com.ruoyi.ems.model.QueryMeter;
import com.ruoyi.ems.service.IElecPgSupplyHService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

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

    @Autowired
    private ElecPvSupplyHMapper pvSupplyHMapper;

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

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

    @Override
    public List<ElecPgSupplyH> selectPgSupplyH(QueryMeter queryMeter) {
        return pgSupplyHMapper.selectPgSupplyH(queryMeter);
    }

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

    @Override
    public int insertBatch(List<ElecPgSupplyH> list) {
        return pgSupplyHMapper.insertBatch(list);
    }

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

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

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

    @Override
    public ElecPgSupplyH calDaySupplyByH(QueryMeter param) {
        return pgSupplyHMapper.calDaySupplyByH(param);
    }

    @Override
    public List<ElecPgSupplyH> calMonthSupplyByH(ElecPgSupplyH param) {
        return pgSupplyHMapper.calMonthSupplyByH(param);
    }

    @Override
    public Map<String, Object> selectSupplyByH() {
        String thisDay = DateTimeUtil.currentDateTime(DateTimeUtil.DateFormatter.yyyy_MM_dd);
        Map<String, Map<String, Object>> supplyByHMap = pgSupplyHMapper.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> selectSupplyByDay() {
        String thisDay = DateTimeUtil.currentDateTime(DateTimeUtil.DateFormatter.yyyy_MM_dd);
        Map<String, Object> thisDaySupply = pgSupplyHMapper.calThisDaySupply(thisDay);
        Map<String, Object> thisDayPv = pvSupplyHMapper.calThisDayPv(thisDay);
        return new HashMap<String, Object>() {{
            put("supply", thisDaySupply);
            put("pv", thisDayPv);
        }};
    }
}
