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.common.EnumHelperUtil;
import com.ylcm.sys.domain.AdMedia;
import com.ylcm.sys.enums.MediaRankEnum;
import com.ylcm.sys.enums.PicUploadEnum;

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

@Data
public class AdMediaImportDTO implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3863153959765813542L;

    @ApiModelProperty(value = "媒体名称")
    @ExcelProperty(index = 0)
    private String name;
    
    @ApiModelProperty(value = "媒体logo")
    @ExcelProperty(index = 1)
    private String imgUrl;
    
    @ApiModelProperty(value = "媒体等级")
    @ExcelProperty(index = 2)
    private String rankName;
    
    private String msg = "";

    public void check() {
    	if (StringUtils.isBlank(name)) {
			msg = "媒体名称不能为空";
			return;
		}
    	if (name.length() > 10) {
    		msg = "媒体名称长度不能超过10个字";
			return;
    	}
    	if (StringUtils.isBlank(rankName)) {
			msg = "媒体等级不能为空";
			return;
		}
    }
    
    public AdMedia toMedia() {
    	AdMedia adMedia = new AdMedia();
    	
    	if (StringUtils.isNotBlank(imgUrl)) {
			imgUrl = Constants.PIC_BASE_URL + PicUploadEnum.MEDIA.getName() + imgUrl;
		}
    	
    	BeanUtils.copyProperties(this, adMedia);
    	
    	MediaRankEnum mediaRankEnum = EnumHelperUtil.getOneByName(MediaRankEnum.class, rankName);
    	if (mediaRankEnum != null) {
			adMedia.setRank(mediaRankEnum.getCode());
		}
    	
    	return adMedia;
    }
}
