package com.ylcm.sys.excel.model;

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

import com.alibaba.excel.annotation.ExcelProperty;
import com.ylcm.sys.common.LoginUtil;
import com.ylcm.sys.common.Util;
import com.ylcm.sys.domain.User;

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

@Data
public class UserImportDTO {

	@ExcelProperty(index = 0)
	private String loginName; // 登录名
	
	@ExcelProperty(index = 1)
	private String nickName; // 用户昵称
	
	@ExcelProperty(index = 2)
	private String telephone; // 手机号
	
	@ExcelProperty(index = 3)
	private String email;//邮箱
	
	@ExcelProperty(index = 4)
	@ApiModelProperty("角色")
	private String role;
	
	@ExcelProperty(index = 5)
	private String sex; //性别
	
	private String msg = "";
	
	public void check() {
    	if (StringUtils.isBlank(loginName)) {
			msg = "登录名不能为空";
			return;
		}
    	if (StringUtils.isBlank(role)) {
			msg = "角色不能为空";
			return;
		}
	}
	
	public User toUser() {
		User user = new User();
		
		BeanUtils.copyProperties(this, user);
		if(Util.isNull(sex) || (!sex.contains("男") && !sex.contains("女")) ){
			
		}else if(sex.contains("男")){
			user.setSex(0);
		}else{
			user.setSex(1);
		}
		user.setLoginPwd(LoginUtil.generatePassword(LoginUtil.getMD5("yangguang88")));
		
		return user;
	}
}
