package org.nl.acs.device.domain;

import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.DeviceDriverDefination;
import org.nl.acs.opc.DeviceExtraManageDto;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.IdType;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.io.Serializable;
import java.util.*;

/**
* @author jiaolm
* @date 2023-05-09
*/
@Data
@Builder
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@TableName("acs_device")
public class Device  implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableField(exist = false)
    private String id;

    @TableField(exist = false)
    String functionCode = null;

    @TableField(exist = false)
    private int status_code = 0;

    @TableField(exist = false)
    private String status_message = "";

    private String is_config;

    private BigDecimal seq_num;

    private String update_time;

    @TableField(exist = false)
    private String device_type_name;

    @TableField(exist = false)
    private String region_name;

    @TableField(exist = false)
    private Integer has_goods = 0;

    @TableField(exist = false)
    private String material_type;

    @TableField(exist = false)
    private String quantity;

    @TableField(exist = false)
    private String islock;

    @TableField(exist = false)
    private String batch;

    @TableField(exist = false)
    private Boolean is_exist;

    @TableField(exist = false)
    private Boolean is_entrance;

    @TableField(exist = false)
    private String opc_server_code;

    @TableField(exist = false)
    private String opc_plc_code;

    /* 粉桶号 */
    @TableField(exist = false)
    private String barrels_code;

    /* 配合批号 */
    @TableField(exist = false)
    private String cooperate_code;

    /* 粉种名称 */
    @TableField(exist = false)
    private String powder_name;

    /* 粉桶状态 */
    @TableField(exist = false)
    private String barrels_status;

    @ApiModelProperty(value = "设备标识")
    @TableId(type= IdType.ASSIGN_ID)
    private String device_id;

    @ApiModelProperty(value = "设备编码")
    @NotBlank
    private String device_code;

    @ApiModelProperty(value = "设备名字")
    @NotBlank
    private String device_name;

    @ApiModelProperty(value = "设备类型")
    private String device_type;

    @ApiModelProperty(value = "所属区域")
    private String region;

    @ApiModelProperty(value = "生产厂家")
    private String manufacturer;

    @ApiModelProperty(value = "生产厂家电话")
    private String manufacturer_phone;


    @ApiModelProperty(value = "opcServer标识")
    private String opc_server_id;

    @ApiModelProperty(value = "opcPlc标识")
    private String opc_plc_id;

    @ApiModelProperty(value = "是否为路由设备")
    @NotBlank
    private String is_route;

    @ApiModelProperty(value = "设备驱动类型")
    private String driver_code;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "是否启用")
    @NotBlank
    private String is_active;

    @ApiModelProperty(value = "是否删除")
    @NotBlank
    private String is_delete;

    @ApiModelProperty(value = "创建者")
    @NotBlank
    @TableField(fill= FieldFill.INSERT)
    private String create_by;

    @ApiModelProperty(value = "创建时间")
    @NotBlank
    @TableField(fill= FieldFill.INSERT)
    private String create_time;

    @ApiModelProperty(value = "修改者")
    @TableField(fill= FieldFill.INSERT_UPDATE)
    private String update_by;

    @ApiModelProperty(value = "地址号")
    private String address;

    @TableField(exist = false)
    private DeviceDriver deviceDriver;

    @TableField(exist = false)
    private DeviceDriverDefination deviceDriverDefination;

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

    @TableField(exist = false)
    private List<DeviceExtraManageDto> extra = new LinkedList();

    @TableField(exist = false)
    private String perfix;

    @TableField(exist = false)
    private Map<String, Object> extra_map = new LinkedHashMap();

    public Map<String, Object> getExtraValue() {
        if (this.extra_map.size() > 0) {
            return this.extra_map;
        } else {
            Map<String, Object> result = new LinkedHashMap();
            Iterator var2 = this.extra.iterator();

            while (var2.hasNext()) {
                DeviceExtraManageDto dto = (DeviceExtraManageDto) var2.next();
                result.put(dto.getExtra_code(), dto.parseName());
            }

            this.extra_map = result;
            return result;
        }
    }
}
