diff --git a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs index d0de1e4d..e4da44d1 100644 --- a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs +++ b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs @@ -40,20 +40,33 @@ namespace JNPF.TaskScheduler.Listener if (eqpSpotInsTemEquipHsByCirculate != null && eqpSpotInsTemEquipHsByCirculate.Count > 0) { - List ids = eqpSpotInsTemEquipHsByCirculate.Select(x => x.id).ToList(); - List lastPlans = db.Queryable() - .GroupBy(a => new { a.spot_ins_tem_equip_id }) - .Where(a => ids.Contains(a.spot_ins_tem_equip_id)) - .Select(a => new SpotInsRecordLastDTO() - { - spot_ins_tem_equip_id = a.spot_ins_tem_equip_id, - create_time = SqlFunc.AggregateMax(a.create_time.Value) - }).ToList(); - + //查询最后一条数据加上周期是否等于现在等于表示周期到了 已废除 + // List ids = eqpSpotInsTemEquipHsByCirculate.Select(x => x.id).ToList(); + // List lastPlans = db.Queryable() + // .GroupBy(a => new { a.spot_ins_tem_equip_id }) + // .Where(a => ids.Contains(a.spot_ins_tem_equip_id)) + // .Select(a => new SpotInsRecordLastDTO() + // { + // spot_ins_tem_equip_id = a.spot_ins_tem_equip_id, + // create_time = SqlFunc.AggregateMax(a.create_time.Value) + // }).ToList(); + // + // foreach (var item in eqpSpotInsTemEquipHsByCirculate) + // { + // var lastPlan = lastPlans.FirstOrDefault(x => x.spot_ins_tem_equip_id == item.id); + // if (lastPlan == null || lastPlan.create_time == null || lastPlan.create_time.AddHours((double)item.plan_cycle).ToString("yyyy-MM-dd HH") == DateTime.Now.ToString("yyyy-MM-dd HH")) + // { + // tobeCreateTemplets.Add(item); + // } + // } + + //整除表示一个周期到了 foreach (var item in eqpSpotInsTemEquipHsByCirculate) { - var lastPlan = lastPlans.FirstOrDefault(x => x.spot_ins_tem_equip_id == item.id); - if (lastPlan == null || lastPlan.create_time == null || lastPlan.create_time.AddHours((double)item.plan_cycle).ToString("yyyy-MM-dd HH") == DateTime.Now.ToString("yyyy-MM-dd HH")) + TimeSpan ts1 = new TimeSpan(Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm")).Ticks); + TimeSpan ts2 = new TimeSpan(Convert.ToDateTime(item.start_time.ToString("yyyy-MM-dd HH:mm")).Ticks); + TimeSpan ts3 = ts1.Subtract(ts2).Duration(); + if (ts3.TotalMinutes * 10 / 60 % (10 * (double)item.plan_cycle)==0) { tobeCreateTemplets.Add(item); } @@ -70,7 +83,7 @@ namespace JNPF.TaskScheduler.Listener if (equipments.FirstOrDefault(x => x.id == item.equip_id) == null) continue; - string code = $"{DateTime.Now.ToString("yyyyMMddHH")+(index++).ToString().PadLeft(3,'0')}"; + string code = $"{DateTime.Now.ToString("yyyyMMddHHmm")+(index++).ToString().PadLeft(3,'0')}"; tobeCreateList.Add(new EqpSpotInsRecordH() { id = SnowflakeIdHelper.NextId(), @@ -144,6 +157,7 @@ namespace JNPF.TaskScheduler.Listener }); if (!dbResult.IsSuccess) { + Console.WriteLine(dbResult.ErrorMessage); Log.Error(dbResult.ErrorMessage); } Log.Information($"---------------生成{tobeCreateList.Count}个计划---------------"); @@ -152,6 +166,7 @@ namespace JNPF.TaskScheduler.Listener } catch (Exception e) { + Console.WriteLine(e.Message); Log.Error(e.Message); }