ims数据源修改

This commit is contained in:
lihao 2025-11-21 14:43:32 +08:00
parent 0e55b1ddf9
commit 3a6141761f
3 changed files with 71 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package nc.bs.ic.m4d.sign.rule;
import nc.bs.dao.BaseDAO;
import nc.bs.logging.Log;
import nc.bs.uapbd.util.GyImsDbUtil;
import nc.bs.uapbd.util.MyHelper;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.vo.ic.m4d.entity.MaterialOutHeadVO;
@ -71,7 +72,7 @@ public class UpdateGyimsRule implements IRule<MaterialOutVO> {
String updateSql = "update BIPOutMainTab set status = '2' where vbillcode in (" + ids + ")";
// 3. 执行更新注意这里不需要再传递参数SQL已拼接完成
int rows = getImsDao().executeUpdate(updateSql);
int rows = GyImsDbUtil.update(updateSql);
}
} catch (BusinessException e) {

View File

@ -3,6 +3,7 @@ package nc.bs.mmpac.pmo.pac0002.bp.rule;
import nc.bs.dao.BaseDAO;
import nc.bs.logging.Log;
import nc.bs.uapbd.util.GyImsDbUtil;
import nc.bs.uapbd.util.MyHelper;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.jdbc.framework.SQLParameter;
@ -169,7 +170,11 @@ public class AfterApproveSyncImsRule implements IRule<PMOAggVO> {
private String buildSQL(String tableName, String[] columns, String pkColumn, Object pkValue) throws BusinessException {
// ¼ì²é¼Ç¼ÊÇ·ñ´æÔÚ
String checkSql = "SELECT COUNT(1) FROM " + tableName + " WHERE " + pkColumn + " = '" + pkValue + "'";
Integer count = (Integer) getImsDao().executeQuery(checkSql, new ColumnProcessor());
Map<String,Object> map = GyImsDbUtil.queryOne(checkSql);
if(map.isEmpty()){
return buildInsertSQL(tableName, columns);
}
Integer count = (Integer) GyImsDbUtil.queryOne(checkSql).get("");
if (count > 0) {
// ¹¹½¨UPDATE SQL
@ -379,7 +384,7 @@ public class AfterApproveSyncImsRule implements IRule<PMOAggVO> {
*/
private void pushData(String headSql, SQLParameter headParams, List<String> bodySqlList, List<SQLParameter> bodyParameterList) throws BusinessException {
logger.error("gyIms-PMO-headSql = " + headSql);
int headRowsAffected = getImsDao().executeUpdate(headSql, headParams);
int headRowsAffected = GyImsDbUtil.update(headSql, headParams);
if (headRowsAffected != 1) {
NCCForUAPLogger.debug("gyIms-PMO-headSql = " + headSql);
}
@ -387,7 +392,8 @@ public class AfterApproveSyncImsRule implements IRule<PMOAggVO> {
for (int i = 0; i < bodySqlList.size(); i++) {
String bodySql = bodySqlList.get(i);
SQLParameter parameter = bodyParameterList.get(i);
int bodyRowsAffected = getImsDao().executeUpdate(bodySql, parameter);
int bodyRowsAffected = GyImsDbUtil.update(bodySql, parameter);
if (bodyRowsAffected != 1) {
NCCForUAPLogger.debug("gyIms-PMO-bodySql = " + bodySql);
}

View File

@ -1,6 +1,7 @@
package nc.bs.uapbd.util;
import nc.bs.logging.Log;
import nc.jdbc.framework.SQLParameter;
import nc.vo.pub.BusinessException;
import java.sql.*;
@ -334,7 +335,7 @@ public class GyImsDbUtil {
* @throws BusinessException 更新异常
*/
public static int update(String sql) throws BusinessException {
return update(sql, null);
return update(sql, (Object[]) null);
}
/**
@ -537,5 +538,63 @@ public class GyImsDbUtil {
return false;
}
}
/**
* 执行更新SQLINSERTUPDATEDELETE
*
* @param sql 更新SQL语句
* @param params 参数数组
* @return int 影响的行数
* @throws BusinessException 更新异常
*/
public static int update(String sql, SQLParameter parameter) throws BusinessException {
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = getConnection();
conn.setAutoCommit(false);
pstmt = conn.prepareStatement(sql);
// 核心修改1绑定参数替换原重复执行的executeUpdate假设SQLParameter有getParams()返回参数数组
if (parameter != null && parameter.getParameters() != null) {
Object[] params = parameter.getParameters().toArray();
for (int i = 0; i < params.length; i++) {
Object value = params[i];
// 简单参数绑定索引从1开始空值处理
if (value == null) {
pstmt.setNull(i + 1, Types.VARCHAR); // 默认VARCHAR可根据实际调整
} else {
pstmt.setObject(i + 1, value);
}
}
}
logger.info("执行更新SQL: " + sql);
int rows = pstmt.executeUpdate();
conn.commit();
logger.info("更新成功,影响行数: " + rows);
return rows;
} catch (SQLException e) {
if (conn != null) {
try {
conn.rollback();
logger.info("事务已回滚");
} catch (SQLException rollbackEx) {
logger.error("回滚事务异常", rollbackEx);
}
}
logger.error("执行更新SQL失败: " + sql, e);
throw new BusinessException("执行更新SQL失败: " + e.getMessage(), e);
} finally {
closeResources(null, pstmt, conn);
}
}
}