package com.gci.boot.modules.vehicles.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.SelectQuery;
import com.gci.boot.annotation.repeat.TableRepeat;
import com.gci.boot.common.config.CancelConverter;
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.hibernate.validator.constraints.Range;
import org.springframework.format.annotation.DateTimeFormat;

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

@Data
@TableName("tb_upkeep_rule")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "保养规则表", description = "保养规则表")
@TableRepeat(aClass = TbUpkeepRule.class,groups = {SaveValidated.class, UpdateValidated.class})
public class TbUpkeepRule implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("主键id")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @ExcelIgnore
    private String id;

    @ApiModelProperty("规则名称")
    @NotBlank(message = "规则名称不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 128,message = "规则名称不能超过128位",groups = {SaveValidated.class,UpdateValidated.class})
    @SelectQuery
    @ExcelProperty(value = "保养规则名称",index = 0)
    @ColumnWidth(value = 30)
    private String name;

    @ApiModelProperty("适用车种")
    @NotBlank(message = "适用车种不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "适用车种",index = 1,converter = DictConverter.class)
    @Dict(dicCode = "vehicle_type")
    @ColumnWidth(value = 20)
    @SelectQuery(Type = SelectQuery.SelectType.EQ)
    private String vehicleType;

    @ApiModelProperty("适用车型")
    @NotBlank(message = "适用车型不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 32,message = "适用车型不能超过32位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "适用型号",index = 3)
    @ColumnWidth(value = 30)
    private String vehicleModel;

    @ApiModelProperty("适用品牌")
    @NotBlank(message = "适用品牌不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "适用品牌",index = 2,converter = DictConverter.class)
    @Dict(dicCode = "vehicle_brand")
    @ColumnWidth(value = 20)
    private String vehicleBrand;

    @ApiModelProperty("规则类型 1-按时间，2-按里程，3-按时间或里程")
    @NotBlank(message = "规则类型不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "规则类型",index = 4,converter = DictConverter.class)
    @SelectQuery
    @Dict(dicCode = "upkeep_rule_type")
    @ColumnWidth(value = 15)
    private String ruleType;

    @ApiModelProperty("里程间隔设置")
    @Range(min = 0, max = 99999999, message = "里程间隔设置在[0,99999999]之间!",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "里程保养间隔规则(KM)",index = 5)
    @ColumnWidth(value = 20)
    private Integer mileage;

    @ApiModelProperty("时间间隔设置")
    @Range(min = 0, max = 99999999, message = "时间间隔设置在[0,99999999]之间!",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "时间间隔保养规则(天)",index = 6)
    @ColumnWidth(value = 25)
    private Integer time;

    @ApiModelProperty("规则状态1-启用，2-禁用")
    @NotBlank(message = "规则状态不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "状态",index = 7,converter = DictConverter.class)
    @SelectQuery
    @Dict(dicCode = "upkeep_rule_status")
    @ColumnWidth(value = 15)
    private String ruleStatus;

    @ApiModelProperty("备注")
    @Length(max = 200,message = "备注不能超过200位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "备注")
    @ColumnWidth(value = 30)
    private String remark;


    /**所属机构*/
    @ApiModelProperty(value = "所属部门")
    @ExcelIgnore
    private String sysOrgCode;
    /**创建日期*/
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建日期")
    @com.alibaba.excel.annotation.format.DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    @ExcelProperty(value = "创建时间",index = 8)
    @ColumnWidth(value = 30)
    private Date createTime;
    /**更新日期*/
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新日期")
    @ExcelIgnore
    private Date updateTime;
    /**创建人*/
    @ApiModelProperty(value = "创建人")
    @ExcelIgnore
    @Dict(dicCode = "username",dictTable = "sys_user",dicText = "realname")
    private String createBy;
    /**更新人*/
    @ApiModelProperty(value = "更新人")
    @ExcelIgnore
    private String updateBy;
//    /**作废标志--默认0-正常，1-作废*/
//    @ApiModelProperty(value = "作废标志")
//    @ExcelProperty(value = "数据状态", converter = CancelConverter.class)
//    @ColumnWidth(value = 15)
//    private Integer cancelFlag;
}
