package org.sky.system.rule.tenant;

import org.sky.core.literule.annotation.LiteRuleComponent;
import org.sky.core.literule.core.RuleComponent;
import org.sky.core.tool.constant.KdConstant;
import org.sky.system.pojo.entity.Role;
import org.sky.system.pojo.entity.Tenant;
import org.sky.system.rule.context.TenantContext;

import static org.sky.system.rule.constant.TenantRuleConstant.TENANT_ROLE_RULE;


/**
 * 租户角色构建
 *
 */
@LiteRuleComponent(id = TENANT_ROLE_RULE, name = "租户角色构建")
public class TenantRoleRule extends RuleComponent {
	@Override
	public void process() {
		// 获取上下文
		TenantContext contextBean = this.getContextBean(TenantContext.class);
		Tenant tenant = contextBean.getTenant();
		// 新建租户对应的默认角色
		Role role = new Role();
		role.setTenantId(tenant.getTenantId());
		role.setParentId(KdConstant.TOP_PARENT_ID);
		role.setRoleName("管理员");
		role.setRoleAlias("admin");
		role.setSort(2);
		role.setIsDeleted(KdConstant.DB_NOT_DELETED);
		// 设置上下文
		contextBean.setRole(role);
	}
}
