diff --git a/ic/src/private/nc/bs/ic/m4r/approve/rule/AfterApprovingSynchronizeRuleMES.java b/ic/src/private/nc/bs/ic/m4r/approve/rule/AfterApprovingSynchronizeRuleMES.java index d5afcd1..e420d26 100644 --- a/ic/src/private/nc/bs/ic/m4r/approve/rule/AfterApprovingSynchronizeRuleMES.java +++ b/ic/src/private/nc/bs/ic/m4r/approve/rule/AfterApprovingSynchronizeRuleMES.java @@ -12,10 +12,12 @@ import nc.jdbc.framework.processor.ColumnProcessor; import nc.vo.bd.cust.CustomerVO; import nc.vo.bd.material.MaterialVO; import nc.vo.bd.rack.RackVO; +import nc.vo.bd.stordoc.StordocVO; import nc.vo.bd.supplier.SupplierVO; import nc.vo.ic.m4r.entity.InvCountBillVO; import nc.vo.ic.m4r.entity.InvCountBodyVO; import nc.vo.ic.m4r.entity.InvCountHeaderVO; +import nc.vo.org.DeptVO; import nc.vo.pub.BusinessException; import nc.vo.pub.lang.UFDate; import nc.vo.pub.lang.UFDouble; @@ -29,8 +31,7 @@ import java.text.SimpleDateFormat; * 盘点(审批后传MES) */ public class AfterApprovingSynchronizeRuleMES implements IRule { - private static final String INV_COUNT_URL = "/GTHINKING/AjaxService/N_MISPRO/InvCount.ashx/SaveData"; // 盘点单同步接口 - private static final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final String INV_COUNT_URL = "/GTHINKING/AjaxService/U20231172_N_XSSJJSA/102397009.ashx/KCPD_INSERT"; // 盘点单同步接口 private static final String logginfo = "OALOG"; private static final Log obmlog = Log.getInstance(logginfo); private static final BaseDAO dao = new BaseDAO(); @@ -79,72 +80,86 @@ public class AfterApprovingSynchronizeRuleMES implements IRule { obmlog.debug("AfterApprovingSynchronizeRule-跳过处理销售出库单,因为此单据组织非电缆: " + hvo.getVbillcode()); return null; } + + // 按照新规范构建请求数据 JSONObject requestData = new JSONObject(); - // 操作类型为新增 - requestData.put("operation_type", "I"); - // 构建info对象 - 按照接口要求设置必填字段 - JSONObject info = new JSONObject(); + // 盘点主信息 盘点单号 为空时自动生成 + requestData.put("PDDH", null); - // 必填字段 - info.put("storeId", hvo.getCwarehouseid()); // 仓库ID(cwarehouseid) - 必填 - info.put("departmentId", hvo.getCdptvid()); // 部门ID(cdptvid) - 必填 + // 获取仓库编码 + String warehouseCode = transferCodeByPk(StordocVO.getDefaultTableName(), StordocVO.CODE, StordocVO.PK_STORDOC, hvo.getCwarehouseid()); + requestData.put("CKID", warehouseCode); + + // 盘点部门编码 + String deptCode = transferCodeByPk(DeptVO.getDefaultTableName(), DeptVO.CODE, DeptVO.PK_DEPT, hvo.getCdptvid()); + requestData.put("BMID", deptCode); + // 盘点人 + requestData.put("PDR", getStringValue(hvo.getCountoperator())); // 日期处理 - 盘点日期 UFDate dcountdate = hvo.getDcountdate(); if (dcountdate != null) { - info.put("date", dateTimeFormat.format(dcountdate.toDate())); // 盘点日期(dcountdate) - 必填 + requestData.put("PDRQ", dcountdate.toString()); // 盘点日期 - 必填 } else { - // 如果盘点日期为空,使用单据日期 - UFDate dbilldate = hvo.getDbilldate(); - if (dbilldate != null) { - info.put("date", dateTimeFormat.format(dbilldate.toDate())); - } else { - // 接口要求此字段必填,如果没有日期则使用当前日期 - info.put("date", dateTimeFormat.format(new java.util.Date())); - } + requestData.put("PDRQ", null); } + // 备注 + requestData.put("BZ", getStringValue(hvo.getVnote())); - // 其他主表字段 - info.put("worker", getStringValue(hvo.getCountoperator())); // 盘点人(countoperator) - info.put("mark", "N"); // 生成标志,默认为N - info.put("remark", getStringValue(hvo.getVnote())); // 备注(vnote) - - // 构建details明细数组 + // 构建明细数组 JSONArray details = new JSONArray(); if (bvos != null) { for (InvCountBodyVO bvo : bvos) { JSONObject detail = new JSONObject(); - // 序号 - 转换为浮点数 - detail.put("sequenceNum", bvo.getCrowno()); - // 物料ID(cmaterialvid) - 必填 - detail.put("materialId", transferCodeByPk(MaterialVO.getDefaultTableName(), MaterialVO.PK_MATERIAL, MaterialVO.CODE, bvo.getCmaterialvid())); - // 库位(clocationid) - 必填 - detail.put("storageId", transferCodeByPk(RackVO.getDefaultTableName(), RackVO.CODE, RackVO.PK_RACK, bvo.getClocationid())); - // 物料批号(vbatchcode) - 必填 - detail.put("batchNum", getStringValue(bvo.getVbatchcode())); - // 盘存数量 - 使用实盘主数量 - UFDouble countNum = bvo.getNcountnum(); - detail.put("panQty", countNum.doubleValue()); // 盘存数量(ncountnum) - 必填 - // 客户ID - detail.put("customId", transferCodeByPk(CustomerVO.getDefaultTableName(), CustomerVO.CODE, CustomerVO.PK_CUSTOMER, bvo.getCasscustid())); - // 供应商ID - detail.put("supplierId", transferCodeByPk(SupplierVO.getDefaultTableName(), SupplierVO.CODE, SupplierVO.PK_SUPPLIER, bvo.getCvendorid())); - // 生产日期处理 - detail.put("manufactureDate", null); - detail.put("color", null); - // 包装信息(可能来自自定义属性) - detail.put("packLen", null); - detail.put("packSize", null); - // 备注 - detail.put("remark", getStringValue(bvo.getVnotebody())); // 备注(vnotebody) + // 获取序号并转换为浮点数 + String crownStr = bvo.getCrowno(); + try { + detail.put("XH", Double.parseDouble(crownStr)); // 序号 - 必填 + } catch (NumberFormatException e) { + detail.put("XH", null); // 默认序号 + } + // 物料编码 - 必填 + detail.put("WLID", transferCodeByPk(MaterialVO.getDefaultTableName(), MaterialVO.CODE, MaterialVO.PK_MATERIAL, bvo.getCmaterialvid())); + // 货位 + detail.put("KW", transferCodeByPk(RackVO.getDefaultTableName(), RackVO.CODE, RackVO.PK_RACK, bvo.getClocationid())); + // 物料批号 + detail.put("WLPH", getStringValue(bvo.getVbatchcode())); + + // 盘存数量 -> 实盘主数量 + UFDouble pcNum = bvo.getNcountnum(); + // 账面主数量 + UFDouble zmNum = bvo.getNonhandnum(); + if (pcNum != null) { + // 盘存数量 -> 实盘主数量 + detail.put("PCSL", pcNum.getDouble()); + if (zmNum != null) { + // 盘盈数量 -> 账面主数量 - 实盘主数量 + detail.put("PYSL", zmNum.getDouble() - pcNum.getDouble()); + // 盘亏数量 -> 实盘主数量 - 账面主数量 + detail.put("PKSL", pcNum.getDouble() - zmNum.getDouble()); + } else { + detail.put("PYSL", null); + detail.put("PKSL", null); + } + } else { + detail.put("PCSL", null); + detail.put("PYSL", null); + detail.put("PKSL", null); + } + // 盈亏单价 + detail.put("YCDJ", null); + // 盈亏原因 + detail.put("YKYY", getStringValue(bvo.getVnotebody())); + // 客户编码 + detail.put("KHID", transferCodeByPk(CustomerVO.getDefaultTableName(), CustomerVO.CODE, CustomerVO.PK_CUSTOMER, bvo.getCasscustid())); + // 供应商编码 + detail.put("GYSID", transferCodeByPk(SupplierVO.getDefaultTableName(), SupplierVO.CODE, SupplierVO.PK_SUPPLIER, bvo.getCvendorid())); + details.add(detail); } } - info.put("details", details); - - // 将info对象添加到请求数据中 - requestData.put("info", info); + requestData.put("DETAILS", details); return requestData; }