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

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.gci.boot.annotation.Query.OrderQuery;
import com.gci.boot.annotation.Query.SelectQuery;
import com.gci.boot.annotation.fileUrl.FileUrl;
import com.gci.boot.annotation.fileUrl.handle.FileUrlHandle;
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 org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.*;

/**
 * <p>
 *
 * </p>
 *
 * @author 2464
 * @since 2023-08-25
 */
@Data
@TableName("tb_vehicle")
@ApiModel(value = "TbVehicle对象", description = "")
@TableRepeat(aClass = TbVehicle.class,groups = {SaveValidated.class,UpdateValidated.class})
public class TbVehicle implements Serializable {

    private static final long serialVersionUID = 1L;

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

    @JsonPropertyDescription("所属项目")
    @SelectQuery(Type = SelectQuery.SelectType.IN)
    @Length(max = 32,message = "所属项目数据错误!",groups = {SaveValidated.class,UpdateValidated.class})
    @Dict(dicCode = "id",dictTable = "tb_projects",dicText = "project_name")
    @ExcelProperty(value = "所属项目",converter = DictConverter.class)
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String projectId;

    @JsonPropertyDescription("车牌号")
    @NotBlank(message = "车牌号不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @FieldRepeat(message = "车牌号码不能重复！")
    @SelectQuery
    @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 = "车牌号")
    @Excel(name = "车牌号")
    private String plateNumber;

    @JsonPropertyDescription("车架号")
    @NotBlank(message = "车架号不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @SelectQuery
    @FieldRepeat(message = "车架号不能重复!")
    @Length(max = 20,message = "车架号不能超过20位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "车架号")
    @Excel(name = "车架号")
    private String frameNumber;

    @JsonPropertyDescription("所属车商")
    @NotBlank(message = "所属车商不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 32,message = "所属车商数据错误！",groups = {SaveValidated.class,UpdateValidated.class})
    @Dict(dicCode = "id",dictTable = "tb_vehicle_supplier_archives",dicText = "shortened")
    @Excel(name = "所属车商",dict = "tb_vehicle_supplier_archives,shortened,id")
    @ExcelProperty(value = "所属车商",converter = DictConverter.class)
    private String dealer;

    @JsonPropertyDescription("制造商")
    @Length(max = 32,message = "制造商不能超过32位！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "制造商")
    private String manufacturer;

    @JsonPropertyDescription("交付时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @NotNull(message = "交付时间不能为空!",groups = {SaveValidated.class,UpdateValidated.class})
    @SelectQuery(Type = SelectQuery.SelectType.EQ)
    @com.alibaba.excel.annotation.format.DateTimeFormat("yyyy年MM月dd日")
    @ExcelProperty(value = "交付时间")
    private Date deliveryTime;

    @JsonPropertyDescription("车辆品牌")
    @NotBlank(message = "车辆品牌不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Dict(dicCode = "vehicle_brand")
    @ExcelProperty(value = "车辆品牌",converter = DictConverter.class)
    @Excel(name = "品牌",dict = "vehicle_brand")
    @SelectQuery(Type = SelectQuery.SelectType.EQ)
    private String vehicleBrand;

    @JsonPropertyDescription("车辆型号")
    @NotBlank(message = "车辆型号不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "车辆型号")
    @Excel(name = "型号")
    @SelectQuery
    private String vehicleModel;


    @JsonPropertyDescription("车辆种类")
    @NotBlank(message = "车辆种类不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Dict(dicCode = "vehicle_type")
    @ExcelProperty(value = "车辆种类",converter = DictConverter.class)
    @SelectQuery(Type = SelectQuery.SelectType.EQ)
    @Excel(name = "车辆种类",dict = "vehicle_type")
    private String vehicleType;

    @JsonPropertyDescription("车辆识别代码（VIN码）")
    @FieldRepeat(message = "VIN码不能重复！")
    @Length(max = 20,message = "VIN码不能超过20位！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "车辆识别代码（VIN码）")
    @SelectQuery(Type = SelectQuery.SelectType.LIKE)
    private String vinCode;

    @JsonPropertyDescription("电池编码")
    @ExcelProperty(value = "电池编码")
    @Length(max = 32,message = "电池编码不能超过32位！",groups = {SaveValidated.class,UpdateValidated.class})
    private String batteryCode;

    @JsonPropertyDescription("钥匙编码")
    @ExcelProperty(value = "钥匙编码")
    @Length(max = 32,message = "钥匙编码不能超过32位！",groups = {SaveValidated.class,UpdateValidated.class})
    private String keyCode;

    @JsonPropertyDescription("发动机号码")
    @Length(max = 20,message = "发动机号码不能超过20位！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty("发动机号码")
    private String engineNumber;

    @JsonPropertyDescription("电池品牌及型号")
    @Length(max = 32,message = "电池品牌及型号不能超过32位！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelIgnore
    private String batteryBrandAndModel;

    @JsonPropertyDescription("电控品牌及型号")
    @Length(max = 32,message = "电控品牌及型号不能超过32位！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelIgnore
    private String electronicControlBrandAndModel;

    @JsonPropertyDescription("整备质量")
    @Digits(integer = 6 , fraction = 2,message = "整备质量整数不能超过6位，小数不能超过2位",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelIgnore
    private BigDecimal curbWeight;

    @JsonPropertyDescription("机构名称")
    @Length(max = 32,message = "机构名称不能超过32位!",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty
    private String thirdOrganization;

    @JsonPropertyDescription("验收费用")
    @ExcelProperty
    @Digits(integer = 6,fraction = 2,message = "验收费用整数不能超过6位，小数不能超过2位",groups = {SaveValidated.class,UpdateValidated.class})
    private BigDecimal acceptanceFee;

    @JsonPropertyDescription("车身颜色")
    @Dict(dicCode = "body_color")
    @ExcelProperty(value = "车身颜色",converter = DictConverter.class)
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String bodyColor;

    @JsonPropertyDescription("燃料类型")
    @Dict(dicCode = "fuel_type")
    @ExcelProperty(value = "燃料类型",converter = DictConverter.class)
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String fuelType;

    @JsonPropertyDescription("纯电续航里程（单位：公里）")
    @Max(value = 2147483647,message = "续航里程不能超过2147483647！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "纯电续航里程（单位：公里）")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Integer electricRange;

    @JsonPropertyDescription("电池容量（单位：千瓦时）")
    @Max(value = 2147483647,message = "电池容量不能超过2147483647！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty("电池容量（单位：千瓦时）")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Integer batteryCapacity;

    @JsonPropertyDescription("主机设备号")
    @FieldRepeat(message = "主机设备号不能重复!")
    @Length(max = 20,message = "主机设备号不能超过20位！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty("主机设备号")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String hostDeviceNumber;

    @JsonPropertyDescription("注册日期")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @ExcelIgnore
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Date registrationDate;

    @JsonPropertyDescription("发证日期")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @ExcelIgnore
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Date issuanceDate;

    @JsonPropertyDescription("年审有效期")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @ExcelIgnore
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Date annualInspectionPeriod;

    @JsonPropertyDescription("使用性质")
    @Dict(dicCode = "usage_nature")
    @ExcelIgnore
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String usageNature;

    @JsonPropertyDescription("定位终端ID")
    @FieldRepeat(message = "定位终端ID不能重复！")
    @Length(max = 20,message = "定位终端ID不能超过20位！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "定位终端ID")
    private String locationTerminalId;

    @JsonPropertyDescription("主动安全设备ID")
    @Length(max = 20,message = "主动安全设备ID不能超过20位！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "主动安全设备ID")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String activeSafetyDeviceId;

    @JsonPropertyDescription("视频设备ID")
    @Length(max = 20,message = "视频设备ID不能超过20位！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelProperty(value = "视频设备ID")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String videoDeviceId;

    @JsonPropertyDescription("备注")
    @ExcelProperty(value = "备注")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String remark;

    @JsonPropertyDescription("车辆照片的url地址")
    @Length(max = 128,message = "车辆照片文件名过长!",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelIgnore
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    @JsonDeserialize(using = FileUrlHandle.class)
    @FileUrl
    private String vehiclePhoto;

    @JsonPropertyDescription("行驶证照片的url地址")
    @Length(max = 128,message = "行驶证文件名过长!",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelIgnore
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    @JsonDeserialize(using = FileUrlHandle.class)
    @FileUrl
    private String drivingLicensePhoto;

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

    @JsonPropertyDescription("创建时间")
    @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;

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

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

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

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

    @JsonPropertyDescription("车辆价格")
    @ExcelIgnore
    @NotNull(message = "车辆价格不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Min(value = 0,message = "车辆价格不能低于0万元",groups = {SaveValidated.class,UpdateValidated.class})
    @Max(value = 10000,message = "车辆价格不能超过9999.9999万元",groups = {SaveValidated.class,UpdateValidated.class})
    @Digits(integer = 4 , fraction = 4,message = "车辆价格整数不能超过4位，小数不能超过4位",groups = {SaveValidated.class,UpdateValidated.class})
    private Double price;

    @ApiModelProperty("来源（1车辆档案，2采购交车）")
    @ExcelIgnore
    private String sourceType;

    @JsonPropertyDescription("油卡卡号")
    @SelectQuery(Type = SelectQuery.SelectType.LIKE)
    @Length(max = 32,message = "油卡卡号不能超过32位！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelIgnore
    private String oilCard;

    @JsonPropertyDescription("交付时间开始")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @TableField(exist = false)
    @ExcelIgnore
    private Date deliveryTimeStart;

    @JsonPropertyDescription("交付时间结束")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @TableField(exist = false)
    @ExcelIgnore
    private Date deliveryTimeEnd;

}
