Beispiel #1
0
        /// <summary>
        /// 更新订单温湿度上报进度
        /// </summary>
        /// <param name="relation">包含运单信息以及运单温湿度数据上报的进度</param>
        /// <returns></returns>
        public static bool UpdataUploadDataNode(RelationModel relation)//, ref List<long> _ignoreTempRelationList)
        {
            bool isArrived = false;
            //试图获取当前运单的下一个节点
            NodeInfo nodeInfo = NodeUploadServer.GetNextUploadNodeInfo(relation.CurrentUploadDataNodeId, relation.Number);

            //如果存在下一个节点并且当前上报进度等于下一个节点的创建时间,则更新上报进度的节点
            if (nodeInfo != null && DateTime.Parse(relation.CurrentUploadDataTime) >= DateTime.Parse(nodeInfo.OperateAt))
            {
                relation.CurrentUploadDataNodeId = nodeInfo.Id;
            }
            //查询当前节点是否已经运抵
            if (relation.CurrentUploadDataNodeId != -1)
            {
                string sql     = "select arrived from waybill_node where id = " + relation.CurrentUploadDataNodeId;
                object arrived = DbHelperMySQL.GetSingle(sql);
                if (arrived == null)
                {
                    throw new Exception("获取节点信息失败");
                }
                isArrived = (arrived.ToString() == "2" && (relation.CurrentUploadNodeId == 0));
            }
            //if (isArrived)
            //    _ignoreTempRelationList.Remove(relation.Id);
            return(UpdateCurrentRelationUploadDataNode(relation, isArrived));
            //}
            //else {

            //return UpdateCurrentRelationUploadDataNode(relation, false);
            //}
            //查询当前节点冷藏载体的下一条温湿度数据,如果大于下一个节点的时间,则进入下一个节点
            //string sql = "select StorageId from waybill_Node where id = " + relation.CurrentUploadDataNodeId;
            //object storageId = DbHelperMySQL.GetSingle(sql);
            //if (storageId == null)
            //    throw new Exception(string.Format("获取下一节点失败:R【{0}】 O【{1}】 N【{2}】", relation.RelationId, relation.Number, relation.CurrentUploadDataNodeId));
            //sql = string.Format("select dataTime from history_data_{0} where dataTime > '{1}' limit 1", storageId, relation.CurrentUploadDataTime);
            //object dataTime = DbHelperMySQL.GetSingle(sql);
            //if (dataTime != null && Convert.ToDateTime(dataTime) > DateTime.Parse(relation.CurrentUploadDataTime))
            //{
            //    if (nodeInfo != null)
            //        relation.CurrentUploadDataNodeId = nodeInfo.Id;
            //    else
            //    {
            //        //查询当前节点是否已经运抵
            //        sql = "select arrived from waybill_node where id = " + relation.CurrentUploadDataNodeId;
            //        object arrived = DbHelperMySQL.GetSingle(sql);
            //        if (arrived == null)
            //            throw new Exception("获取节点信息失败");
            //        isArrived = arrived.ToString() == "2";
            //        if (isArrived)
            //            _ignoreTempRelationList.Remove(relation.Id);
            //    }
            //}
            //else
            //    _ignoreTempRelationList.Add(relation.Id);
            //return UpdateCurrentRelationUploadDataNode(relation, isArrived);
        }
Beispiel #2
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);
        }