package com.jeeplus.test.wdt.merchantCompany.service.dto;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.jeeplus.core.query.Query;
import com.jeeplus.core.query.QueryType;
import com.jeeplus.core.service.dto.BaseDTO;
import com.jeeplus.test.core.excel.converter.ExcelMerchantProductListDTOConverter;
import com.jeeplus.test.core.excel.converter.ExcelSettledPlatformListDTOConverter;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;
import java.util.stream.Collectors;


/**
 * 入驻商家表
 * @author: 徐滕
 * @version: 2024-01-04 10:42
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ColumnWidth(20)
public class MerchantCompanyExportDTO extends BaseDTO {

    private static final long serialVersionUID = 1L;

    /**
     * 公司名称
     */
    @ExcelProperty("公司名称")
    private String companyName;

    /**
     * 公司类型
     */
    @ExcelProperty("公司类型")
    private String companyType;

    /**
     * 联系人名称
     */
    @ExcelProperty("联系人名称")
    private String linkmanName;

    /**
     * 联系人电话
     */
    @ExcelProperty("联系人电话")
    private String linkmanPhone;

    /**
     * 从业人员
     */
    //@ExcelProperty("从业人员")
    private Integer practitionerCount;

    /**
     * 年销售额
     */
    @ExcelProperty("年销售额")
    private String annualSales;

    /**
     * 是否为电商小铺
     */
    @ExcelProperty("是否为电商小铺")
    private Integer commerceShop;

    /**
     * 网络零售额
     */
    //@ExcelProperty("网络零售额")
    private String onlineRetailSales;

    /**
     * 入驻平台
     */
    @ExcelProperty("入驻平台")
    private String settledPlatformStr;


    /**
     * 年销售额区间
     */
    @ExcelIgnore
    private String[] annualSalesList;

    /**
     * 网络零售额区间
     */
    @ExcelIgnore
    private String[] onlineRetailSalesList;

    /**
     * 创建时间区间
     */
    @ExcelIgnore
    private String[] dates;

    /**
     * 入驻平台
     */
    @ExcelIgnore
    @Query(type = QueryType.EQ, javaField = "settledPlatformDTO.id", tableColumn = "msp.id")
    private SettledPlatformDTO settledPlatformDTO;

    /**
     * 入驻平台列表
     */
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    @ExcelProperty(value = "入驻平台", converter = ExcelSettledPlatformListDTOConverter.class)
    private List<SettledPlatformDTO> settledPlatformDTOList = Lists.newArrayList ( );


    /**
     * 入驻产品
     */
    @ExcelIgnore
    @Query(type = QueryType.EQ, javaField = "merchantProductDTO.id", tableColumn = "mp.id")
    private MerchantProductDTO merchantProductDTO;

    /**
     * 入驻产品列表
     */
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    @ExcelProperty(value = "入驻产品", converter = ExcelMerchantProductListDTOConverter.class)
    private List<MerchantProductDTO> merchantProductDTOList = Lists.newArrayList ( );



    /**
     * 获取包含的入驻平台id列表
     *
     * @return
     */
    public List <String> getSettledPlatformIdList() {
        if ( settledPlatformDTOList == null ) {
            return Lists.newArrayList ( );
        }
        List <String> settledPlatformIdList = settledPlatformDTOList.stream ( ).map ( settledPlatformDTO -> settledPlatformDTO.getId ( ) ).collect ( Collectors.toList ( ) );
        return settledPlatformIdList;
    }

    /**
     * 设置入驻平台
     *
     * @param settledPlatformIdList
     */
    public void setSettledPlatformIdList(List <String> settledPlatformIdList) {
        for (String settledPlatformId : settledPlatformIdList) {
            SettledPlatformDTO postDTO = new SettledPlatformDTO ( settledPlatformId );
            settledPlatformDTOList.add ( postDTO );
        }
    }

    /**
     * 获取包含的入驻产品id列表
     *
     * @return
     */
    public List <String> getMerchantProductIdList() {
        if ( settledPlatformDTOList == null ) {
            return Lists.newArrayList ( );
        }
        List <String> merchantProductIdList = merchantProductDTOList.stream ( ).map ( merchantProductDTO -> merchantProductDTO.getId ( ) ).collect ( Collectors.toList ( ) );
        return merchantProductIdList;
    }

    /**
     * 设置入驻产品
     *
     * @param merchantProductIdList
     */
    public void setMerchantProductIdList(List <String> merchantProductIdList) {
        for (String merchantProductId : merchantProductIdList) {
            MerchantProductDTO postDTO = new MerchantProductDTO ( merchantProductId );
            merchantProductDTOList.add ( postDTO );
        }
    }
}
