重构盘点单审批后同步 MES 接口逻辑

- 更新盘点单同步接口 URL
- 重新定义请求数据结构,按照新规范构建请求参数- 优化日期处理逻辑
- 添加仓库编码、部门编码等字段的处理
- 重构明细数组,增加序号转换、物料编码、货位等字段
- 添加盘存数量、盘盈数量、盘亏数量等计算字段
- 优化异常处理和日志记录
This commit is contained in:
张明 2025-05-19 10:34:21 +08:00
parent aa04553939
commit 2821eb9d68
1 changed files with 66 additions and 51 deletions

View File

@ -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<InvCountBillVO> {
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<InvCountBillVO> {
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;
}