package com.muchinfo.mtp3pojos.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;

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

/**
 * <p>
 * 资金账户表 - 导历史
 * </p>
 *
 * @author XKF
 * @since 2024-04-16
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("TAACCOUNT")
@ApiModel(value="Taaccount对象", description="资金账户表 - 导历史")
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Taaccount extends Model<Taaccount> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "资金账户ID")
    private Long accountid;

    @ApiModelProperty(value = "用户ID")
    @TableField("USERID")
    private Long userid;

    @ApiModelProperty(value = "货币ID")
    @TableField("CURRENCYID")
    private Integer currencyid;

    @ApiModelProperty(value = "变动标志(当前账户资金有任何变动更新为1系统结算时更新0;供清算时使用) 0：无变动 1：有变动 ")
    @TableField("CHANGEFLAG")
    private Integer changeflag;

    @ApiModelProperty(value = "资金密码")
    @TableField("PASSWORD")
    private String password;

    @ApiModelProperty(value = "交易状态 - 1:正常 2:受限 3:冻结(停用) 4:禁止建仓(人工受限) 5:禁止交易(人工冻结) 6:待激活 7:已删除(注销)")
    @TableField("TRADESTATUS")
    private Integer tradestatus;

    @ApiModelProperty(value = "签约状态 - 1:未签约 2:签约待审核 3:签约中 4:已签约 5:解约待审核 6:解约中 7:已解约 8:已解绑 9:绑卡中")
    @TableField("SIGNSTATUS")
    private Integer signstatus;

    @ApiModelProperty(value = "是否母账号 0:不是母账户 1:是母账户")
    @TableField("ISMAIN")
    private Integer ismain;

    @ApiModelProperty(value = "所属根账号")
    @TableField("PARENTACCOUNTID")
    private Long parentaccountid;

    @ApiModelProperty(value = "关联用户")
    @TableField("RELATEDUSERID")
    private Long relateduserid;

    @ApiModelProperty(value = "关联用户交易权限状态 - 1:正常(可交易) 2:受限(可平仓，不可建仓) 3:冻结(不可交易)")
    @TableField("RELATEDACCOUNTSTATUS")
    private Integer relatedaccountstatus;

    @ApiModelProperty(value = "账号类型 - 1:外部账号 2:内部账号 3:内部做市自营账号 4:内部做市接单账号")
    @TableField("TAACCOUNTTYPE")
    private Integer taaccounttype;

    @ApiModelProperty(value = "是否机构分润账号 0:不是 1:是")
    @TableField("ISRECKONACCOUNT")
    private Integer isreckonaccount;

    @ApiModelProperty(value = "是否机构接单账号 0:不是 1:是")
    @TableField("ISMARKETACCOUNT")
    private Integer ismarketaccount;

    @ApiModelProperty(value = "期初余额")
    @TableField("BALANCE")
    private BigDecimal balance;

    @ApiModelProperty(value = "期初冻结保证金")
    @TableField("ORIFREEZEMARGIN")
    private BigDecimal orifreezemargin;

    @ApiModelProperty(value = "期初占用保证金")
    @TableField("ORIUSEDMARGIN")
    private BigDecimal oriusedmargin;

    @ApiModelProperty(value = "期初其他冻结保证金(出金冻结资金 交割买方冻结 申购冻结 全款买入 商城买入)")
    @TableField("ORIOTHERFREEZEMARGIN")
    private BigDecimal oriotherfreezemargin;

    @ApiModelProperty(value = "期初手续费冻结")
    @TableField("ORIFREEZECHARGE")
    private BigDecimal orifreezecharge;

    @ApiModelProperty(value = "期初授信金额")
    @TableField("ORIMORTGAGECREDIT")
    private BigDecimal orimortgagecredit;

    @ApiModelProperty(value = "期初其它授信金额")
    @TableField("ORIOTHERCREDIT")
    private BigDecimal oriothercredit;

    @ApiModelProperty(value = "期初出金冻结")
    @TableField("ORIOUTAMOUNTFREEZE")
    private BigDecimal orioutamountfreeze;

    @ApiModelProperty(value = "冻结保证金")
    @TableField("FREEZEMARGIN")
    private BigDecimal freezemargin;

    @ApiModelProperty(value = "占用保证金")
    @TableField("USEDMARGIN")
    private BigDecimal usedmargin;

    @ApiModelProperty(value = "其他冻结保证金(交割买方冻结 申购冻结 全款买入 商城买入)")
    @TableField("OTHERFREEZEMARGIN")
    private BigDecimal otherfreezemargin;

    @ApiModelProperty(value = "手续费冻结")
    @TableField("FREEZECHARGE")
    private BigDecimal freezecharge;

    @ApiModelProperty(value = "授信金额")
    @TableField("MORTGAGECREDIT")
    private BigDecimal mortgagecredit;

    @ApiModelProperty(value = "其它授信金额")
    @TableField("OTHERCREDIT")
    private BigDecimal othercredit;

    @ApiModelProperty(value = "出金冻结")
    @TableField("OUTAMOUNTFREEZE")
    private BigDecimal outamountfreeze;

    @ApiModelProperty(value = "今日入金金额(包括三方入金)")
    @TableField("INAMOUNT")
    private BigDecimal inamount;

    @ApiModelProperty(value = "期末余额")
    @TableField("CURRENTBALANCE")
    private BigDecimal currentbalance;

    @ApiModelProperty(value = "今日出金金额(包括三方出金)")
    @TableField("OUTAMOUNT")
    private BigDecimal outamount;

    @ApiModelProperty(value = "今日手续费支出")
    @TableField("PAYCHARGE")
    private BigDecimal paycharge;

    @ApiModelProperty(value = "今日平仓盈亏")
    @TableField("CLOSEPL")
    private BigDecimal closepl;

    @ApiModelProperty(value = "今日授信增加")
    @TableField("CREDITINCREASE")
    private BigDecimal creditincrease;

    @ApiModelProperty(value = "今日授信减少")
    @TableField("CREDITDECREASE")
    private BigDecimal creditdecrease;

    @ApiModelProperty(value = "今日其它授信增加")
    @TableField("OTHERCREDITINCREASE")
    private BigDecimal othercreditincrease;

    @ApiModelProperty(value = "今日其它授信减少")
    @TableField("OTHERCREDITDECREASE")
    private BigDecimal othercreditdecrease;

    @ApiModelProperty(value = "今日划转金额(母子账号资金划转，从划入账号为正，从账号划出为负)")
    @TableField("TRANSFERAMOUNT")
    private BigDecimal transferamount;

    @ApiModelProperty(value = "其他支出(交割付款 申购付款 全款买入 商城买入 卖家退货)")
    @TableField("OTHERPAY")
    private BigDecimal otherpay;

    @ApiModelProperty(value = "其他收入(交割收款 申购收款 全款卖出 商城卖出 买家退货 会员手续费收入)")
    @TableField("OTHERINCOME")
    private BigDecimal otherincome;

    @ApiModelProperty(value = "出金阈值")
    @TableField("OUTTHRESHOLD")
    private BigDecimal outthreshold;

    @ApiModelProperty(value = "激活时间")
    @TableField("TRADESTATUSCHANGETIME")
    private Date tradestatuschangetime;

    @ApiModelProperty(value = "账户状态变更时间")
    @TableField("CHANGETIME")
    private Date changetime;

    @ApiModelProperty(value = "今日三方入金")
    @TableField("THIRDINAMOUNT")
    private BigDecimal thirdinamount;

    @ApiModelProperty(value = "今日三方出金")
    @TableField("THIRDOUTAMOUNT")
    private BigDecimal thirdoutamount;

    @ApiModelProperty(value = "本金余额[外部子母账户实际出入金余额]")
    @TableField("CAPITALBALANCE")
    private BigDecimal capitalbalance;

    @ApiModelProperty(value = "所属上级账户")
    @TableField("FROMACCOUNTID")
    private Long fromaccountid;

    @ApiModelProperty(value = "账号层级路径(逗号分隔,首尾加逗号)")
    @TableField("SUBLEVELPATH")
    private String sublevelpath;

    @ApiModelProperty(value = "服务分组")
    @TableField("SERIVCEGROUP")
    private Long serivcegroup;

    @ApiModelProperty(value = "账户名称")
    @TableField("ACCOUNTNAME")
    private String accountname;

    @ApiModelProperty(value = "账户标识 - 0\1 (默认为0， 当上级账户与本账户的关联用户均为自己时更新为1)")
    @TableField("ACCOUNTFLAG")
    private Integer accountflag;

    @ApiModelProperty(value = "期初欠款")
    @TableField("ORIDEBT")
    private BigDecimal oridebt;

    @ApiModelProperty(value = "期末欠款")
    @TableField("CURDEBT")
    private BigDecimal curdebt;

    @ApiModelProperty(value = "修改时间")
    @TableField("MODIFYTIME")
    private Date modifytime;

    @ApiModelProperty(value = "修改来源 - 1:管理端 2:终端")
    @TableField("MODIFYSRC")
    private Integer modifysrc;

    @ApiModelProperty(value = "修改人")
    @TableField("MODIFIERID")
    private Long modifierid;

    @TableField(select = false)
    private BigDecimal cur_risk_rate;
    @TableField(select = false)
    private BigDecimal floatpl;
    @TableField(select = false)
    private BigDecimal avaiablemoney;
    @TableField(select = false)
    private BigDecimal avaiableoutmoney;
    @TableField(select = false)
    private BigDecimal floatnetvalue;
    @TableField(select = false)
    private List<Taaccount> children;
    @TableField(select = false)
    private Set<Long> set_msg; //记录多个ID,需要发送登录变更通知

    @Override
    public Serializable pkVal() {
        return this.accountid;
    }

    public Taaccount(Long accountid, Long userid,String password) {
        this.accountid = accountid;
        this.userid = userid;
        this.password = password;
        this.currencyid = 1;
        this.changeflag = 0;
        this.tradestatus = 1;
        this.signstatus = 1;
        this.ismain = 1;
        this.parentaccountid = accountid;
        this.fromaccountid = accountid;
        this.sublevelpath = "," + accountid + ",";
        this.taaccounttype = 2;
        this.isreckonaccount = 1;
        this.ismarketaccount = 0;
        this.accountflag = 0;
        this.balance = BigDecimal.ZERO;
        this.orifreezemargin = BigDecimal.ZERO;
        this.oriusedmargin = BigDecimal.ZERO;
        this.oriotherfreezemargin = BigDecimal.ZERO;
        this.orifreezecharge = BigDecimal.ZERO;
        this.orimortgagecredit = BigDecimal.ZERO;
        this.oriothercredit = BigDecimal.ZERO;
        this.orioutamountfreeze = BigDecimal.ZERO;
        this.currentbalance = BigDecimal.ZERO;
        this.freezemargin = BigDecimal.ZERO;
        this.usedmargin = BigDecimal.ZERO;
        this.otherfreezemargin = BigDecimal.ZERO;
        this.freezecharge = BigDecimal.ZERO;
        this.mortgagecredit = BigDecimal.ZERO;
        this.othercredit = BigDecimal.ZERO;
        this.outamountfreeze = BigDecimal.ZERO;
        this.inamount = BigDecimal.ZERO;
        this.outamount = BigDecimal.ZERO;
        this.paycharge = BigDecimal.ZERO;
        this.closepl = BigDecimal.ZERO;
        this.creditincrease = BigDecimal.ZERO;
        this.creditdecrease = BigDecimal.ZERO;
        this.othercreditincrease = BigDecimal.ZERO;
        this.othercreditdecrease = BigDecimal.ZERO;
        this.transferamount = BigDecimal.ZERO;
        this.otherpay = BigDecimal.ZERO;
        this.otherincome = BigDecimal.ZERO;
        this.outthreshold = BigDecimal.ZERO;
        this.changetime = new Date();
        this.oridebt = BigDecimal.ZERO;
        this.curdebt = BigDecimal.ZERO;
    }
}
