重构采购入库同步 MES 接口逻辑

- 修改了 AfterSigningSynchronizeRuleMES 类的逻辑,增加了判断是否需要同步到 MES 的方法
-重构了 buildSyncData 方法,优化了请求数据的构建过程
- 新增了 PurchaseReceiptRuleMES 类,用于处理采购收货单推送 MES 系统的逻辑
- 优化了代码结构,提高了可读性和可维护性
This commit is contained in:
张明 2025-05-21 16:23:51 +08:00
parent 5884103604
commit 0bdb98af27
5 changed files with 453 additions and 237 deletions

View File

@ -4,7 +4,7 @@ import com.yonyou.cloud.ncc.plugin.entity.OperationInfo;
import nc.bs.ic.general.sign.ISignBP; import nc.bs.ic.general.sign.ISignBP;
import nc.bs.ic.general.sign.ISignRuleProvider; import nc.bs.ic.general.sign.ISignRuleProvider;
import nc.bs.ic.general.sign.SignBPTemplate; import nc.bs.ic.general.sign.SignBPTemplate;
import nc.bs.ic.m45.sign.rule.AfterSigningSynchronizeRuleMES; import nc.bs.ic.m45.sign.rule.PurchaseReceiptRuleMES;
import nc.bs.ic.m45.base.BPPlugInPoint; import nc.bs.ic.m45.base.BPPlugInPoint;
import nc.bs.ic.m45.insert.rule.InsertOrSignRewritePayPlanInvoiceRule; import nc.bs.ic.m45.insert.rule.InsertOrSignRewritePayPlanInvoiceRule;
import nc.bs.ic.m45.sign.rule.*; import nc.bs.ic.m45.sign.rule.*;
@ -51,6 +51,7 @@ public class SignBP implements ISignBP<PurchaseInVO>, ISignRuleProvider<Purchase
processor.addAfterRule(new SignM45AndRewriteCTPayPlan()); processor.addAfterRule(new SignM45AndRewriteCTPayPlan());
processor.addAfterRule(new SignInsertFeeDetailRule()); processor.addAfterRule(new SignInsertFeeDetailRule());
// 签字后推送至MES系统 // 签字后推送至MES系统
processor.addAfterRule(new PurchaseReceiptRuleMES());
processor.addAfterRule(new AfterSigningSynchronizeRuleMES()); processor.addAfterRule(new AfterSigningSynchronizeRuleMES());
} }

View File

@ -10,12 +10,13 @@ import nc.jdbc.framework.processor.ColumnProcessor;
import nc.vo.bd.material.MaterialVO; import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.material.measdoc.MeasdocVO; import nc.vo.bd.material.measdoc.MeasdocVO;
import nc.vo.bd.psn.PsndocVO; import nc.vo.bd.psn.PsndocVO;
import nc.vo.bd.rack.RackVO;
import nc.vo.bd.stordoc.StordocVO; import nc.vo.bd.stordoc.StordocVO;
import nc.vo.bd.supplier.SupplierVO; import nc.vo.bd.supplier.SupplierVO;
import nc.vo.cmp.util.StringUtils;
import nc.vo.ic.m45.entity.PurchaseInVO;
import nc.vo.ic.m45.entity.PurchaseInBodyVO; import nc.vo.ic.m45.entity.PurchaseInBodyVO;
import nc.vo.ic.m45.entity.PurchaseInHeadVO; import nc.vo.ic.m45.entity.PurchaseInHeadVO;
import nc.vo.ic.m45.entity.PurchaseInVO;
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;
@ -24,246 +25,166 @@ import nc.vo.pubapp.pattern.pub.SqlBuilder;
import nc.vo.vorg.DeptVersionVO; import nc.vo.vorg.DeptVersionVO;
import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys; import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* 采购收货单签字后推送MES系统 * 采购入库签字后同步到MES
*/ */
public class AfterSigningSynchronizeRuleMES implements IRule<PurchaseInVO> { public class AfterSigningSynchronizeRuleMES implements IRule<PurchaseInVO> {
private static final String PURCHASE_IN_URL = "/GTHINKING/AjaxService/N_CGSJJSA/102223002.ashx/CGSH_INSERT"; // 采购收货单同步接口
// MES接口URL
private static final String ADD_URL = "/GTHINKING/AjaxService/N_KCSJJS/101527010.ashx/gt_rec_api_cgrkdj";
private static final String DELETE_URL = "/GTHINKING/AjaxService/N_KCSJJS/101527010.ashx/gt_rec_api_qxcgrkdj";
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();
@Override @Override
public void process(PurchaseInVO[] purchaseInVOS) { public void process(PurchaseInVO[] purchaseInVOs) {
try { try {
if (purchaseInVOS == null || purchaseInVOS.length == 0) { if (purchaseInVOs == null || purchaseInVOs.length == 0) {
return;
}
// 检查并筛选采购收货单
List<PurchaseInVO> filteredPurchaseInVOS = checkAndFilterBills(purchaseInVOS);
if (filteredPurchaseInVOS.isEmpty()) {
return; return;
} }
// 初始化HTTP请求工具类 // 初始化HTTP请求工具类
IHttpPostOtherSys httpPostOtherSys = NCLocator.getInstance().lookup(IHttpPostOtherSys.class); IHttpPostOtherSys httpPostOtherSys = NCLocator.getInstance().lookup(IHttpPostOtherSys.class);
// 处理每个采购收货单 for (PurchaseInVO purchaseInVO : purchaseInVOs) {
for (PurchaseInVO purchaseInVO : filteredPurchaseInVOS) { // 判断是否需要同步到MES
PurchaseInHeadVO head = purchaseInVO.getHead(); if (!isSyncToMES(purchaseInVO)) {
PurchaseInBodyVO[] bodys = purchaseInVO.getBodys(); continue;
// 构建要发送的数据 }
JSONObject syncData = buildSyncData(head, bodys);
// 发送数据到MES系统 PurchaseInHeadVO hvo = (PurchaseInHeadVO) purchaseInVO.getParentVO();
httpPostOtherSys.sendToExternalSystem(PURCHASE_IN_URL, syncData); PurchaseInBodyVO[] bvos = (PurchaseInBodyVO[]) purchaseInVO.getChildrenVO();
// 构建请求参数
JSONObject requestParam = buildSyncData(hvo, bvos);
if (requestParam != null) {
// 获取操作类型
String operationType = (String) requestParam.get("operation_type");
// 根据操作类型选择URL
String url = "I".equals(operationType) ? ADD_URL : DELETE_URL;
obmlog.debug("采购入库同步MES-开始处理单据: " + hvo.getVbillcode());
obmlog.debug("采购入库同步MES-请求参数: " + requestParam.toJSONString());
// 调用MES接口
httpPostOtherSys.sendToExternalSystem(url, requestParam);
}
} }
} catch (Exception e) { } catch (Exception e) {
obmlog.error("AfterSigningSynchronizeRuleMES-处理异常:" + e.getMessage(), e); obmlog.error("采购入库同步MES-处理异常:" + e.getMessage(), e);
ExceptionUtils.wrappException(e); ExceptionUtils.wrappException(e);
} }
} }
/** /**
* 检查并筛选需要同步的单据 * 判断是否需要同步到MES
*/ */
private List<PurchaseInVO> checkAndFilterBills(PurchaseInVO[] purchaseInVOS) throws BusinessException { private boolean isSyncToMES(PurchaseInVO purchaseInVO) {
List<PurchaseInVO> result = new ArrayList<>(); // 此处根据业务规则判断是否需要同步
return true;
for (PurchaseInVO vo : purchaseInVOS) {
// 检查组织是否为电缆组织
if (vo.getHead() != null && "0001A110000000000677".equals(vo.getHead().getPk_org())) {
result.add(vo);
}
}
return result;
}
/**
* 构建明细数据
*/
private JSONArray buildDetailsData(PurchaseInBodyVO[] bodys) throws BusinessException {
JSONArray details = new JSONArray();
if (bodys != null) {
for (PurchaseInBodyVO body : bodys) {
JSONObject detailItem = new JSONObject();
// 收货单号必填
detailItem.put("orderNo", null);
// 收货单序号必填- 使用正确的表体字段crowno
detailItem.put("orderSn", body.getCrowno());
// 事务类型必填- 使用表体字段cbodytranstypecode
detailItem.put("type", null);
// 分类必填- H:货款, F:费用, L:劳务
detailItem.put("costOrder", null);
// 采购订单号 - 来源单据号vsourcebillcode
detailItem.put("poNo", body.getVsourcebillcode());
// 采购订单序号 - 来源单据行号vsourcerowno
detailItem.put("poSn", body.getVsourcerowno());
// 物料编码必填
String materialCode = transferCodeByPk(MaterialVO.getDefaultTableName(), MaterialVO.CODE,
MaterialVO.PK_MATERIAL, body.getCmaterialvid());
detailItem.put("materialId", materialCode);
// 计量单位必填- 使用单位castunitid而不是主单位cunitid
detailItem.put("unit", transferCodeByPk(MeasdocVO.getDefaultTableName(), MeasdocVO.CODE, MeasdocVO.PK_MEASDOC, body.getCastunitid()));
// 物料批号
detailItem.put("batchNum", null);
// 制令号 - 在PurchaseInBodyVO中没有直接对应字段可以从vdef字段获取
detailItem.put("productNum", null); // 假设vdef1存储制令号
// 换算系数必填
String scaleFactor = body.getVchangerate();
detailItem.put("scaleFactor", transferSpecialField(scaleFactor));
// TODO 文档必填但是没有对应关系必填
UFDouble taxRate = body.getNtaxrate();
detailItem.put("taxRate", taxRate != null ? taxRate.getDouble() : null);
// 应收数量必填- 使用nshouldassistnum
UFDouble recQty = body.getNshouldassistnum();
detailItem.put("recQty", recQty != null ? recQty.getDouble() : null);
// 主应收数量必填- 使用nshouldnum
UFDouble mainRecQty = body.getNshouldnum();
detailItem.put("mainRecQty", mainRecQty != null ? mainRecQty.getDouble() : null);
// 辅应收数量 - 这可能是自定义字段
detailItem.put("assitRecQty", null);
// 原币含税价格 -
UFDouble priceIncludeTax = body.getNpickupnum();
detailItem.put("priceIncludeTax", priceIncludeTax != null ? priceIncludeTax.getDouble() : null);
// 原币含税金额 - 使用norigtaxmny
UFDouble amountIncludeTax = body.getNorigtaxmny();
detailItem.put("amountIncludeTax", amountIncludeTax != null ? amountIncludeTax.getDouble() : null);
// 原币无税价格 -
UFDouble priceNoTax = body.getNorigprice();
detailItem.put("priceNoTax", priceNoTax != null ? priceNoTax.getDouble() : null);
// 原币无税金额 - 使用norigmny
UFDouble amountNoTax = body.getNqtnetprice();
detailItem.put("amountNoTax", amountNoTax != null ? amountNoTax.getDouble() : null);
// 税额 - 使用ntax
UFDouble taxAmount = body.getNtax();
detailItem.put("taxAmount", taxAmount != null ? taxAmount.getDouble() : null);
// 备注 - 使用vnotebody
detailItem.put("remark", body.getVnotebody());
// 原收货单信息
detailItem.put("oldOrderNo", null);
detailItem.put("oldOrderSn", null);
details.add(detailItem);
}
}
return details;
} }
/** /**
* 构建符合MES系统接口规范的请求数据 * 构建符合MES系统接口规范的请求数据
*/ */
private JSONObject buildSyncData(PurchaseInHeadVO head, PurchaseInBodyVO[] bodys) throws BusinessException { private JSONObject buildSyncData(PurchaseInHeadVO hvo, PurchaseInBodyVO[] bvos) throws BusinessException {
// 创建请求数据 obmlog.debug("采购入库同步MES-开始构建数据: " + hvo.getVbillcode());
JSONObject requestData = new JSONObject(); JSONObject requestData = new JSONObject();
JSONObject data = new JSONObject(); // 设置操作类型
requestData.put("operation_type", "I"); // 签字为新增操作
// 设置收货单主表信息 // 构建data数组
// 收货单号必填 List<JSONObject> dataList = new ArrayList<>();
data.put("orderNo", head.getVbillcode());
// 收货日期
UFDate dbilldate = head.getDbilldate();
data.put("orderDate", dbilldate != null ? dbilldate.toString().substring(0, 10) : null);
// 收货类型
data.put("orderType", "P");
// 事务类型
data.put("type", null);
// 仓库编码
String storeId = transferCodeByPk(StordocVO.getDefaultTableName(), StordocVO.CODE,
StordocVO.PK_STORDOC, head.getCwarehouseid());
data.put("storeId", storeId);
// 采购部门ID必填- 注意根据字段字典采购部门字段为cdptid而不是cdeptid JSONObject dataObj = new JSONObject();
String departmentId = transferCodeByPk(DeptVersionVO.getDefaultTableName(), DeptVersionVO.CODE,
DeptVersionVO.PK_VID, head.getCdptvid());
data.put("departmentId", departmentId);
// 采购员 - 采购员字段为cbizid
String purchaser = transferCodeByPk(PsndocVO.getDefaultTableName(), PsndocVO.CODE,
PsndocVO.PK_PSNDOC, head.getCbizid());
data.put("purchaser", purchaser);
// 供应商编码必填
String supplyId = transferCodeByPk(SupplierVO.getDefaultTableName(), SupplierVO.CODE,
SupplierVO.PK_SUPPLIER, head.getCvendorid());
data.put("supplyId", supplyId);
// 货币ID
data.put("currency", null);
// 汇率必填
data.put("rate", null);
// 结算方式
data.put("settleType", null);
// 开票依据
data.put("billBasis", null);
// 生成方式必填- P:按采购订单, Z:直接生成
data.put("genType", "P");
// 分类必填- N:货物, Y:费用
data.put("costOrder", "N");
// 是否退货必填- N:, Y:
data.put("returned", head.getFreplenishflag());
// 备注
data.put("remark", head.getVnote());
// 维护人信息
data.put("creatorNo", null); // 创建人
data.put("creator", head.getBillmaker()); // 制单人
data.put("creatTime", head.getDmakedate() != null ? head.getCreationtime().toString() : null); // 创建时间
// 构建明细数据 // 设置入库单基本信息
JSONArray details = buildDetailsData(bodys); UFDate billDate = hvo.getDbilldate();
data.put("Details", details); dataObj.put("orderDate", billDate != null ? billDate.toString().substring(0, 10) : ""); // 入库日期 - 格式yyyy-MM-dd
requestData.put("Data", data); dataObj.put("originalOrderNo", hvo.getVbillcode()); // 采购收货单号
// 仓库编码 - 使用正确的仓库字段(cwarehouseid)
dataObj.put("warehouseId", transferCodeByPk(StordocVO.getDefaultTableName(),
StordocVO.CODE, StordocVO.PK_STORDOC, hvo.getCwarehouseid())); // 仓库编码
obmlog.debug("AfterSigningSynchronizeRuleMES-采购收货单请求数据: " + requestData.toJSONString()); // 部门ID - 采购部门最新版本(cdptid)而非cdptvidcdptvid是部门版本信息
dataObj.put("departmentId", transferCodeByPk(DeptVersionVO.getDefaultTableName(),
DeptVersionVO.CODE, DeptVersionVO.PK_VID, hvo.getCdptvid())); // 部门编码
// 保管员
dataObj.put("creator", transferCodeByPk(PsndocVO.getDefaultTableName(),
PsndocVO.NAME, PsndocVO.PK_PSNDOC, hvo.getCwhsmanagerid())); // 保管员
dataObj.put("remark", hvo.getVnote()); // 备注
// 添加采购员信息 - 来自cbizid字段
String purchaser = transferCodeByPk(PsndocVO.getDefaultTableName(),
PsndocVO.NAME, PsndocVO.PK_PSNDOC, hvo.getCbizid());
if (purchaser != null && !purchaser.isEmpty()) {
dataObj.put("purchaser", purchaser); // 采购员
}
// 添加供应商信息 - 来自cvendorid字段
String supplier = transferCodeByPk(SupplierVO.getDefaultTableName(),
SupplierVO.CODE, SupplierVO.PK_SUPPLIER, hvo.getCvendorid());
if (supplier != null && !supplier.isEmpty()) {
dataObj.put("supplierId", supplier); // 供应商编码
}
// 构建明细
List<JSONObject> detailsList = new ArrayList<>();
if (bvos != null) {
for (PurchaseInBodyVO bvo : bvos) {
JSONObject detailMap = new JSONObject();
// TODO 没有字段
detailMap.put("originalOrderNo", hvo.getVbillcode()); // 采购收货单号
detailMap.put("sequenceNum", bvo.getCrowno()); // 采购收货单序号
// 物料编码 - 必填
detailMap.put("materialId", transferCodeByPk(MaterialVO.getDefaultTableName(),
MaterialVO.CODE, MaterialVO.PK_MATERIAL, bvo.getCmaterialoid())); // 物料编码
// 库位编码 - 根据字段表使用clocationid而非cspaceid
detailMap.put("storageId", transferCodeByPk(RackVO.getDefaultTableName(),
RackVO.CODE, RackVO.PK_RACK, bvo.getClocationid())); // 库位编码
detailMap.put("batchNum", bvo.getVbatchcode()); // 物料批号
// 数量信息 - 根据字段表修正
UFDouble assistNum = bvo.getNassistnum(); // 实收数量
detailMap.put("quantity", assistNum != null ? assistNum.doubleValue() : null); // 入库数量
UFDouble mainNum = bvo.getNnum(); // 实收主数量
detailMap.put("mQuantity", mainNum != null ? mainNum.doubleValue() : null); // 主入库数量
// 供应商编码 - 根据字段表使用cvendorid而非csupplierid
detailMap.put("supplierId", transferCodeByPk(SupplierVO.getDefaultTableName(),
SupplierVO.CODE, SupplierVO.PK_SUPPLIER, bvo.getCvendorid())); // 供应商编码
// 生产日期 - 字段表确认为dproducedate
UFDate produceDate = bvo.getDproducedate();
if (produceDate != null) {
detailMap.put("manufactureDate", produceDate.toString().substring(0, 10));
}
detailsList.add(detailMap);
}
}
dataObj.put("details", detailsList);
dataList.add(dataObj);
requestData.put("data", dataList);
return requestData; return requestData;
} }
/** /**
* 转换特殊字段 1/1 转换为小数 1.0 * 根据主键查询对应的编码
*/ */
private String transferCodeByPk(String tableName, String selectField, String pkField, Object pk) throws BusinessException {
private String transferSpecialField(String field) { if (pk == null || "".equals(pk.toString().trim())) {
if (field == null || field.trim().isEmpty()) {
return null;
}
String[] split = field.split("/");
if (split.length == 2) {
String numStr = split[0].trim();
String denStr = split[1].trim();
if (denStr.equals("0")) {
return "0.00"; // 分母不能为零
}
try {
BigDecimal numerator = new BigDecimal(numStr);
BigDecimal denominator = new BigDecimal(denStr);
return numerator.divide(denominator, 2, RoundingMode.HALF_UP).toString();
} catch (NumberFormatException e) {
return field; // 非法数字返回原字段
}
}
return field;
}
/**
* 根据主键查询编码
*/
private String transferCodeByPk(String tableName, String selectField, String pkField, String pk) throws BusinessException {
if (StringUtils.isEmpty(pk)) {
return null; return null;
} }
SqlBuilder sqlBuilder = new SqlBuilder(); SqlBuilder sqlBuilder = new SqlBuilder();
sqlBuilder.append(" select " + selectField); sqlBuilder.append(" select " + selectField);
sqlBuilder.append(" from " + tableName); sqlBuilder.append(" from " + tableName);
sqlBuilder.append(" where "); sqlBuilder.append(" where ");
sqlBuilder.append(pkField, pk); sqlBuilder.append(pkField, pk.toString());
Object o = dao.executeQuery(sqlBuilder.toString(), new ColumnProcessor()); Object o = dao.executeQuery(sqlBuilder.toString(), new ColumnProcessor());
if (o == null) { if (o == null) {
throw new BusinessException("未查询到编码信息sql【" + sqlBuilder + ""); obmlog.warn("未查询到编码信息sql【" + sqlBuilder + "");
return null;
} }
return o.toString(); return o.toString();
} }

View File

@ -0,0 +1,312 @@
package nc.bs.ic.m45.sign.rule;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Log;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.material.measdoc.MeasdocVO;
import nc.vo.bd.psn.PsndocVO;
import nc.vo.bd.stordoc.StordocVO;
import nc.vo.bd.supplier.SupplierVO;
import nc.vo.cmp.util.StringUtils;
import nc.vo.ic.m45.entity.PurchaseInVO;
import nc.vo.ic.m45.entity.PurchaseInBodyVO;
import nc.vo.ic.m45.entity.PurchaseInHeadVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.pattern.pub.SqlBuilder;
import nc.vo.vorg.DeptVersionVO;
import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
/**
* (前置)采购收货单推送MES系统,后续调用采购入库
*/
public class PurchaseReceiptRuleMES implements IRule<PurchaseInVO> {
private static final String PURCHASE_IN_URL = "/GTHINKING/AjaxService/N_CGSJJSA/102223002.ashx/CGSH_INSERT"; // 采购收货单同步接口
private static final String PURCHASE_DELETE_URL = "/GTHINKING/AjaxService/N_CGSJJSA/102223002.ashx/CGSH_DELETE"; // 采购收货单删除接口
private static final String logginfo = "OALOG";
private static final Log obmlog = Log.getInstance(logginfo);
private static final BaseDAO dao = new BaseDAO();
@Override
public void process(PurchaseInVO[] purchaseInVOS) {
try {
if (purchaseInVOS == null || purchaseInVOS.length == 0) {
return;
}
// 检查并筛选采购收货单
List<PurchaseInVO> filteredPurchaseInVOS = checkAndFilterBills(purchaseInVOS);
if (filteredPurchaseInVOS.isEmpty()) {
return;
}
// 初始化HTTP请求工具类
IHttpPostOtherSys httpPostOtherSys = NCLocator.getInstance().lookup(IHttpPostOtherSys.class);
// 处理每个采购收货单
for (PurchaseInVO purchaseInVO : filteredPurchaseInVOS) {
PurchaseInHeadVO head = purchaseInVO.getHead();
PurchaseInBodyVO[] bodys = purchaseInVO.getBodys();
// 每次新增采购收货单前先删除第三方系统中已有的数据再进行新增
String orderNo = head.getVbillcode();
boolean deleteSuccess = deletePurchaseReceipt(orderNo);
if (deleteSuccess) {
// 构建要发送的数据
JSONObject syncData = buildSyncData(head, bodys);
// 发送数据到MES系统
obmlog.debug("PurchaseReceiptRuleMES-准备发送采购收货单数据: " + orderNo);
httpPostOtherSys.sendToExternalSystem(PURCHASE_IN_URL, syncData);
}
}
} catch (Exception e) {
obmlog.error("AfterSigningSynchronizeRuleMES-处理异常:" + e.getMessage(), e);
ExceptionUtils.wrappException(e);
}
}
/**
* 删除第三方系统中的采购收货单
*
* @param orderNo 要删除的采购收货单号
* @return 删除操作是否成功
* @throws BusinessException 业务异常
*/
public boolean deletePurchaseReceipt(String orderNo) throws BusinessException {
try {
if (orderNo == null || orderNo.trim().isEmpty()) {
throw new BusinessException("采购收货单号不能为空");
}
obmlog.debug("PurchaseReceiptRuleMES-准备删除第三方系统采购收货单: " + orderNo);
// 构建请求数据
JSONObject requestData = new JSONObject();
JSONObject dataObj = new JSONObject();
dataObj.put("orderNo", orderNo);
requestData.put("Data", dataObj);
// 初始化HTTP请求工具类
IHttpPostOtherSys httpPostOtherSys = NCLocator.getInstance().lookup(IHttpPostOtherSys.class);
// 发送删除请求
String response = httpPostOtherSys.callMes(PURCHASE_DELETE_URL, requestData);
obmlog.debug("PurchaseReceiptRuleMES-删除请求返回结果: " + response);
// 解析返回结果
JSONObject jsonResponse = JSONObject.parseObject(response);
boolean isSuccess = jsonResponse.getBooleanValue("Success");
String errorMessage = jsonResponse.getString("ErrorMessage");
if (!isSuccess) {
obmlog.error("PurchaseReceiptRuleMES-删除采购收货单失败: " + orderNo + ", 错误信息: " + errorMessage);
throw new BusinessException("删除采购收货单失败: " + (errorMessage != null ? errorMessage : "未知错误"));
}
obmlog.debug("PurchaseReceiptRuleMES-成功删除采购收货单: " + orderNo);
return true;
} catch (Exception e) {
obmlog.error("PurchaseReceiptRuleMES-删除采购收货单异常:" + e.getMessage(), e);
throw new BusinessException("删除采购收货单时发生异常: " + e.getMessage(), e);
}
}
/**
* 检查并筛选需要同步的单据
*/
private List<PurchaseInVO> checkAndFilterBills(PurchaseInVO[] purchaseInVOS) throws BusinessException {
List<PurchaseInVO> result = new ArrayList<>();
for (PurchaseInVO vo : purchaseInVOS) {
// 检查组织是否为电缆组织
if (vo.getHead() != null && "0001A110000000000677".equals(vo.getHead().getPk_org())) {
result.add(vo);
}
}
return result;
}
/**
* 构建符合MES系统接口规范的请求数据
*/
private JSONObject buildSyncData(PurchaseInHeadVO head, PurchaseInBodyVO[] bodys) throws BusinessException {
// 创建请求数据
JSONObject requestData = new JSONObject();
JSONObject data = new JSONObject();
// 设置收货单主表信息
// 收货单号必填- 映射为vbillcode
data.put("orderNo", head.getVbillcode());
// 收货日期 - 映射为dbilldate (格式yyyy-MM-dd)
UFDate dbilldate = head.getDbilldate();
data.put("orderDate", dbilldate != null ? dbilldate.toString().substring(0, 10) : null);
// 收货类型 - 默认为"P"(外购)
data.put("orderType", "P");
// 事务类型
data.put("type", "WGRK");
// 仓库编码 - 映射为cwarehouseid
data.put("storeId", transferCodeByPk(StordocVO.getDefaultTableName(), StordocVO.CODE,
StordocVO.PK_STORDOC, head.getCwarehouseid()));
// 采购部门ID必填- 映射为cdptvid
data.put("departmentId", transferCodeByPk(DeptVersionVO.getDefaultTableName(), DeptVersionVO.CODE,
DeptVersionVO.PK_VID, head.getCdptvid()));
// 采购员 - 映射为cbizid
String purchaser = transferCodeByPk(PsndocVO.getDefaultTableName(), PsndocVO.CODE,
PsndocVO.PK_PSNDOC, head.getCbizid());
data.put("purchaser", purchaser);
// 供应商编码必填- 映射为cvendorid
String supplyId = transferCodeByPk(SupplierVO.getDefaultTableName(), SupplierVO.CODE,
SupplierVO.PK_SUPPLIER, head.getCvendorid());
data.put("supplyId", supplyId);
// 货币ID - 暂无明确映射
data.put("currency", null);
//汇率必填
data.put("rate", 1);
// 结算方式 - 默认为"S"(转账)
data.put("settleType", "S");
// 开票依据 - 默认为"S"(实收数)
data.put("billBasis", "S");
// 生成方式必填- 默认为"P"(按采购订单)
data.put("genType", "P");
// 分类必填- 默认为"N"(货物)
data.put("costOrder", "N");
// 是否退货必填- 映射为freplenishflag如果为Y则为退货
data.put("returned", head.getFreplenishflag());
// 备注 - 映射为vnote
data.put("remark", head.getVnote());
// 维护人信息
data.put("creatorNo", null); // 创建人工号
data.put("creator", head.getBillmaker()); // 制单人
data.put("creatTime", head.getDmakedate() != null ? head.getDmakedate().toString() : null); // 创建时间
// 构建明细数据
JSONArray details = new JSONArray();
if (bodys != null) {
for (PurchaseInBodyVO body : bodys) {
JSONObject detailItem = new JSONObject();
// 收货单号必填- 在buildSyncData方法中设置
detailItem.put("orderNo", dbilldate != null ? dbilldate.toString().substring(0, 10) : null);
// 收货单序号必填- 映射为行号(crowno)
detailItem.put("orderSn", body.getCrowno());
// 事务类型必填- 使用表体字段cbodytranstypecode
detailItem.put("type", "WGRK");
// 分类必填- 默认设置为"H" - H:货款, F:费用, L:劳务
detailItem.put("costOrder", "H");
// 采购订单号 - 来源单据号(vsourcebillcode)
detailItem.put("poNo", body.getVsourcebillcode());
// 采购订单序号 - 来源单据行号(vsourcerowno)
detailItem.put("poSn", body.getVsourcerowno());
// 物料编码必填- 映射为cmaterialvid
String materialCode = transferCodeByPk(MaterialVO.getDefaultTableName(), MaterialVO.CODE,
MaterialVO.PK_MATERIAL, body.getCmaterialvid());
detailItem.put("materialId", materialCode);
// 计量单位必填- 映射为castunitid而不是cunitid
detailItem.put("unit", transferCodeByPk(MeasdocVO.getDefaultTableName(), MeasdocVO.CODE,
MeasdocVO.PK_MEASDOC, body.getCastunitid()));
// 物料批号 - 映射为vbatchcode
detailItem.put("batchNum", body.getVbatchcode());
// 制令号 - 在BIP系统中没有对应字段可以从自定义字段获取
detailItem.put("productNum", body.getVbdef1()); // 假设存储在自定义字段1中
// 换算系数必填- 映射为vchangerate
String scaleFactor = body.getVchangerate();
detailItem.put("scaleFactor", transferSpecialField(scaleFactor));
// 税率必填- 映射为ntaxrate
UFDouble taxRate = body.getNtaxrate();
detailItem.put("taxRate", taxRate != null ? taxRate.doubleValue() : null);
// 应收数量必填- 映射为nshouldassistnum
UFDouble recQty = body.getNshouldassistnum();
detailItem.put("recQty", recQty != null ? recQty.doubleValue() : null);
// 主应收数量必填- 映射为nshouldnum
UFDouble mainRecQty = body.getNshouldnum();
detailItem.put("mainRecQty", mainRecQty != null ? mainRecQty.doubleValue() : null);
// 辅应收数量 - 在BIP系统中没有明确对应字段
detailItem.put("assitRecQty", null);
// 原币含税价格 - 映射为npickupnum
UFDouble priceIncludeTax = body.getNpickupnum();
detailItem.put("priceIncludeTax", priceIncludeTax != null ? priceIncludeTax.doubleValue() : null);
// 原币含税金额 - 映射为norigtaxmny
UFDouble amountIncludeTax = body.getNorigtaxmny();
detailItem.put("amountIncludeTax", amountIncludeTax != null ? amountIncludeTax.doubleValue() : null);
// 原币无税价格 - 映射为norigprice
UFDouble priceNoTax = body.getNorigprice();
detailItem.put("priceNoTax", priceNoTax != null ? priceNoTax.doubleValue() : null);
// 原币无税金额 - 映射为nqtnetprice
UFDouble amountNoTax = body.getNqtnetprice();
detailItem.put("amountNoTax", amountNoTax != null ? amountNoTax.doubleValue() : null);
// 税额 - 映射为ntax
UFDouble taxAmount = body.getNtax();
detailItem.put("taxAmount", taxAmount != null ? taxAmount.doubleValue() : null);
// 备注 - 映射为vnotebody
detailItem.put("remark", body.getVnotebody());
// 原收货单信息 - 如果是退货单需要设置原单信息
detailItem.put("oldOrderNo", null);
detailItem.put("oldOrderSn", null);
details.add(detailItem);
}
}
data.put("Details", details);
requestData.put("Data", data);
obmlog.debug("PurchaseReceiptRuleMES-采购收货单请求数据: " + requestData.toJSONString());
return requestData;
}
/**
* 转换特殊字段 1/1 转换为小数 1.0
*/
private String transferSpecialField(String field) {
if (field == null || field.trim().isEmpty()) {
return null;
}
String[] split = field.split("/");
if (split.length == 2) {
String numStr = split[0].trim();
String denStr = split[1].trim();
if (denStr.equals("0")) {
return "0.00"; // 分母不能为零
}
try {
BigDecimal numerator = new BigDecimal(numStr);
BigDecimal denominator = new BigDecimal(denStr);
return numerator.divide(denominator, 2, RoundingMode.HALF_UP).toString();
} catch (NumberFormatException e) {
return field; // 非法数字返回原字段
}
}
return field;
}
/**
* 根据主键查询编码
*/
private String transferCodeByPk(String tableName, String selectField, String pkField, String pk) throws BusinessException {
if (StringUtils.isEmpty(pk)) {
return null;
}
SqlBuilder sqlBuilder = new SqlBuilder();
sqlBuilder.append(" select " + selectField);
sqlBuilder.append(" from " + tableName);
sqlBuilder.append(" where ");
sqlBuilder.append(pkField, pk);
Object o = dao.executeQuery(sqlBuilder.toString(), new ColumnProcessor());
if (o == null) {
throw new BusinessException("未查询到编码信息sql【" + sqlBuilder + "");
}
return o.toString();
}
}

View File

@ -74,10 +74,10 @@ public class AfterSigningSynchronizeRuleMES implements IRule<SaleOutVO> {
*/ */
private JSONObject buildSyncData(SaleOutHeadVO hvo, SaleOutBodyVO[] bvos) throws BusinessException { private JSONObject buildSyncData(SaleOutHeadVO hvo, SaleOutBodyVO[] bvos) throws BusinessException {
obmlog.debug("AfterSigningSynchronizeRule-开始处理销售出库单: " + hvo.getVbillcode()); obmlog.debug("AfterSigningSynchronizeRule-开始处理销售出库单: " + hvo.getVbillcode());
if (!hvo.getPk_org().equals("0001A110000000000677")) { // if (!hvo.getPk_org().equals("0001A110000000000677")) {
obmlog.debug("AfterSigningSynchronizeRule-跳过处理销售出库单,因为此单据组织非电缆: " + hvo.getVbillcode()); // obmlog.debug("AfterSigningSynchronizeRule-跳过处理销售出库单,因为此单据组织非电缆: " + hvo.getVbillcode());
return null; // return null;
} // }
JSONObject requestData = new JSONObject(); JSONObject requestData = new JSONObject();
JSONObject dataObj = new JSONObject(); JSONObject dataObj = new JSONObject();
@ -90,18 +90,17 @@ public class AfterSigningSynchronizeRuleMES implements IRule<SaleOutVO> {
dataObj.put("actureDate", dbilldate.toString().substring(0, 10)); // 实际日期 - 单据日期(dbilldate)格式yyyy-MM-dd dataObj.put("actureDate", dbilldate.toString().substring(0, 10)); // 实际日期 - 单据日期(dbilldate)格式yyyy-MM-dd
dataObj.put("orderType", null); // 收货类型 - 无对应字段 dataObj.put("orderType", null); // 收货类型 - 无对应字段
dataObj.put("type", "XSCK"); // 事务类型 - 销售出库 dataObj.put("type", "XSCK"); // 事务类型 - 销售出库
// 汇率 默认为1
dataObj.put("exRate", 1);
// 部门ID - 部门(cdptvid) // 部门ID - 部门(cdptvid)
dataObj.put("departmentId", transferCodeByPk(DeptVO.getDefaultTableName(), dataObj.put("departmentId", transferCodeByPk(DeptVO.getDefaultTableName(),
DeptVO.CODE, DeptVO.PK_DEPT, hvo.getCdptvid())); // 采购部门ID DeptVO.CODE, DeptVO.PK_DEPT, hvo.getCdptvid())); // 采购部门ID
// 仓库编码 - 仓库(cwarehouseid) // 仓库编码 - 仓库(cwarehouseid)
dataObj.put("storeId", transferCodeByPk(RackVO.getDefaultTableName(), dataObj.put("storeId", transferCodeByPk(RackVO.getDefaultTableName(),
RackVO.CODE, RackVO.PK_RACK, hvo.getCwarehouseid())); // 仓库编码 RackVO.CODE, RackVO.PK_RACK, hvo.getCwarehouseid())); // 仓库编码
// 采购员 - 业务员(cbizpersonid) // 采购员 - 业务员(cbizpersonid)
dataObj.put("purchaser", transferCodeByPk(PsndocVO.getDefaultTableName(), dataObj.put("purchaser", transferCodeByPk(PsndocVO.getDefaultTableName(),
PsndocVO.CODE, PsndocVO.PK_PSNDOC, hvo.getCbizid())); PsndocVO.CODE, PsndocVO.PK_PSNDOC, hvo.getCbizid()));
// 客户ID - 订单客户(ccustomerid)这里因为是采购所以用供应商映射 // 客户ID - 订单客户(ccustomerid)这里因为是采购所以用供应商映射
dataObj.put("supplyId", transferCodeByPk(CustomerVO.getDefaultTableName(), dataObj.put("supplyId", transferCodeByPk(CustomerVO.getDefaultTableName(),
CustomerVO.CODE, CustomerVO.PK_CUSTOMER, hvo.getCcustomerid())); CustomerVO.CODE, CustomerVO.PK_CUSTOMER, hvo.getCcustomerid()));
@ -126,58 +125,45 @@ public class AfterSigningSynchronizeRuleMES implements IRule<SaleOutVO> {
//客户ID //客户ID
dataObj.put("customId", transferCodeByPk(CustomerVO.getDefaultTableName(), CustomerVO.CODE, CustomerVO.PK_CUSTOMER, hvo.getCcustomerid())); dataObj.put("customId", transferCodeByPk(CustomerVO.getDefaultTableName(), CustomerVO.CODE, CustomerVO.PK_CUSTOMER, hvo.getCcustomerid()));
//生成标志 //生成标志
dataObj.put("mark", "Y"); dataObj.put("mark", "W");
//备注 //备注
dataObj.put("remark", hvo.getVnote()); dataObj.put("remark", hvo.getVnote());
// 构建Details明细数组 // 构建Details明细数组
JSONArray details = new JSONArray(); JSONArray details = new JSONArray();
if (bvos != null) { if (bvos != null) {
for (SaleOutBodyVO bvo : bvos) { for (SaleOutBodyVO bvo : bvos) {
// 汇率
dataObj.put("exRate", bvo.getNchangestdrate());
JSONObject detail = new JSONObject(); JSONObject detail = new JSONObject();
detail.put("orderNo", hvo.getVbillcode()); // 提货单ID - 单据号(vbillcode) - 必填 detail.put("orderNo", hvo.getVbillcode()); // 提货单ID - 单据号(vbillcode) - 必填
detail.put("sequenceNum", bvo.getCrowno()); // 提货单序号 - 行号(crowno) - 必填 detail.put("sequenceNum", bvo.getCrowno()); // 提货单序号 - 行号(crowno) - 必填
detail.put("type", "XSCK"); // 事务类型 - 默认XSCK detail.put("type", "XSCK"); // 事务类型 - 默认XSCK
// 来源单据信息 // 来源单据信息
detail.put("saleOrderNo", bvo.getVsourcebillcode()); // SOID - 来源单据号(vsourcebillcode) detail.put("saleOrderNo", bvo.getVsourcebillcode()); // SOID - 来源单据号(vsourcebillcode)
detail.put("saleSequenceNum", bvo.getVsourcerowno()); // SO序号 - 来源单据行号(vsourcerowno) detail.put("saleSequenceNum", bvo.getVsourcerowno()); // SO序号 - 来源单据行号(vsourcerowno)
detail.put("allocationNum", null); // 分配号 detail.put("allocationNum", null); // 分配号
// 物料信息 - 必填 // 物料信息 - 必填
detail.put("materialId", transferCodeByPk(MaterialVO.getDefaultTableName(), detail.put("materialId", transferCodeByPk(MaterialVO.getDefaultTableName(),
MaterialVO.CODE, MaterialVO.PK_MATERIAL, bvo.getCmaterialoid())); // 物料ID - 必填 MaterialVO.CODE, MaterialVO.PK_MATERIAL, bvo.getCmaterialoid())); // 物料ID - 必填
detail.put("unit", transferCodeByPk(MeasdocVO.getDefaultTableName(), detail.put("unit", transferCodeByPk(MeasdocVO.getDefaultTableName(),
MeasdocVO.CODE, MeasdocVO.PK_MEASDOC, bvo.getCunitid())); // 计量单位 - 必填 MeasdocVO.CODE, MeasdocVO.PK_MEASDOC, bvo.getCunitid())); // 计量单位 - 必填
detail.put("productNum", null); // 制令号 detail.put("productNum", null); // 制令号
// 库位 - 必填 // 库位 - 必填
detail.put("storageId", transferCodeByPk(RackVO.getDefaultTableName(), detail.put("storageId", transferCodeByPk(RackVO.getDefaultTableName(),
RackVO.CODE, RackVO.PK_RACK, bvo.getClocationid())); // 库位 - 必填 RackVO.CODE, RackVO.PK_RACK, bvo.getClocationid())); // 库位 - 必填
detail.put("batchNum", bvo.getVbatchcode()); // 物料批号 - 必填 detail.put("batchNum", bvo.getVbatchcode()); // 物料批号 - 必填
detail.put("scaleFactor", transferSpecialField(bvo.getVchangerate())); // 换算系数 - 必填 detail.put("scaleFactor", transferSpecialField(bvo.getVchangerate())); // 换算系数 - 必填
// 数量信息 - 必填 // 数量信息 - 必填
detail.put("issuedQty", bvo.getNshouldassistnum()); // 应发数量 - 必填 detail.put("issuedQty", bvo.getNshouldassistnum()); // 应发数量 - 必填
detail.put("mIssuedQty", bvo.getNshouldnum()); // 主应发数量 - 必填 detail.put("mIssuedQty", bvo.getNshouldnum()); // 主应发数量 - 必填
detail.put("actQry", bvo.getNassistnum()); // 实发数量 - 必填 detail.put("actQry", bvo.getNassistnum()); // 实发数量 - 必填
detail.put("mActQry", bvo.getNnum()); // 主实发数量 - 必填 detail.put("mActQry", bvo.getNnum()); // 主实发数量 - 必填
detail.put("assistActQry", bvo.getNassistnum()); // 辅助实发数量 - 必填 detail.put("assistActQry", bvo.getNassistnum()); // 辅助实发数量 - 必填
// 客户和供应商信息 // 客户和供应商信息
detail.put("customId", transferCodeByPk(CustomerVO.getDefaultTableName(), detail.put("customId", transferCodeByPk(CustomerVO.getDefaultTableName(),
CustomerVO.CODE, CustomerVO.PK_CUSTOMER, bvo.getCasscustid())); // 客户ID CustomerVO.CODE, CustomerVO.PK_CUSTOMER, bvo.getCasscustid())); // 客户ID
detail.put("supplierId", transferCodeByPk(SupplierVO.getDefaultTableName(), detail.put("supplierId", transferCodeByPk(SupplierVO.getDefaultTableName(),
SupplierVO.CODE, SupplierVO.PK_SUPPLIER, bvo.getCvendorid())); // 供应商ID SupplierVO.CODE, SupplierVO.PK_SUPPLIER, bvo.getCvendorid())); // 供应商ID
detail.put("manufactureDate", bvo.getDproducedate()); // 生产日期 detail.put("manufactureDate", bvo.getDproducedate()); // 生产日期
detail.put("color", null); // 颜色 detail.put("color", null); // 颜色
detail.put("properties", null); detail.put("properties", null);

View File

@ -12,12 +12,10 @@ import nc.vo.bd.cust.CustomerVO;
import nc.vo.bd.material.MaterialVO; import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.material.measdoc.MeasdocVO; import nc.vo.bd.material.measdoc.MeasdocVO;
import nc.vo.bd.psn.PsndocVO; import nc.vo.bd.psn.PsndocVO;
import nc.vo.bd.rack.RackVO; import nc.vo.bd.stordoc.StordocVO;
import nc.vo.bd.supplier.SupplierVO;
import nc.vo.ic.m4c.entity.SaleOutBodyVO; import nc.vo.ic.m4c.entity.SaleOutBodyVO;
import nc.vo.ic.m4c.entity.SaleOutHeadVO; import nc.vo.ic.m4c.entity.SaleOutHeadVO;
import nc.vo.ic.m4c.entity.SaleOutVO; import nc.vo.ic.m4c.entity.SaleOutVO;
import nc.vo.org.DeptVO;
import nc.vo.pub.BusinessException; import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils; import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.pattern.pub.SqlBuilder; import nc.vo.pubapp.pattern.pub.SqlBuilder;
@ -29,12 +27,12 @@ import java.math.RoundingMode;
/** /**
* 销售交货单(BIP无) 推送至MES * (前置)销售交货单(BIP无) 推送至MES
*/ */
public class SalesDeliveryOrderRuleMES implements IRule<SaleOutVO> { public class SalesDeliveryOrderRuleMES implements IRule<SaleOutVO> {
private static final BaseDAO dao = new BaseDAO(); private static final BaseDAO dao = new BaseDAO();
// MES系统API接口地址 // MES系统API接口地址
private static final String MES_API_URL = "/GTHINKING/AjaxService/N_MISPRO/SalesDeliveryOrder.ashx/SaveData"; private static final String MES_API_URL = "/GTHINKING/AjaxService/N_XSSJJSA/102397002.ashx/SOTH_INSERT";
// 删除销售交货单接口地址 // 删除销售交货单接口地址
private static final String MES_DELETE_API_URL = "/GTHINKING/AjaxService/N_XSSJJSA/102397002.ashx/SOTH_DELETE"; private static final String MES_DELETE_API_URL = "/GTHINKING/AjaxService/N_XSSJJSA/102397002.ashx/SOTH_DELETE";
private static final Log obmlog = Log.getInstance("OALOG"); private static final Log obmlog = Log.getInstance("OALOG");
@ -80,10 +78,10 @@ public class SalesDeliveryOrderRuleMES implements IRule<SaleOutVO> {
obmlog.debug("SalesDeliveryOrderRuleMES-开始处理销售交货单: " + hvo.getVbillcode()); obmlog.debug("SalesDeliveryOrderRuleMES-开始处理销售交货单: " + hvo.getVbillcode());
// 检查组织是否符合条件 // 检查组织是否符合条件
if (!hvo.getPk_org().equals("0001A110000000000677")) { // if (!hvo.getPk_org().equals("0001A110000000000677")) {
obmlog.debug("SalesDeliveryOrderRuleMES-跳过处理销售交货单,因为此单据组织非电缆: " + hvo.getVbillcode()); // obmlog.debug("SalesDeliveryOrderRuleMES-跳过处理销售交货单,因为此单据组织非电缆: " + hvo.getVbillcode());
return null; // return null;
} // }
JSONObject requestData = new JSONObject(); JSONObject requestData = new JSONObject();
JSONObject info = new JSONObject(); JSONObject info = new JSONObject();
@ -106,9 +104,10 @@ public class SalesDeliveryOrderRuleMES implements IRule<SaleOutVO> {
info.put("invoicingBasis", "S"); // 必填开票依据 info.put("invoicingBasis", "S"); // 必填开票依据
info.put("settlementType", "S"); // 必填结算方式 info.put("settlementType", "S"); // 必填结算方式
// 仓库编码 // 仓库编码
info.put("warehouseId", transferCodeByPk(RackVO.getDefaultTableName(), info.put("warehouseId", transferCodeByPk(StordocVO.getDefaultTableName(),
RackVO.CODE, RackVO.PK_RACK, hvo.getCwarehouseid())); // 必填仓库编码 StordocVO.CODE, StordocVO.PK_STORDOC, hvo.getCwarehouseid())); // 必填仓库编码
info.put("type", "XSJH"); // 必填事务类型销售交货 // 必填事务类型
info.put("type", "XSCK");
// 必填生成方式 // 必填生成方式
info.put("genType", "S"); info.put("genType", "S");
// 必填是否退货 // 必填是否退货
@ -123,18 +122,16 @@ public class SalesDeliveryOrderRuleMES implements IRule<SaleOutVO> {
info.put("creatorNo", null); // 维护人工号 info.put("creatorNo", null); // 维护人工号
info.put("creator", null); // 维护人 info.put("creator", null); // 维护人
info.put("creatTime", null); // 维护时间 info.put("creatTime", null); // 维护时间
// 表头字段需要表体字段
// 必填汇率
info.put("exchangeRate", 1);
// 必填货币编码
info.put("currency", "CNY");
// 构建明细数组 // 构建明细数组
JSONArray details = new JSONArray(); JSONArray details = new JSONArray();
if (bvos != null) { if (bvos != null) {
for (SaleOutBodyVO bvo : bvos) { for (SaleOutBodyVO bvo : bvos) {
JSONObject detail = new JSONObject(); JSONObject detail = new JSONObject();
// 表头字段需要表体字段
// 必填汇率
info.put("exchangeRate", bvo.getNchangestdrate());
// 必填货币编码
info.put("currency", transferCodeByPk(CurrtypeVO.getDefaultTableName(),
CurrtypeVO.CODE, CurrtypeVO.PK_CURRTYPE, bvo.getCorigcurrencyid()));
// 必填字段 // 必填字段
detail.put("orderNo", hvo.getVbillcode()); // 必填交货单号 detail.put("orderNo", hvo.getVbillcode()); // 必填交货单号
detail.put("orderSn", bvo.getCrowno()); // 必填交货单序号 detail.put("orderSn", bvo.getCrowno()); // 必填交货单序号
@ -148,10 +145,9 @@ public class SalesDeliveryOrderRuleMES implements IRule<SaleOutVO> {
detail.put("unit", transferCodeByPk(MeasdocVO.getDefaultTableName(), detail.put("unit", transferCodeByPk(MeasdocVO.getDefaultTableName(),
MeasdocVO.CODE, MeasdocVO.PK_MEASDOC, bvo.getCunitid())); // 必填计量单位 MeasdocVO.CODE, MeasdocVO.PK_MEASDOC, bvo.getCunitid())); // 必填计量单位
detail.put("scaleFactor", transferSpecialField(bvo.getVchangerate())); // 必填换算系数 detail.put("scaleFactor", transferSpecialField(bvo.getVchangerate())); // 必填换算系数
detail.put("taxRate", bvo.getNtaxrate()); // 必填税率 detail.put("taxRate", bvo.getNtaxrate().getDouble()); // 必填税率
detail.put("recQty", bvo.getNshouldassistnum()); // 必填应收数量 detail.put("recQty", bvo.getNshouldassistnum().getDouble()); // 必填应收数量
detail.put("mainRecQty", bvo.getNnum()); // 必填主应收数量 detail.put("mainRecQty", bvo.getNnum().getDouble()); // 必填主应收数量
// 非必填字段 // 非必填字段
detail.put("batchNum", null); // 物料批号 detail.put("batchNum", null); // 物料批号
detail.put("productNum", null); // 制令号 detail.put("productNum", null); // 制令号