package com.fzm.mall.server.front.asset.model.vo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.fzm.mall.server.front.asset.mapper.TranOrderMapper;
import com.fzm.mall.server.front.asset.model.TranOrder;
import com.fzm.mall.server.front.goods.mapper.GoodSkuMapper;
import com.fzm.mall.server.front.util.CopyUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

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

/**
 * <p>
 * 用户资产-转让
 * </p>
 *
 * @author fzm
 * @since 2021-08-17
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "UserAssetTransfer对象", description = "用户资产-转让")
public class UserAssetTransferVO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户资产表自增id")
    private Long id;

    @ApiModelProperty(value = "转让编号")
    private String tranId;

    @ApiModelProperty(value = "用户uid")
    private String uid;

    @ApiModelProperty(value = "用户昵称")
    private String uNickName;

    @ApiModelProperty(value = "用户头像")
    private String uHeadUrl;

    @ApiModelProperty(value = "资产名称 如:btc、金币")
    private String coin;

    @ApiModelProperty(value = "转让数量")
    private Integer number;

    @ApiModelProperty(value = "剩余数量")
    private Integer stock;

    @ApiModelProperty(value = "转让价格")
    private BigDecimal price;

    @ApiModelProperty(value = "转让方式（1->单价；2->打包价）")
    private Integer type;

    @ApiModelProperty(value = "备注")
    private String note;

    @ApiModelProperty(value = "商品编号")
    private String goodsId;

    @ApiModelProperty(value = "商品名称")
    private String goodsName;

    @ApiModelProperty(value = "规格编号")
    private String skuId;

    @ApiModelProperty(value = "状态 1->可用，2->已撤销")
    private Integer status;

    @ApiModelProperty(value = "信息入库时间")
    private Long createTime;

    @ApiModelProperty(value = "信息更新时间")
    private Long updateTime;

    @ApiModelProperty(value = "规格图片")
    private String thumb;

    @ApiModelProperty(value = "已转让总数")
    private Integer transferOrderTotal;

    @ApiModelProperty(value = "规格值")
    private List<String> propValList;

    @ApiModelProperty(value = "转赠记录集合")
    private List<TranOrderVO> recordList;

    public void listRecord(TranOrderMapper tranOrderMapper) {
        List<TranOrder> recordList = tranOrderMapper.list(tranId, TranOrder.TRAN_ORDER_STATUS_SUCCESS);
        setRecordList(CopyUtil.toList(recordList, TranOrderVO.class));

        int sum = 0;
        if (CollectionUtils.isNotEmpty(recordList)){
            for (TranOrder tranOrder : recordList) {
                sum = sum + tranOrder.getNumber();
            }
        }
        setTransferOrderTotal(sum);
    }

    public void listProval(GoodSkuMapper goodSkuMapper) {
        List<String> valList = goodSkuMapper.listProval(skuId);
        setPropValList(valList);
    }
}
