package cn.estsh.i3plus.pojo.screen.bean;

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.List;

/**
 * @author Wynne.Lu
 * @date 2021/5/19 15:15
 * @desc
 */
@Entity
@Data
@Table(name = "SCR_MENU")
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@DynamicInsert
@DynamicUpdate
@Builder
@ApiModel("通用界面-功能目录")
public class ScrMenu extends BaseBean implements Serializable {
    private static final long serialVersionUID = 5910610229414359976L;

    @Column(name = "MENU_NAME")
    @ApiParam(value = "菜单名称")
    private String menuName;

    @Column(name = "MENU_CODE")
    @ApiParam(value = "功能代码(唯一校验，路径跳转使用)")
    private String menuCode;

    @Column(name = "PARENT_ID")
    @ApiParam(value = "父级菜单id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long parentId;

    public long getParentIdVal() {
        if (parentId == null) {
            return CommonEnumUtil.PARENT.DEFAULT.getValue().longValue();
        } else {
            return parentId.longValue();
        }
    }

    @Column(name = "PARENT_NAME_RDD")
    @ApiParam(value = "父级菜单名称")
    private String parentNameRdd;

    @Column(name = "MENU_SORT")
    @ApiParam(value = "菜单排序")
    private Integer menuSort;

    @Column(name = "MENU_ICON")
    @ApiParam(value = "菜单图标")
    private String menuIcon;

    @Lob
    @Column(name = "MENU_STYLE")
    @ApiParam(value = "菜单样式")
    private String menuStyle;

    @Column(name = "MENU_TYPE")
    @ApiParam(value = "菜单类型")
    private Integer menuType;

    @Column(name = "MENU_URL")
    @ApiParam(value = "菜单url")
    private String menuUrl;

    @Column(name = "SCREEN_CODE")
    @ApiParam(value = "页面代码")
    private String screenCode;

    @Column(name = "SCREEN_NAME")
    @ApiParam(value = "页面名称")
    private String screenName;

    @Column(name = "SOFT_TYPE")
    @ApiParam(value = "所属模块")
    private Integer softType;

    @Transient
    @ApiParam(value = "菜单子集")
    private List<ScrMenu> menuList;
}
