package org.dromara.zhishu.domain.dto;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dromara.common.excel.annotation.ExcelDictFormat;
import org.dromara.common.excel.convert.ExcelDictConvert;
import org.dromara.zhishu.annotation.EnableExcelComment;
import org.dromara.zhishu.converter.PriceDivideBy100Converter;
import org.springframework.util.StringUtils;

@Data
@NoArgsConstructor
@AllArgsConstructor
@AutoMapper(target = SuccessDataItemDto.class)  // 添加注解
@EnableExcelComment
@HeadRowHeight(30)  // 设置表头行高为30磅
public class SuccessDataItemDto {

    /**
     * 拉取商品表主键
     */
    @ExcelIgnore
    private String id;

    /**
     * ISBN
     */
    @ExcelProperty(value = "ISBN")
    @ColumnWidth(15)
    private String isbn;

    /**
     * 三方平台商品Id
     */
    @ExcelProperty(value = "商品id")
    @ColumnWidth(15)
    private String trilateralId;

    /**
     * 商品编码
     */
    @ExcelProperty(value = "商品编码")
    @ColumnWidth(15)
    private String goodsCode;
    /**
     * 图片
     */
    @ExcelIgnore
    private Object img;

    /**
     * 书名
     */
    @ExcelProperty(value = "商品名称")
    @ColumnWidth(15)
    private String title;

    /**
     * 库存
     */
    @ExcelProperty(value = "库存数量")
    @ColumnWidth(15)
    private String stock;

    /**
     * 完成时间
     */
    @ExcelProperty(value = "创建时间")
    @ColumnWidth(15)
    private String finishTime;

    /**
     * 价格
     */
    @ExcelProperty(value = "价格", converter = PriceDivideBy100Converter.class)
    @ColumnWidth(15)
    private String totalPrice;

    /**
     * sku编码
     */
    @ExcelProperty(value = "规格编码/货号")
    @ColumnWidth(15)
    private String skuCode;

    /**
     * skuId
     */
    @ExcelIgnore
    private String skuId;

    /**
     * 是否在售
     */
    @ExcelProperty(value = "是否在架上", converter = ExcelDictConvert.class)
    @ExcelDictFormat(readConverterExp = "0=下架,1=上架")
    @ColumnWidth(15)
    private String isOnSale;

    /**
     * 图片选择
     */
    @ExcelIgnore
    private String imageSelect;

    /**
     * 权重
     */
    @ExcelIgnore
    private String priority;

    /**
     * 图片
     */
    @ExcelProperty(value = "商品图片")
    @ColumnWidth(15)
    private String imageBigUrl;

    /**
     * quality
     */
    @ExcelIgnore
    private String quality;

    /**
     * 店铺类型
     */
    @ExcelIgnore
    private String shopType;


    /**
     * 判断数据是否有效（至少有一个业务字段有值）
     *
     * @return true: 有效数据, false: 无效数据（提示行产生的空对象）
     */
    public boolean isValidData() {
        return StringUtils.hasText(isbn)
                || StringUtils.hasText(trilateralId)
                || StringUtils.hasText(goodsCode)
                || StringUtils.hasText(title)
                || StringUtils.hasText(stock)
                || StringUtils.hasText(totalPrice)
                || StringUtils.hasText(skuCode)
                || StringUtils.hasText(isOnSale)
                || StringUtils.hasText(imageBigUrl);
    }
}