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.

240 lines
8.4 KiB

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