package com.bohuikeji.frame.module.admin.service.impl;

import com.bohuikeji.frame.module.admin.entity.auth.*;
import com.bohuikeji.frame.module.admin.entity.sys.SysUser;
import com.bohuikeji.frame.module.admin.service.IFieldAuthService;
import com.bohuikeji.frame.module.admin.service.ITFranchiseeInformationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * 字段权限处理工具类
 * @author 10552
 */
@Slf4j
@Service
public class FieldAuthServiceImpl implements IFieldAuthService {


    final ITFranchiseeInformationService franchiseeInformationService;

    private Map<String, BaseAuth> params=new HashMap<>(2);

    public FieldAuthServiceImpl(ITFranchiseeInformationService franchiseeInformationService) {
        this.franchiseeInformationService = franchiseeInformationService;
        params.put("SESSION_USER",new UserAuth());
        params.put("##SESSION_USER##",new UserAuth());
        params.put("##FRAN_IDS##",new FranAuth(franchiseeInformationService));
        params.put("##FRAN_ID##",new FranIdAuth());
        params.put("##FRAN_SQL##",new FranAuth2(franchiseeInformationService));
        params.put("##ROLE_AUTH##",new RoleAuth());
    }
    @Override
    public String formartSql(String sql, SysUser user) {
        for (Map.Entry<String, BaseAuth> entry : params.entrySet()) {
            sql=sql.replaceAll(entry.getKey(),entry.getValue().getValue(user));
        }
        return sql;
    }
}
