package cn.iocoder.yudao.module.system.framework.datapermission.config;

import cn.iocoder.yudao.framework.datapermission.core.rule.dept.DeptDataPermissionRuleCustomizer;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogInstanceDO;
import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogStatisticsDO;
import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogUseDO;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * system 模块的数据权限 Configuration
 */
@Configuration(proxyBeanMethods = false)
public class DataPermissionConfiguration {

    @Bean
    public DeptDataPermissionRuleCustomizer sysDeptDataPermissionRuleCustomizer() {
        return rule -> {
            // dept
            rule.addDeptColumn(AdminUserDO.class);
            rule.addDeptColumn(DeptDO.class, "id");
            rule.addDeptColumn(LogUseDO.class, "use_user_dept");
            rule.addDeptColumn(LogStatisticsDO.class, "dept_id");
            rule.addDeptColumn(LogInstanceDO.class, "dept_id");

            // user
            rule.addUserColumn(AdminUserDO.class, "id");
            rule.addUserColumn(LogUseDO.class, "use_user_id");
            rule.addUserColumn(LogStatisticsDO.class, "user_id");
            rule.addUserColumn(LogInstanceDO.class, "start_user_id");

        };
    }

}
