重构盘点单审批后同步 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.cust.CustomerVO;
import nc.vo.bd.material.MaterialVO; import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.rack.RackVO; import nc.vo.bd.rack.RackVO;
import nc.vo.bd.stordoc.StordocVO;
import nc.vo.bd.supplier.SupplierVO; import nc.vo.bd.supplier.SupplierVO;
import nc.vo.ic.m4r.entity.InvCountBillVO; import nc.vo.ic.m4r.entity.InvCountBillVO;
import nc.vo.ic.m4r.entity.InvCountBodyVO; import nc.vo.ic.m4r.entity.InvCountBodyVO;
import nc.vo.ic.m4r.entity.InvCountHeaderVO; import nc.vo.ic.m4r.entity.InvCountHeaderVO;
import nc.vo.org.DeptVO;
import nc.vo.pub.BusinessException; import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDate; import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble; import nc.vo.pub.lang.UFDouble;
@ -29,8 +31,7 @@ import java.text.SimpleDateFormat;
* 盘点审批后传MES * 盘点审批后传MES
*/ */
public class AfterApprovingSynchronizeRuleMES implements IRule<InvCountBillVO> { public class AfterApprovingSynchronizeRuleMES implements IRule<InvCountBillVO> {
private static final String INV_COUNT_URL = "/GTHINKING/AjaxService/N_MISPRO/InvCount.ashx/SaveData"; // 盘点单同步接口 private static final String INV_COUNT_URL = "/GTHINKING/AjaxService/U20231172_N_XSSJJSA/102397009.ashx/KCPD_INSERT"; // 盘点单同步接口
private static final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final String logginfo = "OALOG"; private static final String logginfo = "OALOG";
private static final Log obmlog = Log.getInstance(logginfo); private static final Log obmlog = Log.getInstance(logginfo);
private static final BaseDAO dao = new BaseDAO(); private static final BaseDAO dao = new BaseDAO();
@ -79,72 +80,86 @@ public class AfterApprovingSynchronizeRuleMES implements IRule<InvCountBillVO> {
obmlog.debug("AfterApprovingSynchronizeRule-跳过处理销售出库单,因为此单据组织非电缆: " + hvo.getVbillcode()); obmlog.debug("AfterApprovingSynchronizeRule-跳过处理销售出库单,因为此单据组织非电缆: " + hvo.getVbillcode());
return null; return null;
} }
// 按照新规范构建请求数据
JSONObject requestData = new JSONObject(); 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) - 必填 String warehouseCode = transferCodeByPk(StordocVO.getDefaultTableName(), StordocVO.CODE, StordocVO.PK_STORDOC, hvo.getCwarehouseid());
info.put("departmentId", hvo.getCdptvid()); // 部门ID(cdptvid) - 必填 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(); UFDate dcountdate = hvo.getDcountdate();
if (dcountdate != null) { if (dcountdate != null) {
info.put("date", dateTimeFormat.format(dcountdate.toDate())); // 盘点日期(dcountdate) - 必填 requestData.put("PDRQ", dcountdate.toString()); // 盘点日期 - 必填
} else { } else {
// 如果盘点日期为空使用单据日期 requestData.put("PDRQ", null);
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("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(); JSONArray details = new JSONArray();
if (bvos != null) { if (bvos != null) {
for (InvCountBodyVO bvo : bvos) { for (InvCountBodyVO bvo : bvos) {
JSONObject detail = new JSONObject(); JSONObject detail = new JSONObject();
// 序号 - 转换为浮点数 // 获取序号并转换为浮点数
detail.put("sequenceNum", bvo.getCrowno()); String crownStr = bvo.getCrowno();
// 物料ID(cmaterialvid) - 必填 try {
detail.put("materialId", transferCodeByPk(MaterialVO.getDefaultTableName(), MaterialVO.PK_MATERIAL, MaterialVO.CODE, bvo.getCmaterialvid())); detail.put("XH", Double.parseDouble(crownStr)); // 序号 - 必填
// 库位(clocationid) - 必填 } catch (NumberFormatException e) {
detail.put("storageId", transferCodeByPk(RackVO.getDefaultTableName(), RackVO.CODE, RackVO.PK_RACK, bvo.getClocationid())); detail.put("XH", null); // 默认序号
// 物料批号(vbatchcode) - 必填 }
detail.put("batchNum", getStringValue(bvo.getVbatchcode())); // 物料编码 - 必填
// 盘存数量 - 使用实盘主数量 detail.put("WLID", transferCodeByPk(MaterialVO.getDefaultTableName(), MaterialVO.CODE, MaterialVO.PK_MATERIAL, bvo.getCmaterialvid()));
UFDouble countNum = bvo.getNcountnum(); // 货位
detail.put("panQty", countNum.doubleValue()); // 盘存数量(ncountnum) - 必填 detail.put("KW", transferCodeByPk(RackVO.getDefaultTableName(), RackVO.CODE, RackVO.PK_RACK, bvo.getClocationid()));
// 客户ID // 物料批号
detail.put("customId", transferCodeByPk(CustomerVO.getDefaultTableName(), CustomerVO.CODE, CustomerVO.PK_CUSTOMER, bvo.getCasscustid())); detail.put("WLPH", getStringValue(bvo.getVbatchcode()));
// 供应商ID
detail.put("supplierId", transferCodeByPk(SupplierVO.getDefaultTableName(), SupplierVO.CODE, SupplierVO.PK_SUPPLIER, bvo.getCvendorid())); // 盘存数量 -> 实盘主数量
// 生产日期处理 UFDouble pcNum = bvo.getNcountnum();
detail.put("manufactureDate", null); // 账面主数量
detail.put("color", null); UFDouble zmNum = bvo.getNonhandnum();
// 包装信息可能来自自定义属性 if (pcNum != null) {
detail.put("packLen", null); // 盘存数量 -> 实盘主数量
detail.put("packSize", null); detail.put("PCSL", pcNum.getDouble());
// 备注 if (zmNum != null) {
detail.put("remark", getStringValue(bvo.getVnotebody())); // 备注(vnotebody) // 盘盈数量 -> 账面主数量 - 实盘主数量
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); details.add(detail);
} }
} }
info.put("details", details); requestData.put("DETAILS", details);
// 将info对象添加到请求数据中
requestData.put("info", info);
return requestData; return requestData;
} }