mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-06 22:19:29 +08:00
优化动态脚本执行
This commit is contained in:
@@ -3,15 +3,19 @@ package org.hswebframework.web.controller.script;
|
||||
import org.hswebframework.web.authorization.annotation.Authorize;
|
||||
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
|
||||
import org.hswebframework.web.controller.SimpleGenericEntityController;
|
||||
import org.hswebframework.web.controller.message.ResponseMessage;
|
||||
import org.hswebframework.web.entity.script.ScriptEntity;
|
||||
import org.hswebframework.web.logging.AccessLogger;
|
||||
import org.hswebframework.web.service.script.ScriptService;
|
||||
import org.hswebframework.web.service.script.ScriptExecutorService;
|
||||
import org.hswebframework.web.service.script.ScriptService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 动态脚本
|
||||
* 动态脚本
|
||||
*
|
||||
* @author hsweb-generator-online
|
||||
*/
|
||||
@@ -22,14 +26,42 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class ScriptController implements SimpleGenericEntityController<ScriptEntity, String, QueryParamEntity> {
|
||||
|
||||
private ScriptService scriptService;
|
||||
|
||||
|
||||
private ScriptExecutorService scriptExecutorService;
|
||||
|
||||
@Autowired
|
||||
public void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
public void setScriptExecutorService(ScriptExecutorService scriptExecutorService) {
|
||||
this.scriptExecutorService = scriptExecutorService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptService getService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/{id}/execute")
|
||||
@AccessLogger("执行脚本")
|
||||
@Authorize(action = "execute")
|
||||
public ResponseMessage<Object> executeForGet(@PathVariable String id, @RequestParam(required = false) Map<String, Object> parameters) throws Exception {
|
||||
if (parameters == null) {
|
||||
parameters = new HashMap<>();
|
||||
}
|
||||
Object result = scriptExecutorService.execute(id, parameters);
|
||||
return ResponseMessage.ok(result);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/{id}/execute", method = {RequestMethod.POST, RequestMethod.PUT})
|
||||
@AccessLogger("执行脚本")
|
||||
@Authorize(action = "execute")
|
||||
public ResponseMessage<Object> executeFotPostAndPut(@PathVariable String id,
|
||||
@RequestBody(required = false) Map<String, Object> parameters) throws Exception {
|
||||
return ResponseMessage.ok(executeForGet(id, parameters));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user