Example #1
0
        public static Model.NodeDataUpload.XML GetNextWaitUploadDatas(List <string> senderCodeList, ref List <M_TMSData> loginkData, out RelationModel relation)
        {
            Model.NodeDataUpload.XML result = null;
            relation = new RelationModel();
            try
            {
                relation = GetNextWaitUploadDataOrderRelation(senderCodeList);//, ref _ignoreTempRelationList);
                if (relation != null)
                {
                    NodeInfo nodeInfo = NodeUploadServer.GetNextUploadNodeInfo(relation.CurrentUploadDataNodeId, relation.Number);
                    if (nodeInfo != null)
                    {
                        //从未上报过节点数据
                        if (string.IsNullOrEmpty(relation.CurrentUploadDataTime) || relation.CurrentUploadDataNodeId == null || relation.CurrentUploadDataNodeId == -1)
                        {
                            relation.CurrentUploadDataTime   = nodeInfo.OperateAt;
                            relation.CurrentUploadDataNodeId = nodeInfo.Id;
                            //更新冷链数据上报进度
                            bool   isUpdataRelation = UpdateCurrentRelationUploadDataNode(relation, false);
                            string info             = string.Format("R【{0}】 O【{1}】 N【{2}】 T【{3}】", relation.RelationId, relation.Number, relation.CurrentUploadDataNodeId, relation.CurrentUploadDataTime);
                            throw new Exception(info + (isUpdataRelation ? "更新为首节点成功." : "更新为首节点失败."));
                            //throw new Exception("首个节点暂不上报数据 " );
                        }
                        else
                        {
                            //获取待上报数据
                            DataTable dt = GetStorageData((int)relation.CurrentUploadDataNodeId, DateTime.Parse(relation.CurrentUploadDataTime), DateTime.Parse(nodeInfo.OperateAt).AddDays(1));//结束时间+30分钟改为24小时
                            if (dt == null)
                            {
                                string info = string.Format("R【{0}】 O【{1}】 N【{2}】 T【{3}】", relation.RelationId, relation.Number, relation.CurrentUploadDataNodeId, relation.CurrentUploadDataTime);
                                if ((DateTime.Now - DateTime.Parse(relation.CurrentUploadDataTime)).TotalDays > int.Parse(Utility._StorageDataTimeOut))
                                {
                                    relation.CurrentUploadDataTime   = nodeInfo.OperateAt;
                                    relation.CurrentUploadDataNodeId = nodeInfo.Id;
                                    bool isUpdataRelation = UpdateCurrentRelationUploadDataNode(relation, false);
                                    throw new Exception(info + "放弃等待当前载体温湿度,已过" + int.Parse(Utility._StorageDataTimeOut) + "*24小时 更新为下一节点" + (isUpdataRelation ? "成功." : "失败."));
                                }
                                else
                                {
                                    UpdateHandleTHTime(relation.Id, false);
                                    //_ignoreTempRelationList.Add(relation.Id);
                                    throw new Exception(info + "没有新的载体温湿度.");
                                }
                            }
                            result             = new Model.NodeDataUpload.XML();
                            result.CONTENTLIST = new List <CONTENT>();
                            result.CONTENTLIST.Add(new CONTENT());
                            result.CONTENTLIST[0].DETAILLIST = new List <DETAIL>();
                            DETAIL dModel = new DETAIL();
                            dModel.ECNO  = NodeUploadServer.GetShipmentCodeByTMSOrder(relation.RelationId);
                            dModel.LEGNO = relation.RelationId;
                            Utility.AddLogText(string.Format("dModel:ECNO:{0},LEGNO:{1},RelationId:{2}", dModel.ECNO, dModel.LEGNO, relation.RelationId));
                            GetStorageByNodeId((int)relation.CurrentUploadDataNodeId, ref dModel);
                            loginkData = new List <M_TMSData>();
                            foreach (DataRow row in dt.Rows)
                            {
                                string temp = row["t"] is DBNull ? string.Empty : row["t"].ToString();
                                string hump = string.Empty;
                                try
                                {
                                    hump = row["h"] is DBNull ? string.Empty : row["h"].ToString();
                                }
                                catch
                                {
                                }
                                if (temp == "System.Byte[]")
                                {
                                    temp = System.Text.Encoding.Default.GetString(row["t"] as byte[]);
                                }
                                if (hump == "System.Byte[]")
                                {
                                    hump = System.Text.Encoding.Default.GetString(row["h"] as byte[]);
                                }

                                DETAIL detail = new DETAIL();
                                detail.ECNO          = dModel.ECNO;
                                detail.LEGNO         = dModel.LEGNO;
                                detail.LICENSENO     = dModel.LICENSENO;
                                detail.WAREHOUSECODE = dModel.WAREHOUSECODE;
                                detail.TRACKTIME     = Convert.ToDateTime(row["datatime"]).ToString("yyyy-MM-dd HH:mm:ss");

                                detail.TEMPREATURE = temp.Replace("-300.0", "").Replace("-300", "");
                                detail.HUMIDITY    = hump.Replace("-300.0", "").Replace("-300", "");
                                try
                                {
                                    detail.LONGITUDE = row["lo"] is DBNull ? string.Empty : row["lo"].ToString();
                                }
                                catch
                                {
                                }
                                try
                                {
                                    detail.LATITUDE = row["la"] is DBNull ? string.Empty : row["la"].ToString();
                                }
                                catch
                                {
                                }
                                Utility.AddLogText(string.Format("detail:ECNO:{0},LEGNO:{1}", detail.ECNO, detail.LEGNO));
                                result.CONTENTLIST[0].DETAILLIST.Add(detail);

                                M_TMSData data = new M_TMSData();
                                data.Latitude   = detail.LATITUDE == string.Empty ? null : detail.LATITUDE.ToString();
                                data.Longitude  = detail.LONGITUDE == string.Empty ? null : detail.LONGITUDE.ToString();
                                data.RecordTime = Convert.ToDateTime(row["datatime"]);
                                data.OrderNo    = relation.RelationId;
                                data.JcOrderNo  = relation.Number;
                                data.JcNodeId   = (int)relation.CurrentUploadDataNodeId;
                                Type t = data.GetType();
                                for (int i = 0; i < temp.Split('|').Count(); i++)
                                {
                                    t.GetProperty("T" + (i + 1)).SetValue(data, temp.Split('|')[i].ToString(), null);
                                }
                                for (int i = 0; i < hump.Split('|').Count(); i++)
                                {
                                    t.GetProperty("RH" + (i + 1)).SetValue(data, hump.Split('|')[i].ToString(), null);
                                }
                                loginkData.Add(data);
                                relation.CurrentUploadDataTime = detail.TRACKTIME;
                                if (DateTime.Parse(detail.TRACKTIME) >= DateTime.Parse(nodeInfo.OperateAt))
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        UpdataUploadDataNode(relation);//, ref _ignoreTempRelationList);
                    }
                }
            }
            catch (Exception ex)
            {
                //if (relation != null)
                //    _ignoreTempRelationList.Add(relation.Id);
                throw new Exception(ex.Message);
            }
            return(result);
        }
Example #2
0
        public static Model.NodeDataUpload.XML GetNextWaitUploadDatasProgress(List <string> senderCodeList, ref List <M_TMSData> loginkData, out UploadDataProgress progress)
        {
            Model.NodeDataUpload.XML result = null;
            progress = null;
            try
            {
                progress = GetNextWaitUploadDataProgress(senderCodeList);
                if (progress != null)
                {
                    DataTable dt = GetStorageData(0, progress.uploadProgress, progress.endNodeTime.AddDays(int.Parse(Utility._StorageDataTimeOut)), progress.storageId);
                    if (dt == null)
                    {
                        string info = string.Format("PId【{0}】 RId【{1}】 Time【{2}】", progress.Id, progress.relationId, progress.uploadProgress.ToString("yyyy-MM-dd HH:mm:ss"));
                        if ((DateTime.Now - progress.uploadProgress).TotalDays > int.Parse(Utility._StorageDataTimeOut))
                        {
                            progress.uploadProgress = DateTime.Now; //progress.endNodeTime;
                            UpdateUploadProgress(progress, false);
                            throw new Exception(info + "放弃等待当前载体温湿度,已过" + int.Parse(Utility._StorageDataTimeOut) + "*24小时");
                        }
                        else
                        {
                            UpdateUploadProgress(progress, false);
                            throw new Exception(info + "没有新的载体温湿度.");
                        }
                    }
                    result             = new Model.NodeDataUpload.XML();
                    result.CONTENTLIST = new List <CONTENT>();
                    result.CONTENTLIST.Add(new CONTENT());
                    result.CONTENTLIST[0].DETAILLIST = new List <DETAIL>();
                    DETAIL dModel = new DETAIL();
                    dModel.ECNO  = progress.shipmentCode;
                    dModel.LEGNO = progress.relationId;
                    Utility.AddLogText(string.Format("dModel:ECNO:{0},LEGNO:{1},RelationId:{2}", dModel.ECNO, dModel.LEGNO, progress.relationId));
                    if (progress.storageType == 1)
                    {
                        dModel.WAREHOUSECODE = progress.storageName;
                    }
                    else if (progress.storageType == 2)
                    {
                        dModel.LICENSENO = progress.storageName;
                    }
                    //GetStorageByNodeId((int)relation.CurrentUploadDataNodeId, ref dModel);
                    loginkData = new List <M_TMSData>();
                    foreach (DataRow row in dt.Rows)
                    {
                        string temp = row["t"] is DBNull ? string.Empty : row["t"].ToString();
                        string hump = "-300.0";
                        try
                        {
                            hump = row["h"] is DBNull ? string.Empty : row["h"].ToString();
                        }
                        catch
                        {
                        }
                        if (temp == "System.Byte[]")
                        {
                            temp = System.Text.Encoding.Default.GetString(row["t"] as byte[]);
                        }
                        if (hump == "System.Byte[]")
                        {
                            hump = System.Text.Encoding.Default.GetString(row["h"] as byte[]);
                        }

                        DETAIL detail = new DETAIL();
                        detail.ECNO          = dModel.ECNO;
                        detail.LEGNO         = dModel.LEGNO;
                        detail.LICENSENO     = dModel.LICENSENO;
                        detail.WAREHOUSECODE = dModel.WAREHOUSECODE;
                        detail.TRACKTIME     = Convert.ToDateTime(row["datatime"]).ToString("yyyy-MM-dd HH:mm:ss");

                        detail.TEMPREATURE = temp; //.Replace("-300.0", "").Replace("-300", "");
                        detail.HUMIDITY    = hump; //.Replace("-300.0", "").Replace("-300", "");
                        try
                        {
                            detail.LONGITUDE = row["lo"] is DBNull ? string.Empty : row["lo"].ToString();
                        }
                        catch
                        {
                        }
                        try
                        {
                            detail.LATITUDE = row["la"] is DBNull ? string.Empty : row["la"].ToString();
                        }
                        catch
                        {
                        }
                        Utility.AddLogText(string.Format("detail:ECNO:{0},LEGNO:{1}", detail.ECNO, detail.LEGNO));
                        //result.CONTENTLIST[0].DETAILLIST.Add(detail);

                        M_TMSData data = new M_TMSData();
                        data.Latitude   = detail.LATITUDE == string.Empty ? null : detail.LATITUDE.ToString();
                        data.Longitude  = detail.LONGITUDE == string.Empty ? null : detail.LONGITUDE.ToString();
                        data.RecordTime = Convert.ToDateTime(row["datatime"]);
                        data.OrderNo    = progress.relationId;
                        data.JcOrderNo  = GetJcOrderNoForProgress(progress.relationId);
                        data.JcNodeId   = GetJcNodeIdForProgress(progress.relationId, progress.storageId, progress.nodeTime.ToString("yyyy-MM-dd HH:mm:ss"));
                        Type t = data.GetType();
                        for (int i = 0; i < temp.Split('|').Count(); i++)
                        {
                            t.GetProperty("T" + (i + 1)).SetValue(data, temp.Split('|')[i].ToString(), null);
                        }
                        for (int i = 0; i < hump.Split('|').Count(); i++)
                        {
                            t.GetProperty("RH" + (i + 1)).SetValue(data, hump.Split('|')[i].ToString(), null);
                        }
                        //loginkData.Add(data);
                        progress.uploadProgress = DateTime.Parse(detail.TRACKTIME);
                        if (DateTime.Parse(detail.TRACKTIME) > progress.endNodeTime)
                        {
                            progress.uploadProgress = progress.endNodeTime;
                            if (loginkData.Count == 0)
                            {
                                bool isUpdate = DataUploadServer.UpdateUploadProgress(progress);
                                throw new Exception("仅一条末尾数据且大于节点结束时间,直接更新此进度:" + (isUpdate ? "成功" : "失败"));
                            }
                            break;
                        }
                        else
                        {
                            loginkData.Add(data);
                            result.CONTENTLIST[0].DETAILLIST.Add(detail);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("获取冷链数据失败:" + ex.Message);
            }
            return(result);
        }