Merge branch 'dev' of https://git.tuotong-tech.com/tnb/tnb.server into dev
This commit is contained in:
@@ -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<EqpMaintainTemEquipH> eqpSpotInsTemEquipHsByOne = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "1");
|
||||
List<EqpMaintainTemEquipH> eqpSpotInsTemEquipHsByCirculate = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "2");
|
||||
var db = _repository.CopyNew();
|
||||
List<EqpMaintainTemEquipH> eqpSpotInsTemEquipHsByOne = await db.Queryable<EqpMaintainTemEquipH>().Where(x => x.is_start=="1" && x.plan_cycle_unit == "1").ToListAsync();
|
||||
List<EqpMaintainTemEquipH> eqpSpotInsTemEquipHsByCirculate = await db.Queryable<EqpMaintainTemEquipH>().Where(x => x.is_start=="1" && x.plan_cycle_unit == "2").ToListAsync();
|
||||
List<EqpMaintainRecordH> tobeCreateList = new List<EqpMaintainRecordH>();
|
||||
List<EqpMaintainTemEquipH> tobeCreateTemplets = new List<EqpMaintainTemEquipH>();
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
|
||||
foreach (var item in eqpSpotInsTemEquipHsByOne)
|
||||
{
|
||||
@@ -56,7 +57,7 @@ namespace JNPF.TaskScheduler.Listener
|
||||
|
||||
if (tobeCreateTemplets != null && tobeCreateTemplets.Count > 0)
|
||||
{
|
||||
List<EqpEquipment> equipments = db.Queryable<EqpEquipment>().Where(x => x.life==Tnb.EquipMgr.EquipmentLife.ENABLE).ToList();
|
||||
List<EqpEquipment> equipments = await db.Queryable<EqpEquipment>().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<string> templetIDs = tobeCreateList.Select(x => x.maintain_tem_equip_id).ToList();
|
||||
List<EqpMaintainTemEquipD> spotInsTemEquipDs = db.Queryable<EqpMaintainTemEquipD>().Where(x => templetIDs.Contains(x.maintain_tem_equip_id)).ToList();
|
||||
List<EqpMaintainTemEquipD> spotInsTemEquipDs = await db.Queryable<EqpMaintainTemEquipD>().Where(x => templetIDs.Contains(x.maintain_tem_equip_id)).ToListAsync();
|
||||
List<string> spotInsItemIDs = spotInsTemEquipDs.Select(x => x.maintain_item_id).ToList();
|
||||
List<EqpMaintainItem> spotCheckItems = db.Queryable<EqpMaintainItem>().Where(x => spotInsItemIDs.Contains(x.id)).ToList();
|
||||
List<EqpMaintainItem> spotCheckItems = await db.Queryable<EqpMaintainItem>().Where(x => spotInsItemIDs.Contains(x.id)).ToListAsync();
|
||||
|
||||
|
||||
List<EqpMaintainRecordD> spotInsRecordDs = new List<EqpMaintainRecordD>();
|
||||
foreach (var tobeCreatePlan in tobeCreateList)
|
||||
{
|
||||
List<EqpMaintainRecordD> spotInsRecordDs = new List<EqpMaintainRecordD>();
|
||||
List<string> spotInsItems = spotInsTemEquipDs
|
||||
.Where(x => x.maintain_tem_equip_id == tobeCreatePlan.maintain_tem_equip_id)
|
||||
.Select(x => x.maintain_item_id).ToList();
|
||||
@@ -119,25 +119,30 @@ namespace JNPF.TaskScheduler.Listener
|
||||
});
|
||||
}
|
||||
|
||||
var dbResult = db.Ado.UseTran(() =>
|
||||
{
|
||||
if (tobeCreateList != null && tobeCreateList.Count > 0)
|
||||
{
|
||||
db.Insertable<EqpMaintainRecordH>(tobeCreateList).ExecuteCommand();
|
||||
}
|
||||
|
||||
if (spotInsRecordDs != null && spotInsRecordDs.Count > 0)
|
||||
{
|
||||
db.Insertable<EqpMaintainRecordD>(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<EqpMaintainRecordH>(tobeCreateList).ExecuteCommand();
|
||||
}
|
||||
|
||||
if (spotInsRecordDs != null && spotInsRecordDs.Count > 0)
|
||||
{
|
||||
db.Insertable<EqpMaintainRecordD>(spotInsRecordDs).ExecuteCommand();
|
||||
}
|
||||
});
|
||||
if (!dbResult.IsSuccess)
|
||||
{
|
||||
Console.WriteLine(dbResult.ErrorMessage);
|
||||
Log.Error(dbResult.ErrorMessage);
|
||||
}
|
||||
Log.Information($"---------------生成{tobeCreateList.Count}个计划---------------");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -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<EqpSpotInsTemEquipH> eqpSpotInsTemEquipHsByOne = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "1");
|
||||
List<EqpSpotInsTemEquipH> eqpSpotInsTemEquipHsByCirculate = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "2");
|
||||
var db = _repository.CopyNew();
|
||||
List<EqpSpotInsTemEquipH> eqpSpotInsTemEquipHsByOne = await db.Queryable<EqpSpotInsTemEquipH>().Where(x => x.is_start=="1" && x.plan_cycle_unit == "1").ToListAsync();
|
||||
List<EqpSpotInsTemEquipH> eqpSpotInsTemEquipHsByCirculate = await db.Queryable<EqpSpotInsTemEquipH>().Where(x => x.is_start=="1" && x.plan_cycle_unit == "2").ToListAsync();
|
||||
List<EqpSpotInsRecordH> tobeCreateList = new List<EqpSpotInsRecordH>();
|
||||
List<EqpSpotInsTemEquipH> tobeCreateTemplets = new List<EqpSpotInsTemEquipH>();
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
foreach (var item in eqpSpotInsTemEquipHsByOne)
|
||||
{
|
||||
@@ -80,7 +80,7 @@ namespace JNPF.TaskScheduler.Listener
|
||||
|
||||
if (tobeCreateTemplets != null && tobeCreateTemplets.Count > 0)
|
||||
{
|
||||
List<EqpEquipment> equipments = db.Queryable<EqpEquipment>().Where(x => x.life==Tnb.EquipMgr.EquipmentLife.ENABLE).ToList();
|
||||
List<EqpEquipment> equipments = await db.Queryable<EqpEquipment>().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<string> templetIDs = tobeCreateList.Select(x => x.spot_ins_tem_equip_id).ToList();
|
||||
List<EqpSpotInsTemEquipD> spotInsTemEquipDs = db.Queryable<EqpSpotInsTemEquipD>().Where(x => templetIDs.Contains(x.spot_ins_tem_equip_id)).ToList();
|
||||
List<EqpSpotInsTemEquipD> spotInsTemEquipDs = await db.Queryable<EqpSpotInsTemEquipD>().Where(x => templetIDs.Contains(x.spot_ins_tem_equip_id)).ToListAsync();
|
||||
List<string> spotInsItemIDs = spotInsTemEquipDs.Select(x => x.spot_ins_item_id).ToList();
|
||||
List<EqpSpotInsItem> spotCheckItems = db.Queryable<EqpSpotInsItem>().Where(x => spotInsItemIDs.Contains(x.id)).ToList();
|
||||
List<EqpSpotInsItem> spotCheckItems = await db.Queryable<EqpSpotInsItem>().Where(x => spotInsItemIDs.Contains(x.id)).ToListAsync();
|
||||
|
||||
|
||||
List<EqpSpotInsRecordD> spotInsRecordDs = new List<EqpSpotInsRecordD>();
|
||||
foreach (var tobeCreatePlan in tobeCreateList)
|
||||
{
|
||||
List<EqpSpotInsRecordD> spotInsRecordDs = new List<EqpSpotInsRecordD>();
|
||||
List<string> 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,
|
||||
@@ -148,26 +147,31 @@ namespace JNPF.TaskScheduler.Listener
|
||||
remark = tobeCreateItem.remark
|
||||
});
|
||||
}
|
||||
|
||||
var dbResult = db.Ado.UseTran(() =>
|
||||
{
|
||||
if (tobeCreateList != null && tobeCreateList.Count > 0)
|
||||
{
|
||||
db.Insertable<EqpSpotInsRecordH>(tobeCreateList).ExecuteCommand();
|
||||
}
|
||||
|
||||
if (spotInsRecordDs != null && spotInsRecordDs.Count > 0)
|
||||
{
|
||||
db.Insertable<EqpSpotInsRecordD>(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<EqpSpotInsRecordH>(tobeCreateList).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
if (spotInsRecordDs != null && spotInsRecordDs.Count > 0)
|
||||
{
|
||||
await db.Insertable<EqpSpotInsRecordD>(spotInsRecordDs).ExecuteCommandAsync();
|
||||
}
|
||||
});
|
||||
if (!dbResult.IsSuccess)
|
||||
{
|
||||
Console.WriteLine(dbResult.ErrorMessage);
|
||||
Log.Error(dbResult.ErrorMessage);
|
||||
}
|
||||
Log.Information($"---------------生成{tobeCreateList.Count}个计划---------------");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
Reference in New Issue
Block a user