/*
*  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.dmCard.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import me.zhengjie.base.BaseEntity;
import me.zhengjie.modules.dmuser.domain.DmUser;
import me.zhengjie.modules.system.domain.Dept;
import me.zhengjie.ykt.domain.DmRoomDevice;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
* @website https://el-admin.vip
* @description /
* @author zhirong
* @date 2021-11-10
**/
@Entity
@Data
@Table(name="dm_card")
public class DmCard extends BaseEntity implements Serializable {

    @Id
    @Column(name = "id",nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty(value = "id")
    private Long id;

    @Column(name = "card_number")
    @ApiModelProperty(value = "卡号")
    private String cardNumber;

//    @Column(name = "user_number")
//    @ApiModelProperty(value = "用户工号")
//    private Long userNumber;

    @OneToOne
    @JoinColumn(name = "user_number",referencedColumnName="id")
    @ApiModelProperty(value = "DM用户")
    private DmUser dmUser;

    @Column(name = "user_name")
    @ApiModelProperty(value = "用户名称")
    private String userName;

    @Column(name = "user_type")
    @ApiModelProperty(value = "用户种类(00-正式人员、01-外协单位、02-租户、03-访客)")
    private String userType;

//    @Column(name = "dept_id")
//    @ApiModelProperty(value = "用户部门")
//    private String deptId;

    @OneToOne
    @JoinColumn(name = "dept_id")
    @ApiModelProperty(value = "用户部门")
    private Dept dept;

    @Column(name = "status")
    @ApiModelProperty(value = "开卡状态(00-已开通、01-挂失中、02-已注销)")
    private String status;

    @Column(name = "balance")
    @ApiModelProperty(value = "余额")
    private BigDecimal balance;

    /* 扩展字段 */
    @ApiModelProperty(value = "用户表")
    @Transient
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "dm_user",
                joinColumns = {@JoinColumn(name = "card_id",referencedColumnName = "cardid")},
                inverseJoinColumns = {@JoinColumn(name = "id",referencedColumnName = "id")})
    private List<DmUser> dmUserList;


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