瀏覽代碼

【修复】默认开启SqlRunner,修复tableUniValueFlag查询问题

fengshuonan 4 年之前
父節點
當前提交
7a208fbe86

+ 8 - 28
guns-base-support/guns-system/src/main/java/cn/stylefeng/guns/sys/core/context/SystemContextImpl.java

@ -37,15 +37,12 @@ import cn.stylefeng.guns.sys.modular.role.service.SysRoleService;
import cn.stylefeng.guns.sys.modular.user.entity.SysUser;
import cn.stylefeng.guns.sys.modular.user.param.SysUserParam;
import cn.stylefeng.guns.sys.modular.user.service.SysUserService;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
/**
 * 系统相关上下文接口实现类
@ -70,9 +67,6 @@ public class SystemContextImpl implements SystemContext {
    @Resource
    private SysDictDataService sysDictDataService;
    @Resource
    private DruidDataSource druidDataSource;
    @Override
    public String getNameByUserId(Long userId) {
        return sysUserService.getNameByUserId(userId);
@ -125,27 +119,13 @@ public class SystemContextImpl implements SystemContext {
    @Override
    public boolean tableUniValueFlag(String tableName, String columnName, String value) {
        try {
            DruidPooledConnection connection = druidDataSource.getConnection();
            PreparedStatement preparedStatement = connection.prepareStatement("select count(*) from " + tableName + " where " + columnName + " = ?");
            preparedStatement.setString(1, value);
            ResultSet resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                long sumValue = resultSet.getLong(1);
                if (sumValue == 0L) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return true;
            }
        } catch (SQLException throwables) {
            log.error("执行sql错误!", throwables);
        List<Map<String, Object>> maps = SqlRunner.db().selectList(
                "select " + columnName + " from " + tableName + " where " + columnName + " = {0}", value);
        if (maps != null && maps.size() > 0) {
            return false;
        } else {
            return true;
        }
        return false;
    }
}

+ 1 - 0
guns-main/src/main/resources/application.yml

@ -33,6 +33,7 @@ mybatis-plus:
    db-config:
      id-type: assign_id
      table-underline: true
    enable-sql-runner: true
  configuration-properties:
    prefix:
    blobType: BLOB