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.TableField;
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.TableRepeat;
import com.gci.boot.common.dict.annotation.Dict;
import com.gci.boot.common.dict.annotation.ExcelEnum;
import com.gci.boot.common.dict.excel.DictConverter;
import com.gci.boot.common.dict.excel.EnumConverter;
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.*;
import java.io.Serializable;
import java.util.Date;

@Data
@TableName("tb_violation_record")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "违章记录表对象", description = "违章记录表对象")
@TableRepeat(aClass = TbViolationRecord.class,groups = {SaveValidated.class, UpdateValidated.class})
public class TbViolationRecord implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("主键id")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @NotBlank(message = "id不能为空！",groups = {UpdateValidated.class})
    @ExcelIgnore
    private String id;

    @ApiModelProperty("所属项目_id")
    @SelectQuery
    @NotBlank(message = "所属项目不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 32,message = "所属项目长度不能超过32位",groups = {SaveValidated.class,UpdateValidated.class})
    @Dict(dicCode = "id",dictTable = "tb_projects",dicText = "project_name")
    @ExcelProperty(value = "所属项目",index = 0,converter = DictConverter.class)
    @ColumnWidth(value = 30)
    private String projectId;

    @ApiModelProperty("项目名称")
    @SelectQuery
//    @NotBlank(message = "项目名称不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
//    @Length(max = 255,message = "项目名称长度不能超过255位",groups = {SaveValidated.class,UpdateValidated.class})
//    @ExcelProperty(value = "所属项目")
//    @ColumnWidth(value = 30)
    @ExcelIgnore
    private String projectName;

    @ApiModelProperty("车牌号")
    @NotBlank(message = "车牌号不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @SelectQuery(Type = SelectQuery.SelectType.IN)
    @Pattern(message = "车牌号格式错误",regexp = "^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "车牌号",index = 1)
    @ColumnWidth(value = 15)
    private String plateNumber;

    @ApiModelProperty("负责人")
    @NotBlank(message = "负责人不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 32,message = "负责人长度不能超过32位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "负责人",index = 2)
    @ColumnWidth(value = 15)
    private String director;

    @ApiModelProperty("违章时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @NotNull(message = "违章时间不能为空!",groups = {SaveValidated.class,UpdateValidated.class})
    @com.alibaba.excel.annotation.format.DateTimeFormat("yyyy-MM-dd HH:mm")
    @ExcelProperty(value = "违章时间",index = 3)
    @ColumnWidth(value = 30)
    private Date violationTime;

    @ApiModelProperty("违章地点")
    @NotBlank(message = "违章地点不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 128,message = "违章地点长度不能超过128位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "违章地点",index = 4)
    @ColumnWidth(value = 30)
    private String violationAddress;

    @ApiModelProperty("违章行为")
    @SelectQuery
    @NotBlank(message = "违章行为不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 16,message = "违章行为长度不能超过16位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "违章行为",index = 5,converter = DictConverter.class)
    @ColumnWidth(value = 15)
    @Dict(dicCode = "violation_behavior")
    private String violationAct;

    @ApiModelProperty("违章行为描述")
    @Length(max = 256,message = "违章行为描述长度不能超过256位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelIgnore
    private String violationActDes;

    @ApiModelProperty("违章司机")
    @Length(max = 32,message = "违章司机长度不能超过32位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "违章司机",index = 6)
    @ColumnWidth(value = 15)
    private String violationDriver;

    @ApiModelProperty("违章计分")
    @ExcelIgnore
    @Range(min = 0, max = 32766, message = "违章计分在[0,32766]之间!",groups = {SaveValidated.class,UpdateValidated.class})
    private Integer violationScore;

    @ApiModelProperty("违章费用")
    @ExcelIgnore
    @Range(min = 0, max = 999999, message = "违章费用在[0,999999]之间!",groups = {SaveValidated.class,UpdateValidated.class})
    private Double violationCost;

    @ApiModelProperty("处理期限（天）")
    @ExcelProperty(value = "处理期限（天）",index =7)
    @ColumnWidth(value = 15)
    @Range(min = 0, max = 32766, message = "处理期限（天）在[0,32766]之间!",groups = {SaveValidated.class,UpdateValidated.class})
    private Integer handleTerm;

    @ApiModelProperty("处理时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
//    @com.alibaba.excel.annotation.format.DateTimeFormat("yyyy-MM-dd HH:mm")
//    @ExcelProperty(value = "处理时间")
//    @ColumnWidth(value = 30)
    @ExcelIgnore
    private Date handleTime;

    @ApiModelProperty("处理结果（1-已处理、0-未处理）")
    @SelectQuery(Type = SelectQuery.SelectType.EQ)
    @ExcelEnum("0_未处理,1_已处理")
    @ExcelProperty(value = "处理结果",index = 8,converter = EnumConverter.class)
    @ColumnWidth(value = 15)
    private Integer handleResult;

    @ApiModelProperty("处理凭证（附件url）")
    @Length(max = 5000,message = "处理凭证长度不能超过5000位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelIgnore
    private String handleVoucher;

    @ApiModelProperty("备注")
    @Length(max = 256,message = "备注长度不能超过256位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelIgnore
    private String remark;

    @ApiModelProperty("原始违章短信")
    @Length(max = 512,message = "原始违章短信长度不能超过512位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelIgnore
    private String message;

    @ApiModelProperty("所属机构")
    @ExcelIgnore
    private String sysOrgCode;

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

    @ApiModelProperty("更新时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ExcelIgnore
    private Date updateTime;

    @ApiModelProperty("创建人")
    @ExcelIgnore
    private String createBy;

    @ApiModelProperty("更新人")
    @ExcelIgnore
    private String updateBy;

    @ApiModelProperty("作废标志")
    @Dict(dicCode = "cancel_flag")
    @ExcelIgnore
    private Integer cancelFlag;


    @ApiModelProperty("开始时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @SelectQuery(Type = SelectQuery.SelectType.GE,PropName = "violationTime")
    @ExcelIgnore
    @TableField(exist = false)
    private Date startTime;
    @ApiModelProperty("结束时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @SelectQuery(Type = SelectQuery.SelectType.LE,PropName = "violationTime")
    @ExcelIgnore
    @TableField(exist = false)
    private Date endTime;
}
