package com.iformall.domain.vo;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.TableField;
import com.iformall.domain.po.base.BaseEntity;
import com.iformall.enums.EnumBusiness;
import com.iformall.enums.EnumSubBusiness;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class WxMerchantTradeDailyVo extends BaseEntity {

    protected Long id;


    @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId")
    private String tenantId;
    @io.swagger.annotations.ApiModelProperty(value = "商户id", name = "merchantId")
    private Long merchantId;
    @io.swagger.annotations.ApiModelProperty(value = "b用户id", name = "bUserId")
    private Long bUserId;

    @io.swagger.annotations.ApiModelProperty(value = "交易额", name = "tradeAmt")
    private Integer tradeAmt;

    @Excel(name = "解单金额(元)", width = 20, orderNum = "3")
    @TableField(exist = false)
    private String tradeAmtStr;

    public String getTradeAmtStr() {
        if (tradeAmt != null) {
            return new BigDecimal(tradeAmt).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).toPlainString();
        }
        return null;
    }

    @io.swagger.annotations.ApiModelProperty(value = "解单提交日期", name = "createDate")
    private Date createDate;

    @Excel(name = "上报时间", width = 20, orderNum = "5", format = "yyyy-MM-dd HH:mm:ss")
    @io.swagger.annotations.ApiModelProperty(value = "解单更新日期", name = "updateDate")
    private Date updateDate;

    @Excel(name = "解单日期", width = 20, orderNum = "1")
    @io.swagger.annotations.ApiModelProperty(value = "解单日期", name = "reportDate")
    private String reportDate;

    @Excel(name = "商户名称", width = 20, orderNum = "2")
    @io.swagger.annotations.ApiModelProperty(value="商户名",name="merchantName")
    private String merchantName;

    public String getbUserName() {
        return bUserName;
    }

    public void setbUserName(String bUserName) {
        this.bUserName = bUserName;
    }

    @Excel(name = "操作人", width = 20, orderNum = "6")
    @io.swagger.annotations.ApiModelProperty(value = "b端用户姓名", name = "bUserName")
    private String bUserName;

    public String getbUserPhone() {
        return bUserPhone;
    }

    public void setbUserPhone(String bUserPhone) {
        this.bUserPhone = bUserPhone;
    }

    @Excel(name = "联系电话", width = 20, orderNum = "7")
    @io.swagger.annotations.ApiModelProperty(value = "B端用户手机号", name = "bUserPhone")
    private String bUserPhone;

    @Excel(name = "交易笔数", width = 20, orderNum = "4")
    @io.swagger.annotations.ApiModelProperty(value = "交易笔数", name = "tradeCount")
    private Integer tradeCount;
    @io.swagger.annotations.ApiModelProperty(value = "凭证", name = "proof")
    private String proof;


    @TableField(exist = false)
    private List<WxShopVo> shopVos;

    @TableField(exist = false)
    @Excel(name = "商铺", width = 20, orderNum = "10")
    private String shopsStr;

    @TableField(exist = false)
    private Integer isToday;


    private Integer businessId;
    private Integer subBusinessId;

    @TableField(exist = false)
    @Excel(name = "业态", width = 20, orderNum = "8")
    @io.swagger.annotations.ApiModelProperty(value="经营业态ID:参照wx_business表",name="businessId")
    private String businessName;

    @TableField(exist = false)
    @Excel(name = "子业态", width = 20, orderNum = "9")
    @io.swagger.annotations.ApiModelProperty(value="子业态",name="subBusinessId")
    private String subBusinessName;

    public String getShopsStr() {
        if (shopVos != null && shopVos.size() > 0) {
            return String.join("\n",
                    shopVos.stream().map(
                            s->{return s.getBuildingName()+"-"+s.getFloorName()+"-"+s.getShopNumber();}
                    ).collect(Collectors.toList()));
        } else {
            return null;
        }
    }

    public String getBusinessName() {
        return EnumBusiness.getEnumMessage(businessId);
    }

    public String getSubBusinessName() {
        return EnumSubBusiness.getEnumMessage(subBusinessId);
    }

}
