package cn.stylefeng.team.project.modular.businessrender.sql.impl;

import cn.stylefeng.team.project.modular.businessrender.mapper.BusinessRenderMapper;
import cn.stylefeng.team.project.modular.businessrender.sql.ProjectSqlExecuteApi;
import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy;
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;

import java.util.List;
import java.util.Map;

public class ProjectSqlExecuteImpl implements ProjectSqlExecuteApi {

    @Resource
    private BusinessRenderMapper businessRenderMapper;

    @Override
    public List<Map<String, Object>> customFindPage(Page page, String sql, Map<String, Object> params) {
        return businessRenderMapper.customFindPage(page, sql, params);
    }

    @Override
    public Map<String, Object> findOne(String sql, Map<String, Object> params) {
        return businessRenderMapper.findOne(sql, params);
    }

    @Override
    public List<Map<String, Object>> findList(String sql, Map<String, Object> params) {
        return businessRenderMapper.findList(sql, params);
    }

    @Override
    public int executeDelete(String sql, Map<String, Object> params) {
        try {
            InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().dataPermission(true).build());
            return businessRenderMapper.executeDelete(sql, params);
        } finally {
            InterceptorIgnoreHelper.clearIgnoreStrategy();
        }
    }

    @Override
    public int executeUpdate(String sql, Map<String, Object> params) {
        try {
            InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().dataPermission(true).build());
            return businessRenderMapper.executeUpdate(sql, params);
        } finally {
            InterceptorIgnoreHelper.clearIgnoreStrategy();
        }
    }

}
