| | |
| | | string _rtnStr = ""; |
| | | try |
| | | { |
| | | // 记录方法入口参数 |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"SendErp开始 - keyGuid:{model.keyGuid}, keyNo:{model.keyNo}, keyMeth:{model.keyMeth}, keyProduce:{model.keyProduce}, keyUrl:{model.keyUrl}"); |
| | | |
| | | // 构建ERP请求参数 |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), "SendErp - 开始调用GetErpParam"); |
| | | string _erpJson = GetErpParam(model); |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"SendErp - GetErpParam返回,JSON长度:{_erpJson.Length}, 前100字符:{(_erpJson.Length > 100 ? _erpJson.Substring(0, 100) : _erpJson)}"); |
| | | if (_erpJson.Length <= 0) |
| | | return "-1读取erp参数失败!"; |
| | | string keyUserGuid = model.keyUserGuid; |
| | |
| | | if (string.IsNullOrEmpty(idtype)) |
| | | { |
| | | // 常规接口:按操作类型推送单条业务数据 |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"SendErp - 开始调用HttpPostErp(常规接口) - keyUserGuid:{keyUserGuid}, keyGuid:{keyGuid}, keyNo:{keyNo}, urlType:0, keyUrl:{keyUrl}"); |
| | | (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson, |
| | | keyUserGuid, keyGuid, keyNo, 0, keyUrl); |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"SendErp - HttpPostErp返回 - _rtnInt:{_rtnInt}, _rtnStr:{_rtnStr}"); |
| | | } |
| | | else |
| | | { |
| | | // 带idtype的请求用于特殊流程(如关闭、反关闭),ERP需要额外的状态标记 |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"SendErp - 开始调用HttpPostErp(特殊流程) - keyUserGuid:{keyUserGuid}, keyGuid:{keyGuid}, keyNo:{keyNo}, urlType:2, keyUrl:{keyUrl}, idtype:{idtype}"); |
| | | (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson, |
| | | keyUserGuid, keyGuid, keyNo, 2, keyUrl); |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"SendErp - HttpPostErp返回 - _rtnInt:{_rtnInt}, _rtnStr:{_rtnStr}"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | string keyMeth = model.keyMeth; |
| | | string keyNo = model.keyNo; |
| | | string idtype = model.idtype; // 仅在更新工单状态时使用 |
| | | |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"GetErpParam开始 - keyGuid:{keyGuid}, keyMeth:{keyMeth}, keyProduce:{keyProduce}, keyTaskName:{keyTaskName}, idtype:{idtype}"); |
| | | |
| | | if (keyMeth.ToUpper() == "delete".ToUpper()) |
| | | { |
| | | // 删除操作无需向ERP推送数据,只需返回空串 |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetErpParam - 删除操作,返回空串"); |
| | | return ""; |
| | | } |
| | | try |
| | | { |
| | | System.Data.DataSet dset = new System.Data.DataSet(); |
| | |
| | | new("@keyMeth", keyMeth.ToLower()), |
| | | }; |
| | | // 调用业务定义的存储过程,将MES数据打包给ERP |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"GetErpParam - 开始调用存储过程:{keyProduce}, 参数:@inOrderGuid={keyGuid}, @inEdtUserGuid={keyUserGuid}, @keyMeth={keyMeth.ToLower()}"); |
| | | dset = DbHelperSQL.RunProcedure(keyProduce, parameters, "0"); |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"GetErpParam - 存储过程返回,DataSet表数量:{(dset == null ? 0 : dset.Tables.Count)}"); |
| | | if (dset == null) |
| | | { |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetErpParam - DataSet为null,返回空串"); |
| | | return ""; |
| | | } |
| | | if (dset.Tables.Count <= 0) |
| | | { |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetErpParam - DataSet表数量为0,返回空串"); |
| | | return ""; |
| | | } |
| | | if (dset.Tables[0].Rows.Count <= 0) |
| | | { |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetErpParam - 第一张表行数为0,返回空串"); |
| | | return ""; |
| | | } |
| | | |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"GetErpParam - 第一张表行数:{dset.Tables[0].Rows.Count}, 列数:{dset.Tables[0].Columns.Count}"); |
| | | |
| | | // 常规接口处理逻辑 |
| | | if (string.IsNullOrEmpty(idtype)) |
| | | { |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetErpParam - 常规接口处理逻辑"); |
| | | // 常规出参:第一张表是主数据,第二张表(若存在)是子表集合 |
| | | string _mesGuid = dset.Tables[0].Rows[0][0].ToString(); |
| | | dynamic _datajson = new ExpandoObject(); |
| | | if (dset.Tables.Count > 1) |
| | | { |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"GetErpParam - 多表返回,第二张表行数:{dset.Tables[1].Rows.Count}"); |
| | | // 多表返回时,需要把子表集合挂到datajson中 |
| | | // 结案操作的结构与其他不一样,特殊处理 |
| | | if (keyMeth.ToLower() == "toclose".ToLower() || |
| | | keyMeth.ToLower() == "closure".ToLower() || |
| | | keyMeth.ToLower() == "unfinish") |
| | | { |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetErpParam - 结案操作,使用第二张表"); |
| | | _datajson = dset.Tables[1].Rows[0].RowToDynamic(); |
| | | } |
| | | else |
| | | { |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetErpParam - 常规多表,主表+子表结构"); |
| | | _datajson = dset.Tables[0].Rows[0].RowToDynamic(); |
| | | List<dynamic> _lst = |
| | | dset.Tables[1].TableToDynamicList(); |
| | |
| | | } |
| | | else if (dset.Tables.Count == 1) |
| | | { |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetErpParam - 单表返回"); |
| | | _datajson = dset.Tables[0].Rows[0].RowToDynamic(); |
| | | } |
| | | |
| | |
| | | // datajson = JsonConvert.SerializeObject(_datajson), |
| | | // }; |
| | | // return JsonConvert.SerializeObject(_obj); |
| | | string jsonResult = JsonConvert.SerializeObject(_datajson); |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"GetErpParam - 常规接口JSON构建完成,长度:{jsonResult.Length}"); |
| | | return jsonResult; |
| | | return JsonConvert.SerializeObject(_datajson); |
| | | } |
| | | |
| | | // 订单回传标识处理逻辑(带idtype) |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetErpParam - 订单回传标识处理逻辑(idtype)"); |
| | | List<dynamic> _datajson22 = new List<dynamic>(); |
| | | dynamic _ob = new ExpandoObject(); |
| | | _ob.ENTRY = dset.Tables[0].TableToDynamicList(); |
| | |
| | | // datajson = JsonConvert.SerializeObject(_datajson22), |
| | | // }; |
| | | // return JsonConvert.SerializeObject(_obj22); |
| | | string jsonResult22 = JsonConvert.SerializeObject(_datajson22); |
| | | Gs.Toolbox.LogHelper.Debug(this.ToString(), |
| | | $"GetErpParam - idtype接口JSON构建完成,长度:{jsonResult22.Length}"); |
| | | return jsonResult22; |
| | | return JsonConvert.SerializeObject(_datajson22); |
| | | } |
| | | catch (Exception ex) |
| | | { |