Exemplo n.º 1
0
        /// <summary>
        /// 更新冷链数据上报处理进度
        /// </summary>
        /// <param name="progress"></param>
        /// <returns></returns>
        public static bool UpdateUploadProgress(UploadDataProgress progress, bool haveData = true)
        {
            int    handleFlag = 0;
            string sql        = string.Empty;

            try
            {
                if (haveData && progress.endNodeTime > progress.uploadProgress)
                {
                    sql = string.Format("update uploadDataProgress set lastHandleTime='{0}',uploadProgress='{1}' where Id = {2}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), progress.uploadProgress.ToString("yyyy-MM-dd HH:mm:ss"), progress.Id);
                    DbHelperMySQL.ExecuteSql(sql);
                    return(true);//如果还有数据则不更新标记
                }
                handleFlag = progress.endNodeTime <= progress.uploadProgress ? 1 : 0;
                sql        = string.Format("update uploadDataProgress set handleFlag='{0}',lastHandleTime='{1}',uploadProgress='{3}' where Id = {2}", handleFlag, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), progress.Id, progress.uploadProgress.ToString("yyyy-MM-dd HH:mm:ss"));
                return(DbHelperMySQL.ExecuteSql(sql) == 1);
            }
            finally
            {
                try
                {
                    if (Utility._LinkType == "2" && handleFlag == 1)
                    {
                        //检查是否所有节点与冷链数据都已经上报完成
                        sql = string.Format("select count(*)-p.c as count from waybill_node n INNER JOIN (select Count(*) c from uploaddataprogress where relationId='{0}' and handleFlag=1) p  where n.scannumber='{0}';", progress.relationId);
                        int count = Convert.ToInt32(DbHelperMySQL.GetSingle(sql));
                        if (count == 1)
                        {
                            //数据已上报完成
                            M_TMSEnd end = new M_TMSEnd()
                            {
                                Arrived = true, OrderNo = progress.relationId, JcOrderNo = GetJcOrderNoForProgress(progress.relationId)
                            };
                            string xmlStr       = Utility.ParseXMLToString(end);
                            string receiverCode = TMSOrderServer.GetAllLoginkSenderCode("2")[0];
                            LoginkHelp.Send(Utility._SecurityURL, Utility._TransportURL, Utility._MyCode, Utility._MyPwd, receiverCode, xmlStr, ActionType.JTWL_ENTRUST_TRANS_BookingNoteStatus);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("上报TMSEnd失败:" + ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        public static bool UpdateCurrentRelationUploadDataNode(RelationModel relation, bool isArrived)
        {
            if (relation.CurrentUploadDataNodeId == -1 || string.IsNullOrEmpty(relation.CurrentUploadDataTime))
            {
                return(true);
            }
            string sql = string.Format("update huadong_tmsorder_waybillbase set CurrentUploadDataNodeId = '{0}',CurrentUploadDataTime='{1}'  where id='{2}'", isArrived ? 0 : relation.CurrentUploadDataNodeId, relation.CurrentUploadDataTime, relation.Id);

            try
            {
                bool result = DbHelperMySQL.ExecuteSql(sql) > 0;
                UpdateHandleTHTime(relation.Id, result);
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("RelationId[" + relation.RelationId + "] 更新节点冷链数据进度出错:" + ex.Message + " SQL[" + sql + "]");
            }
            finally
            {
                if (isArrived && Utility._LinkType == "2")
                {
                    try
                    {
                        //数据已上报完成
                        M_TMSEnd end = new M_TMSEnd()
                        {
                            Arrived = true, OrderNo = relation.RelationId, JcOrderNo = relation.Number
                        };
                        string xmlStr       = Utility.ParseXMLToString(end);
                        string receiverCode = TMSOrderServer.GetAllLoginkSenderCode(relation.CustomerId.ToString())[0];
                        LoginkHelp.Send(Utility._SecurityURL, Utility._TransportURL, Utility._MyCode, Utility._MyPwd, receiverCode, xmlStr, ActionType.JTWL_ENTRUST_TRANS_BookingNoteStatus);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("上报TMSEnd失败[" + ex.Message + "]");
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 暂时忽略掉的关系
        /// </summary>
        //private List<int> _ignoreTempRelationList = new List<int>();

        #region Logink正式环境
        private void _bw_DoWork(object sender, DoWorkEventArgs e)
        {
            DateTime      dtNow     = DateTime.Now;
            string        msg       = dtNow.ToString() + ":【节点上报】 ";
            string        xmlResult = string.Empty;
            RelationModel relation  = new RelationModel();

            try
            {
                List <string> senderCodeList = null;
                M_TMSNode     loginkNode     = null;
                if (Utility._LinkType == "2")
                {
                    senderCodeList = TMSOrderServer.GetAllLoginkSenderCode();
                    if (senderCodeList.Count == 0)
                    {
                        msg += "没有配置通过运管平台交换数据的上游发货单位";
                        return;
                    }
                }
                Model.NodeUpload.MESSAGEDETAIL.XML details = NodeUploadServer.GetFirstWaitUploadNode(senderCodeList, ref loginkNode, out relation);

                if (relation != null && relation.Id != 0)
                {
                    msg += string.Format("Relation【{0}】 Number【{1}】 CustomerId【{3}】 当前上报节点Id【{2}】 ", relation.RelationId, relation.Number, relation.CurrentUploadNodeId, relation.CustomerId);
                }
                if (details == null)
                {
                    if (relation != null && relation.Id != 0)                  // && !_ignoreTempRelationList.Contains(relation.Id))
                    {
                        NodeUploadServer.UpdateHandleTime(relation.Id, false); //_ignoreTempRelationList.Add(relation.Id);
                    }
                    msg += "暂无需要上报的节点";
                    return;
                }
                //运管平台上报
                if (senderCodeList != null)
                {
                    string nodeXml      = Utility.ParseXMLToString(loginkNode);
                    string receiverCode = TMSOrderServer.GetAllLoginkSenderCode(relation.CustomerId.ToString())[0];
                    LoginkHelp.Send(Utility._SecurityURL, Utility._TransportURL, Utility._MyCode, Utility._MyPwd, receiverCode, nodeXml, ActionType.LOGINK_CN_TRANSPORT_PREBOOKING);
                    msg += "上报成功 Receiver[" + receiverCode + "]";
                    bool isArrived = false;
                    if (details.CONTENTLIST[0].DETAILLIST[0].TRACKTYPE == "18")//正常签收
                    {
                        isArrived = true;
                        msg      += " 当前为签收节点 ";
                    }
                    bool isUpdate = NodeUploadServer.UpdateCurrentUploadNodeId(relation, isArrived, senderCodeList);
                    Utility.SaveXMLRequestAndRespond(nodeXml, string.Empty, "Node", relation.RelationId);
                    msg += isUpdate ? "更新当前上报节点成功" : "更新当前上报节点失败";
                    return;
                }
                #region 大华东供应链节点上报处理
                _UploadXML.MESSAGEHEAD.SENDTIME = dtNow.ToString("yyyy-MM-dd HH:mm:ss");
                _UploadXML.MESSAGEHEAD.FILENAME = dtNow.ToString("yyyyMMddHHmmss");
                _UploadXML.MESSAGEDETAIL        = "<![CDATA[" + Utility.ParseXMLToString <Model.NodeUpload.MESSAGEDETAIL.XML>(details) + "]]>";
                string xmlRequest = Utility.ParseXMLToString <Model.NodeUpload.XML>(_UploadXML).Replace("<", "&lt;").Replace(">", "&gt;");
                Utility.AddLogText("上传前:" + xmlRequest);
                StringBuilder param = new StringBuilder();
                param.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.webservice.vtradex.com\" > ");
                param.Append("<soapenv:Header/>");
                param.Append("<soapenv:Body>");
                param.Append("<ser:tmsShipmentInTransitXml>" + xmlRequest + "</ser:tmsShipmentInTransitXml>");
                param.Append("</soapenv:Body>");
                param.Append("</soapenv:Envelope>");
                xmlResult = HTTPHelper.SendHTTPRequest(param.ToString(), "tmsShipmentInTransitXml", "tmsShipmentInTransitXml");
                Model.NodeUpload.XML uploadResult = Utility.ParseXMLToObjec <Model.NodeUpload.XML>(xmlResult);
                if (uploadResult.MSGCODE == "0" || string.IsNullOrEmpty(uploadResult.MSGCODE))
                {
                    msg += "上报失败" + " " + uploadResult.MSGCONTENT;
                }
                else if (uploadResult.MSGCODE == "1")
                {
                    msg += "上报成功 ";
                    try
                    {
                        bool isArrived = false;
                        if (details.CONTENTLIST[0].DETAILLIST[0].TRACKTYPE == "18")//正常签收
                        {
                            isArrived = true;
                            msg      += " 当前为签收节点 ";
                        }
                        bool isUpdate = NodeUploadServer.UpdateCurrentUploadNodeId(relation, isArrived, senderCodeList);
                        msg += isUpdate ? "更新当前上报节点成功" : "更新当前上报节点失败";
                        if (isArrived && isUpdate)
                        {
                            UploadCarrierArrived(details.CONTENTLIST[0].DETAILLIST[0], relation.CurrentUploadDataTime);
                        }
                    }
                    catch (Exception ex1)
                    {
                        msg += ex1.Message;
                    }
                }
                Utility.SaveXMLRequestAndRespond(param.ToString(), xmlResult, "Node", relation.RelationId);
                #endregion
            }
            catch (Exception ex)
            {
                msg += ex.Message;
                Utility.SaveErrLog(ex.Message, "Node");
                if (!ex.Message.Contains("重新开始") && !ex.Message.Contains("成功"))
                {
                    if (relation != null)
                    {
                        NodeUploadServer.UpdateHandleTime(relation.Id, false);
                    }
                    SendEmail(new Exception(msg));
                }
            }
            finally
            {
                Console.WriteLine(msg.Replace("\n", ""));
            }
        }
        /// <summary>
        /// 暂时忽略掉的关系
        /// </summary>
        //private List<long> _ignoreTempRelationList = new List<long>();


        #region Logink正式环境
        private void _bw_DoWork(object sender, DoWorkEventArgs e)
        {
            DateTime      dtNow     = DateTime.Now;
            string        msg       = dtNow.ToString() + ":【订单温湿度上报】 ";
            string        xmlResult = string.Empty;
            RelationModel relation  = new RelationModel();

            try
            {
                List <string>    senderCodeList = null;
                List <M_TMSData> loginkData     = null;
                if (Utility._LinkType == "2")
                {
                    senderCodeList = TMSOrderServer.GetAllLoginkSenderCode();
                    if (senderCodeList.Count == 0)
                    {
                        msg += "没有配置通过运管平台交换数据的上游发货单位";
                        return;
                    }
                }
                XML details = DataUploadServer.GetNextWaitUploadDatas(senderCodeList, ref loginkData, out relation);
                if (relation != null && relation.Id != 0)
                {
                    msg += string.Format("R【{0}】 O【{1}】 N【{2}】 T【{3}】", relation.RelationId, relation.Number, relation.CurrentUploadDataNodeId, relation.CurrentUploadDataTime);
                }
                if (details == null)
                {
                    if (relation != null && relation.Id != 0)                    // && !_ignoreTempRelationList.Contains(relation.Id))
                    {
                        DataUploadServer.UpdateHandleTHTime(relation.Id, false); //_ignoreTempRelationList.Add(relation.Id);
                    }
                    msg += "没有新的节点数据[relationId:" + relation.Id + "]";
                    return;
                }
                //运管平台上报
                if (senderCodeList != null)
                {
                    string dataXml      = Utility.ParseXMLToString(loginkData);
                    string receiverCode = TMSOrderServer.GetAllLoginkSenderCode()[0];
                    LoginkHelp.Send(Utility._SecurityURL, Utility._TransportURL, Utility._MyCode, Utility._MyPwd, receiverCode, dataXml, ActionType.LOGINK_CN_TRANSPORT_PREBOOKING);
                    msg += "上报成功 Receiver[" + receiverCode + "]";
                    bool isUpdate = DataUploadServer.UpdataUploadDataNode(relation);//, ref _ignoreTempRelationList);
                    Utility.SaveXMLRequestAndRespond(dataXml, string.Empty, "Temperature", relation.RelationId);
                    msg += isUpdate ? "更新进度成功" : "更新进度失败";
                    return;
                }
                _UploadXML.MESSAGEHEAD.SENDTIME = dtNow.ToString("yyyy-MM-dd HH:mm:ss");
                _UploadXML.MESSAGEHEAD.FILENAME = dtNow.ToString("yyyyMMddHHmmss");
                _UploadXML.MESSAGEDETAIL        = "<![CDATA[" + Utility.ParseXMLToString <Model.NodeDataUpload.XML>(details) + "]]>";
                string        xmlRequest = Utility.ParseXMLToString <Model.NodeUpload.XML>(_UploadXML).Replace("<", "&lt;").Replace(">", "&gt;");
                StringBuilder param      = new StringBuilder();
                param.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.webservice.vtradex.com\" > ");
                param.Append("<soapenv:Header/>");
                param.Append("<soapenv:Body>");
                param.Append("<ser:temperatureXml1>" + xmlRequest + "</ser:temperatureXml1>");
                param.Append("</soapenv:Body>");
                param.Append("</soapenv:Envelope>");
                xmlResult = HTTPHelper.SendHTTPRequest(param.ToString(), "getTmsShipmentTemperature", "temperatureXml1");
                Model.NodeUpload.XML uploadResult = Utility.ParseXMLToObjec <Model.NodeUpload.XML>(xmlResult, param.ToString());
                if (uploadResult.MSGCODE == "0" || string.IsNullOrEmpty(uploadResult.MSGCODE))
                {
                    msg += "上报失败 " + uploadResult.MSGCONTENT;
                }
                else if (uploadResult.MSGCODE == "1")
                {
                    msg += "上报成功 ";
                    try
                    {
                        msg += DataUploadServer.UpdataUploadDataNode(relation) ? "更新进度成功." : "更新进度失败.";
                    }
                    catch (Exception ex1)
                    {
                        msg += ex1.Message;
                    }
                }
                Utility.SaveXMLRequestAndRespond(param.ToString(), xmlResult, "Temperature", relation.RelationId);
            }
            catch (Exception ex)
            {
                msg += ex.Message;
                Utility.SaveErrLog(ex.Message, "Temperature");
                //if (relation.Id != 0 )//&& _ignoreTempRelationList.Contains(relation.Id) == false)
                //    DataUploadServer.UpdateHandleTHTime(relation.Id, false); //_ignoreTempRelationList.Add(relation.Id);
                if (relation != null && relation.CurrentUploadDataNodeId != -1)
                {
                    if (!ex.Message.Contains("重新开始") && !ex.Message.Contains("成功") && !ex.Message.Contains("没有新的载体温湿度"))
                    {
                        DataUploadServer.UpdateHandleTHTime(relation.Id, false);
                        SendEmail(new Exception(msg));
                    }
                }
            }
            finally
            {
                Console.WriteLine(msg.Replace("\n", ""));
            }
        }