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

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
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 java.io.Serializable;
import java.util.Date;
import java.util.List;

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.SelectQuery;
import com.gci.boot.annotation.fileUrl.FileUrl;
import com.gci.boot.annotation.fileUrl.handle.FileUrlHandle;
import com.gci.boot.common.dict.annotation.Dict;
import com.gci.boot.common.validated.SaveValidated;
import com.gci.boot.common.validated.UpdateValidated;
import com.gci.boot.modules.basedata.entity.TbVehicle;
import com.gci.boot.modules.customer.dto.VehicleDto;
import io.swagger.annotations.ApiModel;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 巡检任务
 * </p>
 *
 * @author 2464
 * @since 2023-10-16
 */
@Getter
@Setter
@TableName("tb_inspection_task")
@ApiModel(value = "TbInspectionTask对象", description = "巡检任务")
public class TbInspectionTask implements Serializable {

    private static final long serialVersionUID = 1L;

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

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

    @JsonPropertyDescription("创建时间")
    private Date createTime;

    @JsonPropertyDescription("更新时间")
    private Date updateTime;

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

    @JsonPropertyDescription("更新人")
    private String updateBy;

    @JsonPropertyDescription("巡检时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Excel(name = "巡检时间",format = "yyyy-MM-dd HH:mm:ss",orderNum = "1")
    private Date inspectionTime;

    @JsonPropertyDescription("巡检时间查询")
    @TableField(exist = false)
    @SelectQuery(Type = SelectQuery.SelectType.BETWEEN,PropName = "inspectionTime")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private List<Date> time;

    @JsonPropertyDescription("巡检类型 1-线上巡检 2-回访巡检")
    @NotBlank(message = "巡检类型不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @SelectQuery(Type = SelectQuery.SelectType.EQ,PropName = "inspectionType")
    @Dict(dicCode = "inspection_type")
    @Excel(name = "巡检类型",dict = "inspection_type",mergeVertical = true,mergeRely = {0},orderNum = "4")
    private String inspectionType;

    @JsonPropertyDescription("巡检模板Id")
    @NotBlank(message = "巡检模板不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 32,message = "巡检模板id不能超过32位字符！",groups = {SaveValidated.class,UpdateValidated.class})
    @SelectQuery(Type = SelectQuery.SelectType.EQ,PropName = "inspectionTemplateId")
    @Dict(dicCode = "id", dicText = "name", dictTable = "tb_inspection_template")
    @Excel(name = "巡检模板",dict = "tb_inspection_template,name,id",needMerge = true,orderNum = "3")
    private String inspectionTemplateId;

    @JsonPropertyDescription("处理方案")
    @Excel(name = "处理方案",groupName = "异常处理",mergeVertical = true,mergeRely = {1},orderNum = "7")
    private String handlePlan;

    @JsonPropertyDescription("处理结果")
    @Dict(dicCode = "result_status")
    @Excel(name = "处理方案",dict = "result_status",mergeVertical = true,mergeRely = {1},groupName = "异常处理",orderNum = "8")
    private String handleType;

    @JsonPropertyDescription("处理时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Excel(name = "处理时间",format = "yyyy-MM-dd HH:mm:ss",mergeVertical = true,mergeRely = {1},groupName = "异常处理",orderNum = "9")
    private Date handleTime;

    @JsonPropertyDescription("来源（1用户，2计划）")
    private String sourceType;

    @JsonPropertyDescription("巡检结果")
    @Dict(dicCode = "inspection_result")
    @NotBlank(message = "巡检结果不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Excel(name = "巡检结果",dict = "inspection_result",needMerge = true,orderNum = "6")
    @SelectQuery(Type = SelectQuery.SelectType.EQ)
    private String inspectionResult;

    @JsonPropertyDescription("备注")
    @Length(max = 500, message = "备注不能超过500个字符！",groups = {SaveValidated.class,UpdateValidated.class})
    @Excel(name = "备注",orderNum = "11",needMerge = true)
    private String remark;

    @JsonPropertyDescription("附件")
    @JsonDeserialize(using = FileUrlHandle.class)
    @FileUrl
    private String attachment;

    @JsonPropertyDescription("回访id")
    @Dict(dicCode = "id",dictTable = "tb_customer_follow",dicText = "follow_no")
    private String followId;

    @JsonPropertyDescription("巡检人")
    @SelectQuery(Type = SelectQuery.SelectType.EQ,PropName = "inspectionUserId")
    @Dict(dicCode = "id", dicText = "realname", dictTable = "sys_user")
    @Excel(name = "巡检人",dict = "sys_user,realname,id",needMerge = true,orderNum = "2")
    private String inspectionUserId;

    @TableField(exist = false)
    @JsonPropertyDescription("车辆列表")
    @ExcelCollection(name = "车辆信息",orderNum = "10")
    @Valid
    private List<VehicleDto> vehicleList;

    @TableField(exist = false)
    @NotBlank(message = "关联项目不能为空！",groups = {SaveValidated.class, UpdateValidated.class})
    @JsonPropertyDescription("关联项目id")
    @Dict(dicCode = "id",dictTable = "tb_projects",dicText = "project_name")
    @SelectQuery(Type = SelectQuery.SelectType.LIKE,PropName = "projectIds")
    @Excel(name = "项目",dict = "tb_projects,project_name,id",needMerge = true,orderNum = "0")
    private String projectIds;

    @TableField(exist = false)
    @JsonPropertyDescription("关联车辆id")
    private String vehicleIds;

    @TableField(exist = false)
    @JsonPropertyDescription("巡检信息")
    @NotNull(message = "巡检信息不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @ExcelCollection(name = "巡检内容",orderNum = "5")
    @Valid
    private List<TbInspectionTaskPart> partList;

    @TableField(exist = false)
    private List<TbInspectionTaskVehicle> vehicles;
}
