/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.dm.modbus.data.domain;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import me.zhengjie.base.BaseEntity;
import me.zhengjie.modules.dm.modbus.device.domain.DmModbusDevice;
import me.zhengjie.modules.dm.modbus.group.domain.DmModbusGroup;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;

/**
* @website https://el-admin.vip
* @description /
* @author wld
* @date 2022-05-21
**/
@Entity
@Data
@Table(name="dm_modbus_data")
public class DmModbusData extends BaseEntity implements Serializable {

    @Id
    @Column(name = "data_id")
    @ApiModelProperty(value = "数据id")
    @JSONField(serializeUsing = ToStringSerializer.class)
    private Long dataId;

    @Column(name = "call_the_roll",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "采集端（硬件）点名")
    private String callTheRoll;

    @Column(name = "data_describe")
    @ApiModelProperty(value = "采集端描述")
    private String describe;

    @Column(name = "data_type",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "采集端数据类型")
    private String dataType;

    @Column(name = "hardware_register_type",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "采集端寄存器类型")
    private String hardwareRegisterType;

    @Column(name = "hardware_register_address",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "采集端寄存器地址")
    private String hardwareRegisterAddress;

    @Column(name = "is_fetch_bit")
    @ApiModelProperty(value = "采集端启用取位用逗号分隔")
    private String isFetchBit;

    @Column(name = "linear_conversion_id")
    @ApiModelProperty(value = "采集端关联线性转换id")
    @JSONField(serializeUsing = ToStringSerializer.class)
    private Long linearConversionId;

    @Column(name = "software_register_type",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "转发端(软件)寄存器类型")
    private String softwareRegisterType;

    @Column(name = "software_register_address",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "转发端(软件)寄存器地址")
    private String softwareRegisterAddress;

    @Column(name = "group_id",nullable = false)
    @NotNull
    @ApiModelProperty(value = "转发端(软件)寄存器地址")
    @JSONField(serializeUsing = ToStringSerializer.class)
    private Long groupId;

    public void copy(DmModbusData source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}