2312上推送标识字段调整

This commit is contained in:
mzr 2025-04-16 16:32:42 +08:00
parent 0fb9071653
commit 7eafe36ea8
1 changed files with 223 additions and 220 deletions

View File

@ -1,6 +1,5 @@
package nccloud.api.so.so.UpCdate; package nccloud.api.so.so.UpCdate;
import nc.jdbc.framework.processor.MapListProcessor;
import org.springframework.util.ObjectUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@ -10,13 +9,13 @@ import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.JdbcSession; import nc.jdbc.framework.JdbcSession;
import nc.jdbc.framework.PersistenceManager; import nc.jdbc.framework.PersistenceManager;
import nc.jdbc.framework.exception.DbException; import nc.jdbc.framework.exception.DbException;
import nc.jdbc.framework.processor.ArrayListProcessor;
import nc.jdbc.framework.processor.ColumnProcessor; import nc.jdbc.framework.processor.ColumnProcessor;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.vo.pub.BusinessException; import nc.vo.pub.BusinessException;
import nccloud.api.rest.utils.ResultMessageUtil; import nccloud.api.rest.utils.ResultMessageUtil;
import nccloud.ws.rest.resource.AbstractNCCRestResource; import nccloud.ws.rest.resource.AbstractNCCRestResource;
import org.json.JSONString; import org.json.JSONString;
import org.apache.http.client.methods.CloseableHttpResponse;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
@ -27,86 +26,90 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import nc.itf.cm.productcostcollect.IProductCostCollectService;
/**
* BIP流水3天内未认领退回NCC并修改推送标识
* 2005适配2312
*/
@Path("so/so/UpCdate") @Path("so/so/UpCdate")
public class Updateinformer extends AbstractNCCRestResource { public class Updateinformer extends AbstractNCCRestResource {
@Override @Override
public String getModule() { public String getModule() {
return "so"; return "so";
} }
// 用于存储手工维护的必填字段和字段说明 // 用于存储手工维护的必填字段和字段说明
private Map<String, String> requiredFields; private Map<String, String> requiredFields;
// 构造方法初始化必填字段及其说明 // 构造方法初始化必填字段及其说明
public Updateinformer() { public Updateinformer() {
// 初始化必填字段列表及字段说明 // 初始化必填字段列表及字段说明
requiredFields = new HashMap<>(); requiredFields = new HashMap<>();
requiredFields.put("pk_org", "业务单元"); requiredFields.put("pk_org", "业务单元");
requiredFields.put("array.vbillcode", "单据编号"); requiredFields.put("array.vbillcode", "单据编号");
requiredFields.put("array.crowno", "行号"); requiredFields.put("array.crowno", "行号");
requiredFields.put("array.sendQty", "发货数量"); requiredFields.put("array.sendQty", "发货数量");
} }
@POST @POST
@Path("/Updateinformer") @Path("/Updateinformer")
@Consumes({"application/json"}) @Consumes({"application/json"})
@Produces({"application/json"}) @Produces({"application/json"})
public JSONString Updateinformer(JSONString json) { public JSONString Updateinformer(JSONString json) {
JSONObject returnJson = new JSONObject(); JSONObject returnJson = new JSONObject();
try { try {
JSONObject object = JSON.parseObject(json.toJSONString()); JSONObject object = JSON.parseObject(json.toJSONString());
if (object == null) { if (object == null) {
return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null"));
} }
// 校验必填字段 // 校验必填字段
// String tipsStr = checkRequiredFields(object); // String tipsStr = checkRequiredFields(object);
// if (!tipsStr.equals("")) { // if (!tipsStr.equals("")) {
// return ResultMessageUtil.exceptionToJSON(new NullPointerException(tipsStr)); // return ResultMessageUtil.exceptionToJSON(new NullPointerException(tipsStr));
// } // }
Object obj = object.getOrDefault("array", ""); Object obj = object.getOrDefault("array", "");
if (obj.equals("")) { if (obj.equals("")) {
return ResultMessageUtil.exceptionToJSON(new NullPointerException("array:null")); return ResultMessageUtil.exceptionToJSON(new NullPointerException("array:null"));
} }
ArrayList<?> arrayList = new ArrayList<>(); ArrayList<?> arrayList = new ArrayList<>();
if (obj instanceof JSONArray) { if (obj instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) obj; JSONArray jsonArray = (JSONArray) obj;
arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class));
} }
// StringBuilder sqlStr = new StringBuilder(); // StringBuilder sqlStr = new StringBuilder();
List sqlStr = new ArrayList(); List sqlStr = new ArrayList();
ArrayList<String> pk_list=null; ArrayList<String> pk_list = null;
// for (int i = 0; i < arrayList.size(); i++) { // for (int i = 0; i < arrayList.size(); i++) {
// Map dataMap = (Map) arrayList.get(i); // Map dataMap = (Map) arrayList.get(i);
// pk_list.add((String) dataMap.get("pk_informer")); // pk_list.add((String) dataMap.get("pk_informer"));
// } // }
String result = ""; String result = "";
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (arrayList.size() > 1) { if (arrayList.size() > 1) {
for (int i = 0; i < arrayList.size(); i++) { for (int i = 0; i < arrayList.size(); i++) {
Map dataMap = (Map) arrayList.get(i); Map dataMap = (Map) arrayList.get(i);
sb.append("'").append(dataMap.get("pk_informer")).append("'"); sb.append("'").append(dataMap.get("pk_informer")).append("'");
if (i < arrayList.size() - 1) { if (i < arrayList.size() - 1) {
sb.append(","); sb.append(",");
} }
} }
result = sb.toString(); result = sb.toString();
}else { } else {
Map dataMap = (Map) arrayList.get(0); Map dataMap = (Map) arrayList.get(0);
result= "'"+(String) dataMap.get("pk_informer")+"'"; result = "'" + (String) dataMap.get("pk_informer") + "'";
} }
String sqlser="select pk_informer from cmp_informer where pk_informer in("+result+")"; String sqlser = "select pk_informer from cmp_informer where pk_informer in(" + result + ")";
// ArrayList<String> results = (ArrayList<String>) getQueryService().executeQuery(sqlser, new ArrayListProcessor()); // ArrayList<String> results = (ArrayList<String>) getQueryService().executeQuery(sqlser, new ArrayListProcessor());
List<Map<String,String>> results = (List<Map<String, String>>) getQueryService().executeQuery(sqlser, new MapListProcessor()); List<Map<String, String>> results = (List<Map<String, String>>) getQueryService().executeQuery(sqlser, new MapListProcessor());
// if (results != null || results.size()!=arrayList.size()) { // if (results != null || results.size()!=arrayList.size()) {
// vbillcodes.add(dataMap.get("pk_informer")); // vbillcodes.add(dataMap.get("pk_informer"));
// }else { // }else {
@ -114,190 +117,190 @@ public class Updateinformer extends AbstractNCCRestResource {
// returnJson.put("msg", "ʧ°Ü,"+dataMap.get("pk_informer")+"²»´æÔÚ"); // returnJson.put("msg", "ʧ°Ü,"+dataMap.get("pk_informer")+"²»´æÔÚ");
// return (JSONString) returnJson; // return (JSONString) returnJson;
// } // }
ArrayList<String> result2 = new ArrayList<>(); ArrayList<String> result2 = new ArrayList<>();
System.out.println(results.getClass()); System.out.println(results.getClass());
for (int i = 0; i < results.size(); i++) { for (int i = 0; i < results.size(); i++) {
Map aa=results.get(i); Map aa = results.get(i);
result2.add((String) aa.get("pk_informer")); result2.add((String) aa.get("pk_informer"));
} }
ArrayList<Object> vbillcodes = new ArrayList<>(); ArrayList<Object> vbillcodes = new ArrayList<>();
for (int i = 0; i < arrayList.size(); i++) { for (int i = 0; i < arrayList.size(); i++) {
Map dataMap = (Map) arrayList.get(i); Map dataMap = (Map) arrayList.get(i);
Object pkInformer = dataMap.get("pk_informer"); Object pkInformer = dataMap.get("pk_informer");
Object status = dataMap.get("status"); Object status = dataMap.get("status");
if (pkInformer == null || status == null) { if (pkInformer == null || status == null) {
continue; // 处理 null continue; // 处理 null
} }
//判断字符串在不在results查询对象里面 // 判断字符串在不在results查询对象里面
//将results里面的所有值改为string类型 // 将results里面的所有值改为string类型
String pk_informer= (String) dataMap.get("pk_informer"); String pk_informer = (String) dataMap.get("pk_informer");
if (result2.contains(pk_informer)) { if (result2.contains(pk_informer)) {
vbillcodes.add(dataMap.get("pk_informer")); vbillcodes.add(dataMap.get("pk_informer"));
sqlStr.add("UPDATE cmp_informer SET def01 = '" + dataMap.get("status") + "' where pk_informer='"+dataMap.get("pk_informer") sqlStr.add("UPDATE cmp_informer SET vdef1 = '" + dataMap.get("status") + "' where pk_informer='" + dataMap.get("pk_informer")
+ "';"); + "';");
} }
} }
returnJson.put("codeList", vbillcodes); returnJson.put("codeList", vbillcodes);
int succState = executeUpdate(sqlStr); int succState = executeUpdate(sqlStr);
returnJson.put("state", '1'); returnJson.put("state", '1');
if (succState == 0) { if (succState == 0) {
returnJson.put("msg", "失败"); returnJson.put("msg", "失败");
}else { } else {
returnJson.put("msg", "成功,已修改"+succState+""); returnJson.put("msg", "成功,已修改" + succState + "");
} }
return ResultMessageUtil.toJSON(returnJson); return ResultMessageUtil.toJSON(returnJson);
} catch (DbException e) { } catch (DbException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
/** /**
* updateSqls为要执行的sql语句返回影响行数量 * updateSqls为要执行的sql语句返回影响行数量
*/ */
public int executeUpdate(List<String> updateSqls) throws DbException { public int executeUpdate(List<String> updateSqls) throws DbException {
if (updateSqls == null) { if (updateSqls == null) {
return 0; return 0;
} }
int ret = 0; int ret = 0;
PersistenceManager manager = null; PersistenceManager manager = null;
JdbcSession session = null; JdbcSession session = null;
Connection connection = null; Connection connection = null;
try { try {
manager = PersistenceManager.getInstance(); manager = PersistenceManager.getInstance();
session = manager.getJdbcSession(); session = manager.getJdbcSession();
connection = session.getConnection(); // 获取实际的数据库连接 connection = session.getConnection(); // 获取实际的数据库连接
// 开始事务 // 开始事务
connection.setAutoCommit(false); // 禁用自动提交手动管理事务 connection.setAutoCommit(false); // 禁用自动提交手动管理事务
// 执行批量操作 // 执行批量操作
for (String sql : updateSqls) { for (String sql : updateSqls) {
session.addBatch(sql); session.addBatch(sql);
} }
// 执行批处理 // 执行批处理
ret = session.executeBatch(); ret = session.executeBatch();
// 提交事务 // 提交事务
connection.commit(); // 批处理成功后提交事务 connection.commit(); // 批处理成功后提交事务
} catch (DbException e) { } catch (DbException e) {
if (connection != null) { if (connection != null) {
try { try {
// 如果发生异常回滚事务 // 如果发生异常回滚事务
connection.rollback(); connection.rollback();
} catch (SQLException rollbackEx) { } catch (SQLException rollbackEx) {
// 记录回滚异常的详细信息 // 记录回滚异常的详细信息
throw new DbException("Error during transaction rollback", rollbackEx) { throw new DbException("Error during transaction rollback", rollbackEx) {
@Override @Override
public boolean isDataIntegrityViolation() { public boolean isDataIntegrityViolation() {
return false; return false;
} }
@Override @Override
public boolean isBadSQLGrammar() { public boolean isBadSQLGrammar() {
return false; return false;
} }
}; };
} }
} }
throw e; // 将原始异常抛出 throw e; // 将原始异常抛出
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {
if (connection != null) { if (connection != null) {
try { try {
// 恢复自动提交模式确保不会影响其他操作 // 恢复自动提交模式确保不会影响其他操作
connection.setAutoCommit(true); connection.setAutoCommit(true);
} catch (SQLException e) { } catch (SQLException e) {
// 忽略恢复自动提交时的异常 // 忽略恢复自动提交时的异常
} }
} }
if (manager != null) { if (manager != null) {
manager.release(); manager.release();
} }
} }
return ret; return ret;
} }
// 方法检查必填项并返回转化后的Map // 方法检查必填项并返回转化后的Map
public static String checkRequiredFields(JSONObject data) throws Exception { public static String checkRequiredFields(JSONObject data) throws Exception {
String returnStr = ""; String returnStr = "";
// 2. 检查必填字段 pk_org // 2. 检查必填字段 pk_org
String pkOrg = (String) data.getOrDefault("pk_org", ""); String pkOrg = (String) data.getOrDefault("pk_org", "");
if (pkOrg.isEmpty()) { if (pkOrg.isEmpty()) {
return "字段pk_org缺失或为空!"; return "字段pk_org缺失或为空!";
} }
// 3. 获取并检查 array 字段 // 3. 获取并检查 array 字段
Object array = data.getOrDefault("array", null); Object array = data.getOrDefault("array", null);
if (array == null || !(array instanceof JSONArray) || ((JSONArray) array).isEmpty()) { if (array == null || !(array instanceof JSONArray) || ((JSONArray) array).isEmpty()) {
return "array对象为空或不存在!"; return "array对象为空或不存在!";
} }
ArrayList<?> arrayList = new ArrayList<>(); ArrayList<?> arrayList = new ArrayList<>();
if (array instanceof JSONArray) { if (array instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) array; JSONArray jsonArray = (JSONArray) array;
arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class));
} }
// 5. 遍历每个对象检查必填字段 // 5. 遍历每个对象检查必填字段
for (int i = 0; i < arrayList.size(); i++) { for (int i = 0; i < arrayList.size(); i++) {
Map item = (Map) arrayList.get(i); Map item = (Map) arrayList.get(i);
// 检查必填字段 'crowno' // 检查必填字段 'crowno'
if (item.getOrDefault("crowno", "").toString().isEmpty()) { if (item.getOrDefault("crowno", "").toString().isEmpty()) {
return "" + (i + 1) + " 项缺少必填字段crowno!"; return "" + (i + 1) + " 项缺少必填字段crowno!";
} }
// 检查必填字段 'vbillcode' // 检查必填字段 'vbillcode'
if (item.getOrDefault("vbillcode", "").toString().isEmpty()) { if (item.getOrDefault("vbillcode", "").toString().isEmpty()) {
return "" + (i + 1) + " 项缺少必填字段vbillcode!"; return "" + (i + 1) + " 项缺少必填字段vbillcode!";
} }
// 检查必填字段 'sendQty' // 检查必填字段 'sendQty'
if (item.getOrDefault("sendQty", "").toString().isEmpty()) { if (item.getOrDefault("sendQty", "").toString().isEmpty()) {
return "" + (i + 1) + " 项缺少必填字段sendQty!"; return "" + (i + 1) + " 项缺少必填字段sendQty!";
} }
} }
return returnStr; return returnStr;
} }
/* /*
*创建时间2024-11-28 *创建时间2024-11-28
*作用查询 *作用查询
*传值 *传值
*返回值必填项map对象 *返回值必填项map对象
*/ */
private String getSaleorderBPK(String pk_org, String vbillcode, String crowno) throws BusinessException { private String getSaleorderBPK(String pk_org, String vbillcode, String crowno) throws BusinessException {
String sql = " select b.csaleorderbid from so_saleorder h \n" String sql = " select b.csaleorderbid from so_saleorder h \n"
+ "left join so_saleorder_b b on h.csaleorderid=b.csaleorderid\n" + "left join so_saleorder_b b on h.csaleorderid=b.csaleorderid\n"
+ "left join org_salesorg o on h.pk_org=o.pk_salesorg\n" + "left join org_salesorg o on h.pk_org=o.pk_salesorg\n"
+ "where h.vbillcode='" + vbillcode + "' and o.code='" + pk_org + "' and b.crowno='" + crowno + "' "; + "where h.vbillcode='" + vbillcode + "' and o.code='" + pk_org + "' and b.crowno='" + crowno + "' ";
String saleorderBPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor()); String saleorderBPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor());
return saleorderBPK; return saleorderBPK;
} }
/* /*
*创建时间2024-11-28 *创建时间2024-11-28
*作用查询 *作用查询
*传值 *传值
*返回值必填项map对象 *返回值必填项map对象
*/ */
private int updateSaleBSQty(String sql) throws BusinessException { private int updateSaleBSQty(String sql) throws BusinessException {
BaseDAO baseDAO = new BaseDAO(); BaseDAO baseDAO = new BaseDAO();
int succInt = baseDAO.executeUpdate(sql); int succInt = baseDAO.executeUpdate(sql);
return succInt; return succInt;
} }
public IUAPQueryBS getQueryService() { public IUAPQueryBS getQueryService() {
return NCLocator.getInstance().lookup(IUAPQueryBS.class); return NCLocator.getInstance().lookup(IUAPQueryBS.class);
} }
} }