Ejemplo n.º 1
0
        private bool DealInspectionTrack(BaseDataClient client, DateTime dtBegin, DateTime dtEnd, bool bFlag)
        {
            List <InspectionTrack>        All    = new List <InspectionTrack>();
            List <InspectionTrack>        Add    = new List <InspectionTrack>();
            List <InspectionTrack>        Edit   = new List <InspectionTrack>();
            List <InspectionTrack>        Delete = new List <InspectionTrack>();
            List <InspectionTrackHistory> HAdd   = new List <InspectionTrackHistory>();

            long lBegin = TimeConvert.DateTimeToTimeStamp(dtBegin) / 1000;
            long lEnd   = TimeConvert.DateTimeToTimeStamp(dtEnd) / 1000;
            var  recv   = client.Getinspectionlist(lBegin, lEnd, true);

            if (recv == null)
            {
                return(false);
            }

            Bll bll = new Bll(false, false, true, false);//第三参数要设置为true
            List <InspectionTrack> itList = bll.InspectionTracks.ToList();

            if (itList == null)
            {
                itList = new List <InspectionTrack>();
            }

            List <InspectionTrackHistory> itHList = bll.InspectionTrackHistorys.ToList();

            if (itHList == null)
            {
                itHList = new List <InspectionTrackHistory>(0);
            }

            foreach (patrols item in recv)
            {
                InspectionTrack        now     = itList.Find(p => p.Abutment_Id == item.id);
                InspectionTrackHistory history = itHList.Find(p => p.Abutment_Id == item.id);

                if (item.state == "新建" || item.state == "已下达" || item.state == "执行中")
                {
                    if (now == null)
                    {
                        now = new InspectionTrack();

                        now.Abutment_Id  = item.id;
                        now.Code         = item.code;
                        now.Name         = item.name;
                        now.CreateTime   = (item.createTime + nEightHourSecond) * 1000;
                        now.dtCreateTime = TimeConvert.TimeStampToDateTime(now.CreateTime);
                        now.State        = item.state;
                        now.StartTime    = (item.startTime + nEightHourSecond) * 1000;
                        now.dtStartTime  = TimeConvert.TimeStampToDateTime(now.StartTime);
                        now.EndTime      = (item.endTime + nEightHourSecond) * 1000;
                        now.dtEndTime    = TimeConvert.TimeStampToDateTime(now.EndTime);
                        Add.Add(now);
                    }
                    else
                    {
                        now.State = item.state;
                        Edit.Add(now);
                    }
                }
                else
                {
                    if (now != null)
                    {
                        Delete.Add(now);
                    }

                    if (history == null)
                    {
                        history = new InspectionTrackHistory();

                        history.Abutment_Id  = item.id;
                        history.Code         = item.code;
                        history.Name         = item.name;
                        history.CreateTime   = (item.createTime + nEightHourSecond) * 1000;
                        history.dtCreateTime = TimeConvert.TimeStampToDateTime(history.CreateTime);
                        history.State        = item.state;
                        history.StartTime    = (item.startTime + nEightHourSecond) * 1000;
                        history.dtStartTime  = TimeConvert.TimeStampToDateTime(history.StartTime);
                        history.EndTime      = (item.endTime + nEightHourSecond) * 1000;
                        history.dtEndTime    = TimeConvert.TimeStampToDateTime(history.EndTime);

                        HAdd.Add(history);
                    }
                }
            }

            bll.InspectionTracks.AddRange(Add);
            bll.InspectionTracks.EditRange(Edit);
            bll.InspectionTracks.RemoveList(Delete);
            bll.InspectionTrackHistorys.AddRange(HAdd);

            All.AddRange(Add);
            All.AddRange(Edit);
            DealPatrolPoint(bll, All, Delete, HAdd, client);

            return(true);
        }