You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
6.0 KiB

1 year ago
  1. package com.spring.ifs.utils;
  2. import com.spring.ifs.data.IfsParamBean;
  3. import ifs.fnd.ap.*;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. /**
  8. * @description: IFS的通用方法
  9. * @author LR
  10. * @date 2024/12/9 11:18
  11. * @version 1.0
  12. */
  13. public class IfsPlsqlUtils {
  14. /**
  15. * @description: 调用查询的通用方法-- 返回单个Bean
  16. * @author LR
  17. * @date 2024/12/9 11:21
  18. * @version 1.0
  19. */
  20. public static Record execSqlSearchGetRecord(Server srv, StringBuilder searchSql, Map<String, String> inParam) throws APException {
  21. //创建查询体
  22. PlsqlSelectCommand selCmd = new PlsqlSelectCommand(srv, searchSql.toString());
  23. //获取绑定参数
  24. Record bindVars = selCmd.getBindVariables();
  25. //循环设置入参
  26. for(Map.Entry<String, String> entry : inParam.entrySet()) {
  27. String key = entry.getKey();
  28. String value = entry.getValue();
  29. //设置入参
  30. bindVars.add(key, value).setBindVariableDirection(BindVariableDirection.IN);
  31. }
  32. //执行查询
  33. RecordCollection result = selCmd.executeQuery();
  34. //判断是否查询到数据
  35. if (null == result || result.size() == 0){
  36. return null;
  37. }else {
  38. return result.get(0);
  39. }
  40. }
  41. /**
  42. * @description: 执行参数返回 集合参数
  43. * @author LR
  44. * @date 2024/12/9 11:36
  45. * @version 1.0
  46. */
  47. public static RecordCollection execSqlSearchGetRecordCollection(Server srv, StringBuilder searchSql, Map<String, String> inParam) throws APException {
  48. //创建查询体
  49. PlsqlSelectCommand selCmd = new PlsqlSelectCommand(srv, searchSql.toString());
  50. //获取绑定参数
  51. Record bindVars = selCmd.getBindVariables();
  52. //循环设置入参
  53. for(Map.Entry<String, String> entry : inParam.entrySet()) {
  54. String key = entry.getKey();
  55. String value = entry.getValue();
  56. //设置入参
  57. bindVars.add(key, value).setBindVariableDirection(BindVariableDirection.IN);
  58. }
  59. //执行查询
  60. RecordCollection result = selCmd.executeQuery();
  61. //判断是否查询到数据
  62. if (null == result || result.size() == 0){
  63. return null;
  64. }else {
  65. return result;
  66. }
  67. }
  68. /**
  69. * @description: 执行存储过程 返回需要的数据
  70. * @author LR
  71. * @date 2024/12/9 16:17
  72. * @version 1.0
  73. */
  74. public static Map<String, String> execProcedureGetRecord(Server srv, String packageName, String methodName,
  75. PlsqlBaseMethodType methodType, PlsqlBaseMethodAction methodAction, Map<String, String> inParam) throws APException {
  76. //创建查询体
  77. Record profile = new Record("PROFILE");
  78. //填充参数
  79. //循环设置入参
  80. for(Map.Entry<String, String> entry : inParam.entrySet()) {
  81. String key = entry.getKey();
  82. String value = entry.getValue();
  83. //设置入参
  84. profile.add(key, value);
  85. }
  86. //创建执行的框体
  87. PlsqlBaseMethodCommand methodCommand = new PlsqlBaseMethodCommand(
  88. srv,
  89. methodType,
  90. packageName,
  91. methodName,
  92. profile,
  93. methodAction);
  94. //执行
  95. methodCommand.execute();
  96. //转换类型
  97. Map<String, String> resultMap = IfsConverterToMap.ConverterIfsToMap(profile);
  98. //返回结果集
  99. return resultMap;
  100. }
  101. /**
  102. *
  103. * @Title: execProcedureGetRecord
  104. * @Description: 调用特殊的存储过程 出参和入参严格规范后的数据 入参和出参 不重复的数据
  105. * @author: LR
  106. * @date 2024年12月10日 下午3:54:22
  107. * @return: Map<String,String>
  108. * @throws
  109. */
  110. public static Map<String, String> execProcedureGetRecord(Server srv, String packageName, String methodName,
  111. List<IfsParamBean> inParams, List<IfsParamBean> outParams) throws APException {
  112. Map<String, String> resultMap = new HashMap<>();
  113. //创建查询体
  114. StringBuilder searchSql = new StringBuilder();
  115. searchSql.append("BEGIN ifsapp.").append(packageName).append(".").append(methodName).append("(");
  116. //首先循环写入出参
  117. for(int i = 0; i < outParams.size(); i++) {
  118. IfsParamBean param = outParams.get(i);
  119. //判断一下是否有入参
  120. if(inParams != null) {
  121. searchSql.append(":").append(param.getColumnName()).append(", ");
  122. }else {
  123. searchSql.append(":").append(param.getColumnName());
  124. //判断是否是最后一个参数
  125. if(i < outParams.size() - 1) {
  126. searchSql.append(", ");
  127. }
  128. }
  129. }
  130. //然后填充入参
  131. for(int i = 0; i < inParams.size(); i++) {
  132. IfsParamBean param = inParams.get(i);
  133. searchSql.append(":").append(param.getColumnName());
  134. //判断是否是最后一个参数
  135. if(i < inParams.size() - 1) {
  136. searchSql.append(", ");
  137. }
  138. }
  139. //拼接最终的sql
  140. searchSql.append("); END;");
  141. //打印最终调用的sql语句
  142. System.err.println(searchSql.toString());
  143. PlsqlSelectCommand selCmd = new PlsqlSelectCommand(srv, searchSql.toString());
  144. Record bindVars = selCmd.getBindVariables();
  145. //循环设置入参
  146. for(IfsParamBean param : inParams) {
  147. bindVars.add(param.getColumnName(), param.getColumnValue()).setBindVariableDirection(BindVariableDirection.IN);
  148. }
  149. //循环设置出参
  150. for(IfsParamBean param : outParams) {
  151. bindVars.add(param.getColumnName()).setBindVariableDirection(BindVariableDirection.OUT);
  152. }
  153. //执行查询
  154. selCmd.executeQuery();
  155. //遍历返回结果集
  156. for(IfsParamBean param : outParams) {
  157. String columnName = param.getColumnName();
  158. String columnValue = bindVars.find(param.getColumnName()).getString();
  159. resultMap.put(columnName, columnValue);
  160. }
  161. //返回结果集
  162. return resultMap;
  163. }
  164. }