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

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

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
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.validated.SaveValidated;
import com.gci.boot.common.validated.UpdateValidated;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.*;

/**
 * <p>
 * 耗材详情
 * </p>
 *
 * @author 2464
 * @since 2023-09-12
 */
@Getter
@Setter
@TableName("tb_consumables_template_part")
@ApiModel(value = "TbConsumablesTemplatePart对象", description = "耗材详情")
@TableRepeat(aClass = TbConsumablesTemplatePart.class,groups = {SaveValidated.class,UpdateValidated.class})
public class TbConsumablesTemplatePart implements Serializable {

    private static final long serialVersionUID = 1L;

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

    @ApiModelProperty("名称")
    @NotBlank(message = "耗材名称不能为空！",groups = {SaveValidated.class, UpdateValidated.class})
    @Length(max = 64,message = "耗材名称不能超过64位字符！",groups = {SaveValidated.class,UpdateValidated.class})
    @SelectQuery
    @Excel(name = "耗材名称",orderNum = "2")
    private String name;

    @ApiModelProperty("规格")
    @NotBlank(message = "规格不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 64,message = "规格不能超过64位字符！",groups = {SaveValidated.class,UpdateValidated.class})
    @Excel(name = "规格",orderNum = "7")
    private String specification;

    @ApiModelProperty("排序")
    private Integer sort;

    @ApiModelProperty("模板id")
    private String templateId;

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

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

    @ApiModelProperty("更新时间")
    @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 = "14")
    private Date updateTime;

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

    @ApiModelProperty("更新人")
    @Dict(dictTable = "sys_user", dicCode = "username", dicText = "realname")
    @Excel(name = "更新人",dict = "sys_user,realname,username",orderNum = "13")
    private String updateBy;

    @ApiModelProperty("所属项目id")
    @NotBlank(message = "所属项目不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Dict(dicCode = "id",dictTable = "tb_projects",dicText = "project_name")
    @FieldRepeat(message = "所属项目，耗材名称，入库时间，规格,供应商不能重复！",other = "name,storageTime,supplier,specification")
    @SelectQuery(Type = SelectQuery.SelectType.EQ)
    @OrderQuery
    @Excel(name = "所属项目",dict = "tb_projects,project_name,id",orderNum = "1")
    private String projectId;

    @ApiModelProperty("入库数量")
    @NotNull(message = "入库数量不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Max(value = 2147483647,message = "入库数量最大值不能超过2147483647！",groups = {SaveValidated.class,UpdateValidated.class})
    @Min(value = 0,message = "入库数量最小值为0！",groups = {SaveValidated.class,UpdateValidated.class})
    @Excel(name = "入库数量",orderNum = "3")
    private Integer quantity;

    @ApiModelProperty("单位")
    @Dict(dicCode = "units")
    @NotBlank(message = "单位不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Excel(name = "单位",dict = "units",orderNum = "6")
    private String units;

    @ApiModelProperty("入库时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @NotNull(message = "入库时间不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Excel(name = "入库时间",format = "yyyy-MM-dd",orderNum = "12")
    private Date storageTime;

    @TableField(exist = false)
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @SelectQuery(PropName = "storageTime",Type = SelectQuery.SelectType.BETWEEN)
    private List<Date> time;

    @ApiModelProperty("经办人")
    @NotBlank(message = "经办人不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 32,message = "经办人不能超过32位字符！",groups = {SaveValidated.class,UpdateValidated.class})
    @Excel(name = "经办人",orderNum = "10")
    private String responsiblePerson;

    @ApiModelProperty("供应商")
    @NotBlank(message = "供应商不能为空！",groups = {SaveValidated.class,UpdateValidated.class})
    @Length(max = 32,message = "供应商不能超过32位字符！",groups = {SaveValidated.class,UpdateValidated.class})
    @Excel(name = "供应商",orderNum = "11")
    private String supplier;

    @ApiModelProperty("单价")
    @NotNull(message = "单价不能为空!",groups = {SaveValidated.class,UpdateValidated.class})
    @Min(value = 0,message = "单价最小值为0!",groups = {SaveValidated.class,UpdateValidated.class})
    @Digits(integer = 10,fraction = 2,message = "单价整数部分不能大于10位，小数部分不能大于2位！")
    @Excel(name = "单价",numFormat = "#.##",orderNum = "8")
    private BigDecimal unitPrice;

    @ApiModelProperty("总价")
    @NotNull(message = "总价不能为空!",groups = {SaveValidated.class,UpdateValidated.class})
    @Min(value = 0,message = "总价最小值为0!",groups = {SaveValidated.class,UpdateValidated.class})
    @Digits(integer = 10,fraction = 2,message = "单价整数部分不能大于10位，小数部分不能大于2位！")
    @Excel(name = "总价",numFormat = "#.##",orderNum = "9")
    private BigDecimal totalPrice;

    @ApiModelProperty("库存数量")
    @Excel(name = "库存数量",orderNum = "5")
    private Integer remainingQuantity;

    @ApiModelProperty("出库数量总计")
    @TableField(exist = false)
    @Excel(name = "出库数量",orderNum = "4")
    private Integer outQuantityCount = 0;

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

    @ApiModelProperty("出库记录")
    @TableField(exist = false)
    private List<TbConsumablesTemplateOutPart> outPartList;

    /**
     * 库存数量查询
     */
    @TableField(exist = false)
    @SelectQuery(Type = SelectQuery.SelectType.GE,PropName = "remainingQuantity")
    private Integer remainingQuantityStart;
    @TableField(exist = false)
    @SelectQuery(Type = SelectQuery.SelectType.LE,PropName = "remainingQuantity")
    private Integer remainingQuantityEnd;
}
