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.Dept;
import org.sky.system.pojo.entity.Tenant;
import org.sky.system.rule.context.TenantContext;

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


/**
 * 租户机构构建
 *
 */
@LiteRuleComponent(id = TENANT_DEPT_RULE, name = "租户机构构建")
public class TenantDeptRule extends RuleComponent {
	@Override
	public void process() {
		// 获取上下文
		TenantContext contextBean = this.getContextBean(TenantContext.class);
		Tenant tenant = contextBean.getTenant();

		// 新建租户对应的默认部门
		Dept dept = new Dept();
		dept.setTenantId(tenant.getTenantId());
		dept.setParentId(KdConstant.TOP_PARENT_ID);
		dept.setAncestors(String.valueOf(KdConstant.TOP_PARENT_ID));
		dept.setDeptName(tenant.getTenantName());
		dept.setFullName(tenant.getTenantName());
		dept.setDeptCategory(1);
		dept.setSort(2);
		dept.setIsDeleted(KdConstant.DB_NOT_DELETED);

		// 设置上下文
		contextBean.setDept(dept);

	}
}
