|
|
package com.spring.ifs.utils;
import com.spring.ifs.data.IfsParamBean;import ifs.fnd.ap.*;
import java.math.BigDecimal;import java.util.HashMap;import java.util.List;import java.util.Map;
/*** @description: IFS的通用方法* @author LR* @date 2024/12/9 11:18* @version 1.0*/public class IfsPlsqlUtils {
/** * @description: 调用查询的通用方法-- 返回单个Bean * @author LR * @date 2024/12/9 11:21 * @version 1.0 */ public static Record execSqlSearchGetRecord(Server srv, StringBuilder searchSql, Map<String, String> inParam) throws APException { //创建查询体
PlsqlSelectCommand selCmd = new PlsqlSelectCommand(srv, searchSql.toString()); //获取绑定参数
Record bindVars = selCmd.getBindVariables(); //循环设置入参
for(Map.Entry<String, String> entry : inParam.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); //设置入参
bindVars.add(key, value).setBindVariableDirection(BindVariableDirection.IN); } //执行查询
RecordCollection result = selCmd.executeQuery(); //判断是否查询到数据
if (null == result || result.size() == 0){ return null; }else { return result.get(0); } }
/** * @description: 执行参数返回 集合参数 * @author LR * @date 2024/12/9 11:36 * @version 1.0 */ public static RecordCollection execSqlSearchGetRecordCollection(Server srv, StringBuilder searchSql, Map<String, String> inParam) throws APException { //创建查询体
PlsqlSelectCommand selCmd = new PlsqlSelectCommand(srv, searchSql.toString()); //获取绑定参数
Record bindVars = selCmd.getBindVariables(); //循环设置入参
for(Map.Entry<String, String> entry : inParam.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); //设置入参
bindVars.add(key, value).setBindVariableDirection(BindVariableDirection.IN); } //执行查询
RecordCollection result = selCmd.executeQuery(); //判断是否查询到数据
if (null == result || result.size() == 0){ return null; }else { return result; } }
/** * @description: 执行存储过程 返回需要的数据 * @author LR * @date 2024/12/9 16:17 * @version 1.0 */ public static Map<String, String> execProcedureGetRecord(Server srv, String packageName, String methodName, PlsqlBaseMethodType methodType, PlsqlBaseMethodAction methodAction, Map<String, String> inParam) throws APException { //创建查询体
Record profile = new Record("PROFILE"); //填充参数
//循环设置入参
for(Map.Entry<String, String> entry : inParam.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); //设置入参
profile.add(key, value); } //创建执行的框体
PlsqlBaseMethodCommand methodCommand = new PlsqlBaseMethodCommand( srv, methodType, packageName, methodName, profile, methodAction); //转换类型
Map<String, String> resultMap = null; //执行
try{ methodCommand.execute(); resultMap = IfsConverterToMap.ConverterIfsToMap(profile); }catch(ManualDecisionException e){ //转换类型
resultMap = IfsConverterToMap.ConverterIfsToMap(profile); System.out.print(e.getMessage()); //填充警告信息
resultMap.put("WARNING", e.getMessage()); }
//返回结果集
return resultMap; }
/** * @description: 执行存储过程 返回需要的数据 * @author LR * @date 2024/12/9 16:17 * @version 1.0 */ public static Map<String, String> execProcedureGetRecordForParamType(Server srv, String packageName, String methodName, PlsqlBaseMethodType methodType, PlsqlBaseMethodAction methodAction, Map<String, Object> inParam) throws APException { //创建查询体
Record profile = new Record("PROFILE"); //填充参数
//循环设置入参
for(Map.Entry<String, Object> entry : inParam.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); //设置入参
//区分不同类型 使用不同的添加入参方法
if (value instanceof String){ profile.add(key, (String)value, DataType.ALPHA); }else if (value instanceof BigDecimal){ profile.add(key, (BigDecimal)value, DataType.DECIMAL); }else if (value instanceof Integer){ profile.add(key, (Integer)value, DataType.INTEGER); }else if (value instanceof Long){ profile.add(key, (Long)value, DataType.INTEGER); }else if (value instanceof Double){ profile.add(key, (Double)value, DataType.FLOAT); }else if (value instanceof Float){ profile.add(key, (Float)value, DataType.FLOAT); }else if (value instanceof Boolean) { profile.add(key, (Boolean) value, DataType.BOOLEAN); } } //创建执行的框体
PlsqlBaseMethodCommand methodCommand = new PlsqlBaseMethodCommand( srv, methodType, packageName, methodName, profile, methodAction); //执行
methodCommand.execute(); //转换类型
Map<String, String> resultMap = IfsConverterToMap.ConverterIfsToMap(profile); //返回结果集
return resultMap; } /** * * @Title: execProcedureGetRecord * @Description: 调用特殊的存储过程 出参和入参严格规范后的数据 入参和出参 不重复的数据 * @author: LR * @date 2024年12月10日 下午3:54:22 * @return: Map<String,String> * @throws */ public static Map<String, String> execProcedureGetRecord(Server srv, String packageName, String methodName, List<IfsParamBean> inParams, List<IfsParamBean> outParams) throws APException { Map<String, String> resultMap = new HashMap<>(); //创建查询体
StringBuilder searchSql = new StringBuilder(); searchSql.append("BEGIN ifsapp.").append(packageName).append(".").append(methodName).append("("); //首先循环写入出参
for(int i = 0; i < outParams.size(); i++) { IfsParamBean param = outParams.get(i); //判断一下是否有入参
if(inParams != null) { searchSql.append(":").append(param.getColumnName()).append(", "); }else { searchSql.append(":").append(param.getColumnName()); //判断是否是最后一个参数
if(i < outParams.size() - 1) { searchSql.append(", "); } } } //然后填充入参
for(int i = 0; i < inParams.size(); i++) { IfsParamBean param = inParams.get(i); searchSql.append(":").append(param.getColumnName()); //判断是否是最后一个参数
if(i < inParams.size() - 1) { searchSql.append(", "); } } //拼接最终的sql
searchSql.append("); END;"); //打印最终调用的sql语句
System.err.println(searchSql.toString()); PlsqlSelectCommand selCmd = new PlsqlSelectCommand(srv, searchSql.toString()); Record bindVars = selCmd.getBindVariables(); //循环设置入参
for(IfsParamBean param : inParams) { bindVars.add(param.getColumnName(), param.getColumnValue()).setBindVariableDirection(BindVariableDirection.IN); } //循环设置出参
for(IfsParamBean param : outParams) { bindVars.add(param.getColumnName()).setBindVariableDirection(BindVariableDirection.OUT); } //执行查询
selCmd.executeQuery(); //遍历返回结果集
for(IfsParamBean param : outParams) { String columnName = param.getColumnName(); String columnValue = bindVars.find(param.getColumnName()).getString(); resultMap.put(columnName, columnValue); } //返回结果集
return resultMap; }
}
|