package com.linkwechat.wecom.domain;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.linkwechat.common.core.domain.BaseEntity;
import com.linkwechat.common.utils.bean.BeanUtils;
import com.linkwechat.wecom.domain.dto.WeDepartMentDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 企业微信组织架构相关对象 we_department
 *
 * @author ruoyi
 * @date 2020-09-01
 */
@ApiModel
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@TableName("we_department")
public class WeDepartment extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * $column.columnComment
     */
    @ApiModelProperty(value = "主键")
    @TableId(type = IdType.AUTO)
    @TableField("id")
    private Long id;

    /**
     * 父节点的id
     */
    @ApiModelProperty("父节点的id")
    @TableField(value = "dept_id")
    private Long deptId;

    /**
     * 部门名称
     */
    @NotBlank(message = "部门名称不可为空")
    @ApiModelProperty("部门名称")
    @TableField(value = "name")
    private String name;


    /**
     * 父节点的id
     */
    @NotNull(message = "父节点的id不可为空")
    @ApiModelProperty("父节点的id")
    @TableField(value = "parent_id")
    private Long parentId;

    /**
     * 企业Id
     */
    @ApiModelProperty("企业Id")
    @TableField(value = "corp_id")
    private String corpId;

    /**
     * 删除标识
     */
    @ApiModelProperty("删除标识 0 正常 1 无效")
    @TableField(value = "del_flag")
    private Integer delFlag;

    /**
     * 系统通讯录部门转化为企业微信通讯录部门的dto对象
     */
    public WeDepartMentDto.DeartMentDto transformDeartMentDto(WeDepartment weDepartment) {
        WeDepartMentDto.DeartMentDto deartMentDto = new WeDepartMentDto().new DeartMentDto();
        deartMentDto.setId(this.getDeptId());
        deartMentDto.setName(this.getName());
        deartMentDto.setParentid(this.getParentId());
        return deartMentDto;

    }

    /**
     * 企业微信通讯录部门的dto对象转化为系统通讯录部门对象
     */
    public static WeDepartment transformWeDepartment(WeDepartMentDto.DeartMentDto deartMentDto) {
        WeDepartment weDepartment = new WeDepartment();
        weDepartment.setDeptId(deartMentDto.getId());
        weDepartment.setName(deartMentDto.getName());
        weDepartment.setParentId(deartMentDto.getParentid());
        return weDepartment;
    }


}
