解决online连接数爆炸的严重bug

This commit is contained in:
D 2024-03-24 01:30:01 +08:00
parent 27c826567a
commit 4c1d7ab978
2 changed files with 28 additions and 10 deletions

View File

@ -0,0 +1,21 @@
package com.ruoyi.online.config;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.ruoyi.online.utils.SqlMapper;
@Configuration
public class SqlMapperConfiguration {
@Autowired
private SqlSessionFactory sqlSessionFactory;
@Bean
public SqlMapper getSqlMapper() {
SqlSession sqlSession = sqlSessionFactory.openSession();
return new SqlMapper(sqlSession);
}
}

View File

@ -6,8 +6,6 @@ import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -31,13 +29,14 @@ import jakarta.servlet.http.HttpServletResponse;
@Anonymous @Anonymous
@RequestMapping("/online") @RequestMapping("/online")
public class OnLineController extends BaseController { public class OnLineController extends BaseController {
@Autowired
private SqlSessionFactory sqlSessionFactory;
@Autowired @Autowired
private IOnlineMbService onlineMbService; private IOnlineMbService onlineMbService;
@Resource(name = "ss") @Resource(name = "ss")
private PermissionService permissionService; private PermissionService permissionService;
@Autowired
private SqlMapper sqlMapper;
@RequestMapping("/api/**") @RequestMapping("/api/**")
public Object api(@RequestParam(required = false) HashMap<String, Object> params, public Object api(@RequestParam(required = false) HashMap<String, Object> params,
@RequestBody(required = false) HashMap<String, Object> data, HttpServletRequest request, @RequestBody(required = false) HashMap<String, Object> data, HttpServletRequest request,
@ -70,9 +69,9 @@ public class OnLineController extends BaseController {
List<OnlineMb> selectOnlineMbList = onlineMbService.selectOnlineMbList(selectOnlineMb); List<OnlineMb> selectOnlineMbList = onlineMbService.selectOnlineMbList(selectOnlineMb);
if (selectOnlineMbList.size() == 0) { if (selectOnlineMbList.size() == 0) {
return AjaxResult.error("没有资源"+selectOnlineMb.getPath()); return AjaxResult.error("没有资源" + selectOnlineMb.getPath());
} else if (selectOnlineMbList.size() > 1) { } else if (selectOnlineMbList.size() > 1) {
return AjaxResult.error(500,"系统错误,在线接口重复"); return AjaxResult.error(500, "系统错误,在线接口重复");
} else { } else {
OnlineMb onlineMb = selectOnlineMbList.get(0); OnlineMb onlineMb = selectOnlineMbList.get(0);
boolean permissionFlag = true; boolean permissionFlag = true;
@ -87,7 +86,7 @@ public class OnLineController extends BaseController {
} }
} }
if (!permissionFlag) { if (!permissionFlag) {
return AjaxResult.error(403,"没有权限,请联系管理员授权"); return AjaxResult.error(403, "没有权限,请联系管理员授权");
} }
if (onlineMb.getDeptId() != null && onlineMb.getDeptId().equals("1")) { if (onlineMb.getDeptId() != null && onlineMb.getDeptId().equals("1")) {
object.put("deptId", SecurityUtils.getDeptId()); object.put("deptId", SecurityUtils.getDeptId());
@ -97,15 +96,13 @@ public class OnLineController extends BaseController {
} }
String sql = "<script>\n" + onlineMb.getSql() + "\n</script>"; String sql = "<script>\n" + onlineMb.getSql() + "\n</script>";
SqlSession sqlSession = sqlSessionFactory.openSession();
SqlMapper sqlMapper = new SqlMapper(sqlSession);
return switch (onlineMb.getActuator()) { return switch (onlineMb.getActuator()) {
case "selectList" -> getDataTable(sqlMapper.selectList(sql, object)); case "selectList" -> getDataTable(sqlMapper.selectList(sql, object));
case "insert" -> toAjax(sqlMapper.insert(sql, object)); case "insert" -> toAjax(sqlMapper.insert(sql, object));
case "selectOne" -> success(sqlMapper.selectOne(sql, object)); case "selectOne" -> success(sqlMapper.selectOne(sql, object));
case "update" -> toAjax(sqlMapper.update(sql, object)); case "update" -> toAjax(sqlMapper.update(sql, object));
case "delete" -> toAjax(sqlMapper.delete(sql, object)); case "delete" -> toAjax(sqlMapper.delete(sql, object));
default -> AjaxResult.error(500,"系统错误,执行器错误"); default -> AjaxResult.error(500, "系统错误,执行器错误");
}; };
} }
} }