package com.xhpc.charging.station.service;

import com.xhpc.charging.station.mapper.XhpcRateTimeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 费率时段Service业务层处理
 *
 * @author yuyang
 * @date 2021-07-20
 */
@Service
public class XhpcRateTimeServiceImpl implements IXhpcRateTimeService {

    @Autowired
    private XhpcRateTimeMapper xhpcRateTimeMapper;

    /**
     * 获取本时间段的电费
     *
     * @param date
     * @return
     */
    @Override
    public Map<String, Object> getXhpcRateTime(String date, Long datchargingStationIde) {

        //判断本时间段的电费
        Map<String, Object> hpcRateTimeMap = xhpcRateTimeMapper.getXhpcRateTime(date, datchargingStationIde);
        //该判断防止某个时间段费率没有录入
        if (hpcRateTimeMap == null) {
            //获取剩余时间费率
            return new HashMap<>();
        }
        Map<String, Object> map = new HashMap<>();
        Long rateId = Long.valueOf(hpcRateTimeMap.get("rateId").toString());
        Map<String, Object> xhpcTimeType = xhpcRateTimeMapper.getXhpcTimeType(datchargingStationIde, rateId);
        map.put("startTime", hpcRateTimeMap.get("startTime"));
        map.put("endTime", hpcRateTimeMap.get("endTime"));
        map.putAll(xhpcTimeType);
        return map;
    }

}
