update 提炼springdoc
This commit is contained in:
parent
4c1d7ab978
commit
c499985432
6
pom.xml
6
pom.xml
@ -200,6 +200,12 @@
|
|||||||
<version>${ruoyi.version}</version>
|
<version>${ruoyi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- knife4j -->
|
<!-- knife4j -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.xiaoymin</groupId>
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>ruoyi</artifactId>
|
<artifactId>ruoyi</artifactId>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
@ -69,6 +68,18 @@
|
|||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-online</artifactId>
|
<artifactId>ruoyi-online</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- knife4j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -142,8 +142,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.xiaoymin</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,6 +6,8 @@ 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;
|
||||||
@ -35,15 +37,9 @@ public class OnLineController extends BaseController {
|
|||||||
private PermissionService permissionService;
|
private PermissionService permissionService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SqlMapper sqlMapper;
|
private SqlSessionFactory sqlSessionFactory;
|
||||||
|
|
||||||
@RequestMapping("/api/**")
|
public Map<String, Object> getParams(HashMap<String, Object> params, HashMap<String, Object> data) {
|
||||||
public Object api(@RequestParam(required = false) HashMap<String, Object> params,
|
|
||||||
@RequestBody(required = false) HashMap<String, Object> data, HttpServletRequest request,
|
|
||||||
HttpServletResponse response) {
|
|
||||||
OnlineMb selectOnlineMb = new OnlineMb();
|
|
||||||
selectOnlineMb.setPath(request.getRequestURI().replace("/online/api", ""));
|
|
||||||
selectOnlineMb.setMethod(request.getMethod());
|
|
||||||
Map<String, Object> object = new HashMap<>();
|
Map<String, Object> object = new HashMap<>();
|
||||||
HashMap<String, Object> object_params = new HashMap<String, Object>();
|
HashMap<String, Object> object_params = new HashMap<String, Object>();
|
||||||
String keyregex = "params\\[(.*?)\\]";
|
String keyregex = "params\\[(.*?)\\]";
|
||||||
@ -66,6 +62,47 @@ public class OnLineController extends BaseController {
|
|||||||
object.putAll(data);
|
object.putAll(data);
|
||||||
}
|
}
|
||||||
object.put("params", object_params);
|
object.put("params", object_params);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean checkPermission(String permission) {
|
||||||
|
return switch (permission) {
|
||||||
|
case "hasPermi" -> permissionService.hasPermi(permission);
|
||||||
|
case "lacksPermi" -> !permissionService.lacksPermi(permission);
|
||||||
|
case "hasAnyPermi" -> permissionService.hasAnyPermi(permission);
|
||||||
|
case "hasRole" -> permissionService.hasRole(permission);
|
||||||
|
case "lacksRole" -> !permissionService.lacksRole(permission);
|
||||||
|
case "hasAnyRoles" -> permissionService.hasAnyRoles(permission);
|
||||||
|
default -> true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object processingMapper(String sqlContext, String actuatot, Map<String, Object> params) {
|
||||||
|
String sql = "<script>\n" + sqlContext + "\n</script>";
|
||||||
|
SqlSession sqlSession = sqlSessionFactory.openSession();
|
||||||
|
SqlMapper sqlMapper = new SqlMapper(sqlSession);
|
||||||
|
Object res = null;
|
||||||
|
res = switch (actuatot) {
|
||||||
|
case "selectList" -> getDataTable(sqlMapper.selectList(sql, params));
|
||||||
|
case "insert" -> toAjax(sqlMapper.insert(sql, params));
|
||||||
|
case "selectOne" -> success(sqlMapper.selectOne(sql, params));
|
||||||
|
case "update" -> toAjax(sqlMapper.update(sql, params));
|
||||||
|
case "delete" -> toAjax(sqlMapper.delete(sql, params));
|
||||||
|
default -> AjaxResult.error(500, "系统错误,执行器错误");
|
||||||
|
};
|
||||||
|
sqlSession.close();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/api/**")
|
||||||
|
public Object api(@RequestParam(required = false) HashMap<String, Object> params,
|
||||||
|
@RequestBody(required = false) HashMap<String, Object> data, HttpServletRequest request,
|
||||||
|
HttpServletResponse response) {
|
||||||
|
OnlineMb selectOnlineMb = new OnlineMb();
|
||||||
|
selectOnlineMb.setPath(request.getRequestURI().replace("/online/api", ""));
|
||||||
|
selectOnlineMb.setMethod(request.getMethod());
|
||||||
|
|
||||||
|
Map<String, Object> object = getParams(params, data);
|
||||||
|
|
||||||
List<OnlineMb> selectOnlineMbList = onlineMbService.selectOnlineMbList(selectOnlineMb);
|
List<OnlineMb> selectOnlineMbList = onlineMbService.selectOnlineMbList(selectOnlineMb);
|
||||||
if (selectOnlineMbList.size() == 0) {
|
if (selectOnlineMbList.size() == 0) {
|
||||||
@ -74,20 +111,9 @@ public class OnLineController extends BaseController {
|
|||||||
return AjaxResult.error(500, "系统错误,在线接口重复");
|
return AjaxResult.error(500, "系统错误,在线接口重复");
|
||||||
} else {
|
} else {
|
||||||
OnlineMb onlineMb = selectOnlineMbList.get(0);
|
OnlineMb onlineMb = selectOnlineMbList.get(0);
|
||||||
boolean permissionFlag = true;
|
if (!checkPermission(onlineMb.getPermissionValue()))
|
||||||
if (onlineMb.getPermissionType() != null) {
|
|
||||||
switch (onlineMb.getPermissionType()) {
|
|
||||||
case "hasPermi" -> permissionFlag = permissionService.hasPermi(onlineMb.getPermissionValue());
|
|
||||||
case "lacksPermi" -> permissionFlag = !permissionService.lacksPermi(onlineMb.getPermissionValue());
|
|
||||||
case "hasAnyPermi" -> permissionFlag = permissionService.hasAnyPermi(onlineMb.getPermissionValue());
|
|
||||||
case "hasRole" -> permissionFlag = permissionService.hasRole(onlineMb.getPermissionValue());
|
|
||||||
case "lacksRole" -> permissionFlag = !permissionService.lacksRole(onlineMb.getPermissionValue());
|
|
||||||
case "hasAnyRoles" -> permissionFlag = permissionService.hasAnyRoles(onlineMb.getPermissionValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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());
|
||||||
}
|
}
|
||||||
@ -95,15 +121,7 @@ public class OnLineController extends BaseController {
|
|||||||
object.put("userId", SecurityUtils.getUserId());
|
object.put("userId", SecurityUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
String sql = "<script>\n" + onlineMb.getSql() + "\n</script>";
|
return processingMapper(onlineMb.getSql(), onlineMb.getActuator(), object);
|
||||||
return switch (onlineMb.getActuator()) {
|
|
||||||
case "selectList" -> getDataTable(sqlMapper.selectList(sql, object));
|
|
||||||
case "insert" -> toAjax(sqlMapper.insert(sql, object));
|
|
||||||
case "selectOne" -> success(sqlMapper.selectOne(sql, object));
|
|
||||||
case "update" -> toAjax(sqlMapper.update(sql, object));
|
|
||||||
case "delete" -> toAjax(sqlMapper.delete(sql, object));
|
|
||||||
default -> AjaxResult.error(500, "系统错误,执行器错误");
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package com.ruoyi.online.service.impl;
|
package com.ruoyi.online.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ruoyi.online.mapper.OnlineMbMapper;
|
|
||||||
import com.ruoyi.online.domain.OnlineMb;
|
import com.ruoyi.online.domain.OnlineMb;
|
||||||
|
import com.ruoyi.online.mapper.OnlineMbMapper;
|
||||||
import com.ruoyi.online.service.IOnlineMbService;
|
import com.ruoyi.online.service.IOnlineMbService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user