package com.seer.teach.mall.config;

import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.data.permission.rule.role.RoleDataPermissionRuleCustomizer;
import com.seer.teach.common.enums.RoleEnum;
import com.seer.teach.mall.entity.GoodsEntity;
import com.seer.teach.mall.entity.OrderChildEntity;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

//
// @Configuration
public class DataPermissionConfiguration {


    @Bean
    public RoleDataPermissionRuleCustomizer roleDataPermissionRuleCustomizer() {
        return (rule, dataPermissionCondition) -> {
            rule.addUserColumn(GoodsEntity.class, GoodsEntity::getMerchantUserId);
            rule.addUserColumn(OrderChildEntity.class, OrderChildEntity::getMerchantUserId);
            rule.setCondition(() -> {
                List<String> roleIds = StpUtil.getRoleList();
                return roleIds.contains(RoleEnum.TEACHER.getCode());
            });
        };
    }
}