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