//上报第三方运单 public ResultModel <int> UploadThirdOrderForCustomer(Model_ThirdPartOrder orderInfo, int customerId) { if (orderInfo != null) { LogServer.AddLogText("--------------------------------------------------------------", orderInfo.RelationId); } else { LogServer.AddLogText("实体为空", "XXX"); } ResultModel <int> result = new ResultModel <int>(); try { LogServer.AddLogText(string.Format("上报第三方运单{0},customerId:{1}", orderInfo.RelationId, customerId), orderInfo.RelationId); result.Data = PDA_HuadongTmsOrderServer.UploadThirdPartyOrder(orderInfo, customerId); LogServer.AddLogText("退出运单逻辑", orderInfo.RelationId); } catch (Exception ex) { HandleExcepthin(result, ex); LogServer.AddLogText("运单错误", orderInfo.RelationId); } finally { if (orderInfo != null) { LogServer.AddLogText("--------------------------------------------------------------", orderInfo.RelationId); } } return(result); }
/// <summary> /// 上传第三方运单号 /// </summary> private static void UploadThirdOrder() { ResultModelOfint result = new ResultModelOfint(); //List<Model_Huadong_Tms_Order> list = new List<Model_Huadong_Tms_Order>(); string msg = string.Empty; string err = string.Empty; Model_ThirdPartOrder hdOrder = null; try { //根据每次查询运单数量为条件查询几条信息 DataTable dt = HuadongTmsOrderServer.GethuadongTmsOrder(Common._MaxUploadOrderCount); if (dt != null && dt.Rows.Count > 0) { DataRow row = dt.Rows[0]; hdOrder = new Model_ThirdPartOrder(); hdOrder.Idk__BackingField = Convert.ToInt32(row["id"]); hdOrder.RelationIdk__BackingField = row["relationId"].ToString(); hdOrder.OperateAtk__BackingField = row["OperateAt"].ToString(); result = Common._PdaServer.UploadThirdPartyOrder(hdOrder); //foreach (DataRow row in dt.Rows) //{ // Model_Huadong_Tms_Order huadong = new Model_Huadong_Tms_Order(); // huadong.Idk__BackingField = Convert.ToInt32(row["id"]); // huadong.RelationIdk__BackingField = row["relationId"].ToString(); // list.Add(huadong); // msg = huadong.RelationIdk__BackingField; //} //FrmParent.ParentForm.SetNewInfo("正在上报第三方运单" + msg + ",请稍候...", null); ////后台接口,上传数据 //result = Common._PdaServer.UploadHuadongTmsOrder(list.ToArray()); } } catch (Exception ex) { err = ex.Message; throw ex; } finally { if (result.Data == 1 || result.Data == 2) { HuadongTmsOrderServer.DeleteUploadHuadongTmsOrder(new List <string>() { hdOrder.RelationIdk__BackingField }); if (result.Data == 2 && hdOrder != null) { WaybillServer.DeleteThirdNodeByOptAt(hdOrder.RelationIdk__BackingField, hdOrder.OperateAtk__BackingField); } } else if (string.IsNullOrEmpty(err)) { err = result.Message; } err = err == null ? string.Empty : err; FrmParent.ParentForm.SetNewInfo(string.Format("{0}{1} {2}", (msg.Length == 0 ? "没有待上报的第三方运单." : "上报第三方运单"), msg, (err.Length == 0 ? (msg.Length == 0 ? "" : "成功") : "失败 " + err)), err.Length == 0); } }
//弃用 public ResultModel <int> UploadThirdPartyOrder(Model_ThirdPartOrder orderInfo) { ResultModel <int> result = new ResultModel <int>(); try { //result.Data = PDA_HuadongTmsOrderServer.UploadThirdPartyOrder(orderInfo); result.Data = PDA_HuadongTmsOrderServer.UploadThirdPartyOrder(orderInfo, 669); } catch (Exception ex) { HandleExcepthin(result, ex); } return(result); }
/// <summary> /// 创建第三方运单 /// </summary> /// <param name="orderInfo"></param> /// <returns>0:处理失败; 1:处理成功; 2:运单已存在</returns> public static int UploadThirdPartyOrder(Model_ThirdPartOrder orderInfo, int customerId = 0) { int result = 0; try { LogServer.AddLogText(string.Format("进入创建第三方运单逻辑{0},操作时间{1}", orderInfo.RelationId, orderInfo.OperateAt), orderInfo.RelationId); if (orderInfo == null) { result = 1; } string sql = string.Empty; Model_ThirdCustomer customerInfo = new Model_ThirdCustomer(); //检查是否已经创建过第三方运单的关联运单 Model_Waybill_Base IsExist = CheckThirdPartyNumberExist(orderInfo.RelationId); LogServer.AddLogText(string.Format("CheckThirdPartyNumberExist:{0}", IsExist != null ? 1 : 0), orderInfo.RelationId); if (IsExist == null) { #region 获取自动生成的运单号 //sql = "select concat('99', 1000000000 + Count(*) + 1) from waybill_base where company = 1"; //object obj = _SqlHelp.ExecuteScalar(sql); string number = string.Empty; string nHead = "981000000000"; if (customerId != 2) { nHead = "991000000000"; } int jLen = orderInfo.RelationId.Length; //if (orderInfo.RelationId.Length >= 12) // jLen = 10; //number = nHead.Substring(0, 12 - orderInfo.RelationId.Length) + orderInfo.RelationId; if (orderInfo.RelationId.Length > 9) { string str1 = orderInfo.RelationId.ToString().Substring(orderInfo.RelationId.Length - 9); number = nHead.Substring(0, 12 - str1.Length) + str1; } else { number = nHead.Substring(0, 12 - orderInfo.RelationId.Length) + orderInfo.RelationId; } LogServer.AddLogText("拼接后的运单号:" + number + "", orderInfo.RelationId); //if (obj != null) //{ // number = obj.ToString(); // if (obj.ToString() == "System.Byte[]") // number = Encoding.Default.GetString(obj as byte[]); //} #endregion #region 旧版通过配置文件获取第三方供应商名称,新版查询根据CustomerID查询 int Huadong_Id = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Huadong_Id"]); string Huadong_Name = System.Configuration.ConfigurationManager.AppSettings["Huadong_Name"]; if (customerId != 0) { Huadong_Id = customerId; customerInfo = PDA_CustomerServer.GetThirdCustomers(customerId).First(); Huadong_Name = customerInfo.CustomerName; } #endregion List <string> sqlList = new List <string>(); //更新关系ID sql = string.Format("update huadong_tms_order set relationId='{0}' where (SHIPDETAILID = '{0}' or LEGCODE = '{0}' )", orderInfo.RelationId); sql += customerId == 0 ? string.Empty : (" and customerId = " + customerId); int count = _SqlHelp.ExecuteNonQuery(sql); LogServer.AddLogText(string.Format("更新第三方运单relationId:{0},结果:{1}", sql, count), orderInfo.RelationId); if (count == 0) { LogServer.AddLogText(string.Format("第三方运单不存在时,先插入一条空信息的运单,待第三方运单同步回来时更新运单信息", orderInfo.RelationId, orderInfo.OperateAt, customerId), orderInfo.RelationId); //第三方运单不存在时,先插入一条空信息的运单,待第三方运单同步回来时更新运单信息 sqlList.Add(string.Format("INSERT INTO `coldchain_logistics_db`.`huadong_tms_order` ( `relationId`, `code`, `SRCEXPNO`, `ROADID`, `SHIPDETAILID`, `TOTALID`, `LEGCODE`, `SHIPMENTCODE`, `CONSIGNORCODE`, `CONSIGNORNAME`, `DEPTNO`, `DEPTNAME`, `CUSTOMERCODE`, `CUSTOMERNAME`, `AREAHOUSE`, `SALESMAN`, `TRANSMODEID`, `ERPTRANSMODENAME`, `OPERATIONTYPE`, `DEMANDARRIVETIME`, `TRANSPORTTYPE`, `ORDERINSTANCY`, `TRANSPORTCATEGORY`, `ROUTENO`, `TRANSDEADLINE`, `FROMGTRANSID`, `FROMGTRANSNAME`, `TOGTRANSID`, `TOGTRANSNAME`, `RECEIVEADDR`, `RECEIVEMAN`, `RECEIVEPHONE`, `CREDATE`, `INOUTFLAG`, `WMSROUTEWAVENO`, `PRINTTYPE`, `TOTALQUNTITY`, `WHOLEQUNTITY`, `PARTQUNTITY`, `JFQUNTITY`, `DESCRIPTION`, `EXTCOL0`, `EXTCOL1`, `EXTCOL2`, `EXTCOL3`, `EXTCOL4`, `EXTCOL5`, `EXTCOL6`, `EXTCOL7`, `EXTCOL8`, `EXTCOL9`, `EXTCOL10`, `EXTCOL11`, `EXTCOL12`, `EXTCOL13`, `EXTCOL14`, `EXTCOL15`, `EXTCOL16`, `EXTCOL17`, `EXTCOL18`, `EXTCOL19`, `senderOrg`, `senderPerson`, `senderTel`, `senderAddress`, `receiverOrg`, `receiverPerson`, `receiverTel`, `receiverAddress`, `SecretKey`, `CreateTime`, `customerId`) VALUES ( '{0}', '', '', '', '{0}', '', '{0}', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 0, 0,0, 0, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '未知', '{1}', '{2}');", orderInfo.RelationId, orderInfo.OperateAt, customerId)); } LogServer.AddLogText("开始添加关联运单", orderInfo.RelationId); //插入本系统自用的关联运单 sqlList.Add(string.Format("insert into huadong_tmsorder_waybillbase(relationId,number{2}) values('{0}', '{1}'{3})", orderInfo.RelationId, number, customerId != 0 ? ",customerId" : "", customerId != 0 ? "," + customerId : "")); string updateReceiverIdSql = string.Empty; if (customerInfo.LinkType == 2) { sql = string.Format("insert into waybill_base (number,senderId,senderOrg,senderPerson,senderTel,senderAddress,receiverId,receiverOrg,receiverPerson, receiverTel, receiverAddress, billingCount, stage, beginAt, signinAt, picPostbackAt, company) select '{4}' as number, {0} as senderId, '{1}' as senderOrg, senderPerson , senderTel , senderAddress ,null as receiverId, receiverOrg , receiverPerson , receiverTel , receiverAddress,(if(isnull(JFQUNTITY),0,JFQUNTITY)) as billingCount, 0 as stage, '{2}' as beginAt, null as signinAt, null as picPostbackAt, 1 as company from huadong_tms_order where (SHIPDETAILID = '{3}' or LEGCODE = '{3}') and customerId={5} limit 1", Huadong_Id, Huadong_Name, orderInfo.OperateAt, orderInfo.RelationId, number, customerId); //宁波医药 updateReceiverIdSql = ("update waybill_base set receiverId = (select Id from customer where BindReceiverOrg=receiverOrg order by lastUpdateTime desc limit 1) where number = '" + number + "'"); } else { sql = string.Format("insert into waybill_base (number,senderId,senderOrg,senderPerson,senderTel,senderAddress,receiverId,receiverOrg,receiverPerson, receiverTel, receiverAddress, billingCount, stage, beginAt, signinAt, picPostbackAt, company) select '{4}' as number, {0} as senderId, '{1}' as senderOrg, EXTCOL12 as senderPerson, '' as senderTel, EXTCOL11 as senderAddress,null as receiverId, CUSTOMERNAME as receiverOrg, RECEIVEMAN as receiverPerson, RECEIVEPHONE as receiverTel, RECEIVEADDR as receiverAddress,0 as billingCount, 0 as stage, '{2}' as beginAt, null as signinAt, null as picPostbackAt, 1 as company from huadong_tms_order where SHIPDETAILID = '{3}' or LEGCODE = '{3}' limit 1", Huadong_Id, Huadong_Name, orderInfo.OperateAt, orderInfo.RelationId, number); //大华东 updateReceiverIdSql = ("update waybill_base set receiverId = (select Id from customer where fullName=receiverOrg order by lastUpdateTime desc limit 1) where number = '" + number + "'"); } sqlList.Add(sql); sqlList.Add(updateReceiverIdSql); foreach (string item in sqlList) { LogServer.AddLogText(item, orderInfo.RelationId); } result = _SqlHelp.ExecuteTranstration(sqlList) ? 1 : 0; LogServer.AddLogText(string.Format("执行结果:{0}", result), orderInfo.RelationId); //回滚暂存表中的可用节点 if (result == 1) { HuaDongFcCoTable(orderInfo.RelationId); HuaDongFcCoPictures(orderInfo.RelationId); } LogServer.AddLogText("创建第三方运单逻辑结束", orderInfo.RelationId); } else { //判断运单操作时间先后,操作时间早的更新后的 if (Convert.ToDateTime(orderInfo.OperateAt) < IsExist.BeginAt) { sql = string.Format("update waybill_base set beginAt='{0}' where number='{1}' ;", orderInfo.OperateAt, IsExist.Number); int updatbeginAt = _SqlHelp.ExecuteNonQuery(sql); LogServer.AddLogText(string.Format("sql:{0},结果:{1}", sql, updatbeginAt), orderInfo.RelationId); result = 1; } else { result = 1; } } } catch (Exception ex) { throw ex; } return(result); }