package cn.pluss.platform.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

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

/**
 * <p>
 * 订单分账信息表
 * </p>
 *
 * @author bzg
 * @since 2021-11-26
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("tb_pluss_merchant_order_split")
@NoArgsConstructor
public class MerchantOrderSplit implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final String DEFAULT_IS_DIVISTION = "01";

    public static final String DEFAULT_IS_AGAIN_DIVISION = "Y";

    public static final Integer SUCCESS_DIV_STATUS = 1;

    public static final Integer FAIL_DIV_STATUS = 2;

    public static final Integer PROGRESS_DIV_STATUS = 3;

    @TableId("id")
    private Long id;


    /**
     * 订单号
     */
    @TableField("orderNumber")
    private String orderNumber;


    /**
     * 订单金额
     */
    @TableField("orderAmt")
    private BigDecimal orderAmt;


    /**
     * 支付时间
     */
    @TableField("payTime")
    private Date payTime;

    /**
     * 支付时间 开始时间
     */
    @TableField(exist = false, condition = "payTime &gt; #{%s}")
    private Date payTimeStart;

    /**
     * 支付时间 截止时间
     */
    @TableField(exist = false, condition = "payTime &lt; #{%s}")
    private Date payTimeEnd;

    /**
     * 支付状态 0:待支付 1:支付成功 2:退款中 3:退款成功 4：退款失败
     */
    @TableField("status")
    private Integer status;


    /**
     * 商户单号
     */
    @TableField("mercOrderNo")
    private String mercOrderNo;

    /**
     * 收款商户号
     */
    @TableField("merchantCode")
    private String merchantCode;

    /**
     * 商户名称
     */
    @TableField("merchantName")
    private String merchantName;


    /**
     * 分账模式
     */
    @TableField("divisionMode")
    private String divisionMode;


    /**
     * 分账状态1：受理成功（登记成功） 2：分账成功 -1：分账失败 3：预分账成功(已拆分，待结算) 4：无需分账
     */
    @TableField("divStatus")
    private Integer divStatus;


    /**
     * 分账手续费
     */
    @TableField("fee")
    private BigDecimal fee;


    /**
     * 创建时间
     */
    @TableField(value = "createTime", fill = FieldFill.INSERT)
    private Date createTime;

    /**
     * 创建时间 开始时间
     */
    @TableField(exist = false, condition = "createTime &gt; #{%s}")
    private Date createTimeStart;

    /**
     * 创建时间 截止时间
     */
    @TableField(exist = false, condition = "createTime &lt; #{%s}")
    private Date createTimeEnd;

    /**
     * 手机费承担方
     */
    @TableField("feePayer")
    private String feePayer;


    /**
     * 分账状态码
     */
    @TableField("divStatusCode")
    private String divStatusCode;


    /**
     * 备注
     */
    @TableField("remark")
    private String remark;

    /**
     * 退款金额
     */
    @TableField("refundAmt")
    private BigDecimal refundAmt;

    /**
     * 异步通知地址
     */
    @TableField("notifyUrl")
    private String notifyUrl;

    @TableField(exist = false)
    private List<MerchantOrderSplitDetail> detailList;

    @TableField("merchantId")
    private String merchantId;

    public MerchantOrderSplit(MerchantOrder order,MerchantChannelStatus channel,String divisionMode,String notifyUrl) {
        this.setOrderNumber(order.getOrderNumber());
        this.setOrderAmt(BigDecimal.valueOf(order.getConsumeFee()));
        this.setMercOrderNo(order.getMercOrderNo());
        this.setMerchantCode(order.getMerchantCode());
        this.setMerchantName(order.getMerchantName());
        this.setPayTime(order.getTransDt());
        this.setStatus(1);
        this.setMerchantId(channel.getMerchantId());
        this.setDivisionMode(divisionMode);
        this.setNotifyUrl(notifyUrl);
    }
}