EnginTestController.java
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.sy.controller;
import com.sy.model.GatherInfo;
import lombok.extern.slf4j.Slf4j;
import org.basis.enhance.groovy.entity.EngineExecutorResult;
import org.basis.enhance.groovy.entity.ExecuteParams;
import org.basis.enhance.groovy.entity.ScriptQuery;
import org.basis.enhance.groovy.executor.EngineExecutor;
import org.basis.enhance.groovy.helper.RefreshScriptHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
@RestController
@Slf4j
@RequestMapping("/v1/load-from-redis")
public class EnginTestController {
@Autowired
private EngineExecutor engineExecutor;
@Autowired
private RefreshScriptHelper refreshScriptHelper;
@GetMapping("/x21-check")
public String x21Check(String scriptName) {
// 构建参数
ExecuteParams executeParams = buildGatherInfoParams();
// 执行脚本中指定的方法 changeProduct
EngineExecutorResult executorResult = engineExecutor.execute(
"baseCheck", new ScriptQuery(scriptName), executeParams);
log.info("使用groovy脚本来动态修改闪屏信息=========>>>>>>>>>>>执行结果:{}", executorResult);
return "success";
}
@GetMapping("/form-check")
public String formCheck(String scriptName) {
// 构建参数
ExecuteParams executeParams = buildGatherInfoParams();
// 执行脚本中指定的方法 changeProduct
EngineExecutorResult executorResult = engineExecutor.execute(
"formCheck", new ScriptQuery(scriptName), executeParams);
log.info("使用groovy脚本来动态修改闪屏信息=========>>>>>>>>>>>执行结果:{}", executorResult);
return "success";
}
/**
* 过磅x21报文实体
*/
public ExecuteParams buildGatherInfoParams(){
GatherInfo gatherInfo = new GatherInfo();
gatherInfo.setAreaid("4604600000");
gatherInfo.setChnlno("4604601010");
gatherInfo.setBarcode("fe3-4c1b-befe-afa4a68d80c1");
gatherInfo.setGrosswt(new BigDecimal("6478"));
gatherInfo.setSeqno("20220630184441000028");
gatherInfo.setIetype("I");
gatherInfo.setVename("豫A61CR7");
ExecuteParams executeParams = new ExecuteParams();
executeParams.put("gatherInfo", gatherInfo);
return executeParams;
}
@GetMapping("/refreshCache")
public String refresh(String scriptName) {
// 手动刷新脚本到内存
boolean flag = refreshScriptHelper.refresh(new ScriptQuery(scriptName), true);
System.out.println("是否刷新成功:" + flag);
return String.valueOf(flag);
}
/**
* 手动刷新所有脚本到内存
* url: http://localhost:1234/v1/refresh/test02
*/
@GetMapping("/refreshCacheAll")
public String refreshAll() throws Exception {
// 手动刷新所有脚本到内存
boolean flag = refreshScriptHelper.refreshAll();
System.out.println("是否刷新成功:" + flag);
return String.valueOf(flag);
}
}