|
@ -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;
|
|
|
}
|
|
|
|
|
|
}
|