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.AdPlatform;
import com.ylcm.sys.enums.PicUploadEnum;

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

/**
 *     栏目导入
 * @author admin
 *
 */
@Data
public class AdPlatformImportDTO implements Serializable{

	private static final long serialVersionUID = 3863153959765813542L;

    @ApiModelProperty(value = "栏目名称")
    @ExcelProperty(index = 0)
    private String platformName;
    
    @ApiModelProperty(value = "栏目logo")
    @ExcelProperty(index = 1)
    private String imgUrl;

    @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(platformName)) {
			msg = "栏目名称不能为空";
			return;
		}
		if (platformName.length() > 20) {
			msg = "栏目名称长度不能超过20个字";
			return;
		}
		if (StringUtils.isNotBlank(brandName) && brandName.length() > 20) {
			msg = "栏目内容长度不能超过20个字";
			return;
		}
		if (StringUtils.isBlank(firstInd)) {
			msg = "一级行业不能为空";
			return;
		}
    	if (StringUtils.isBlank(secondInd)) {
			msg = "二级行业不能为空";
			return;
		}
    }
    
    public AdPlatform toAdPlatform() {
    	AdPlatform adPlatform = new AdPlatform();
    	if (StringUtils.isNotBlank(imgUrl)) {
			imgUrl = Constants.PIC_BASE_URL + PicUploadEnum.PLATFORM.getName() + imgUrl;
		}
    	BeanUtils.copyProperties(this, adPlatform);
    	return adPlatform;
    }
}
