private void DealPatrolPointItem(Bll bll, List <InspectionTrack> All, List <InspectionTrackHistory> HAdd, List <PatrolPoint> PAll, List <PatrolPoint> PDelete, List <PatrolPointHistory> PHAdd, WebApiLib.Clients.BaseDataClient client) { try { List <PatrolPointItem> ppiList = bll.PatrolPointItems.ToList(); List <PatrolPointItemHistory> ppiHList = bll.PatrolPointItemHistorys.ToList(); if (ppiList == null) { ppiList = new List <PatrolPointItem>(); } if (ppiHList == null) { ppiHList = new List <PatrolPointItemHistory>(); } List <PatrolPointItem> PIAll = new List <PatrolPointItem>(); List <PatrolPointItem> PIAdd = new List <PatrolPointItem>(); List <PatrolPointItem> PIEdit = new List <PatrolPointItem>(); List <PatrolPointItem> PIDelete = new List <PatrolPointItem>(); List <PatrolPointItemHistory> PIHAdd = new List <PatrolPointItemHistory>(); foreach (PatrolPoint item in PAll) { int Id = item.Id; string deviceId = item.DeviceId; int ParentId = item.ParentId; InspectionTrack it = All.Find(p => p.Id == ParentId); if (it == null) { continue; } int patrolId = (int)it.Abutment_Id; CommunicationClass.SihuiThermalPowerPlant.Models.checkpoints recv = client.Getcheckresults(patrolId, deviceId); if (recv == null || recv.checks.Count() <= 0) { continue; } foreach (CommunicationClass.SihuiThermalPowerPlant.Models.results item2 in recv.checks) { PatrolPointItem now = ppiList.Find(p => p.CheckId == item2.checkId && p.ParentId == Id); if (now == null) { now = new PatrolPointItem(); now.ParentId = Id; now.KksCode = item2.kksCode; now.CheckItem = item2.checkItem; now.StaffCode = item2.staffCode; now.CheckTime = null; now.dtCheckTime = null; if (item2.checkTime != null) { now.CheckTime = (item2.checkTime + nEightHourSecond) * 1000; now.dtCheckTime = TimeConvert.TimeStampToDateTime((long)now.CheckTime); } now.CheckId = item2.checkId; now.CheckResult = item2.checkResult; PIAdd.Add(now); } else { if (item2.checkTime != null) { now.CheckTime = (item2.checkTime + nEightHourSecond) * 1000; now.dtCheckTime = TimeConvert.TimeStampToDateTime((long)now.CheckTime); } now.CheckResult = item2.checkResult; PIEdit.Add(now); } } } foreach (PatrolPoint item in PDelete) { int Id = item.Id; List <PatrolPointItem> lstDelete = ppiList.FindAll(p => p.ParentId == Id).ToList(); if (lstDelete != null && lstDelete.Count() > 0) { PIDelete.AddRange(lstDelete); } } foreach (PatrolPointHistory item in PHAdd) { int Id = item.Id; string deviceId = item.DeviceId; int ParentId = item.ParentId; InspectionTrackHistory ith = HAdd.Find(p => p.Id == ParentId); if (ith == null) { continue; } int patrolId = (int)ith.Abutment_Id; CommunicationClass.SihuiThermalPowerPlant.Models.checkpoints recv = client.Getcheckresults(patrolId, deviceId); if (recv == null || recv.checks.Count() <= 0) { continue; } foreach (CommunicationClass.SihuiThermalPowerPlant.Models.results item2 in recv.checks) { PatrolPointItemHistory history = bll.PatrolPointItemHistorys.Find(p => p.CheckId == item2.checkId && p.ParentId == Id); if (history == null) { history = new PatrolPointItemHistory(); history.ParentId = Id; history.KksCode = item2.kksCode; history.CheckItem = item2.checkItem; history.StaffCode = item2.staffCode; history.CheckTime = null; history.dtCheckTime = null; if (item2.checkTime != null) { history.CheckTime = (item2.checkTime + nEightHourSecond) * 1000; history.dtCheckTime = TimeConvert.TimeStampToDateTime((long)history.CheckTime); } history.CheckId = item2.checkId; history.CheckResult = item2.checkResult; PIHAdd.Add(history); } } } bll.PatrolPointItems.AddRange(PIAdd); bll.PatrolPointItems.EditRange(PIEdit); bll.PatrolPointItems.RemoveList(PIDelete); bll.PatrolPointItemHistorys.AddRange(PIHAdd); } catch (Exception ex) { string strMessage = ex.Message; } return; }
private void DealPatrolPoint(Bll bll, List <InspectionTrack> All, List <InspectionTrack> Delete, List <InspectionTrackHistory> HAdd, WebApiLib.Clients.BaseDataClient client) { List <PatrolPoint> ppList = bll.PatrolPoints.ToList(); List <PatrolPointHistory> ppHList = bll.PatrolPointHistorys.ToList(); List <DbModel.Location.AreaAndDev.DevInfo> devList = bll.DevInfos.ToList(); if (ppList == null) { ppList = new List <PatrolPoint>(); } if (ppHList == null) { ppHList = new List <PatrolPointHistory>(); } if (devList == null) { devList = new List <DbModel.Location.AreaAndDev.DevInfo>(); } List <PatrolPoint> PAll = new List <PatrolPoint>(); List <PatrolPoint> PAdd = new List <PatrolPoint>(); List <PatrolPoint> PEdit = new List <PatrolPoint>(); List <PatrolPoint> PDelete = new List <PatrolPoint>(); List <PatrolPointHistory> PHAdd = new List <PatrolPointHistory>(); foreach (InspectionTrack item in All) { int Id = item.Id; int patrolId = (int)item.Abutment_Id; CommunicationClass.SihuiThermalPowerPlant.Models.patrols recv = client.Getcheckpoints(patrolId); if (recv == null || recv.route.Count() <= 0) { continue; } foreach (CommunicationClass.SihuiThermalPowerPlant.Models.checkpoints item2 in recv.route) { DbModel.Location.AreaAndDev.DevInfo dev1 = devList.Find(p => p.KKS == item2.kksCode); PatrolPoint now = ppList.Find(p => p.DeviceId == item2.deviceId && p.ParentId == Id); if (now == null) { now = new PatrolPoint(); now.ParentId = Id; now.StaffCode = item2.staffCode; now.StaffName = item2.staffName; now.KksCode = item2.kksCode; now.DevName = item2.deviceName; now.DeviceCode = item2.deviceCode; now.DeviceId = item2.deviceId; if (dev1 != null) { now.DevId = dev1.Id; } PAdd.Add(now); } else { now.ParentId = Id; now.StaffCode = item2.staffCode; now.StaffName = item2.staffName; now.KksCode = item2.kksCode; now.DevName = item2.deviceName; now.DeviceCode = item2.deviceCode; now.DeviceId = item2.deviceId; if (dev1 != null) { now.DevId = dev1.Id; } PEdit.Add(now); } } } foreach (InspectionTrack item in Delete) { int Id = item.Id; List <PatrolPoint> lstDelete = ppList.FindAll(p => p.ParentId == Id).ToList(); if (lstDelete != null && lstDelete.Count() > 0) { PDelete.AddRange(lstDelete); } } foreach (InspectionTrackHistory item in HAdd) { int Id = item.Id; int patrolId = (int)item.Abutment_Id; CommunicationClass.SihuiThermalPowerPlant.Models.patrols recv = client.Getcheckpoints(patrolId); if (recv == null || recv.route.Count() <= 0) { continue; } foreach (CommunicationClass.SihuiThermalPowerPlant.Models.checkpoints item2 in recv.route) { DbModel.Location.AreaAndDev.DevInfo dev1 = devList.Find(p => p.KKS == item2.kksCode); PatrolPointHistory history = ppHList.Find(p => p.DeviceId == item2.deviceId && p.ParentId == Id); if (history == null) { history = new PatrolPointHistory(); history.ParentId = Id; history.StaffCode = item2.staffCode; history.StaffName = item2.staffName; history.KksCode = item2.kksCode; history.DevName = item2.deviceName; history.DeviceCode = item2.deviceCode; history.DeviceId = item2.deviceId; if (dev1 != null) { history.DevId = dev1.Id; } PHAdd.Add(history); } } } bll.PatrolPoints.AddRange(PAdd); bll.PatrolPoints.EditRange(PEdit); bll.PatrolPoints.RemoveList(PDelete); bll.PatrolPointHistorys.AddRange(PHAdd); PAll.AddRange(PAdd); PAll.AddRange(PEdit); DealPatrolPointItem(bll, All, HAdd, PAll, PDelete, PHAdd, client); return; }