mirror of
https://gitee.com/ssssssss-team/magic-boot.git
synced 2026-07-28 00:00:12 +08:00
升级springboot3
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package org.ssssssss.magicboot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MagicBootApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MagicBootApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.ssssssss.magicboot.configuration;
|
||||
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Configuration
|
||||
public class MagicBootConfiguration {
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
|
||||
LocalDateTimeSerializer localDateTimeSerializer = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
return builder -> builder.serializerByType(LocalDateTime.class, localDateTimeSerializer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.ssssssss.magicboot.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.ssssssss.magicboot.model.Global;
|
||||
|
||||
@Configuration
|
||||
public class WebConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler(Global.USER_FILES_BASE_URL + "**").addResourceLocations("file:" + Global.getDir() + Global.USER_FILES_BASE_URL);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.ssssssss.magicboot.extension;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.ssssssss.magicapi.modules.db.table.NamedTable;
|
||||
import org.ssssssss.magicboot.model.MagicBootConstants;
|
||||
import org.ssssssss.script.annotation.Comment;
|
||||
import org.ssssssss.script.functions.ExtensionMethod;
|
||||
import org.ssssssss.script.runtime.RuntimeContext;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class NamedTableFunctionExtension implements ExtensionMethod {
|
||||
|
||||
@Override
|
||||
public Class<?> support() {
|
||||
return NamedTable.class;
|
||||
}
|
||||
|
||||
@Comment("保存到表中,当主键有值时则修改,否则插入")
|
||||
public static Object saveOrUpdate(NamedTable namedTable, RuntimeContext runtimeContext, @Comment("各项列和值") Map<String, Object> data){
|
||||
namedTable.setAttribute(MagicBootConstants.COMMON_FIELD, true);
|
||||
namedTable.save(runtimeContext, data,true);
|
||||
return namedTable.getAttribute(MagicBootConstants.ID);
|
||||
}
|
||||
|
||||
@Comment("保存到表中,当主键有值时则修改,否则插入")
|
||||
public static Object saveOrUpdate(NamedTable namedTable, RuntimeContext runtimeContext){
|
||||
return saveOrUpdate(namedTable, runtimeContext, null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.ssssssss.magicboot.extension;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.ssssssss.magicapi.core.context.RequestContext;
|
||||
import org.ssssssss.magicapi.core.servlet.MagicHttpServletRequest;
|
||||
import org.ssssssss.magicapi.modules.servlet.ResponseModule;
|
||||
import org.ssssssss.script.annotation.Comment;
|
||||
import org.ssssssss.script.functions.ExtensionMethod;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
public class ResponseFunctionExtension implements ExtensionMethod {
|
||||
|
||||
@Override
|
||||
public Class<?> support() {
|
||||
return ResponseModule.class;
|
||||
}
|
||||
|
||||
private HttpServletResponse getResponse() {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
if (requestAttributes instanceof ServletRequestAttributes) {
|
||||
return ((ServletRequestAttributes) requestAttributes).getResponse();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Comment("转发")
|
||||
public ResponseModule.NullValue dispatcher(ResponseModule responseModule, String url) throws ServletException, IOException {
|
||||
MagicHttpServletRequest magicHttpServletRequest = RequestContext.getHttpServletRequest();
|
||||
HttpServletRequest request = magicHttpServletRequest.getRequest();
|
||||
request.getRequestDispatcher(url).forward(request, getResponse());
|
||||
return responseModule.end();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.ssssssss.magicboot.interceptor;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.ssssssss.magicapi.modules.db.inteceptor.NamedTableInterceptor;
|
||||
import org.ssssssss.magicapi.modules.db.model.SqlMode;
|
||||
import org.ssssssss.magicapi.modules.db.table.NamedTable;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.ssssssss.magicboot.model.MagicBootConstants.*;
|
||||
|
||||
@Component
|
||||
public class NamedTableHandlerInterceptor implements NamedTableInterceptor {
|
||||
|
||||
@Override
|
||||
public void preHandle(SqlMode sqlMode, NamedTable namedTable) {
|
||||
if(Boolean.TRUE == namedTable.getAttribute(COMMON_FIELD)){
|
||||
if(sqlMode == SqlMode.INSERT) {
|
||||
String id = IdUtil.simpleUUID();
|
||||
namedTable.setAttribute(namedTable.getPrimary(), id);
|
||||
namedTable.column(namedTable.getPrimary(), id);
|
||||
namedTable.column(CREATE_BY, StpUtil.getLoginId());
|
||||
namedTable.column(CREATE_DATE, new Date());
|
||||
}
|
||||
if(sqlMode == SqlMode.UPDATE){
|
||||
namedTable.setAttribute(namedTable.getPrimary(), namedTable.getColumns().get(namedTable.getPrimary()));
|
||||
namedTable.column(UPDATE_BY, StpUtil.getLoginId());
|
||||
namedTable.column(UPDATE_DATE, new Date());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package org.ssssssss.magicboot.interceptor;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.ssssssss.magicapi.core.context.RequestEntity;
|
||||
import org.ssssssss.magicapi.core.interceptor.RequestInterceptor;
|
||||
import org.ssssssss.magicapi.core.model.ApiInfo;
|
||||
import org.ssssssss.magicapi.core.model.Options;
|
||||
import org.ssssssss.magicapi.core.service.MagicAPIService;
|
||||
import org.ssssssss.magicapi.core.service.MagicResourceService;
|
||||
import org.ssssssss.magicapi.core.servlet.MagicHttpServletRequest;
|
||||
import org.ssssssss.magicapi.core.servlet.MagicHttpServletResponse;
|
||||
import org.ssssssss.magicapi.utils.PathUtils;
|
||||
import org.ssssssss.magicboot.model.StatusCode;
|
||||
import org.ssssssss.script.MagicScriptContext;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
@Order(1)
|
||||
public class PermissionInterceptor implements RequestInterceptor, HandlerInterceptor {
|
||||
|
||||
@Autowired
|
||||
MagicAPIService magicAPIService;
|
||||
|
||||
@Autowired
|
||||
MagicResourceService magicResourceService;
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate template;
|
||||
|
||||
/*
|
||||
* 当返回对象时,直接将此对象返回到页面,返回null时,继续执行后续操作
|
||||
*/
|
||||
@Override
|
||||
public Object preHandle(ApiInfo info, MagicScriptContext context, MagicHttpServletRequest request, MagicHttpServletResponse response) {
|
||||
String requireLogin = Objects.toString(info.getOptionValue(Options.REQUIRE_LOGIN), "");
|
||||
if(requireLogin.equals("false")){
|
||||
return null;
|
||||
}
|
||||
if(!StpUtil.isLogin()){
|
||||
return StatusCode.CERTIFICATE_EXPIRED.json();
|
||||
} else {
|
||||
// TODO
|
||||
List<String> permissions = (List<String>) magicAPIService.execute("post", "/system/security/permissions", new HashMap<String, Object>());
|
||||
String permission = Objects.toString(info.getOptionValue(Options.PERMISSION), "");
|
||||
if (StringUtils.isNotBlank(permission) && !permissions.contains(permission)) {
|
||||
return StatusCode.FORBIDDEN.json();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postHandle(RequestEntity requestEntity, Object returnValue) throws Exception {
|
||||
if(StpUtil.isLogin()){
|
||||
try {
|
||||
MagicHttpServletRequest request = requestEntity.getRequest();
|
||||
ApiInfo info = requestEntity.getApiInfo();
|
||||
template.update("insert into sys_oper_log(api_name, api_path, api_method, cost_time, create_by, create_date, user_agent, user_ip) values(?,?,?,?,?,?,?,?)",
|
||||
// PathUtils.replaceSlash(groupServiceProvider.getFullName(info.getGroupId()) + "/" + info.getName()).replace("/","-"),
|
||||
PathUtils.replaceSlash(String.format("/%s/%s", magicResourceService.getGroupName(info.getGroupId()), info.getName())),
|
||||
request.getRequestURI(),
|
||||
request.getMethod(),
|
||||
System.currentTimeMillis() - requestEntity.getRequestTime(),
|
||||
StpUtil.getLoginId(),
|
||||
new Date(requestEntity.getRequestTime()),
|
||||
request.getHeader("User-Agent"),
|
||||
request.getRemoteAddr());
|
||||
} catch (Exception ignored){
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.ssssssss.magicboot.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CodeCacheMap {
|
||||
|
||||
private static Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
public static void put(String key, String value){
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
public static void remove(String key){
|
||||
map.remove(key);
|
||||
}
|
||||
|
||||
public static String get(String key){
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.ssssssss.magicboot.model;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.ssssssss.magicboot.utils.WebUtils;
|
||||
|
||||
@Component
|
||||
public class Global {
|
||||
|
||||
/**
|
||||
* 文件上的根目录
|
||||
*/
|
||||
public static String dir;
|
||||
|
||||
public final static String USER_FILES_BASE_URL = "/userfiles/";
|
||||
|
||||
public static String getDir() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
@Value("${upload.dir:D:/mb/}")
|
||||
public void setDir(String dir) {
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上传文件的根目录
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getUserFilesBaseDir() {
|
||||
String dir = getDir();
|
||||
if (StrUtil.isBlank(dir)) {
|
||||
try {
|
||||
dir = WebUtils.getHttpServletRequest().getSession().getServletContext().getRealPath("/");
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
if (!dir.endsWith("/")) {
|
||||
dir += "/";
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.ssssssss.magicboot.model;
|
||||
|
||||
/**
|
||||
* Magic Boot 中使用的常量
|
||||
*/
|
||||
public class MagicBootConstants {
|
||||
|
||||
/**
|
||||
* 设置通用字段
|
||||
*/
|
||||
public static final String COMMON_FIELD = "setCommonField";
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
public static final String ID = "id";
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
public static final String CREATE_BY = "createBy";
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
public static final String UPDATE_BY = "updateBy";
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
public static final String CREATE_DATE = "createDate";
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
public static final String UPDATE_DATE = "updateDate";
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.ssssssss.magicboot.model;
|
||||
|
||||
import org.ssssssss.magicapi.core.model.JsonBean;
|
||||
|
||||
public enum StatusCode {
|
||||
|
||||
CERTIFICATE_EXPIRED(402, "凭证已过期"),
|
||||
FORBIDDEN(403, "禁止访问");
|
||||
|
||||
StatusCode(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
private int code;
|
||||
|
||||
private String message;
|
||||
|
||||
public JsonBean json(){
|
||||
return new JsonBean<>(this.code, this.message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,348 @@
|
||||
package org.ssssssss.magicboot.model;
|
||||
|
||||
import org.ssssssss.magicboot.utils.WebUtils;
|
||||
|
||||
public class UeditorConfig {
|
||||
|
||||
private String imageActionName ="uploadImage";//执行上传图片的action名称
|
||||
|
||||
private String imageFieldName = "file";//提交的图片表单名称
|
||||
|
||||
private long imageMaxSize = 2048000;//上传大小限制,单位B
|
||||
|
||||
private String[] imageAllowFiles = new String[]{".png", ".jpg", ".jpeg", ".gif", ".bmp"};/* 上传图片格式显示 */
|
||||
|
||||
private boolean imageCompressEnable = true;//是否压缩图片,默认是true
|
||||
|
||||
private int imageCompressBorder = 1600;//图片压缩最长边限制
|
||||
|
||||
private String imageInsertAlign = "none";//插入的图片浮动方式
|
||||
|
||||
private String imageUrlPrefix = WebUtils.getUeditorPrefix();//图片访问路径前缀
|
||||
|
||||
/* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
/* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */
|
||||
/* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */
|
||||
/* {time} 会替换成时间戳 */
|
||||
/* {yyyy} 会替换成四位年份 */
|
||||
/* {yy} 会替换成两位年份 */
|
||||
/* {mm} 会替换成两位月份 */
|
||||
/* {dd} 会替换成两位日期 */
|
||||
/* {hh} 会替换成两位小时 */
|
||||
/* {ii} 会替换成两位分钟 */
|
||||
/* {ss} 会替换成两位秒 */
|
||||
/* 非法字符 \ : * ? " < > | */
|
||||
/* 具请体看线上文档: fex.baidu.com/ueditor/#use-format_upload_filename */
|
||||
private String imagePathFormat = "/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}";
|
||||
|
||||
/*抓取远程图片配置*/
|
||||
private String catcherLocalDomain[] = new String[]{"127.0.0.1", "localhost", "img.baidu.com"};
|
||||
|
||||
private String catcherActionName = "catchimage";/* 执行抓取远程图片的action名称 */
|
||||
|
||||
private String catcherFieldName = "source";/* 提交的图片列表表单名称 */
|
||||
|
||||
private String catcherPathFormat ="/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}"; /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
|
||||
private long catcherMaxSize= 2048000; /* 上传大小限制,单位B */
|
||||
|
||||
private String catcherAllowFiles[] = new String[]{".png", ".jpg", ".jpeg", ".gif", ".bmp"}; /* 抓取图片格式显示 */
|
||||
|
||||
/* 上传文件配置 */
|
||||
private String fileActionName = "uploadFile";
|
||||
|
||||
private String fileFieldName = "file"; /* 提交的文件表单名称 */
|
||||
|
||||
private String filePathFormat = "/ueditor/jsp/upload/file/{yyyy}{mm}{dd}/{time}{rand:6}"; /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
|
||||
private String fileUrlPrefix = WebUtils.getUeditorPrefix(); /* 文件访问路径前缀 */
|
||||
|
||||
private long fileMaxSize = 51200000; /* 上传大小限制,单位B,默认50MB */
|
||||
|
||||
/* 上传文件格式显示 */
|
||||
private String[] fileAllowFiles = new String[]{".png", ".jpg", ".jpeg", ".gif", ".bmp",".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".ogv", ".mov", ".wmv", ".mp4",".mp3", ".wav", ".mid",".rar", ".zip", ".tar", ".gz", ".7z",".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt"};
|
||||
|
||||
/* 列出指定目录下的图片 */
|
||||
private String imageManagerActionName = "listimage";/* 执行图片管理的action名称 */
|
||||
|
||||
private String imageManagerListPath = "/upload/image/"; /* 指定要列出图片的目录 */
|
||||
|
||||
private int imageManagerListSize = 20; /* 每次列出文件数量 */
|
||||
|
||||
private String imageManagerUrlPrefix = WebUtils.getUeditorPrefix(); /* 图片访问路径前缀 */
|
||||
|
||||
private String imageManagerInsertAlign = "none"; /* 插入的图片浮动方式 */
|
||||
|
||||
private String[] imageManagerAllowFiles = new String[]{".png", ".jpg", ".jpeg", ".gif", ".bmp"}; /* 列出的文件类型 */
|
||||
|
||||
/* 列出指定目录下的文件 */
|
||||
private String fileManagerActionName = "listfile";/* 执行文件管理的action名称 */
|
||||
|
||||
private String fileManagerListPath = "/upload/file/"; /* 指定要列出文件的目录 */
|
||||
|
||||
private String fileManagerUrlPrefix = WebUtils.getUeditorPrefix(); /* 文件访问路径前缀 */
|
||||
|
||||
private int fileManagerListSize = 20; /* 每次列出文件数量 */
|
||||
|
||||
/* 列出的文件类型 */
|
||||
private String fileManagerAllowFiles[] = new String[]{".png", ".jpg", ".jpeg", ".gif", ".bmp",".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".ogv", ".mov", ".wmv", ".mp4",".mp3", ".wav", ".mid",".rar", ".zip", ".tar", ".gz", ".7z",".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt"};
|
||||
|
||||
public String getImageActionName() {
|
||||
return imageActionName;
|
||||
}
|
||||
|
||||
public void setImageActionName(String imageActionName) {
|
||||
this.imageActionName = imageActionName;
|
||||
}
|
||||
|
||||
public String getImageFieldName() {
|
||||
return imageFieldName;
|
||||
}
|
||||
|
||||
public void setImageFieldName(String imageFieldName) {
|
||||
this.imageFieldName = imageFieldName;
|
||||
}
|
||||
|
||||
public long getImageMaxSize() {
|
||||
return imageMaxSize;
|
||||
}
|
||||
|
||||
public void setImageMaxSize(long imageMaxSize) {
|
||||
this.imageMaxSize = imageMaxSize;
|
||||
}
|
||||
|
||||
public String[] getImageAllowFiles() {
|
||||
return imageAllowFiles;
|
||||
}
|
||||
|
||||
public void setImageAllowFiles(String[] imageAllowFiles) {
|
||||
this.imageAllowFiles = imageAllowFiles;
|
||||
}
|
||||
|
||||
public boolean isImageCompressEnable() {
|
||||
return imageCompressEnable;
|
||||
}
|
||||
|
||||
public void setImageCompressEnable(boolean imageCompressEnable) {
|
||||
this.imageCompressEnable = imageCompressEnable;
|
||||
}
|
||||
|
||||
public int getImageCompressBorder() {
|
||||
return imageCompressBorder;
|
||||
}
|
||||
|
||||
public void setImageCompressBorder(int imageCompressBorder) {
|
||||
this.imageCompressBorder = imageCompressBorder;
|
||||
}
|
||||
|
||||
public String getImageInsertAlign() {
|
||||
return imageInsertAlign;
|
||||
}
|
||||
|
||||
public void setImageInsertAlign(String imageInsertAlign) {
|
||||
this.imageInsertAlign = imageInsertAlign;
|
||||
}
|
||||
|
||||
public String getImageUrlPrefix() {
|
||||
return imageUrlPrefix;
|
||||
}
|
||||
|
||||
public void setImageUrlPrefix(String imageUrlPrefix) {
|
||||
this.imageUrlPrefix = imageUrlPrefix;
|
||||
}
|
||||
|
||||
public String getImagePathFormat() {
|
||||
return imagePathFormat;
|
||||
}
|
||||
|
||||
public void setImagePathFormat(String imagePathFormat) {
|
||||
this.imagePathFormat = imagePathFormat;
|
||||
}
|
||||
|
||||
public String[] getCatcherLocalDomain() {
|
||||
return catcherLocalDomain;
|
||||
}
|
||||
|
||||
public void setCatcherLocalDomain(String[] catcherLocalDomain) {
|
||||
this.catcherLocalDomain = catcherLocalDomain;
|
||||
}
|
||||
|
||||
public String getCatcherActionName() {
|
||||
return catcherActionName;
|
||||
}
|
||||
|
||||
public void setCatcherActionName(String catcherActionName) {
|
||||
this.catcherActionName = catcherActionName;
|
||||
}
|
||||
|
||||
public String getCatcherFieldName() {
|
||||
return catcherFieldName;
|
||||
}
|
||||
|
||||
public void setCatcherFieldName(String catcherFieldName) {
|
||||
this.catcherFieldName = catcherFieldName;
|
||||
}
|
||||
|
||||
public String getCatcherPathFormat() {
|
||||
return catcherPathFormat;
|
||||
}
|
||||
|
||||
public void setCatcherPathFormat(String catcherPathFormat) {
|
||||
this.catcherPathFormat = catcherPathFormat;
|
||||
}
|
||||
|
||||
public long getCatcherMaxSize() {
|
||||
return catcherMaxSize;
|
||||
}
|
||||
|
||||
public void setCatcherMaxSize(long catcherMaxSize) {
|
||||
this.catcherMaxSize = catcherMaxSize;
|
||||
}
|
||||
|
||||
public String[] getCatcherAllowFiles() {
|
||||
return catcherAllowFiles;
|
||||
}
|
||||
|
||||
public void setCatcherAllowFiles(String[] catcherAllowFiles) {
|
||||
this.catcherAllowFiles = catcherAllowFiles;
|
||||
}
|
||||
|
||||
public String getFileActionName() {
|
||||
return fileActionName;
|
||||
}
|
||||
|
||||
public void setFileActionName(String fileActionName) {
|
||||
this.fileActionName = fileActionName;
|
||||
}
|
||||
|
||||
public String getFileFieldName() {
|
||||
return fileFieldName;
|
||||
}
|
||||
|
||||
public void setFileFieldName(String fileFieldName) {
|
||||
this.fileFieldName = fileFieldName;
|
||||
}
|
||||
|
||||
public String getFilePathFormat() {
|
||||
return filePathFormat;
|
||||
}
|
||||
|
||||
public void setFilePathFormat(String filePathFormat) {
|
||||
this.filePathFormat = filePathFormat;
|
||||
}
|
||||
|
||||
public String getFileUrlPrefix() {
|
||||
return fileUrlPrefix;
|
||||
}
|
||||
|
||||
public void setFileUrlPrefix(String fileUrlPrefix) {
|
||||
this.fileUrlPrefix = fileUrlPrefix;
|
||||
}
|
||||
|
||||
public long getFileMaxSize() {
|
||||
return fileMaxSize;
|
||||
}
|
||||
|
||||
public void setFileMaxSize(long fileMaxSize) {
|
||||
this.fileMaxSize = fileMaxSize;
|
||||
}
|
||||
|
||||
public String[] getFileAllowFiles() {
|
||||
return fileAllowFiles;
|
||||
}
|
||||
|
||||
public void setFileAllowFiles(String[] fileAllowFiles) {
|
||||
this.fileAllowFiles = fileAllowFiles;
|
||||
}
|
||||
|
||||
public String getImageManagerActionName() {
|
||||
return imageManagerActionName;
|
||||
}
|
||||
|
||||
public void setImageManagerActionName(String imageManagerActionName) {
|
||||
this.imageManagerActionName = imageManagerActionName;
|
||||
}
|
||||
|
||||
public String getImageManagerListPath() {
|
||||
return imageManagerListPath;
|
||||
}
|
||||
|
||||
public void setImageManagerListPath(String imageManagerListPath) {
|
||||
this.imageManagerListPath = imageManagerListPath;
|
||||
}
|
||||
|
||||
public int getImageManagerListSize() {
|
||||
return imageManagerListSize;
|
||||
}
|
||||
|
||||
public void setImageManagerListSize(int imageManagerListSize) {
|
||||
this.imageManagerListSize = imageManagerListSize;
|
||||
}
|
||||
|
||||
public String getImageManagerUrlPrefix() {
|
||||
return imageManagerUrlPrefix;
|
||||
}
|
||||
|
||||
public void setImageManagerUrlPrefix(String imageManagerUrlPrefix) {
|
||||
this.imageManagerUrlPrefix = imageManagerUrlPrefix;
|
||||
}
|
||||
|
||||
public String getImageManagerInsertAlign() {
|
||||
return imageManagerInsertAlign;
|
||||
}
|
||||
|
||||
public void setImageManagerInsertAlign(String imageManagerInsertAlign) {
|
||||
this.imageManagerInsertAlign = imageManagerInsertAlign;
|
||||
}
|
||||
|
||||
public String[] getImageManagerAllowFiles() {
|
||||
return imageManagerAllowFiles;
|
||||
}
|
||||
|
||||
public void setImageManagerAllowFiles(String[] imageManagerAllowFiles) {
|
||||
this.imageManagerAllowFiles = imageManagerAllowFiles;
|
||||
}
|
||||
|
||||
public String getFileManagerActionName() {
|
||||
return fileManagerActionName;
|
||||
}
|
||||
|
||||
public void setFileManagerActionName(String fileManagerActionName) {
|
||||
this.fileManagerActionName = fileManagerActionName;
|
||||
}
|
||||
|
||||
public String getFileManagerListPath() {
|
||||
return fileManagerListPath;
|
||||
}
|
||||
|
||||
public void setFileManagerListPath(String fileManagerListPath) {
|
||||
this.fileManagerListPath = fileManagerListPath;
|
||||
}
|
||||
|
||||
public String getFileManagerUrlPrefix() {
|
||||
return fileManagerUrlPrefix;
|
||||
}
|
||||
|
||||
public void setFileManagerUrlPrefix(String fileManagerUrlPrefix) {
|
||||
this.fileManagerUrlPrefix = fileManagerUrlPrefix;
|
||||
}
|
||||
|
||||
public int getFileManagerListSize() {
|
||||
return fileManagerListSize;
|
||||
}
|
||||
|
||||
public void setFileManagerListSize(int fileManagerListSize) {
|
||||
this.fileManagerListSize = fileManagerListSize;
|
||||
}
|
||||
|
||||
public String[] getFileManagerAllowFiles() {
|
||||
return fileManagerAllowFiles;
|
||||
}
|
||||
|
||||
public void setFileManagerAllowFiles(String[] fileManagerAllowFiles) {
|
||||
this.fileManagerAllowFiles = fileManagerAllowFiles;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.ssssssss.magicboot.provider;
|
||||
|
||||
import cn.dev33.satoken.exception.DisableServiceException;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.ssssssss.magicapi.core.context.RequestEntity;
|
||||
import org.ssssssss.magicapi.core.interceptor.ResultProvider;
|
||||
import org.ssssssss.magicapi.core.model.JsonBean;
|
||||
|
||||
@Component
|
||||
public class ExceptionResultProvider implements ResultProvider {
|
||||
|
||||
@Override
|
||||
public Object buildResult(RequestEntity requestEntity, int code, String message, Object data) {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
return new JsonBean<>(code, message, data, (int) (timestamp - requestEntity.getRequestTime()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object buildException(RequestEntity requestEntity, Throwable throwable) {
|
||||
if(throwable.getCause() instanceof DisableServiceException){
|
||||
return buildResult(requestEntity, 500, "此账号已被临时封禁,请联系管理员");
|
||||
}
|
||||
return buildResult(requestEntity, 500, "系统内部出现错误");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.ssssssss.magicboot.utils;
|
||||
|
||||
import cn.hutool.core.net.Ipv4Util;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
public class AddressUtil {
|
||||
|
||||
public static String getAddress(String ip){
|
||||
try {
|
||||
if(Ipv4Util.isInnerIP(ip)){
|
||||
return "内网IP";
|
||||
}
|
||||
return JSONUtil.parseObj(HttpUtil.get("https://whois.pconline.com.cn/ipJson.jsp?json=true&ip=" + ip)).getStr("addr");
|
||||
}catch(IllegalArgumentException e){
|
||||
return "内网IP";
|
||||
}catch(Exception e){
|
||||
return "未知";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.ssssssss.magicboot.utils;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.ssssssss.magicboot.model.Global;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public static Map<String, String> createFileAttr(String originalFilename){
|
||||
String ret = Global.USER_FILES_BASE_URL + DateUtil.today() + "/" + IdUtil.simpleUUID() + "/";
|
||||
String suffix = FileUtil.getSuffix(originalFilename);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("ret", ret);
|
||||
map.put("filePath", ret.substring(1) + originalFilename);
|
||||
map.put("fileNames", originalFilename);
|
||||
map.put("suffix", suffix);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Map<String, String> saveFile(MultipartFile file) {
|
||||
Map<String, String> fileAttr = createFileAttr(file.getOriginalFilename());
|
||||
String fileNames = fileAttr.get("fileNames");
|
||||
String ret = fileAttr.get("ret");
|
||||
String suffix = fileAttr.get("suffix");
|
||||
String realPath = Global.getUserFilesBaseDir() + ret;
|
||||
FileUtil.mkdir(FileUtil.normalize(realPath));
|
||||
File tempFile = new File(realPath + fileNames);
|
||||
if (!tempFile.getParentFile().exists()) {
|
||||
tempFile.getParentFile().mkdir();
|
||||
}
|
||||
try {
|
||||
if (!tempFile.exists()) {
|
||||
file.transferTo(tempFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("state", "SUCCESS");
|
||||
params.put("original", file.getName());
|
||||
params.put("name", file.getName());
|
||||
params.put("size", file.getSize() + "");
|
||||
params.put("type", suffix);
|
||||
params.put("url", fileAttr.get("filePath"));
|
||||
return params;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.ssssssss.magicboot.utils;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
|
||||
public class WebUtils {
|
||||
|
||||
public static HttpServletRequest getHttpServletRequest(){
|
||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
}
|
||||
|
||||
public static String getContextUrl() {
|
||||
HttpServletRequest request = getHttpServletRequest();
|
||||
StringBuffer url = request.getRequestURL();
|
||||
return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getServletContext().getContextPath()).append("/").toString();
|
||||
}
|
||||
|
||||
public static String getUeditorPrefix(){
|
||||
return getContextUrl();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
magic-api:
|
||||
web: /magic/web
|
||||
resource:
|
||||
readonly: true
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
server:
|
||||
port: 8089
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
username: root
|
||||
password: 123456789
|
||||
|
||||
upload:
|
||||
dir: /Users/lvjinze/mb/
|
||||
@@ -0,0 +1,2 @@
|
||||
magic-api:
|
||||
web:
|
||||
@@ -0,0 +1,118 @@
|
||||
server:
|
||||
port: 8081
|
||||
compression:
|
||||
enabled: true
|
||||
min-response-size: 128
|
||||
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 200MB
|
||||
max-request-size: 200MB
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
url: jdbc:mysql://localhost/magic-boot?useSSL=false&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF8&autoReconnect=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: root
|
||||
druid:
|
||||
# 下面为连接池的补充设置,应用到上面所有数据源中
|
||||
# 初始化大小,最小,最大
|
||||
initial-size: 5
|
||||
min-idle: 5
|
||||
max-active: 1000
|
||||
# 配置获取连接等待超时的时间
|
||||
max-wait: 60000
|
||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||
time-between-eviction-runs-millis: 60000
|
||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||
min-evictable-idle-time-millis: 300000
|
||||
validation-query: SELECT 1
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
# 打开PSCache,并且指定每个连接上PSCache的大小
|
||||
pool-prepared-statements: true
|
||||
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
|
||||
max-pool-prepared-statement-per-connection-size: 20
|
||||
filters: stat,wall
|
||||
use-global-data-source-stat: true
|
||||
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
||||
connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||
# 配置监控服务器
|
||||
stat-view-servlet:
|
||||
login-username: admin
|
||||
login-password: 123456
|
||||
reset-enable: false
|
||||
url-pattern: /druid/*
|
||||
# 添加IP白名单
|
||||
#allow:
|
||||
# 添加IP黑名单,当白名单和黑名单重复时,黑名单优先级更高
|
||||
#deny:
|
||||
web-stat-filter:
|
||||
# 添加过滤规则
|
||||
url-pattern: /*
|
||||
# 忽略过滤格式
|
||||
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
|
||||
# 上传路径
|
||||
upload:
|
||||
dir: D:/mb/
|
||||
|
||||
magic-api:
|
||||
web: /magic/web
|
||||
show-sql: true #配置打印SQL
|
||||
sql-column-case: camel
|
||||
resource:
|
||||
location: data/magic-api
|
||||
backup: #备份相关配置
|
||||
enable: true #是否启用
|
||||
max-history: -1 #备份保留天数,-1为永久保留
|
||||
table-name: magic_backup_record_v2 #使用数据库存储备份时的表名
|
||||
page:
|
||||
page: current
|
||||
size: size
|
||||
cache:
|
||||
enable: true #开启缓存,默认是不开启的
|
||||
ttl: 3600000 #有效期1小时,默认-1 即永不过期
|
||||
response-code:
|
||||
success: 200 #执行成功的code值
|
||||
invalid: 400 #参数验证未通过的code值
|
||||
exception: 500 #执行出现异常的code值
|
||||
crud: # CRUD相关配置
|
||||
logic-delete-column: is_del #逻辑删除列
|
||||
logic-delete-value: 1 #逻辑删除值
|
||||
# security:
|
||||
# username: admin
|
||||
# password: 123456
|
||||
|
||||
# Sa-Token配置
|
||||
sa-token:
|
||||
# token名称 (同时也是cookie名称)
|
||||
token-name: token
|
||||
# token有效期,单位s 默认30天, -1代表永不过期
|
||||
timeout: 2592000
|
||||
# token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
||||
activity-timeout: -1
|
||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||
is-concurrent: true
|
||||
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
|
||||
is-share: false
|
||||
# token风格
|
||||
token-style: uuid
|
||||
# 是否输出操作日志
|
||||
is-log: false
|
||||
|
||||
oss:
|
||||
enable: false
|
||||
endpoint: ""
|
||||
accessKeyId: ""
|
||||
accessKeySecret: ""
|
||||
roleArn: ""
|
||||
roleSessionName: ""
|
||||
bucket: ""
|
||||
bucketDomain: ""
|
||||
Reference in New Issue
Block a user