package com.casic.missiles.model.finance;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.ContentStyle;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.enums.poi.BorderStyleEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.casic.missiles.annotation.DictCodeField;
import com.casic.missiles.constants.MeterDictCode;
import com.casic.missiles.dto.business.order.OrderListResponse;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 合同表
 * </p>
 *
 * @author wangpeng
 * @since 2023-03-31
 */
@ColumnWidth(30)
@HeadRowHeight(15)
@ContentRowHeight(20)
@ContentStyle(borderLeft = BorderStyleEnum.THIN, borderBottom = BorderStyleEnum.THIN, borderTop = BorderStyleEnum.THIN, borderRight = BorderStyleEnum.THIN)
@ExcelIgnoreUnannotated
@ApiModel
@Data
@TableName("finance_agreement_info")
public class FinanceAgreementInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键id（列表、更新、详情接口参数）", dataType = "Long")
    @TableId("id")
    private Long id;

    /**
     * 合同编号
     */
    @ExcelProperty("分包项目编号")
    @ApiModelProperty(value = "合同编号（列表、更新接口参数）", dataType = "String")
    @TableField("agreement_no")
    private String agreementNo;

    /**
     * 合同名字
     */
    @ExcelProperty("合同名字")
    @NotBlank(message = "合同名字不能为空")
    @ApiModelProperty(value = "合同名字", dataType = "String")
    @TableField("agreement_name")
    private String agreementName;

    /**
     * 合同种类-收入合同/支出合同-字典
     */
    @DictCodeField(message = "合同种类不合法", cacheName = MeterDictCode.AGREEMENT_KIND)
    @ApiModelProperty(value = "合同种类-收入合同/支出合同-字典code", dataType = "String")
    @TableField("agreement_kind")
    private String agreementKind;

    @ExcelProperty("合同种类")
    @ApiModelProperty(value = "合同种类-收入合同/支出合同-字典value", dataType = "String")
    @TableField(exist = false)
    private String agreementKindName;

    /**
     * 合同类型-采购合同/业务合同等-字典
     */
    @DictCodeField(message = "合同类型不合法", cacheName = MeterDictCode.AGREEMENT_TYPE)
    @ApiModelProperty(value = "合同类型-采购合同/业务合同等-字典code", dataType = "String")
    @TableField("agreement_type")
    private String agreementType;

    @ExcelProperty("合同名字")
    @ApiModelProperty(value = "合同类型-采购合同/业务合同等-字典value", dataType = "String")
    @TableField(exist = false)
    private String agreementTypeName;

    /**
     * 部门id-创建人所在部门
     */
    @ApiModelProperty(value = "部门id-创建人所在部门", dataType = "Long")
    @TableField("dept_id")
    private Long deptId;

    /**
     * 部门-创建人所在部门名
     */
    @ExcelProperty("部门")
    @ApiModelProperty(value = "部门-创建人所在部门名", dataType = "String")
    @TableField("dept_name")
    private String deptName;

    /**
     * 预计签订日期/实际签订日期
     */
    @ExcelProperty("预计签订日期")
    @ApiModelProperty(value = "预计签订日期/实际签订日期", dataType = "String")
    @TableField("estimate_sign_date")
    private String estimateSignDate;

    /**
     * 合同金额
     */
    @ApiModelProperty(value = "合同金额（单位分）", dataType = "Integer")
    @TableField("agreement_amount")
    private Integer agreementAmount;

    @ExcelProperty("合同金额（元）")
    @TableField(exist = false)
    private String agreementAmountExport;

    public String getAgreementAmountExport() {
        if(Objects.nonNull(agreementAmount)) {
            agreementAmountExport = BigDecimal.valueOf(agreementAmount).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).toPlainString();
        }
        return agreementAmountExport;
    }

    /**
     * 合同采购来源-字典code
     */
    @DictCodeField(message = "合同采购来源不合法", cacheName = MeterDictCode.AGREEMENT_SOURCE)
    @ApiModelProperty(value = "合同采购来源-字典code", dataType = "String")
    @TableField("agreement_source")
    private String agreementSource;

    @ExcelProperty("合同采购来源")
    @ApiModelProperty(value = "合同采购来源-字典value", dataType = "String")
    @TableField(exist = false)
    private String agreementSourceName;

    /**
     * 合同开始日期
     */
    @ExcelProperty("合同开始日期")
    @ApiModelProperty(value = "合同开始日期", dataType = "String")
    @TableField("agreement_start_date")
    private String agreementStartDate;

    /**
     * 合同结束日期
     */
    @ExcelProperty("合同结束日期")
    @ApiModelProperty(value = "合同结束日期", dataType = "String")
    @TableField("agreement_end_date")
    private String agreementEndDate;

    /**
     * 单位id-客户id（收入合同该字段为甲方单位，支出合同该字段为乙方单位）
     */
    @ApiModelProperty(value = "单位id-客户id（收入合同该字段为甲方单位，支出合同该字段为乙方单位）", dataType = "String")
    @TableField("customer_id")
    private Long customerId;

    /**
     * 单位（收入合同该字段为甲方单位，支出合同该字段为乙方单位）
     */
    @ExcelProperty("甲方/乙方单位")
    @ApiModelProperty(value = "单位（收入合同该字段为甲方单位，支出合同该字段为乙方单位）", dataType = "String")
    @TableField("first_party")
    private String firstParty;

    /**
     * 负责人（收入合同该字段为甲方负责人，支出合同该字段为乙方负责人）
     */
    @ApiModelProperty(value = "负责人（收入合同该字段为甲方负责人，支出合同该字段为乙方负责人）", dataType = "String")
    @TableField("director")
    private String director;

    /**
     * 负责人（收入合同该字段为乙方负责人，支出合同该字段为甲方负责人）
     */
    @ApiModelProperty(value = "负责人（收入合同该字段为甲方负责人，支出合同该字段为乙方负责人）", dataType = "String")
    @TableField("second_director")
    private String secondDirector;

    /**
     * 单位（收入合同该字段为乙方单位，支出合同该字段为甲方单位）
     */
    @ExcelProperty("乙方/甲方单位")
    @ApiModelProperty(value = "单位（收入合同该字段为乙方单位，支出合同该字段为甲方单位）", dataType = "String")
    @TableField("second_party")
    private String secondParty;

    /**
     * 合同重要内容
     */
    @ApiModelProperty(value = "合同重要内容", dataType = "String")
    @TableField("agreement_important_content")
    private String agreementImportantContent;

    /**
     * 附件-minio文件名
     */
    @ApiModelProperty(value = "附件-minio文件名", dataType = "String")
    @TableField("minio_file_name")
    private String minioFileName;

    /**
     * 合同完成状态-字典code
     */
    @DictCodeField(message = "合同完成状态不合法", cacheName = MeterDictCode.AGREEMENT_STATUS)
    @ApiModelProperty(value = "合同完成状态-字典code（列表返回参数，等价于委托书完成状态）", dataType = "String")
    @TableField("status")
    private String status;

    @ExcelProperty("合同完成状态")
    @ApiModelProperty(value = "合同完成状态-字典value（列表返回参数）", dataType = "String")
    @TableField(exist = false)
    private String statusName;

    /**
     * 审批状态
     */
    @ApiModelProperty(hidden = true)
    @TableField("approval_status")
    private String approvalStatus;

    /**
     * 流程实例id
     */
    @ApiModelProperty(value = "流程实例id（未通过申请编辑接口必传参数）", dataType = "String")
    @TableField("process_id")
    private String processId;

    /**
     * 备注
     */
    @ApiModelProperty(value = "备注", dataType = "String")
    @TableField("remark")
    private String remark;

    /**
     * 创建人
     */
    @ApiModelProperty(value = "创建人id", dataType = "Long")
    @TableField("create_user")
    private Long createUser;

    @ApiModelProperty(value = "创建人名字", dataType = "String")
    @TableField("create_user_name")
    private String createUserName;

    /**
     * 删除标记
     */
    @ApiModelProperty(hidden = true)
    @TableField("is_del")
    private Integer isDel;

    /**
     * 创建时间
     */
    @ApiModelProperty(hidden = true)
    @TableField("create_time")
    private String createTime;

    /**
     * 更新时间
     */
    @ApiModelProperty(hidden = true)
    @TableField("update_time")
    private String updateTime;

    @NotEmpty(message = "委托书信息不能为空")
    @ApiModelProperty(value = "委托书id列表（保存/编辑草稿接口入参使用）", dataType = "List")
    @TableField(exist = false)
    private List<Long> orderIdList;

    @NotEmpty(message = "收款信息不能为空")
    @ApiModelProperty(value = "收款信息（保存/编辑草稿接口入参使用，详情接口出参使用）", dataType = "List")
    @TableField(exist = false)
    private List<FinanceAgreementPaymentInfo> paymentList;

    @ApiModelProperty(value = "委托书信息（详情接口出参使用）", dataType = "List")
    @TableField(exist = false)
    private List<OrderListResponse> orderList;
}
