/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2023/6/15
 */
package org.springblade.modules.business.data.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.constant.RtuDataInfoConstant;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.modules.business.data.entity.RtuRealTimeStatusEntity;
import org.springblade.modules.business.data.entity.RtuRealTimeStatusStoreEntity;
import org.springblade.modules.business.data.mapper.RtuRealTimeStatusHistoreMapper;
import org.springblade.modules.business.data.service.IRtuRealTimeStatusHistoreService;
import org.springframework.stereotype.Service;

import java.util.Date;


/***
 * Date:2023/6/15
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@Service
public class RtuRealTimeStatusServiceHistoreImpl extends BaseServiceImpl<RtuRealTimeStatusHistoreMapper, RtuRealTimeStatusStoreEntity> implements IRtuRealTimeStatusHistoreService {
    @Override
    public boolean saveExtStatus(JSONObject data) {
        String rtuCode = data.getString(RtuDataInfoConstant.RTU_DATA_RTUCODE_KEY);
        RtuRealTimeStatusStoreEntity entity = new RtuRealTimeStatusStoreEntity();
        entity.setRtuCode(rtuCode);
        if (data.containsKey(RtuDataInfoConstant.RTU_DATA_COLLECT_TIME_KEY)) {
            entity.setCollectTime(data.getDate(RtuDataInfoConstant.RTU_DATA_COLLECT_TIME_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_DATA_UP_TIME_KEY)) {
            entity.setUpTime(data.getDate(RtuDataInfoConstant.RTU_DATA_UP_TIME_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_DATA_PICK_TIME_KEY)) {
            entity.setPickTime(data.getDate(RtuDataInfoConstant.RTU_DATA_PICK_TIME_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_DTU_SIGNAL_KEY)) {
            entity.setDtuSignal(data.getDouble(RtuDataInfoConstant.RTU_STATUS_DTU_SIGNAL_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_VOLTAGE_KEY)) {
            entity.setVoltage(data.getDouble(RtuDataInfoConstant.RTU_STATUS_VOLTAGE_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_TEMPERATURE_KEY)) {
            entity.setTemperature(data.getDouble(RtuDataInfoConstant.RTU_STATUS_TEMPERATURE_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_UUID_KEY)) {
            //     entity.set(data.getDouble(RtuDataInfoConstant.RTU_STATUS_UUID_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_CCID_KEY)) {
            //     entity.set(data.getDouble(RtuDataInfoConstant.RTU_STATUS_UUID_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_RTU_STATUS_KEY)) {
            entity.setRtuStatus(data.getInteger(RtuDataInfoConstant.RTU_STATUS_RTU_STATUS_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_RTU_ERROR_KEY)) {
            entity.setRtuError(data.getInteger(RtuDataInfoConstant.RTU_STATUS_RTU_ERROR_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_BATTERY_STATUS_KEY)) {
            entity.setBatteryStatus(data.getString(RtuDataInfoConstant.RTU_STATUS_BATTERY_STATUS_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_BATTERY_IN_KEY)) {
            entity.setBatteryBatteryIn(data.getString(RtuDataInfoConstant.RTU_STATUS_BATTERY_IN_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_BATTERY_OUT_KEY)) {
            entity.setBatteryBatteryOut(data.getString(RtuDataInfoConstant.RTU_STATUS_BATTERY_OUT_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_BATTERY_POWER_KEY)) {
            entity.setBatteryPower(data.getDouble(RtuDataInfoConstant.RTU_STATUS_BATTERY_POWER_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_BATTERY_TEMP_KEY)) {
            entity.setBatteryTemperature(data.getDouble(RtuDataInfoConstant.RTU_STATUS_BATTERY_TEMP_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_SUN_POWER_VOLTAGE_KEY)) {
            entity.setSunPowerVoltage(data.getDouble(RtuDataInfoConstant.RTU_STATUS_SUN_POWER_VOLTAGE_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_STATUS_SUN_POWER_ELECTRIC_KEY)) {
            entity.setSunPowerElectric(data.getDouble(RtuDataInfoConstant.RTU_STATUS_SUN_POWER_ELECTRIC_KEY));
        }
        if (data.containsKey("waterLevelSensorStatus")) {
            entity.setWaterLevelSensorStatus(Integer.valueOf(data.getString("waterLevelSensorStatus")));
        }
        if (data.containsKey("batteryVoltageStatus")) {
            entity.setBatteryVoltageStatus(Integer.valueOf(data.getString("batteryVoltageStatus")));
        }
        if (data.containsKey("acChargeStatus")) {
            entity.setAcChargeStatus(Integer.valueOf(data.getString("acChargeStatus")));
        }
        return this.save(entity);
    }

    @Override
    public boolean saveWarnStatus(JSONObject data) {

        String rtuCode = data.getString(RtuDataInfoConstant.RTU_DATA_RTUCODE_KEY);
        RtuRealTimeStatusStoreEntity entity = new RtuRealTimeStatusStoreEntity();
        entity.setRtuCode(rtuCode);
        if (data.containsKey(RtuDataInfoConstant.RTU_DATA_COLLECT_TIME_KEY)) {
            entity.setCollectTime(data.getDate(RtuDataInfoConstant.RTU_DATA_COLLECT_TIME_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_DATA_UP_TIME_KEY)) {
            entity.setUpTime(data.getDate(RtuDataInfoConstant.RTU_DATA_UP_TIME_KEY));
        }
        if (data.containsKey(RtuDataInfoConstant.RTU_DATA_PICK_TIME_KEY)) {
            entity.setPickTime(data.getDate(RtuDataInfoConstant.RTU_DATA_PICK_TIME_KEY));
        }
        if (data.containsKey("voltage")) {
            entity.setVoltage(data.getDouble("voltage"));
        }
        if (data.containsKey("batteryVoltageStatus")) {
            entity.setBatteryVoltageStatus(Integer.valueOf(data.getString("batteryVoltageStatus")));
        }
        if (data.containsKey("acChargeStatus")) {
            entity.setAcChargeStatus(Integer.valueOf(data.getString("acChargeStatus")));
        }
        if (data.containsKey("waterLevelOverStatus")) {
            entity.setWaterLevelOverStatus(Integer.valueOf(data.getString("waterLevelOverStatus")));
        }
        if (data.containsKey("waterFlowOverStatus")) {
            entity.setWaterFlowOverStatus(Integer.valueOf(data.getString("waterFlowOverStatus")));
        }
        if (data.containsKey("waterQualityStatus")) {
            entity.setWaterQualityStatus(Integer.valueOf(data.getString("waterQualityStatus")));
        }
        if (data.containsKey("waterFlowSensorStatus")) {
            entity.setWaterFlowSensorStatus(Integer.valueOf(data.getString("waterFlowSensorStatus")));
        }
        if (data.containsKey("waterLevelSensorStatus")) {
            entity.setWaterLevelSensorStatus(Integer.valueOf(data.getString("waterLevelSensorStatus")));
        }
        if (data.containsKey("boxDoorStatus")) {
            entity.setBoxDoorStatus(Integer.valueOf(data.getString("boxDoorStatus")));
        }
        if (data.containsKey("rtuMemoryStatus")) {
            entity.setRtuMemoryStatus(Integer.valueOf(data.getString("rtuMemoryStatus")));
        }
        if (data.containsKey("rtuIcCardStatus")) {
            entity.setRtuIcCardStatus(Integer.valueOf(data.getString("rtuIcCardStatus")));
        }
        if (data.containsKey("waterPumpStatus")) {
            entity.setWaterPumpStatus(Integer.valueOf(data.getString("waterPumpStatus")));
        }
        if (data.containsKey("waterRemainOverStatus")) {
            entity.setWaterRemainOverStatus(Integer.valueOf(data.getString("waterRemainOverStatus")));
        }
        return this.save(entity);
    }
}
