From 8c31205e70a15b662c79562bd76c537101910d81 Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Wed, 1 Nov 2023 00:01:24 +0800 Subject: [PATCH] bug --- .../Tnb.EquipMgr/EquSpotInsRecordService.cs | 3 +- .../GenerateMaintainPlanTimeWorker.cs | 64 +++++++++---------- .../GenerateSpotInspectionPlanTimeWorker.cs | 63 +++++++++--------- 3 files changed, 65 insertions(+), 65 deletions(-) diff --git a/EquipMgr/Tnb.EquipMgr/EquSpotInsRecordService.cs b/EquipMgr/Tnb.EquipMgr/EquSpotInsRecordService.cs index ae8bc2a6..ec2b381f 100644 --- a/EquipMgr/Tnb.EquipMgr/EquSpotInsRecordService.cs +++ b/EquipMgr/Tnb.EquipMgr/EquSpotInsRecordService.cs @@ -59,7 +59,7 @@ namespace Tnb.EquipMgr string status = queryJson.ContainsKey("status") ? (queryJson["status"].ToString() ?? "") : ""; DateTime? start_time = queryJson.ContainsKey("start_time") ? queryJson["start_time"].ToString()=="" ? null : Convert.ToDateTime(queryJson["start_time"]) : null; DateTime? end_time = queryJson.ContainsKey("end_time") ? queryJson["end_time"].ToString()=="" ? null : Convert.ToDateTime(queryJson["end_time"]) : null; - + string now = DateTime.Now.ToString("yyyy-MM-dd"); if (string.IsNullOrEmpty(input.sidx)) { input.sidx = "a.create_time"; @@ -80,6 +80,7 @@ namespace Tnb.EquipMgr .WhereIF(!string.IsNullOrEmpty(equioInfo),(a,b,c)=>b.code.Contains(equioInfo)|| b.name.Contains(equioInfo)) .WhereIF(status=="3" && start_time!=null,a=>a.spot_record_date_time>=start_time) .WhereIF(status=="3" && end_time!=null,a=>a.spot_record_date_time<=end_time) + .Where(a=>a.create_time.Value.ToString("yyyy-MM-dd")==now) .OrderBy($"{input.sidx} {input.sort}") .Select((a, b, c,d) => new EqpSpotInsRecordListOutput { diff --git a/taskschedule/Tnb.TaskScheduler/Listener/GenerateMaintainPlanTimeWorker.cs b/taskschedule/Tnb.TaskScheduler/Listener/GenerateMaintainPlanTimeWorker.cs index 4abed741..a58f132d 100644 --- a/taskschedule/Tnb.TaskScheduler/Listener/GenerateMaintainPlanTimeWorker.cs +++ b/taskschedule/Tnb.TaskScheduler/Listener/GenerateMaintainPlanTimeWorker.cs @@ -18,17 +18,18 @@ namespace JNPF.TaskScheduler.Listener // } [SpareTime("0 0 0 * * ?", "生成设备保养计划", ExecuteType = SpareTimeExecuteTypes.Serial,StartNow = false)] - public void GenerateSpotInspectionPlan(SpareTimer timer, long count) + public async void GenerateSpotInspectionPlan(SpareTimer timer, long count) { Log.Information("----------------------开始生成设备保养计划----------------------"); try { - List eqpSpotInsTemEquipHsByOne = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "1"); - List eqpSpotInsTemEquipHsByCirculate = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "2"); + var db = _repository.CopyNew(); + List eqpSpotInsTemEquipHsByOne = await db.Queryable().Where(x => x.is_start=="1" && x.plan_cycle_unit == "1").ToListAsync(); + List eqpSpotInsTemEquipHsByCirculate = await db.Queryable().Where(x => x.is_start=="1" && x.plan_cycle_unit == "2").ToListAsync(); List tobeCreateList = new List(); List tobeCreateTemplets = new List(); - var db = _repository.AsSugarClient(); + foreach (var item in eqpSpotInsTemEquipHsByOne) { @@ -56,7 +57,7 @@ namespace JNPF.TaskScheduler.Listener if (tobeCreateTemplets != null && tobeCreateTemplets.Count > 0) { - List equipments = db.Queryable().Where(x => x.life==Tnb.EquipMgr.EquipmentLife.ENABLE).ToList(); + List equipments = await db.Queryable().Where(x => x.life==Tnb.EquipMgr.EquipmentLife.ENABLE).ToListAsync(); int index = 1; foreach (var item in tobeCreateTemplets) { @@ -67,7 +68,6 @@ namespace JNPF.TaskScheduler.Listener string code = $"{DateTime.Now.ToString("yyyyMMdd")+(index++).ToString().PadLeft(3,'0')}"; tobeCreateList.Add(new EqpMaintainRecordH() { - id = SnowflakeIdHelper.NextId(), code = code, // equip_type_id = item.equip_type_id, equip_id = item.equip_id, @@ -90,14 +90,14 @@ namespace JNPF.TaskScheduler.Listener if (tobeCreateList != null && tobeCreateList.Count > 0) { List templetIDs = tobeCreateList.Select(x => x.maintain_tem_equip_id).ToList(); - List spotInsTemEquipDs = db.Queryable().Where(x => templetIDs.Contains(x.maintain_tem_equip_id)).ToList(); + List spotInsTemEquipDs = await db.Queryable().Where(x => templetIDs.Contains(x.maintain_tem_equip_id)).ToListAsync(); List spotInsItemIDs = spotInsTemEquipDs.Select(x => x.maintain_item_id).ToList(); - List spotCheckItems = db.Queryable().Where(x => spotInsItemIDs.Contains(x.id)).ToList(); + List spotCheckItems = await db.Queryable().Where(x => spotInsItemIDs.Contains(x.id)).ToListAsync(); + List spotInsRecordDs = new List(); foreach (var tobeCreatePlan in tobeCreateList) { - List spotInsRecordDs = new List(); List spotInsItems = spotInsTemEquipDs .Where(x => x.maintain_tem_equip_id == tobeCreatePlan.maintain_tem_equip_id) .Select(x => x.maintain_item_id).ToList(); @@ -119,30 +119,30 @@ namespace JNPF.TaskScheduler.Listener }); } - if (spotInsRecordDs.Count<=0) - { - return; - } - - var dbResult = db.Ado.UseTran(() => - { - if (tobeCreateList != null && tobeCreateList.Count > 0) - { - db.Insertable(tobeCreateList).ExecuteCommand(); - } - - if (spotInsRecordDs != null && spotInsRecordDs.Count > 0) - { - db.Insertable(spotInsRecordDs).ExecuteCommand(); - } - }); - if (!dbResult.IsSuccess) - { - Console.WriteLine(dbResult.ErrorMessage); - Log.Error(dbResult.ErrorMessage); - } - Log.Information($"---------------生成{tobeCreateList.Count}个计划---------------"); } + if (spotInsRecordDs.Count<=0) + { + return; + } + + var dbResult = db.Ado.UseTran(() => + { + if (tobeCreateList != null && tobeCreateList.Count > 0) + { + db.Insertable(tobeCreateList).ExecuteCommand(); + } + + if (spotInsRecordDs != null && spotInsRecordDs.Count > 0) + { + db.Insertable(spotInsRecordDs).ExecuteCommand(); + } + }); + if (!dbResult.IsSuccess) + { + Console.WriteLine(dbResult.ErrorMessage); + Log.Error(dbResult.ErrorMessage); + } + Log.Information($"---------------生成{tobeCreateList.Count}个计划---------------"); } } catch (Exception e) diff --git a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs index 48498fb4..6fd44130 100644 --- a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs +++ b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs @@ -18,17 +18,17 @@ namespace JNPF.TaskScheduler.Listener // } [SpareTime("0 0,30 * * * ?", "生成点巡检计划", ExecuteType = SpareTimeExecuteTypes.Serial,StartNow = false)] - public void GenerateSpotInspectionPlan(SpareTimer timer, long count) + public async void GenerateSpotInspectionPlan(SpareTimer timer, long count) { Log.Information("----------------------开始生成点巡检计划----------------------"); try { - List eqpSpotInsTemEquipHsByOne = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "1"); - List eqpSpotInsTemEquipHsByCirculate = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "2"); + var db = _repository.CopyNew(); + List eqpSpotInsTemEquipHsByOne = await db.Queryable().Where(x => x.is_start=="1" && x.plan_cycle_unit == "1").ToListAsync(); + List eqpSpotInsTemEquipHsByCirculate = await db.Queryable().Where(x => x.is_start=="1" && x.plan_cycle_unit == "2").ToListAsync(); List tobeCreateList = new List(); List tobeCreateTemplets = new List(); - var db = _repository.AsSugarClient(); foreach (var item in eqpSpotInsTemEquipHsByOne) { @@ -80,7 +80,7 @@ namespace JNPF.TaskScheduler.Listener if (tobeCreateTemplets != null && tobeCreateTemplets.Count > 0) { - List equipments = db.Queryable().Where(x => x.life==Tnb.EquipMgr.EquipmentLife.ENABLE).ToList(); + List equipments = await db.Queryable().Where(x => x.life==Tnb.EquipMgr.EquipmentLife.ENABLE).ToListAsync(); int index = 1; foreach (var item in tobeCreateTemplets) { @@ -114,14 +114,14 @@ namespace JNPF.TaskScheduler.Listener if (tobeCreateList != null && tobeCreateList.Count > 0) { List templetIDs = tobeCreateList.Select(x => x.spot_ins_tem_equip_id).ToList(); - List spotInsTemEquipDs = db.Queryable().Where(x => templetIDs.Contains(x.spot_ins_tem_equip_id)).ToList(); + List spotInsTemEquipDs = await db.Queryable().Where(x => templetIDs.Contains(x.spot_ins_tem_equip_id)).ToListAsync(); List spotInsItemIDs = spotInsTemEquipDs.Select(x => x.spot_ins_item_id).ToList(); - List spotCheckItems = db.Queryable().Where(x => spotInsItemIDs.Contains(x.id)).ToList(); + List spotCheckItems = await db.Queryable().Where(x => spotInsItemIDs.Contains(x.id)).ToListAsync(); + List spotInsRecordDs = new List(); foreach (var tobeCreatePlan in tobeCreateList) { - List spotInsRecordDs = new List(); List spotInsItems = spotInsTemEquipDs .Where(x => x.spot_ins_tem_equip_id == tobeCreatePlan.spot_ins_tem_equip_id) .Select(x => x.spot_ins_item_id).ToList(); @@ -130,7 +130,6 @@ namespace JNPF.TaskScheduler.Listener { spotInsRecordDs.Add(new EqpSpotInsRecordD() { - id = SnowflakeIdHelper.NextId(), spot_ins_record_id = tobeCreatePlan.id, spot_ins_tem_equip_id = tobeCreatePlan.spot_ins_tem_equip_id, spot_ins_item_id = tobeCreateItem.id, @@ -149,30 +148,30 @@ namespace JNPF.TaskScheduler.Listener }); } - if (spotInsRecordDs.Count<=0) - { - return; - } - - var dbResult = db.Ado.UseTran(() => - { - if (tobeCreateList != null && tobeCreateList.Count > 0) - { - db.Insertable(tobeCreateList).ExecuteCommand(); - } - - if (spotInsRecordDs != null && spotInsRecordDs.Count > 0) - { - db.Insertable(spotInsRecordDs).ExecuteCommand(); - } - }); - if (!dbResult.IsSuccess) - { - Console.WriteLine(dbResult.ErrorMessage); - Log.Error(dbResult.ErrorMessage); - } - Log.Information($"---------------生成{tobeCreateList.Count}个计划---------------"); } + if (spotInsRecordDs.Count<=0) + { + return; + } + + var dbResult = await db.Ado.UseTranAsync(async () => + { + if (tobeCreateList != null && tobeCreateList.Count > 0) + { + await db.Insertable(tobeCreateList).ExecuteCommandAsync(); + } + + if (spotInsRecordDs != null && spotInsRecordDs.Count > 0) + { + await db.Insertable(spotInsRecordDs).ExecuteCommandAsync(); + } + }); + if (!dbResult.IsSuccess) + { + Console.WriteLine(dbResult.ErrorMessage); + Log.Error(dbResult.ErrorMessage); + } + Log.Information($"---------------生成{tobeCreateList.Count}个计划---------------"); } } catch (Exception e)