GetDataTest.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. //package com.sundata.internalevaluation.calc.custom;
  2. //
  3. //import cn.hutool.core.util.RandomUtil;
  4. //import com.sundata.internalevaluation.script.ScriptUtil;
  5. //import com.sundata.internalevaluation.script.TemplateUtil;
  6. //
  7. //import java.text.SimpleDateFormat;
  8. //import java.util.*;
  9. //
  10. ///**
  11. // * Created by IntelliJ IDEA.
  12. // *
  13. // * @author JoeLazy
  14. // * @date 2025-02-14 17:12:49
  15. // * @description: 测试Java方法获取参数
  16. // */
  17. //public class GetDataTest {
  18. //
  19. // private static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
  20. // private static final String YYYYMMDD = "yyyyMMdd";
  21. // private static final String HHMMSS = "HHmmss";
  22. // private static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
  23. // private static final String YYYY_MM_DD = "yyyy-MM-dd";
  24. // private static final String HH_MM_SS = "HH:mm:ss";
  25. //
  26. // public String getDateTimeNumber() {
  27. // return getStr(YYYYMMDDHHMMSS);
  28. // }
  29. // public String getDateNumber() {
  30. // return getStr(YYYYMMDD);
  31. // }
  32. // public String getTimeNumber() {
  33. // return getStr(HHMMSS);
  34. // }
  35. // public String getDateTime() {
  36. // return getStr(YYYY_MM_DD_HH_MM_SS);
  37. // }
  38. // public String getDate() {
  39. // return getStr(YYYY_MM_DD);
  40. // }
  41. // public String getTime() {
  42. // return getStr(HH_MM_SS);
  43. // }
  44. //
  45. // public String getStr(String format) {
  46. // SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
  47. // return simpleDateFormat.format(nowDate());
  48. // }
  49. //
  50. // public Date nowDate() {
  51. // return new Date();
  52. // }
  53. //
  54. //
  55. // public int getInt(int i) {
  56. // return i;
  57. // }
  58. //
  59. //
  60. // public String getString(String str) {
  61. // return str;
  62. // }
  63. //
  64. //
  65. //// public void aa() {
  66. //// // 模板字符${value}的正则表达式
  67. //// String regex = "\\$\\{([^}]+)}";
  68. //// // 生成正则表达式对象
  69. //// Pattern pattern = Pattern.compile(regex);
  70. ////
  71. //// // 应入参数
  72. //// String[] values = {"workDate","account","orgcode","TaskId","TaskSerialNum"};
  73. //// // 替换模板字符用
  74. //// Map<String,String> inputMap = new HashMap<String,String>();
  75. //// // 造假参数
  76. //// inputMap.put("workDate","'a'");
  77. //// inputMap.put("account","'a'");
  78. //// inputMap.put("orgcode","'a'");
  79. //// inputMap.put("TaskId","'a'");
  80. //// inputMap.put("TaskSerialNum","'a'");
  81. //// // 使用apache的StrSubstitutor替换模板字符
  82. //// StrSubstitutor sub = new StrSubstitutor(inputMap);
  83. ////
  84. ////
  85. //// // 对请求中的数据逻辑说明的sql进行正则匹配
  86. //// Matcher matcher = pattern.matcher(relationModel.getSqlCode());
  87. //// // 判断缺失参数用
  88. //// ArrayList<String> paramList = new ArrayList<String>(Arrays.asList(values));
  89. //// // 游标
  90. //// int matcherCount = 0;
  91. //// // 检查开始
  92. //// while (matcher.find()) {
  93. //// if (!paramList.contains(matcher.group(1))) {
  94. //// String err = "数据初始化逻辑中,该参数[" + matcher.group(1) + "]不应存在!";
  95. //// log.error(err);
  96. //// throw new BusinessException(err);
  97. //// } else {
  98. //// // 排除不缺失参数
  99. //// paramList.remove(matcher.group(1));
  100. //// }
  101. //// matcherCount++;
  102. //// }
  103. ////
  104. //// // 假参数赋值
  105. //// String resolvedString = sub.replace(relationModel.getSqlCode());
  106. //// }
  107. //
  108. //
  109. //
  110. // public static void main(String[] args) {
  111. //// String sql = "select * from a where a = ${a} and b = ${b} and c =${a}";
  112. //// Map<String, Object> map = new HashMap<>();
  113. ////
  114. //// map.put("a", "isA");
  115. //// map.put("b", "isB");
  116. //
  117. //// Map<String, Object> map = new HashMap<>();
  118. //// map.put("isStaff", 0);
  119. //// map.put("isEmployrecord", 0);
  120. //// map.put("isBankBlack", 1);
  121. //// map.put("isIntro", 0);
  122. //// map.put("isCredit", false);
  123. //// map.put("str", "qiao");
  124. //// String script = "${isStaff}==1 || ${isEmployrecord}==1 || ${isBankBlack}==1 || ${isIntro} ==1";
  125. //// script = "isCredit==true";
  126. //// script = "'${str}'=='qiao'";
  127. //// script = TemplateUtil.execute(UUID.randomUUID().toString(), script, map);
  128. //// Object o = ScriptUtil.executeScript(UUID.randomUUID().toString(), script, map);
  129. //
  130. //
  131. //
  132. // // 创建绑定变量
  133. // Map<String, Object> binding = new HashMap<>();
  134. //
  135. // // 创建自定义对象
  136. // binding.put("aNumber", 100);
  137. // binding.put("name", "CodeLife Leno");
  138. // binding.put("location", "china Guangzhou");
  139. //
  140. //
  141. // String scriptStr = """
  142. // "Hello, $name from $location!"
  143. // """;
  144. // System.out.println(ScriptUtil.executeScript(UUID.randomUUID().toString(), scriptStr, binding));
  145. //
  146. // System.out.println("");
  147. //
  148. // test();
  149. //
  150. //// bb(sql, map);
  151. // }
  152. //
  153. //
  154. // static void test() {
  155. // String scriptId = RandomUtil.randomString(10);
  156. // String scriptStr = """
  157. // "Hello, $name from $location!"
  158. // """;
  159. // String scriptId2 = RandomUtil.randomString(10);
  160. // String scriptStr2 = """
  161. // aNumber > 100
  162. // """;
  163. // String templateId = RandomUtil.randomString(10);
  164. // String templateStr = """
  165. // Hello, ${user.name}!
  166. // You have ${messages.size()} new messages.
  167. // <%// 使用 Groovy 脚本计算未读消息数 --%>
  168. // <% def unreadMessages = messages.count { it.startsWith("Unread") } %>
  169. // Unread messages000: ${unreadMessages}
  170. // <%// 条件判断 --%>
  171. // <% if (unreadMessages > 0) { %>
  172. // You have some unread messages.
  173. // <% } else { %>
  174. // All messages are read.
  175. // <% } %>
  176. // Messages:
  177. // <%// 遍历消息列表 --%>
  178. // ${messages.each { msg -> println(" -- " + msg) }}
  179. // """;
  180. //
  181. // // 创建绑定变量
  182. // Map<String, Object> binding = new HashMap<>();
  183. //
  184. // // 创建自定义对象
  185. // User user = new User("Alice");
  186. // binding.put("aNumber", 100);
  187. // binding.put("name", "CodeLife Leno");
  188. // binding.put("location", "china Guangzhou");
  189. // binding.put("user", user);
  190. // // 创建消息列表
  191. // List<String> messages = List.of("Unread Message 1", "Read Message 2", "Unread Message 3");
  192. // binding.put("messages", messages);
  193. //
  194. // System.out.println(ScriptUtil.executeScript(scriptId, scriptStr, binding));
  195. // System.out.println("--------------------------------------------");
  196. // System.out.println(ScriptUtil.executeScript(scriptId2, scriptStr2, binding));
  197. // System.out.println("--------------------------------------------");
  198. //
  199. // templateStr = """
  200. // <% if (approveSts == 03) { %>审批状态:审核中,<% } else { %>其他...,<% } %><% if (agrSts == 01) { %>额度状态:生效,<% } else if (agrSts == 02){ %>额度状态:手动冻结,<% } else if (agrSts == 02){%>额度状态:系统冻结,<% } %>
  201. // """;
  202. //
  203. // binding.put("approveSts",3);
  204. // binding.put("agrSts",1);
  205. //
  206. // System.out.println(TemplateUtil.execute(templateId, templateStr, binding));
  207. // }
  208. //
  209. //
  210. // // 自定义 User 类
  211. // static class User {
  212. // private String name;
  213. //
  214. // public User(String name) {
  215. // this.name = name;
  216. // }
  217. //
  218. // public String getName() {
  219. // return name;
  220. // }
  221. // }
  222. //
  223. //}