diff --git a/ic/src/private/nc/bs/ic/m4a/sign/rule/AfterSignRuleSyncInToMesProcess.java b/ic/src/private/nc/bs/ic/m4a/sign/rule/AfterSignRuleSyncInToMesProcess.java index 1ab715f..9ac008f 100644 --- a/ic/src/private/nc/bs/ic/m4a/sign/rule/AfterSignRuleSyncInToMesProcess.java +++ b/ic/src/private/nc/bs/ic/m4a/sign/rule/AfterSignRuleSyncInToMesProcess.java @@ -3,17 +3,23 @@ package nc.bs.ic.m4a.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.itf.uif.pub.IUifService; +import nc.jdbc.framework.processor.ColumnProcessor; import nc.vo.bd.material.MaterialVersionVO; +import nc.vo.bd.rack.RackVO; import nc.vo.bd.stordoc.StordocVO; +import nc.vo.cmp.util.StringUtils; import nc.vo.ic.m4a.entity.GeneralInBodyVO; import nc.vo.ic.m4a.entity.GeneralInHeadVO; import nc.vo.ic.m4a.entity.GeneralInVO; +import nc.vo.org.StockOrgVO; import nc.vo.pub.BusinessException; import nc.vo.pubapp.pattern.exception.ExceptionUtils; +import nc.vo.pubapp.pattern.pub.SqlBuilder; import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys; import java.util.Objects; @@ -28,6 +34,8 @@ public class AfterSignRuleSyncInToMesProcess implements IRule { private static final IUifService IUIFSERVICE = NCLocator.getInstance().lookup(IUifService.class); + private static final BaseDAO DAO = new BaseDAO(); + public void process(GeneralInVO[] vos) { if (vos != null && vos.length != 0) { @@ -49,7 +57,6 @@ public class AfterSignRuleSyncInToMesProcess implements IRule { // 填充details for (GeneralInBodyVO body : generalInVO.getBodys()) { JSONObject temp = new JSONObject(); - temp.put("orderNo", head.getVbillcode()); // 通知单ID temp.put("sequenceNum", body.getCrowno()); // 通知单序号 temp.put("type", "QTRK"); // 事务类型 @@ -58,11 +65,15 @@ public class AfterSignRuleSyncInToMesProcess implements IRule { throw new BusinessException("物料信息不存在, 主键:" + body.getCmaterialvid()); } temp.put("materialId", materialVersionVO.getCode()); // 物料ID - temp.put("recQty", body.getNnum() != null ? body.getNnum().doubleValue() : null); // 应收数量 - temp.put("actQty", body.getNshouldnum() != null ? body.getNshouldnum().doubleValue() : null); // 实收数量 + temp.put("recQty", body.getNnum() != null ? body.getNnum().doubleValue() : 0); // 应收数量 + temp.put("actQty", body.getNshouldnum() != null ? body.getNshouldnum().doubleValue() : 0); // 实收数量 temp.put("assistActQry", body.getNassistnum() != null ? body.getNassistnum().doubleValue() : 0); // 辅助实收数量 temp.put("productNum", null); // 产品编号 - temp.put("storageId", body.getClocationid()); // 库位 + String RackVOCode = transferCodeByPk(RackVO.getDefaultTableName(), RackVO.CODE, RackVO.PK_RACK, body.getClocationid()); + if (RackVOCode != null && !RackVOCode.isBlank()) { + temp.put("storageId", body.getClocationid()); // 库位 + } + temp.put("batchNum", body.getVbatchcode()); // 物料批号 temp.put("customId", null); // 客户ID temp.put("supplierId", null); // 供应商ID @@ -77,24 +88,18 @@ public class AfterSignRuleSyncInToMesProcess implements IRule { JSONObject info = new JSONObject(); info.put("details", details); // 明细 // 从head中取数 - info.put("orderNo", head.getVbillcode()); // 通知单ID info.put("type", "QTRK"); // 事务类型 info.put("actureDate", head.getDmakedate() != null ? head.getDmakedate().toString() : null); // 实际日期 - + StordocVO warehouse = (StordocVO) IUIFSERVICE.queryByPrimaryKey(StordocVO.class, head.getCwarehouseid()); + if (warehouse.getCode() != null && warehouse.getCode().length() > 4) { + throw new BusinessException("MES系统仓库编码[" + warehouse.getCode() + "]不能超过4位,请选择合适的仓库!"); + } else { + info.put("storeId", warehouse.getCode()); + } info.put("department", null); // 部门 info.put("customId", null); // 客户 info.put("supplierId", null); // 供应商 - - StordocVO warehouse = (StordocVO) IUIFSERVICE.queryByPrimaryKey(StordocVO.class, head.getCwarehouseid()); - if (Objects.isNull(warehouse)) { - throw new BusinessException("仓库信息不存在, 主键:" + head.getCwarehouseid()); - } - if (warehouse.getCode() != null && warehouse.getCode().length() > 4) { - throw new BusinessException("MES系统仓库编码[" + warehouse.getCode() + "]不能超过4位,请选择合适的仓库!"); - } - info.put("storeId", warehouse.getCode()); // 仓库ID - info.put("workerNo", null); // 工人编号 info.put("worker", null); // 工人 info.put("storeKeeper", head.getCwhsmanagerid()); // 库管员 @@ -116,15 +121,17 @@ public class AfterSignRuleSyncInToMesProcess implements IRule { GeneralInHeadVO head = generalInVO.getHead(); obmlog.debug("触发同步其它入库单(M4A), 单据号:" + head.getVbillcode() + ", 出库类型编码:" + head.getVtrantypecode() + "开始拼接数据"); -// if (!generalOutVO.getHead().getPk_org().equals("0001A110000000000677")) { -// obmlog.debug("仅同步山东泰开电缆有限公司,当前组织:" + generalOutVO.getHead().getPk_org()); -// return; // 仅操作山东泰开电缆有限公司 -// } + String orgCode = transferCodeByPk(StockOrgVO.getDefaultTableName(), StockOrgVO.CODE, StockOrgVO.PK_STOCKORG, head.getPk_org()); - // 调拨入库 - if ("4A-02".equals(head.getVtrantypecode())) { - syncTransferIn(generalInVO); + if (!Objects.equals(orgCode, "C034")) { + obmlog.debug("仅同步山东泰开电缆有限公司,当前组织:" + generalInVO.getHead().getPk_org()); + return; // 仅操作山东泰开电缆有限公司 } + +// // 调拨入库 +// if ("4A-02".equals(head.getVtrantypecode())) { +// syncTransferIn(generalInVO); +// } // 其它入库 else if ("4A-01".equals(head.getVtrantypecode())) { syncOtherIn(generalInVO); @@ -205,4 +212,19 @@ public class AfterSignRuleSyncInToMesProcess implements IRule { obmlog.debug("调拨入库单 " + head.getVbillcode() + " 同步成功"); } + 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(); + } } diff --git a/ic/src/private/nc/bs/ic/m4i/sign/rule/AfterSignRuleSyncOutToMesProcess.java b/ic/src/private/nc/bs/ic/m4i/sign/rule/AfterSignRuleSyncOutToMesProcess.java index b50be1d..2d27305 100644 --- a/ic/src/private/nc/bs/ic/m4i/sign/rule/AfterSignRuleSyncOutToMesProcess.java +++ b/ic/src/private/nc/bs/ic/m4i/sign/rule/AfterSignRuleSyncOutToMesProcess.java @@ -3,17 +3,22 @@ package nc.bs.ic.m4i.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.itf.uif.pub.IUifService; +import nc.jdbc.framework.processor.ColumnProcessor; import nc.vo.bd.material.MaterialVersionVO; import nc.vo.bd.stordoc.StordocVO; +import nc.vo.cmp.util.StringUtils; import nc.vo.ic.m4i.entity.GeneralOutBodyVO; import nc.vo.ic.m4i.entity.GeneralOutHeadVO; import nc.vo.ic.m4i.entity.GeneralOutVO; +import nc.vo.org.StockOrgVO; import nc.vo.pub.BusinessException; import nc.vo.pubapp.pattern.exception.ExceptionUtils; +import nc.vo.pubapp.pattern.pub.SqlBuilder; import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys; import java.util.Objects; @@ -27,6 +32,8 @@ public class AfterSignRuleSyncOutToMesProcess implements IRule { private static final Log obmlog = Log.getInstance(logginfo); + private static final BaseDAO DAO = new BaseDAO(); + private final IUifService iUifService = NCLocator.getInstance().lookup(IUifService.class); public void process(GeneralOutVO[] vos) { @@ -42,147 +49,165 @@ public class AfterSignRuleSyncOutToMesProcess implements IRule { } } + private void syncOtherOut(GeneralOutVO generalOutVO) throws BusinessException { + GeneralOutHeadVO head = generalOutVO.getHead(); + obmlog.debug("开始处理其它出库单(4I-01): " + head.getVbillcode()); + // 表体body信息拼接 + JSONArray details = new JSONArray(); + // 填充details + for (GeneralOutBodyVO body : generalOutVO.getBodys()) {// body中取数 + JSONObject temp = new JSONObject(); + temp.put("sequenceNum", body.getCrowno()); // 通知单序号 + temp.put("type", "QTCK"); // 事务类型 + MaterialVersionVO materialVersionVO = (MaterialVersionVO) iUifService.queryByPrimaryKey(MaterialVersionVO.class, body.getCmaterialoid()); + if (Objects.isNull(materialVersionVO)) { + throw new BusinessException("搜索物料信息不存在"); + } + temp.put("materialId", materialVersionVO.getCode()); // 物料ID + temp.put("issuedQty", body.getNnum() != null ? body.getNnum().doubleValue() : null); // 应发数量 + temp.put("actQty", body.getNshouldnum() != null ? body.getNshouldnum().doubleValue() : null); // 实发数量 + temp.put("assistActQry", body.getNassistnum() != null ? body.getNassistnum().doubleValue() : ""); // 辅助实发数量 + temp.put("productNum", null); + temp.put("storageId", body.getClocationid()); // 库位 + temp.put("batchNum", body.getVbatchcode()); // 物料批号 + temp.put("customId", null); + temp.put("supplierId", null); + temp.put("manufactureDate", null); + temp.put("remark", body.getVnotebody()); + details.add(temp); + } + JSONObject info = new JSONObject(); + info.put("details", details); + // 从head中取数 + info.put("type", "QTCK"); // 事务类型 + info.put("actureDate", head.getDmakedate().toString()); // 实际日期 + StordocVO warehouse = (StordocVO) iUifService.queryByPrimaryKey(StordocVO.class, head.getCwarehouseid()); + if (Objects.isNull(warehouse)) { + throw new BusinessException("仓库信息不存在,主键:" + head.getCwarehouseid()); + } + info.put("storeId", warehouse.getCode()); // 仓库ID + info.put("workerNo", null); + info.put("worker", null); + info.put("storeKeeper", head.getCwhsmanagerid()); + info.put("returned", "N"); // 是否退库 + info.put("mark", "N"); // 生成标志 + info.put("remark", head.getVnote()); + + // 拼接数据,先创建一个jsonObject + JSONObject requestData = new JSONObject(); + requestData.put("operation_type", "I");// 操作 + requestData.put("info", info); + obmlog.debug("其它出库(4I-01) requestData:" + requestData.toJSONString()); + HTTP_POST_OTHER_SYS.sendToExternalSystem("/GTHINKING/AjaxService/N_KCSJJS/101527004.ashx/gt_rec_api_qtckdj", requestData); + obmlog.debug("其它出库单(4I-01) " + head.getVbillcode() + " 同步成功"); + } private void syncOtherSystem(GeneralOutVO generalOutVO) throws BusinessException { obmlog.debug("触发同步其它出库单,出库类型编码:" + generalOutVO.getHead().getVtrantypecode() + "开始拼接数据"); -// if (!generalOutVO.getHead().getPk_org().equals("0001A110000000000677")) { -// obmlog.debug("仅同步山东泰开电缆有限公司,当前组织:" + generalOutVO.getHead().getPk_org()); -// return; // 仅操作山东泰开电缆有限公司 -// } + String orgCode = transferCodeByPk(StockOrgVO.getDefaultTableName(), StockOrgVO.CODE, StockOrgVO.PK_STOCKORG, generalOutVO.getHead().getPk_org()); + if (!Objects.equals(orgCode, "C034")) { + obmlog.debug("仅同步山东泰开电缆有限公司,当前组织:" + generalOutVO.getHead().getPk_org()); + return; // 仅操作山东泰开电缆有限公司 + } + + String trantypecode = generalOutVO.getHead().getVtrantypecode(); // 其它出库 - if (generalOutVO.getHead().getVtrantypecode().equals("4I-01")) { - // 表体body信息拼接 - JSONArray details = new JSONArray(); - GeneralOutHeadVO head = generalOutVO.getHead(); - // 填充details - for (GeneralOutBodyVO body : generalOutVO.getBodys()) {// body中取数 - JSONObject temp = new JSONObject(); - temp.put("orderNo", head.getVbillcode()); // 通知单ID - temp.put("sequenceNum", body.getCrowno()); // 通知单序号 - temp.put("type", "QTCK"); // 事务类型 - MaterialVersionVO materialVersionVO = (MaterialVersionVO) iUifService.queryByPrimaryKey(MaterialVersionVO.class, body.getCmaterialoid()); - if (Objects.isNull(materialVersionVO)) { - throw new BusinessException("搜索物料信息不存在"); - } - temp.put("materialId", materialVersionVO.getCode()); // 物料ID - temp.put("issuedQty", body.getNnum() != null ? body.getNnum().doubleValue() : null); // 应发数量 - temp.put("actQty", body.getNshouldnum() != null ? body.getNshouldnum().doubleValue() : null); // 实发数量 - temp.put("assistActQry", body.getNassistnum() != null ? body.getNassistnum().doubleValue() : ""); // 辅助实发数量 - temp.put("productNum", null); - temp.put("storageId", body.getClocationid()); // 库位 - temp.put("batchNum", body.getVbatchcode()); // 物料批号 - temp.put("customId", null); - temp.put("supplierId", null); - temp.put("manufactureDate", null); - temp.put("remark", body.getVnotebody()); - details.add(temp); - } - JSONObject info = new JSONObject(); - info.put("details", details); - // 从head中取数 - info.put("orderNo", head.getVbillcode()); // 通知单ID - info.put("type", "QTCK"); // 事务类型 - info.put("actureDate", head.getDmakedate().toString()); // 实际日期 - StordocVO warehouse = (StordocVO) iUifService.queryByPrimaryKey(StordocVO.class, head.getCwarehouseid()); - if (Objects.isNull(warehouse)) { - throw new BusinessException("仓库信息不存在,主键:" + head.getCwarehouseid()); - } - if (warehouse.getCode() != null && warehouse.getCode().length() > 4) { - throw new BusinessException("MES系统仓库编码[" + warehouse.getCode() + "]不能超过4位,请选择合适的仓库!"); - } - info.put("storeId", warehouse.getCode()); // 仓库ID - info.put("workerNo", null); - info.put("worker", null); - info.put("storeKeeper", head.getCwhsmanagerid()); - info.put("returned", "N"); // 是否退库 - info.put("mark", "N"); // 生成标志 - info.put("remark", head.getVnote()); - - // 拼接数据,先创建一个jsonObject - JSONObject requestData = new JSONObject(); - requestData.put("operation_type", "I");// 操作 - requestData.put("info", info); - obmlog.debug("其它出库requestData:" + requestData.toJSONString()); - IHttpPostOtherSys httpService = NCLocator.getInstance().lookup(IHttpPostOtherSys.class); - httpService.sendToExternalSystem("/GTHINKING/AjaxService/N_KCSJJS/101527004.ashx/gt_rec_api_qtckdj", requestData); - } - // 调拨出库/转库单 - if (generalOutVO.getHead().getVtrantypecode().equals("4I-02")) { - // 表体body信息拼接 - JSONArray details = new JSONArray(); - GeneralOutHeadVO head = generalOutVO.getHead(); - // 填充details - for (GeneralOutBodyVO body : generalOutVO.getBodys()) {// body中取数 - JSONObject temp = new JSONObject(); - temp.put("orderNo", head.getVbillcode()); // 通知单ID - temp.put("sequenceNum", body.getCrowno()); // 通知单序号 - temp.put("type", "DBCK"); // 事务类型 - temp.put("genType", null); - MaterialVersionVO materialVersionVO = (MaterialVersionVO) iUifService.queryByPrimaryKey(MaterialVersionVO.class, body.getCmaterialoid()); - if (Objects.isNull(materialVersionVO)) { - throw new BusinessException("搜索物料信息不存在"); - } - temp.put("materialId", materialVersionVO.getCode()); // 物料ID - temp.put("issuedQty", body.getNnum() != null ? body.getNnum().doubleValue() : null); // 应发数量 - temp.put("actOutQty", body.getNshouldnum() != null ? body.getNshouldnum().doubleValue() : null); // 实发数量 - temp.put("outQty", body.getNnum() != null ? body.getNnum().doubleValue() : null); - temp.put("assistActOutQry", body.getNassistnum() != null ? body.getNassistnum().doubleValue() : 0); // 辅助实发数量 - temp.put("productNum", null); - temp.put("outStorageId", body.getClocationid()); // 库位 - temp.put("outBatchNum", body.getVbatchcode()); // 物料批号 - temp.put("customId", null); - temp.put("supplierId", null); - temp.put("manufactureDate", null); - temp.put("color", null); - temp.put("packLen", null); - temp.put("packSize", null); - temp.put("remark", body.getVnotebody()); - details.add(temp); - } - JSONObject info = new JSONObject(); - info.put("details", details); - // 从head中取数 - info.put("orderNo", head.getVbillcode()); // 通知单ID - info.put("type", "DBCK"); // 事务类型 - info.put("genType", null); - info.put("outDate", head.getDbilldate().toString()); - - StordocVO outWarehouse = (StordocVO) iUifService.queryByPrimaryKey(StordocVO.class, head.getCwarehouseid()); - if (Objects.isNull(outWarehouse)) { - throw new BusinessException("出库仓库信息不存在,主键:" + head.getCwarehouseid()); - } - if (outWarehouse.getCode() != null && outWarehouse.getCode().length() > 4) { - throw new BusinessException("MES系统出库仓库编码[" + outWarehouse.getCode() + "]不能超过4位,请选择合适的仓库!"); - } - info.put("outStoreId", outWarehouse.getCode()); // 仓库ID - - StordocVO inWarehouse = (StordocVO) iUifService.queryByPrimaryKey(StordocVO.class, head.getCotherwhid()); - if (Objects.isNull(inWarehouse)) { - throw new BusinessException("入库仓库信息不存在,主键:" + head.getCotherwhid()); - } - if (inWarehouse.getCode() != null && inWarehouse.getCode().length() > 4) { - throw new BusinessException("MES系统入库仓库编码[" + inWarehouse.getCode() + "]不能超过4位,请选择合适的仓库!"); - } - info.put("inStoreId", inWarehouse.getCode()); // 仓库ID - info.put("workerNo", null); - info.put("worker", null); - info.put("storeKeeper", head.getCwhsmanagerid()); - info.put("returned", "N"); // 是否退库 - info.put("mark", "N"); // 生成标志 - info.put("remark", head.getVnote()); - - // 拼接数据,先创建一个jsonObject - JSONObject requestData = new JSONObject(); - requestData.put("operation_type", "I");// 操作 - requestData.put("info", info); - obmlog.debug("其它出库requestData:" + requestData.toJSONString()); - - HTTP_POST_OTHER_SYS.sendToExternalSystem("/GTHINKING/AjaxService/N_KCSJJS/101527009.ashx/gt_rec_api_dbckdj", requestData); + if ("4I-01".equals(trantypecode)) { + syncOtherOut(generalOutVO); } +// // 调拨出库/转库单 +// else if ("4I-02".equals(trantypecode)) { +// syncTransferOut(generalOutVO); +// } } + private void syncTransferOut(GeneralOutVO generalOutVO) throws BusinessException { + GeneralOutHeadVO head = generalOutVO.getHead(); + obmlog.debug("开始处理调拨出库/转库单(4I-02): " + head.getVbillcode()); + // 表体body信息拼接 + JSONArray details = new JSONArray(); + // 填充details + for (GeneralOutBodyVO body : generalOutVO.getBodys()) {// body中取数 + JSONObject temp = new JSONObject(); + temp.put("orderNo", head.getVbillcode()); // 通知单ID + temp.put("sequenceNum", body.getCrowno()); // 通知单序号 + temp.put("type", "DBCK"); // 事务类型 + temp.put("genType", null); + MaterialVersionVO materialVersionVO = (MaterialVersionVO) iUifService.queryByPrimaryKey(MaterialVersionVO.class, body.getCmaterialoid()); + if (Objects.isNull(materialVersionVO)) { + throw new BusinessException("搜索物料信息不存在"); + } + temp.put("materialId", materialVersionVO.getCode()); // 物料ID + temp.put("issuedQty", body.getNnum() != null ? body.getNnum().doubleValue() : null); // 应发数量 + temp.put("actOutQty", body.getNshouldnum() != null ? body.getNshouldnum().doubleValue() : null); // 实发数量 + temp.put("outQty", body.getNnum() != null ? body.getNnum().doubleValue() : null); + temp.put("assistActOutQry", body.getNassistnum() != null ? body.getNassistnum().doubleValue() : 0); // 辅助实发数量 + temp.put("productNum", null); + temp.put("outStorageId", body.getClocationid()); // 库位 + temp.put("outBatchNum", body.getVbatchcode()); // 物料批号 + temp.put("customId", null); + temp.put("supplierId", null); + temp.put("manufactureDate", null); + temp.put("color", null); + temp.put("packLen", null); + temp.put("packSize", null); + temp.put("remark", body.getVnotebody()); + details.add(temp); + } + JSONObject info = new JSONObject(); + info.put("details", details); + // 从head中取数 + info.put("orderNo", head.getVbillcode()); // 通知单ID + info.put("type", "DBCK"); // 事务类型 + info.put("genType", null); + info.put("outDate", head.getDbilldate().toString()); + + StordocVO outWarehouse = (StordocVO) iUifService.queryByPrimaryKey(StordocVO.class, head.getCwarehouseid()); + if (Objects.isNull(outWarehouse)) { + throw new BusinessException("出库仓库信息不存在,主键:" + head.getCwarehouseid()); + } + info.put("outStoreId", outWarehouse.getCode()); // 仓库ID + + StordocVO inWarehouse = (StordocVO) iUifService.queryByPrimaryKey(StordocVO.class, head.getCotherwhid()); + if (Objects.isNull(inWarehouse)) { + throw new BusinessException("入库仓库信息不存在,主键:" + head.getCotherwhid()); + } + info.put("inStoreId", inWarehouse.getCode()); // 仓库ID + info.put("workerNo", null); + info.put("worker", null); + info.put("storeKeeper", head.getCwhsmanagerid()); + info.put("returned", "N"); // 是否退库 + info.put("mark", "N"); // 生成标志 + info.put("remark", head.getVnote()); + + // 拼接数据,先创建一个jsonObject + JSONObject requestData = new JSONObject(); + requestData.put("operation_type", "I");// 操作 + requestData.put("info", info); + obmlog.debug("调拨出库/转库单(4I-02) requestData:" + requestData.toJSONString()); + + HTTP_POST_OTHER_SYS.sendToExternalSystem("/GTHINKING/AjaxService/N_KCSJJS/101527009.ashx/gt_rec_api_dbckdj", requestData); + obmlog.debug("调拨出库/转库单(4I-02) " + head.getVbillcode() + " 同步成功"); + } + + + 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(); + } } diff --git a/ic/src/private/nccloud/pubift/commen/impl/utils/HttpPostOtherSysImpl.java b/ic/src/private/nccloud/pubift/commen/impl/utils/HttpPostOtherSysImpl.java index 23d59d0..502a8b7 100644 --- a/ic/src/private/nccloud/pubift/commen/impl/utils/HttpPostOtherSysImpl.java +++ b/ic/src/private/nccloud/pubift/commen/impl/utils/HttpPostOtherSysImpl.java @@ -25,21 +25,22 @@ public class HttpPostOtherSysImpl implements IHttpPostOtherSys { private static final String PASSWORD = "BIP@2025bip"; private static final String CLIENT_TYPE = "S"; private static final String EP_ID = ""; - private static final String LOGIN_URL = "/GTHINKING/AjaxService/N_MISPRO/100208057.ashx/Login"; + + private static final String LOGIN_URL = "/GTHINKING/AjaxService/N_MISPRO/100208057.ashx/Login"; // 登录接口路径 private static final String LOG_INFO_NAME = "OALOG"; private static final Log obmlog = Log.getInstance(LOG_INFO_NAME); @Override public String callMes(String url, JSONObject json) { - // String leip = SysParaInitQuery.getParaString(PubEnv.getPk_group(), "LEIP"); - String mesip = "http://192.168.29.32"; - String baseurl = mesip + url; - String tokenValue = this.getMESToken(mesip); + // String leip = SysParaInitQuery.getParaString(PubEnv.getPk_group(), "LEIP"); // 从系统参数获取IP地址(示例) + String mesip = "http://192.168.29.32"; // MES系统IP地址,实际应从配置读取 + String baseurl = mesip + url; // 拼接完整的请求URL + String tokenValue = this.getMESToken(mesip); // 获取MES系统的认证Token Map headers = new HashMap<>(); if (tokenValue != null) { - headers.put("Cookie", ".ASPXAUTH=" + tokenValue); + headers.put("Cookie", ".ASPXAUTH=" + tokenValue); // 将Token放入请求头的Cookie中 } - return doPost(baseurl, headers, json); + return doPost(baseurl, headers, json); // 执行POST请求 } /** @@ -47,26 +48,26 @@ public class HttpPostOtherSysImpl implements IHttpPostOtherSys { */ public void sendToExternalSystem(String apiPath, Map requestData) throws BusinessException { try { - obmlog.debug("HttpPostOtherSys request :" + JSONObject.toJSONString(requestData)); - JSONObject jsonRequest = new JSONObject(requestData); - String response = callMes(apiPath, jsonRequest); - JSONObject jsonResponse = JSONObject.parseObject(response); + obmlog.debug("HttpPostOtherSys 请求数据 :" + JSONObject.toJSONString(requestData)); // 记录请求数据 + JSONObject jsonRequest = new JSONObject(requestData); // 将Map转换为JSONObject + String response = callMes(apiPath, jsonRequest); // 调用MES接口 + JSONObject jsonResponse = JSONObject.parseObject(response); // 解析返回的JSON字符串 - obmlog.debug("三方接口返回::" + jsonResponse.toJSONString()); + obmlog.debug("三方接口返回::" + jsonResponse.toJSONString()); // 记录三方接口返回的数据 - String success = jsonResponse.getString("Success"); - if ("false".equals(success)) { - String errorMessage = jsonResponse.getString("ErrorMessage"); + String success = jsonResponse.getString("Success"); // 获取返回结果中的Success字段 + if ("false".equals(success)) { // 判断请求是否成功 + String errorMessage = jsonResponse.getString("ErrorMessage"); // 获取错误信息 if (errorMessage == null) { - errorMessage = "No error message provided by the external system."; + errorMessage = "外部系统未提供错误消息。"; } - throw new BusinessException("同步mes系统失败,错误消息:" + errorMessage); + throw new BusinessException("同步mes系统失败,错误消息:" + errorMessage); // 抛出业务异常 } } catch (BusinessException e) { - throw e; + throw e; // 直接抛出已捕获的业务异常 } catch (Exception e) { - throw new BusinessException("调用外部接口失败:" + e.getMessage(), e); + throw new BusinessException("调用外部接口失败:" + e.getMessage(), e); // 捕获其他异常并包装为业务异常抛出 } } @@ -74,13 +75,13 @@ public class HttpPostOtherSysImpl implements IHttpPostOtherSys { * 业务请求post方法 */ private String doPost(String baseurl, Map headers, JSONObject jsonPayload) { - try (CloseableHttpClient httpClient = HttpClients.createDefault()) { - HttpPost httpPost = new HttpPost(baseurl); + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { // 创建HttpClient实例 + HttpPost httpPost = new HttpPost(baseurl); // 创建HttpPost请求 - // Set standard headers + // 设置标准请求头 httpPost.setHeader("Content-Type", "application/json;charset=UTF-8"); - // Set custom headers from the map + // 设置自定义请求头 if (headers != null) { for (Map.Entry entry : headers.entrySet()) { httpPost.setHeader(entry.getKey(), entry.getValue()); @@ -88,69 +89,75 @@ public class HttpPostOtherSysImpl implements IHttpPostOtherSys { } if (jsonPayload != null) { - StringEntity stringEntity = new StringEntity(jsonPayload.toJSONString(), "UTF-8"); - httpPost.setEntity(stringEntity); + StringEntity stringEntity = new StringEntity(jsonPayload.toJSONString(), "UTF-8"); // 创建请求体 + httpPost.setEntity(stringEntity); // 设置请求体 } - try (CloseableHttpResponse response = httpClient.execute(httpPost)) { - HttpEntity entity = response.getEntity(); - String responseString = EntityUtils.toString(entity, "UTF-8"); + try (CloseableHttpResponse response = httpClient.execute(httpPost)) { // 执行请求 + HttpEntity entity = response.getEntity(); // 获取响应实体 + String responseString = EntityUtils.toString(entity, "UTF-8"); // 将响应实体转换为字符串 return responseString; } } catch (IOException e) { - // In a real application, use a proper logging framework + // 在实际应用中,应使用合适的日志框架记录错误 // e.printStackTrace(); - throw new RuntimeException("HTTP POST request to " + baseurl + " failed: " + e.getMessage(), e); + throw new RuntimeException("HTTP POST 请求到 " + baseurl + " 失败: " + e.getMessage(), e); // 抛出运行时异常 } } - // 提取 .ASPXAUTH 的值 - This method remains unchanged + // 提取 .ASPXAUTH 的值 - 此方法保持不变 private String extractAspxAuth(String setCookieHeaderLine) { // setCookieHeaderLine 是一行完整的 Set-Cookie 响应头,例如: // ".ASPXAUTH=TOKEN_VALUE; path=/; HttpOnly" // 或 ".ASPXAUTH=TOKEN_VALUE;" - String[] cookieAttributes = setCookieHeaderLine.split(";"); // 按分号分割 + String[] cookieAttributes = setCookieHeaderLine.split(";"); // 按分号分割属性 for (String attribute : cookieAttributes) { String trimmedAttribute = attribute.trim(); // 去除前后空格 - if (trimmedAttribute.startsWith(".ASPXAUTH=")) { + if (trimmedAttribute.startsWith(".ASPXAUTH=")) { // 检查是否是 .ASPXAUTH return trimmedAttribute.substring(".ASPXAUTH=".length()); // 提取等号后的值 } } - return null; // 没有找到 .ASPXAUTH + return null; // 未找到 .ASPXAUTH } + /** + * 获取MES系统的认证Token (通常是从Cookie中获取 .ASPXAUTH) + * + * @param mesIpBase MES系统的基础IP地址 + * @return .ASPXAUTH 的Token值,如果未找到则返回null + */ private String getMESToken(String mesIpBase) { - JSONObject jsonObject = new JSONObject(); + JSONObject jsonObject = new JSONObject(); // 构建登录请求的JSON对象 jsonObject.put("userId", USER_ID); jsonObject.put("password", PASSWORD); jsonObject.put("clientType", CLIENT_TYPE); jsonObject.put("epId", EP_ID); - String loginUrl = mesIpBase + LOGIN_URL; + String loginUrl = mesIpBase + LOGIN_URL; // 拼接完整的登录URL - try (CloseableHttpClient httpClient = HttpClients.createDefault()) { - HttpPost httpPost = new HttpPost(loginUrl); - httpPost.setHeader("Content-Type", "application/json;charset=UTF-8"); + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { // 创建HttpClient实例 + HttpPost httpPost = new HttpPost(loginUrl); // 创建HttpPost请求用于登录 + httpPost.setHeader("Content-Type", "application/json;charset=UTF-8"); // 设置请求内容类型 - StringEntity stringEntity = new StringEntity(jsonObject.toJSONString(), "UTF-8"); - httpPost.setEntity(stringEntity); + StringEntity stringEntity = new StringEntity(jsonObject.toJSONString(), "UTF-8"); // 创建登录请求体 + httpPost.setEntity(stringEntity); // 设置登录请求体 - try (CloseableHttpResponse response = httpClient.execute(httpPost)) { - Header[] setCookieHeaders = response.getHeaders("Set-Cookie"); + try (CloseableHttpResponse response = httpClient.execute(httpPost)) { // 执行登录请求 + Header[] setCookieHeaders = response.getHeaders("Set-Cookie"); // 获取响应头中的Set-Cookie字段 if (setCookieHeaders != null) { for (Header header : setCookieHeaders) { - String aspxAuthValue = extractAspxAuth(header.getValue()); + String aspxAuthValue = extractAspxAuth(header.getValue()); // 从Set-Cookie中提取.ASPXAUTH的值 if (aspxAuthValue != null) { - return aspxAuthValue; // Found and return .ASPXAUTH token value + return aspxAuthValue; // 找到并返回 .ASPXAUTH token 值 } } } - return null; // Return null if .ASPXAUTH cookie is not found, as per + return null; // 如果未找到 .ASPXAUTH cookie,则返回 null } } catch (IOException e) { - - throw new RuntimeException("Failed to get MESToken (cookie) from " + loginUrl + " due to IO issue: " + e.getMessage(), e); + // 记录IO异常,例如网络问题或服务器不可达 + throw new RuntimeException("从 " + loginUrl + " 获取MESToken (cookie) 失败,发生IO问题: " + e.getMessage(), e); } }