Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
javamxd committed Aug 31, 2021
2 parents c1fdf4b + 10554e0 commit 345a333
Show file tree
Hide file tree
Showing 25 changed files with 111 additions and 69 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ magic-api 是一个基于Java的接口快速开发框架,编写接口将通过
<dependency>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-spring-boot-starter</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
</dependency>
```
## 修改application.properties
Expand Down
2 changes: 1 addition & 1 deletion magic-api-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-parent</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
</parent>
<artifactId>magic-api-spring-boot-starter</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,11 @@ public boolean supports(Class<?> clazz) {
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
String web = properties.getWeb();
MagicNotifyService magicNotifyService = magicNotifyServiceProvider.getObject();
WebSocketSessionManager.setMagicNotifyService(magicNotifyService);
if (web != null && !registerWebsocket) {
registerWebsocket = true;
MagicWebSocketDispatcher dispatcher = new MagicWebSocketDispatcher(properties.getClusterConfig().getInstanceId(), magicNotifyServiceProvider.getObject(), Arrays.asList(
MagicWebSocketDispatcher dispatcher = new MagicWebSocketDispatcher(properties.getClusterConfig().getInstanceId(), magicNotifyService, Arrays.asList(
new MagicDebugHandler(),
new MagicWorkbenchHandler(authorizationInterceptorProvider.getIfAvailable(this::createAuthorizationInterceptor))
));
Expand Down
2 changes: 1 addition & 1 deletion magic-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-parent</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
</parent>
<artifactId>magic-api</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public List<FunctionInfo> getFunctionInfos() {
return mappings.values().stream().distinct().collect(Collectors.toList());
}

public FunctionInfo getFunctionInfo(String path) {
return mappings.get(path);
}

private boolean hasConflict(TreeNode<Group> group, String newPath) {
// 获取要移动的接口
List<FunctionInfo> infos = mappings.values().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,25 @@ public static void remove(String sessionId) {
public static void sendToAll(MessageType messageType, Object... values) {
String content = buildMessage(messageType, values);
sendToAll(content);
// 通知其他机器去发送消息
magicNotifyService.sendNotify(new MagicNotify(instanceId, Constants.NOTIFY_WS_S_C, null, content));
}

private static void sendToAll(String content) {
SESSION.values().stream().filter(MagicConsoleSession::writeable).forEach(session -> sendBySession(session, content));
sendToOther(null, content);
}

public static void sendBySessionId(String sessionId, MessageType messageType, Object... values) {
MagicConsoleSession session = findSession(sessionId);
String content = buildMessage(messageType, values);
if (session != null && session.writeable()) {
sendBySession(session, content);
} else if (magicNotifyService != null) {
} else {
sendToOther(sessionId, content);
}
}

private static void sendToOther(String sessionId, String content){
if (magicNotifyService != null) {
// 通知其他机器去发送消息
magicNotifyService.sendNotify(new MagicNotify(instanceId, Constants.NOTIFY_WS_S_C, sessionId, content));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import org.ssssssss.magicapi.model.ApiInfo;
import org.ssssssss.magicapi.model.Backup;
import org.ssssssss.magicapi.model.JsonBean;
import org.ssssssss.magicapi.provider.ApiServiceProvider;
import org.ssssssss.magicapi.provider.MagicAPIService;
import org.ssssssss.magicapi.provider.MagicBackupService;

import javax.servlet.http.HttpServletRequest;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -74,7 +72,10 @@ public JsonBean<ApiInfo> get(HttpServletRequest request, String id) {
@ResponseBody
public JsonBean<List<Backup>> backupList(HttpServletRequest request, String id) {
isTrue(allowVisit(request, Authorization.VIEW, getApiInfo(id)), PERMISSION_INVALID);
return new JsonBean<>(magicBackupService.backupById(id));
return new JsonBean<>(magicBackupService.backupById(id)
.stream()
.sorted(Comparator.comparing(Backup::getCreateDate).reversed())
.collect(Collectors.toList()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import org.ssssssss.magicapi.model.Backup;
import org.ssssssss.magicapi.model.FunctionInfo;
import org.ssssssss.magicapi.model.JsonBean;
import org.ssssssss.magicapi.provider.FunctionServiceProvider;
import org.ssssssss.magicapi.provider.MagicAPIService;
import org.ssssssss.magicapi.provider.MagicBackupService;

import javax.servlet.http.HttpServletRequest;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -52,7 +50,10 @@ public JsonBean<Backup> backups(HttpServletRequest request, String id, Long time
@ResponseBody
public JsonBean<List<Backup>> backupList(HttpServletRequest request, String id) {
isTrue(allowVisit(request, Authorization.VIEW, getFunctionInfo(id)), PERMISSION_INVALID);
return new JsonBean<>(magicBackupService.backupById(id));
return new JsonBean<>(magicBackupService.backupById(id)
.stream()
.sorted(Comparator.comparing(Backup::getCreateDate).reversed())
.collect(Collectors.toList()));
}

@RequestMapping("/function/move")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Backup {
/**
* 备份时间
*/
private long createDate;
private Long createDate = 0L;

/**
* 标签,只允许有一个
Expand Down Expand Up @@ -58,11 +58,11 @@ public void setType(String type) {
this.type = type;
}

public long getCreateDate() {
public Long getCreateDate() {
return createDate;
}

public void setCreateDate(long createDate) {
public void setCreateDate(Long createDate) {
this.createDate = createDate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class NamedTable {

String logicDeleteColumn;

String logicDeleteValue;
Object logicDeleteValue;

Map<String, Object> columns = new HashMap<>();

Expand All @@ -46,7 +46,19 @@ public NamedTable(String tableName, SQLModule sqlModule, Function<String, String
this.sqlModule = sqlModule;
this.rowMapColumnMapper = rowMapColumnMapper;
this.logicDeleteColumn = sqlModule.getLogicDeleteColumn();
this.logicDeleteValue = sqlModule.getLogicDeleteValue();
String deleteValue = sqlModule.getLogicDeleteValue();
this.logicDeleteValue = deleteValue;
if(deleteValue != null){
if((deleteValue.startsWith("'") || deleteValue.startsWith("\"")) && deleteValue.length() > 2){
this.logicDeleteValue = deleteValue.substring(1,deleteValue.length() - 1);
}else{
try {
this.logicDeleteValue = Integer.parseInt(deleteValue);
} catch (NumberFormatException e) {
this.logicDeleteValue = deleteValue;
}
}
}
}

@Comment("使用逻辑删除")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface MagicAPIService extends MagicModule {
*
* @param method 请求方法
* @param path 请求路径
* @param context 请求上下文,主要给脚本中使用
* @param context 变量信息
*/
Object execute(String method, String path, Map<String, Object> context);

Expand All @@ -28,10 +28,18 @@ public interface MagicAPIService extends MagicModule {
*
* @param method 请求方法
* @param path 请求路径
* @param context 请求上下文,主要给脚本中使用
* @param context 变量信息
*/
Object call(String method, String path, Map<String, Object> context);

/**
* 执行MagicAPI中的函数
*
* @param path 函数路径
* @param context 变量信息
*/
Object invoke(String path, Map<String, Object> context);

/**
* 保存接口
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ public Object call(String method, String path, Map<String, Object> context) {
}
}

@Override
public Object invoke(String path, Map<String, Object> context) {
FunctionInfo functionInfo = magicFunctionManager.getFunctionInfo(path);
if (functionInfo == null) {
throw new MagicServiceException(String.format("找不到对应函数 [%s]", path));
}
MagicScriptContext scriptContext = new MagicScriptContext(context);
scriptContext.putMapIntoContext(context);
SimpleScriptContext simpleScriptContext = new SimpleScriptContext();
simpleScriptContext.setAttribute(MagicScript.CONTEXT_ROOT, scriptContext, ScriptContext.ENGINE_SCOPE);
return ((MagicScript) ScriptManager.compile("MagicScript", functionInfo.getScript())).eval(simpleScriptContext);
}

@Override
public String saveApi(ApiInfo info) {
// 非空验证
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -18,6 +19,7 @@ public class JsonUtils {

static {
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
}

public static String toJsonString(Object target) {
Expand Down
2 changes: 1 addition & 1 deletion magic-editor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-parent</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
</parent>
<artifactId>magic-editor</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion magic-editor/src/console/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "magic-editor",
"version": "1.4.0",
"version": "1.4.1",
"private": false,
"description": "magic-editor for magic-api",
"main": "dist/magic-editor.umd.min.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<span v-else-if="typeof value === 'string'" class="string">"{{value.replace(/"/g, "\"")}}"</span>
<span v-else-if="typeof value === 'number'" class="number">{{value}}</span>
<span v-else-if="typeof value === 'boolean'" class="boolean">{{value}}</span>
<span v-else-if="value == null" class="boolean">null</span>
<span v-else>{{value}}</span>
<magic-structure-array v-if="value && Array.isArray(value) && expandKeys[key]" :data="value" :indent="indent + 1" :simple="false"/>
<magic-structure-object v-else-if="value && typeof value === 'object' && expandKeys[key]" :data="value" :indent="indent + 1" :simple="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<span v-else-if="typeof value === 'string'" class="string">"{{value.replace(/"/g, "\"")}}"</span>
<span v-else-if="typeof value === 'number'" class="number">{{value}}</span>
<span v-else-if="typeof value === 'boolean'" class="boolean">{{value}}</span>
<span v-else-if="value == null" class="boolean">null</span>
<span v-else>{{value}}</span>
</span>
<span>}</span>
Expand All @@ -28,6 +29,7 @@
<span v-else-if="typeof value === 'string'" class="string">"{{value.replace(/"/g, "\"")}}"</span>
<span v-else-if="typeof value === 'number'" class="number">{{value}}</span>
<span v-else-if="typeof value === 'boolean'" class="boolean">{{value}}</span>
<span v-else-if="value == null" class="boolean">null</span>
<span v-else>{{value}}</span>
<magic-structure-array v-if="value && Array.isArray(value) && expandKeys[key]" :data="value" :indent="indent + 1" :simple="false"/>
<magic-structure-object v-else-if="value && typeof value === 'object' && expandKeys[key]" :data="value" :indent="indent + 1" :simple="false"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div class="ma-structure-container">
<span :class="type.substring(10).toLowerCase()" v-if="displayText">{{ data }}</span>
<span class="boolean" v-else-if="!type">null</span>
<magic-structure-array v-else-if="Array.isArray(jsonData)" :data="jsonData"/>
<magic-structure-object v-else :data="jsonData"/>
</div>
Expand Down
21 changes: 0 additions & 21 deletions magic-editor/src/console/src/components/layout/magic-debug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,6 @@ export default {
},
variables() {
return this.info && this.info.ext && this.info.ext.variables || []
/*return [{
name: "11",
type: "java.lang.String",
value: "abcd"
},{
name: "11",
type: "xx.xx.xx",
value: `[{
"ne" : {
"xx" :1
},
"name": "xx",
"b" : true,
"i" : 1,
"arr" : ${JSON.stringify(new Array(301).fill(1).map((it,index) => index))},
"arr1" : [{
"name": 123
},2,3,4,5,6,7,8,9,10],
"f" : 123.456
}]`
}]*/
}
}
}
Expand Down
37 changes: 26 additions & 11 deletions magic-editor/src/console/src/components/layout/magic-log.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<template>
<div ref="container" class="ma-log" @contextmenu.prevent="e=>onContextMenu(e)">
<div v-for="(item, key) in logs" :key="'run_log_' + key">
<div v-for="(item, key) in logs" :key="'run_log_' + key" :class="{collapse: item.newline&&!item.expand}">
<div>{{ item.timestamp }}</div>
<div v-show="!item.throwable" :style="{color :'var(--log-'+ item.level.toLocaleLowerCase() + '-color)'}">
<div :style="{color :'var(--log-'+ item.level.toLocaleLowerCase() + '-color)'}">
{{ item.level }}
</div>
<i class="ma-icon" :class="{'ma-icon-expand': !item.expand, 'ma-icon-collapse': item.expand}" v-if="item.newline" @click.stop="doExpand(item)"></i>
<div :class="{throwable: item.throwable === true}" v-html="item.message"></div>
</div>
</div>
Expand All @@ -28,22 +29,21 @@ export default {
bus.$on('ws_log', rows => this.onLogReceived(rows[0]))
},
methods: {
doExpand(item){
item.expand = !item.expand;
},
onLogReceived(row){
row.timestamp = utils.formatDate(new Date())
let throwable = row.throwable
delete row.throwable
row.message = (row.message || '').replace(/ /g, '&nbsp;').replace(/\n/g,'<br>')
this.logs.push(row)
row.expand = false;
if (throwable) {
let messages = throwable.replace(/ /g, '&nbsp;').split('\n');
for (let i = 0; i < messages.length; i++) {
this.logs.push({
level: row.level,
message: messages[i],
throwable: true
})
}
row.message += throwable.replace(/ /g, '&nbsp;').replace(/\n/g,'<br>')
row.throwable = true
}
row.newline = row.message.indexOf('<br>') > -1
this.logs.push(row)
let container = this.$refs.container;
this.$nextTick(() => container.scrollTop = container.scrollHeight)
},
Expand Down Expand Up @@ -92,4 +92,19 @@ export default {
.ma-log .throwable {
color: var(--log-error-color)
}
.ma-log i{
margin-right: -10px;
margin-left: -10px;
font-size: 12px;
width: 20px;
display: inline-block;
height: 20px;
text-align: center;
}
.ma-log .collapse{
height: 20px;
line-height: 20px;
overflow: hidden;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ export default {
requestGroup('group/create', this.createGroupObj).success(data => {
this.createGroupObj.id = data
this.createGroupObj.folder = true
this.createGroupObj.paths = []
this.createGroupObj.options = []
bus.$emit('report', 'group_create')
bus.$emit('status', `分组「${this.createGroupObj.name}」创建成功`)
this.deleteOrAddGroupToTree(this.tree, this.createGroupObj)
Expand Down
Loading

0 comments on commit 345a333

Please sign in to comment.