物料修改更新ims
This commit is contained in:
parent
5fc4bd1a6e
commit
e0fa187e52
|
|
@ -100,7 +100,7 @@ public class MaterialToGyImsListener implements IBusinessListener {
|
|||
MaterialVO[] useVOs = ArrayClassConvertUtil.convert(objs, MaterialVO.class);
|
||||
// 更新启用状态
|
||||
|
||||
// updateEnableStatus(useVOs);
|
||||
updateIms(useVOs);
|
||||
|
||||
|
||||
|
||||
|
|
@ -243,5 +243,76 @@ public class MaterialToGyImsListener implements IBusinessListener {
|
|||
}
|
||||
|
||||
|
||||
private void updateIms(MaterialVO[] useVOs) throws BusinessException {
|
||||
// 执行单条SQL更新
|
||||
BaseDAO gyimsDao = new BaseDAO("gyims");
|
||||
gyimsDao.setAddTimeStamp(false);
|
||||
List<String> code = new ArrayList<>();
|
||||
for (MaterialVO materialVO : useVOs) {
|
||||
code.add(materialVO.getPk_material());
|
||||
}
|
||||
String placeholders = String.join(",", Collections.nCopies(code.size(), "?"));
|
||||
placeholders = code.get(0);
|
||||
String sql = " \t\tSELECT\n" +
|
||||
"\t* \n" +
|
||||
"from bd_material a " +
|
||||
"where a.pk_material IN ('" + placeholders + "')";
|
||||
List<Map<String, Object>> remain = (List<Map<String, Object>>) new BaseDAO("design").executeQuery(sql, new MapListProcessor());
|
||||
|
||||
// 定义需要更新的字段(与表结构一致,pk_material作为更新条件)
|
||||
String[] fields = {
|
||||
"pk_material", "code", "name", "materialspec", "materialtype",
|
||||
"materialshortname", "pk_measdoc", "pk_marbasclass", "memo",
|
||||
"enablestate", "itemtype", "itemattribute", "itemmodel", "status", "createdate"
|
||||
};
|
||||
|
||||
for (Map<String, Object> data : remain) {
|
||||
// 设置状态为U更新
|
||||
data.put("status", "U");
|
||||
String pkMaterial = (String) data.get("pk_material");
|
||||
if (pkMaterial == null) {
|
||||
continue; // 主键为空时跳过更新
|
||||
}
|
||||
|
||||
// 构建SET部分
|
||||
List<String> setParts = new ArrayList<>();
|
||||
for (String field : fields) {
|
||||
if ("pk_material".equals(field)) {
|
||||
continue; // 主键作为条件,不参与更新
|
||||
}
|
||||
Object value = data.get(field);
|
||||
StringBuilder part = new StringBuilder();
|
||||
part.append(field).append("=");
|
||||
|
||||
// 处理字段值(字符串加单引号并转义,null特殊处理)
|
||||
if (value instanceof String) {
|
||||
part.append("'").append(((String) value).replace("'", "''")).append("'");
|
||||
} else if (value == null) {
|
||||
part.append("NULL");
|
||||
} else {
|
||||
part.append(value);
|
||||
}
|
||||
setParts.add(part.toString());
|
||||
}
|
||||
|
||||
if (setParts.isEmpty()) {
|
||||
continue; // 无更新字段时跳过
|
||||
}
|
||||
|
||||
// 拼接更新SQL
|
||||
String setClause = String.join(", ", setParts);
|
||||
String updateSql = "UPDATE BIPItemTab SET " + setClause +
|
||||
" WHERE pk_material='" + pkMaterial.replace("'", "''") + "'";
|
||||
|
||||
try {
|
||||
int rowsAffected = gyimsDao.executeUpdate(updateSql);
|
||||
String K = "1"; // 保持原代码调试标记风格
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("更新失败:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue