/// <summary> /// 执行所有任务 /// </summary> void ExecuteAllTask() { //停留位置判断:设置的停留多长时间就多长时间循环一次查询,然后比较那个车的最近两个点是不是在同一个地点,如果是的话记录下来,然后如果在途的车都在那个点停留的车数是不是超过设定值 CarStopTimeDAO carStopTimeDAO = CarStopTimeDAO.GetInstance(); taskSimpleScheduler.StartNewTask("获取设定值", () => { if (isExeFinish) { isExeFinish = false; var entity = carStopTimeDAO.GetSettingTime(this.rTxtOutputer.Output); if (this.warning == null) { this.warning = entity; } else if (warning.StopNumber != entity.StopNumber || warning.StopTime != entity.StopTime) { this.warning = entity; } isExeFinish = true; } }, 10 * 1000, OutputError); while (true) { if (warning != null) { taskSimpleScheduler.StartNewTask("车辆异常停留位置监测", () => { if (isExeFinish && warning != null) { isExeFinish = false; carStopTimeDAO.SaveToCarStopTime(this.rTxtOutputer.Output, warning); isExeFinish = true; } }, (int)(warning.StopTime * 60 * 1000), OutputError); break; } } }
public AbnormalStayWarning GetSettingTime(Action <string, eOutputType> output) { AbnormalStayWarning warning = SelfDber.Entity <AbnormalStayWarning>("where IsDeleted=0"); if (warning == null) { output("未设置异常停留位置预警信息!", eOutputType.Error); return(null); } if (warning.StopTime <= 0) { output("设置停车时间限制小于等于0,请正确设置!", eOutputType.Error); return(null); } if (warning.StopNumber <= 0) { output("设置停车数量限制小于等于0,请正确设置!", eOutputType.Error); return(null); } return(warning); }
/// <summary> /// 生成车辆异常停留位置数据 /// </summary> /// <param name="output"></param> /// <returns></returns> public void SaveToCarStopTime(Action <string, eOutputType> output, AbnormalStayWarning warning) { //查询所有在途的车辆,然后判断该车辆最近的两次经纬度是否在同一点 List <ShowEntity> list = GetInRouteCars(); if (list == null || list.Count <= 0) { output("暂无在途车辆!", eOutputType.Warn); return; } foreach (var item in list) { item.isStop = false; //如果车辆已报修并且未处理就不管了 DataTable dtIsRepair = SelfDber.ExecuteDataTable(String.Format("select count(1) from CMCSTBCARREPAIRINFO t where t.isdeleted=0 and t.repairstatus=0 and t.carid='{0}'", item.CarId)); if (dtIsRepair != null && dtIsRepair.Rows.Count > 0 && dtIsRepair.Rows[0][0].ToString() != "0")//车辆去修理了就不管 { continue; } //List<CarLongLatHistory> historyList = SelfDber.Entities<CarLongLatHistory>(string.Format(" where TransportRecordId='{0}' and CreationTime>=to_date('{1}','yyyy-mm-dd hh24:mi:ss') order by CreationTime desc", item.ID, DateTime.Now.AddMinutes(-(double)warning.StopTime))); List <CarLongLatHistory> historyList = SelfDber.Entities <CarLongLatHistory>(string.Format(" where TransportRecordId='{0}' and CreationTime>=to_date('{1}','yyyy-mm-dd hh24:mi:ss') order by CreationTime desc", item.ID, DateTime.Parse("2020-04-10 11:05:58").AddMinutes(-(double)warning.StopTime))); if (historyList.Count <= 1) { continue; } historyList = historyList.OrderByDescending(a => a.CreationTime).ToList(); var distance = GaodeHelper.GetTwoPointDistance((double)historyList.First().Latitude, (double)historyList.First().Longitude, (double)historyList.Last().Latitude, (double)historyList.Last().Longitude); if (distance <= 5)//距离在5米内默认没移动 { item.StopMintes = (historyList.First().CreationTime - historyList.Last().CreationTime).TotalMinutes; item.LONGITUDE = historyList.First().Longitude.ToString(); item.LATITUDE = historyList.First().Latitude.ToString(); item.isStop = true; } } foreach (var item in list) { StopErrorInfo entity = SelfDber.Entity <StopErrorInfo>(string.Format(" where TransportRecordId='{0}' and StartTime is not null and EndTime is null order by StartTime desc", item.ID)); //同一批次其他的车没停,百分之几的车停了那停的车就算异常 bool isPercent = (list.Count(a => a.MineSendId == item.MineSendId && a.isStop) < (list.Count(a => a.MineSendId == item.MineSendId) * warning.StopNumber) / 100m); if (item.isStop && entity == null && isPercent) { entity = new StopErrorInfo(); entity.TransportRecordId = item.ID; entity.StopPoint = item.LONGITUDE + "," + item.LATITUDE; string place = GaodeHelper.GetLocation(entity.StopPoint); if (string.IsNullOrWhiteSpace(place)) { continue; } entity.StopPlace = place; entity.StopTime = decimal.Parse(item.StopMintes.ToString("F0")); entity.StopTime = entity.StopTime > warning.StopTime ? entity.StopTime : warning.StopTime; entity.StartTime = DateTime.Now; entity.StopNum = Math.Round((list.Count(a => a.MineSendId == item.MineSendId && a.isStop) / list.Count(a => a.MineSendId == item.MineSendId)) * 100m, 2, MidpointRounding.AwayFromZero); entity.Remark = string.Format("货车:{0},于{1}开始在{2}异常停留时间超过{3}分钟!", item.CARNUMBER, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entity.StopPlace, entity.StopTime); if (SelfDber.Insert(entity) > 0) { output(entity.Remark, eOutputType.Normal); string updateSql = string.Format("update cmcstbbuyfueltransport t set t.isstoperr=1 where t.id='{0}'", item.ID); SelfDber.Execute(updateSql); } } else if (entity != null)//如果没有异常停留需要将异常停留信息结束 { entity.EndTime = DateTime.Now; entity.StopTime = decimal.Parse((entity.StartTime - entity.EndTime).TotalMinutes.ToString("F0")); entity.Remark = string.Format("货车:{0},于{1}至{2}在{3}异常停留{4}分钟!", item.CARNUMBER, entity.StartTime.ToString("yyyy-MM-dd HH:mm:ss"), entity.EndTime.ToString("yyyy-MM-dd HH:mm:ss"), entity.StopPlace, entity.StopTime); if (SelfDber.Update(entity) > 0) { output(entity.Remark, eOutputType.Normal); string updateSql = string.Format("update cmcstbbuyfueltransport t set t.isstoperr=1 where t.id='{0}'", item.ID); SelfDber.Execute(updateSql); } } } }