package com.hotent.uc.params.role;

import com.hotent.uc.manager.RoleManager;
import com.hotent.uc.model.Role;
import com.hotent.uc.util.OperateLogUtil;
import com.hotent.uc.util.UpdateCompare;
import com.hotent.base.annotation.ExcelColumn;
import com.hotent.base.util.AppUtil;
import com.hotent.base.util.BeanUtils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 角色vo类
 * @author zhangxw
 *
 */
@ApiModel
public class RoleVo implements UpdateCompare {

	@ApiModelProperty(name="name",notes="角色名称",required=true)
	@ExcelColumn(value = "name", col = 0)
	private String name;
	
	@ApiModelProperty(name="code",notes="角色编码",required=true)
	@ExcelColumn(value = "code", col = 1)
	private String code;
	
	@ApiModelProperty(name="enabled",notes="是否禁用 0:禁用；1：正常（默认为正常）")
	@ExcelColumn(value = "enabled", col = 2)
	private Integer enabled;
	
	@ApiModelProperty(name="description",notes="角色描述")
	@ExcelColumn(value = "description", col = 3)
	private String description;

	@ApiModelProperty(value = "分管扩展组织id")
	private String extOrgId;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Integer getEnabled() {
		return enabled;
	}

	public void setEnabled(Integer enabled) {
		this.enabled = enabled;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public static Role parse(RoleVo roleVo){
		Role role = new Role();
		role.setName(roleVo.getName());
		role.setCode(roleVo.getCode());
		role.setDescription(roleVo.getDescription());
		role.setEnabled(BeanUtils.isEmpty(roleVo.getEnabled())?1:roleVo.getEnabled());
		return role;
	}

	@Override
	public String compare() throws Exception {
	    RoleManager roleService =	AppUtil.getBean(RoleManager.class);
	    Role oldRole=roleService.getByAlias(this.code);
		return OperateLogUtil.compare(this,changeVo(oldRole));
	}


	public RoleVo changeVo(Role role) {
		RoleVo roleVo=new RoleVo();
		if (BeanUtils.isEmpty(role)) return roleVo;
		roleVo.setCode(role.getCode());  
		roleVo.setDescription(role.getDescription());
		roleVo.setEnabled(role.getEnabled());
		roleVo.setName(role.getName());
		return roleVo;
	}

	public String getExtOrgId() {
		return extOrgId;
	}

	public void setExtOrgId(String extOrgId) {
		this.extOrgId = extOrgId;
	}
}
