package com.ylcm.sys.excel.model;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;

import com.alibaba.excel.annotation.ExcelProperty;
import com.ylcm.sys.common.Constants;
import com.ylcm.sys.domain.AdProduct;
import com.ylcm.sys.enums.PicUploadEnum;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 *    产品导入
 * @author admin
 *
 */
@Data
public class AdProductImportDTO implements Serializable{

	private static final long serialVersionUID = 3863153959765813542L;

    @ApiModelProperty(value = "产品名称")
    @ExcelProperty(index = 0)
    private String productName;

    @ApiModelProperty(value = "产品logo")
    @ExcelProperty(index = 1)
    private String nameImgUrl;
    
    @ApiModelProperty(value = "产品品牌")
    @ExcelProperty(index = 2)
    private String brandName;
    
    @ApiModelProperty(value = "一级行业")
    @ExcelProperty(index = 3)
    private String firstInd;

    @ApiModelProperty(value = "二级行业")
    @ExcelProperty(index = 4)
    private String secondInd;
    
    
    private String msg = "";

    public void check() {
        if (StringUtils.isBlank(productName)) {
			msg = "产品名称不能为空";
			return;
		}
		if (productName.length() > 50) {
			msg = "产品名称长度不能超过50个字";
			return;
		}
		if (StringUtils.isNotBlank(brandName) && brandName.length() > 10) {
			msg = "品牌长度不能超过10个字";
			return;
		}
		if (StringUtils.isBlank(firstInd)) {
			msg = "一级行业不能为空";
			return;
		}
    	if (StringUtils.isBlank(secondInd)) {
			msg = "二级行业不能为空";
			return;
		}
    }
    
    public AdProduct toAdProduct() {
    	AdProduct adProduct = new AdProduct();
    	if (StringUtils.isNotBlank(nameImgUrl)) {
    		nameImgUrl = Constants.PIC_BASE_URL + PicUploadEnum.PRODUCT.getName() + nameImgUrl;
		}
    	BeanUtils.copyProperties(this, adProduct);
    	return adProduct;
    }
}
