优化动态脚本执行

This commit is contained in:
zhouhao
2017-09-19 16:27:18 +08:00
parent b8a06b6841
commit 8fc01a51a6
6 changed files with 151 additions and 7 deletions

View File

@@ -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));
}
}