package com.gci.boot.modules.basedata.entity;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gci.boot.annotation.Query.OrderQuery;
import com.gci.boot.annotation.Query.SelectQuery;
import com.gci.boot.annotation.repeat.FieldRepeat;
import com.gci.boot.annotation.repeat.TableRepeat;
import com.gci.boot.common.dict.annotation.Dict;
import com.gci.boot.common.dict.excel.DictConverter;
import com.gci.boot.common.validated.SaveValidated;
import com.gci.boot.common.validated.UpdateValidated;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;

/**
 * @author 24642
 */
@Data
@TableName("tb_repair_shop_archives")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="维修厂档案表对象", description="维修厂档案表对象")
@TableRepeat(aClass = TbRepairShopArchives.class,groups = {SaveValidated.class,UpdateValidated.class})
public class TbRepairShopArchives implements Serializable {
    private static final long serialVersionUID = 1L;
    /**主键id*/
    @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "主键id")
    @NotBlank(message = "id不能为空！",groups = {UpdateValidated.class})
    @ExcelIgnore
    private String id;

    @ApiModelProperty(value = "全称")
    @NotBlank(message = "全称不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @SelectQuery()
    @FieldRepeat(message = "全称不能重复！")
    @Length(max = 128,message = "全称不能超过128位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "全称")
    private String name;

    @ApiModelProperty(value = "简称")
    @SelectQuery()
    @FieldRepeat(message = "简称不能重复！")
    @Length(max = 32,message = "简称不能超过32位！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "简称")
    private String shortened;

    @ApiModelProperty(value = "联系人")
    @NotBlank(message = "联系人不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 32,message = "联系人不能超过32位！")
    @SelectQuery
    @ExcelProperty(value = "联系人")
    private String contact;

    @ApiModelProperty(value = "联系电话")
    @NotBlank(message = "联系电话不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Pattern(regexp = "^(?:(?:\\+|00)86)?1\\d{10}$",message = "联系电话格式错误!",groups = {SaveValidated.class,UpdateValidated.class})
    @SelectQuery
    @ExcelProperty(value = "联系电话")
    private String phone;

    @ApiModelProperty(value = "地址")
    @NotBlank(message = "地址不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 128,message = "地址不能超过128位！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "地址")
    private String address;

    /**所属机构*/
    @ApiModelProperty(value = "所属部门")
    @ExcelIgnore
    @NotBlank(message = "所属部门不能为空",groups = {SaveValidated.class, UpdateValidated.class})
    @Dict(dictTable = "sys_depart",dicCode = "org_code",dicText = "depart_name")
    private String sysOrgCode;

    /**创建日期*/
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建日期")
    @OrderQuery(sort = 1)
    @ExcelIgnore
    private Date createTime;

    /**更新人*/
    @ApiModelProperty(value = "更新人")
    @ExcelProperty(value = "更新人",converter = DictConverter.class)
    @Dict(dictTable = "sys_user",dicCode = "username",dicText = "realname")
    @ColumnWidth(value = 15)
    private String updateBy;

    /**更新日期*/
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新日期")
    @ExcelProperty(value = "更新时间")
    @com.alibaba.excel.annotation.format.DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    @ColumnWidth(value = 30)
    private Date updateTime;

    /**创建人*/
    @ApiModelProperty(value = "创建人")
    @ExcelIgnore
    private String createBy;


    /**作废标志*/
    @ApiModelProperty(value = "作废标志")
    @Dict(dicCode = "cancel_flag")
    @ExcelProperty(value = "状态",converter = DictConverter.class)
    private Integer cancelFlag;


//    @NotBlank(message = "供应商类型不能为空",groups = {SaveValidated.class, UpdateValidated.class})
    @Dict(dicCode = "supplier_type")
    @ExcelProperty(value = "供应商类型",converter = DictConverter.class)
    @ColumnWidth(value = 15)
    private String type;
    @Length(max = 256,groups = {SaveValidated.class,UpdateValidated.class},message = "备注长度不能超过256")
    @ApiModelProperty(value = "备注")
    @ExcelProperty("备注")
    @ColumnWidth(value = 30)
    private String remark;
}
