From ce5886c7b5a5fbaba10a29a86a875ff03283a5cd Mon Sep 17 00:00:00 2001 From: mzr Date: Tue, 27 May 2025 10:44:27 +0800 Subject: [PATCH] =?UTF-8?q?saleUpdateLJpc=E6=8E=A5=E5=8F=A3=E7=9A=84?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=80=BC=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/so/so/salepc/saleUpdateLJpc.java | 432 +++++++++--------- 1 file changed, 223 insertions(+), 209 deletions(-) diff --git a/so/src/public/nccloud/api/so/so/salepc/saleUpdateLJpc.java b/so/src/public/nccloud/api/so/so/salepc/saleUpdateLJpc.java index bda49ab..f8a3205 100644 --- a/so/src/public/nccloud/api/so/so/salepc/saleUpdateLJpc.java +++ b/so/src/public/nccloud/api/so/so/salepc/saleUpdateLJpc.java @@ -6,14 +6,15 @@ import com.alibaba.fastjson.JSONObject; import nc.bs.dao.BaseDAO; import nc.bs.framework.common.NCLocator; import nc.itf.uap.IUAPQueryBS; -import nc.jdbc.framework.ConnectionFactory; import nc.jdbc.framework.JdbcSession; import nc.jdbc.framework.PersistenceManager; import nc.jdbc.framework.exception.DbException; import nc.jdbc.framework.processor.ColumnProcessor; import nc.jdbc.framework.processor.MapListProcessor; +import nc.jdbc.framework.processor.MapProcessor; import nc.vo.pub.BusinessException; import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.commons.lang.StringUtils; import nccloud.ws.rest.resource.AbstractNCCRestResource; import org.json.JSONString; @@ -30,236 +31,249 @@ import java.util.Map; @Path("so/so/salepc") public class saleUpdateLJpc extends AbstractNCCRestResource { - @Override - public String getModule() { - return "so"; - } - // 用于存储手工维护的必填字段和字段说明 - private Map requiredFields; - // 构造方法,初始化必填字段及其说明 - public saleUpdateLJpc() { - // 初始化必填字段列表及字段说明 - requiredFields = new HashMap<>(); - requiredFields.put("pk_org", "业务单元"); - requiredFields.put("array.vbillcode", "单据编号"); - requiredFields.put("array.crowno", "行号"); - requiredFields.put("array.sendQty", "发货数量"); - } + @Override + public String getModule() { + return "so"; + } - @POST - @Path("/saleUpdateLJpc") - @Consumes({"application/json"}) - @Produces({"application/json"}) - public JSONString saleUpdateLJpc(JSONString json) { - JSONObject returnJson = new JSONObject(); - try { - 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)); - } - String pk_org = (String) object.getOrDefault("pk_org", ""); - Object obj = object.getOrDefault("array", ""); - ArrayList arrayList = new ArrayList<>(); - if (obj instanceof JSONArray) { - JSONArray jsonArray = (JSONArray) obj; - arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); - } + // 用于存储手工维护的必填字段和字段说明 + private Map requiredFields; + + // 构造方法,初始化必填字段及其说明 + public saleUpdateLJpc() { + // 初始化必填字段列表及字段说明 + requiredFields = new HashMap<>(); + requiredFields.put("pk_org", "业务单元"); + requiredFields.put("array.vbillcode", "单据编号"); + requiredFields.put("array.crowno", "行号"); + requiredFields.put("array.sendQty", "发货数量"); + } + + @POST + @Path("/saleUpdateLJpc") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString saleUpdateLJpc(JSONString json) { + JSONObject returnJson = new JSONObject(); + try { + JSONObject object = JSON.parseObject(json.toJSONString()); + if (object == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); + } + // 校验必填字段 + String tipsStr = checkRequiredFields(object); + if (!tipsStr.isEmpty()) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException(tipsStr)); + } + String pk_org = (String) object.getOrDefault("pk_org", ""); + Object obj = object.getOrDefault("array", ""); + 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(); - for (int i = 0; i < arrayList.size(); i++) { - Map dataMap = (Map) arrayList.get(i); + List sqlStr = new ArrayList(); + List resList = new ArrayList<>(); + for (int i = 0; i < arrayList.size(); i++) { + Map dataMap = (Map) arrayList.get(i); - String sqlser="SELECT b.csaleorderid, b.vbdef6, b.vbdef12 " - + "FROM so_saleorder_b b " - + "LEFT JOIN so_saleorder h ON b.csaleorderid = h.csaleorderid " - + "LEFT JOIN org_salesorg o ON h.pk_org = o.pk_salesorg " - + "WHERE b.dr=0 and h.vbillcode = '" + dataMap.get("vbillcode") + "' " - + "AND o.code = '" + pk_org + "' " - + "AND b.csaleorderbid = '" + dataMap.get("crowno") + "'"; - List> results = (List>) getQueryService().executeQuery(sqlser, new MapListProcessor()); - if (results.size()==0){ - returnJson.put("state", 'N'); - returnJson.put("msg", "失败,单据"+dataMap.get("vbillcode")+"行号:"+dataMap.get("crowno")+"不存在"); - return ResultMessageUtil.toJSON(returnJson); - } - if (dataMap.get("sendQty")!=null){ - sqlStr.add("UPDATE so_saleorder_b b " - + "SET b.vbdef6 = '1001A11000000C0W6P7S',b.vbdef12 = '"+dataMap.get("sendQty")+"'" - + "WHERE b.csaleorderid IN (" - + " SELECT h.csaleorderid" - + " FROM so_saleorder h" - + " LEFT JOIN org_salesorg o ON h.pk_org = o.pk_salesorg" - + " WHERE h.vbillcode = '" + dataMap.get("vbillcode") + "' " - + " AND o.code = '" + pk_org + "' " - + " AND b.csaleorderbid = '" + dataMap.get("crowno") + "' and b.dr=0 " - + ");"); - } - } + String sqlser = "SELECT b.csaleorderid, b.vbdef6, b.vbdef12 " + + "FROM so_saleorder_b b " + + "LEFT JOIN so_saleorder h ON b.csaleorderid = h.csaleorderid " + + "LEFT JOIN org_salesorg o ON h.pk_org = o.pk_salesorg " + + "WHERE b.dr=0 and h.vbillcode = '" + dataMap.get("vbillcode") + "' " + + "AND o.code = '" + pk_org + "' " + + "AND b.csaleorderbid = '" + dataMap.get("crowno") + "'"; + List> results = (List>) getQueryService().executeQuery(sqlser, new MapListProcessor()); + if (results.size() == 0) { + returnJson.put("state", 'N'); + returnJson.put("msg", "失败,单据" + dataMap.get("vbillcode") + "行号:" + dataMap.get("crowno") + "不存在"); + return ResultMessageUtil.toJSON(returnJson); + } + if (dataMap.get("sendQty") != null) { + sqlStr.add("UPDATE so_saleorder_b b " + + "SET b.vbdef6 = '1001A11000000C0W6P7S',b.vbdef12 = '" + dataMap.get("sendQty") + "'" + + "WHERE b.csaleorderid IN (" + + " SELECT h.csaleorderid" + + " FROM so_saleorder h" + + " LEFT JOIN org_salesorg o ON h.pk_org = o.pk_salesorg" + + " WHERE h.vbillcode = '" + dataMap.get("vbillcode") + "' " + + " AND o.code = '" + pk_org + "' " + + " AND b.csaleorderbid = '" + dataMap.get("crowno") + "' and b.dr=0 " + + ");"); + } + JSONObject resJson = new JSONObject(dataMap); + String csaleorderbid = dataMap.getOrDefault("csaleorderbid", "") + ""; + if (StringUtils.isNotEmpty(csaleorderbid)) { + String sql = " select sb.csaleorderbid,sb.vbdef19,sb.vbdef20" + + " from so_saleorder_b sb" + + " where sb.csaleorderbid='" + csaleorderbid + "' "; + Map soMap = (Map) getQueryService().executeQuery(sql, new MapProcessor()); + resJson.put("vbdef19", soMap.getOrDefault("vbdef19", "")); + resJson.put("vbdef20", soMap.getOrDefault("vbdef20", "")); + } + resList.add(resJson); + } // int succState = updateSaleBSQty(sqlStr.toString()); - int succState = executeUpdate(sqlStr); + int succState = executeUpdate(sqlStr); - if (succState == arrayList.size()) { - returnJson.put("state", 'Y'); - returnJson.put("msg", "成功,已修改"+succState+"行"); + if (succState == arrayList.size()) { + returnJson.put("state", 'Y'); + returnJson.put("msg", "成功,已修改" + succState + "行"); - }else { - returnJson.put("state", 'N'); - returnJson.put("msg", "失败,已修改"+succState+"行"); - } - return ResultMessageUtil.toJSON(returnJson); - } catch (DbException e) { - throw new RuntimeException(e); - } catch (Exception e) { - throw new RuntimeException(e); - } - } + } else { + returnJson.put("state", 'N'); + returnJson.put("msg", "失败,已修改" + succState + "行"); + } + returnJson.put("resList", resList); + return ResultMessageUtil.toJSON(returnJson); + } catch (Exception e) { + throw new RuntimeException(e); + } + } - /** - * updateSqls为要执行的sql语句。返回影响行数量 - */ - public int executeUpdate(List updateSqls) throws DbException { - if (updateSqls == null) { - return 0; - } + /** + * updateSqls为要执行的sql语句。返回影响行数量 + */ + public int executeUpdate(List 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 = ConnectionFactory.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); + } } \ No newline at end of file