package com.fastbee.deviceData.api.devlink.service;

import com.fastbee.common.utils.DateUtils;
import com.fastbee.deviceData.domain.DeviceRealtimedataMeteorology;
import com.fastbee.deviceData.domain.DeviceRealtimedataMoisture;
import com.fastbee.deviceData.mapper.DeviceRealtimedataMeteorologyMapper;
import com.fastbee.deviceData.mapper.DeviceRealtimedataMoistureMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;

/**
 * devLink墒情设备数据服务
 */
@Service
public class DevLinkMoistureDataService extends DevLinkRealTimeDataService{
    @Autowired
    private DevLinkAuthorizationService authorizationService;
    @Autowired
    private DeviceRealtimedataMoistureMapper moistureMapper;
    //封装数据
    public DeviceRealtimedataMoisture setData(Map<String, String> propertiesMap){
        DeviceRealtimedataMoisture build = DeviceRealtimedataMoisture.builder()
                .deviceId(propertiesMap.get("deviceId"))
                .soilTemp(toBigDecimalValue(propertiesMap.get("soilTemp")))
                .soilHumi(toBigDecimalValue(propertiesMap.get("soilHumi")))
                .soilEc(toBigDecimalValue(propertiesMap.get("soilEc")))
                .soilPh(toBigDecimalValue(propertiesMap.get("soilPh")))
                .soilTemp1(toBigDecimalValue(propertiesMap.get("soilTemp_1")))
                .soilHumi1(toBigDecimalValue(propertiesMap.get("soilHumi_1")))
                .soilTemp2(toBigDecimalValue(propertiesMap.get("soilTemp_2")))
                .soilHumi2(toBigDecimalValue(propertiesMap.get("soilHumi_2")))
                .soilTemp3(toBigDecimalValue(propertiesMap.get("soilTemp_3")))
                .soilHumi3(toBigDecimalValue(propertiesMap.get("soilHumi_3")))
                .soilTemp4(toBigDecimalValue(propertiesMap.get("soilTemp_4")))
                .soilHumi4(toBigDecimalValue(propertiesMap.get("soilHumi_4")))
                .airTemp(toBigDecimalValue(propertiesMap.get("airTemp")))
                .mppTemp(toBigDecimalValue(propertiesMap.get("mppTemp")))
                .batteryCap(toBigDecimalValue(propertiesMap.get("batteryCap")))
                .batteryVolt(toBigDecimalValue(propertiesMap.get("batteryVolt")))
                .batteryCur(toBigDecimalValue(propertiesMap.get("batteryCur")))
                .batteryPower(toBigDecimalValue(propertiesMap.get("batteryPower")))
                .loadVolt(toBigDecimalValue(propertiesMap.get("loadVolt")))
                .loadCur(toBigDecimalValue(propertiesMap.get("loadCur")))
                .loadPower(toBigDecimalValue(propertiesMap.get("loadPower")))
                .photVolt(toBigDecimalValue(propertiesMap.get("photVolt")))
                .photCur(toBigDecimalValue(propertiesMap.get("photCur")))
                .photPower(toBigDecimalValue(propertiesMap.get("photPower")))
                .cumChargeDay(toBigDecimalValue(propertiesMap.get("cum_charge_day")))
                .cumChargeMon(toBigDecimalValue(propertiesMap.get("cum_charge_mon")))
                .cumChargeYear(toBigDecimalValue(propertiesMap.get("cum_charge_year")))
                .cumChargeAll(toBigDecimalValue(propertiesMap.get("cum_charge_all")))
                .cumEleDay(toBigDecimalValue(propertiesMap.get("cum_ele_day")))
                .cumEleMon(toBigDecimalValue(propertiesMap.get("cum_ele_mon")))
                .cumEleYear(toBigDecimalValue(propertiesMap.get("cum_ele_year")))
                .cumEleAll(toBigDecimalValue(propertiesMap.get("cum_ele_all")))
                .shoudong(toLongValue(propertiesMap.get("shoudong")))
                .control(toLongValue(propertiesMap.get("control")))
                //TODO set实时时间
                .saveTime(DateUtils.getNowDate())
                .build();
        System.err.println(build);
        return build;

    }
    public static void main(String[] args) {
        DevLinkMoistureDataService devLinkMoistureDataService = new DevLinkMoistureDataService();
        Map<String, String> metDeviceRealData = devLinkMoistureDataService.getMetDeviceRealData("3270");
        devLinkMoistureDataService.setData(metDeviceRealData);
    }
}
