添加脚本语言groovydemo

This commit is contained in:
476474485@qq.com 2024-06-18 11:08:43 +08:00
parent 80d870073f
commit 37d45b8ab0
1 changed files with 31 additions and 20 deletions

View File

@ -6,8 +6,6 @@ import com.hzya.frame.sysnew.grovy.service.IGroovyIntegrationService;
import com.hzya.frame.util.GroovyUtil; import com.hzya.frame.util.GroovyUtil;
import com.hzya.frame.web.entity.BaseResult; import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity; import com.hzya.frame.web.entity.JsonResultEntity;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -24,28 +22,41 @@ import org.springframework.stereotype.Service;
public class GroovyIntegrationServiceImpl implements IGroovyIntegrationService { public class GroovyIntegrationServiceImpl implements IGroovyIntegrationService {
private static final Logger logger = LoggerFactory.getLogger(GroovyIntegrationServiceImpl.class); private static final Logger logger = LoggerFactory.getLogger(GroovyIntegrationServiceImpl.class);
// public static void main(String[] args) {
// HelloWorld helloWorld = new HelloWorld();
// System.out.println(helloWorld.sayHello());
// }
public static void main(String[] args) throws IllegalAccessException, InstantiationException {
GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
// 动态编译和加载Groovy脚本
Class<?> groovyClass = groovyClassLoader.parseClass("println(\"1231231\")");
// 创建Groovy类的实例
GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
// 执行Groovy脚本
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", "张三");
Object returnObj = groovyObject.invokeMethod("run", jsonObject.toJSONString());
}
@Override @Override
public JsonResultEntity groovyScriptExecution(JSONObject jsonObject) { public JsonResultEntity groovyScriptExecution(JSONObject jsonObject) {
Object object = GroovyUtil.execute(jsonObject); Object object = GroovyUtil.execute(jsonObject);
return BaseResult.getSuccessMessageEntity(object); return BaseResult.getSuccessMessageEntity(object);
} }
public static void main(String[] args) {
java.lang.String str = "{\"project_org\":\"\",\"modify_time\":\"2024-06-17 16:52:34\",\"project_duty_dept\":null,\"project_name\":\"凯伍德组织档案\",\"document_rule_num\":1,\"add_status\":\"0\",\"delete_status\":\"1\",\"project_dutier\":\"\",\"id\":\"fb12734c8267488b96833633e68a7abc\",\"data_status\":\"F\",\"modify_user_id\":\"c796fd9ba4c9f5ff3cc2fa41a040e443\",\"sorts\":1,\"project_memo\":\"\",\"document_rule\":\"XM-2024-06-17-00001\",\"create_user_id\":\"c796fd9ba4c9f5ff3cc2fa41a040e443\",\"create_time\":\"2024-06-17 16:42:18\",\"company_id\":null,\"project_sh_name\":\"\",\"project_code\":\"01004\",\"project_currtype\":\"\",\"update_status\":\"0\",\"sts\":\"Y\",\"org_id\":\"0\",\"project_parentpro\":\"\",\"project_bill_type\":\"\"}";
A88772 s = new A88772();
s .execute(str);
}
static class A88772 {
String execute(String jsonStr) {
com.alibaba.fastjson.JSONObject reqData = com.alibaba.fastjson.JSON.parseObject(jsonStr);
com.alibaba.fastjson.JSONObject returnObject = new com.alibaba.fastjson.JSONObject();
com.alibaba.fastjson.JSONObject ufinterfaceObject = new com.alibaba.fastjson.JSONObject();
ufinterfaceObject.put("billtype", "supplier"); ufinterfaceObject.put("isexchange", "Y");
ufinterfaceObject.put("replace", "Y"); ufinterfaceObject.put("sender", "OA");
ufinterfaceObject.put("account", "01"); ufinterfaceObject.put("groupcode", "00");
com.alibaba.fastjson.JSONObject billObject = new com.alibaba.fastjson.JSONObject();
com.alibaba.fastjson.JSONObject billheadObject = new com.alibaba.fastjson.JSONObject();
billheadObject.put("code", reqData.get("project_code")); billheadObject.put("supprop", "0");
billheadObject.put("custstate", "1"); billheadObject.put("pk_supplierclass", "S01");
billheadObject.put("pk_country", "CN"); billheadObject.put("pk_timezone", "P0800");
billheadObject.put("pk_format", "ZH-CN"); billheadObject.put("enablestate", "2");
billheadObject.put("name", reqData.get("project_sh_name")); billheadObject.put("pk_group", "00");
billheadObject.put("pk_org", "003"); billheadObject.put("taxpayerid", "087981489021135119");
returnObject.put("ufinterface",ufinterfaceObject); billObject.put("billhead", billheadObject); returnObject.put("bill",billObject);
System.out.println( returnObject.toJSONString());
return returnObject.toJSONString();
}
}
} }