This commit is contained in:
2023-11-01 00:01:24 +08:00
parent 4cfefb9150
commit 8c31205e70
3 changed files with 65 additions and 65 deletions

View File

@@ -59,7 +59,7 @@ namespace Tnb.EquipMgr
string status = queryJson.ContainsKey("status") ? (queryJson["status"].ToString() ?? "") : ""; 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? 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; 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)) if (string.IsNullOrEmpty(input.sidx))
{ {
input.sidx = "a.create_time"; 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(!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" && 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) .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}") .OrderBy($"{input.sidx} {input.sort}")
.Select((a, b, c,d) => new EqpSpotInsRecordListOutput .Select((a, b, c,d) => new EqpSpotInsRecordListOutput
{ {

View File

@@ -18,17 +18,18 @@ namespace JNPF.TaskScheduler.Listener
// } // }
[SpareTime("0 0 0 * * ?", "生成设备保养计划", ExecuteType = SpareTimeExecuteTypes.Serial,StartNow = false)] [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("----------------------开始生成设备保养计划----------------------"); Log.Information("----------------------开始生成设备保养计划----------------------");
try try
{ {
List<EqpMaintainTemEquipH> eqpSpotInsTemEquipHsByOne = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "1"); var db = _repository.CopyNew();
List<EqpMaintainTemEquipH> eqpSpotInsTemEquipHsByCirculate = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "2"); 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<EqpMaintainRecordH> tobeCreateList = new List<EqpMaintainRecordH>();
List<EqpMaintainTemEquipH> tobeCreateTemplets = new List<EqpMaintainTemEquipH>(); List<EqpMaintainTemEquipH> tobeCreateTemplets = new List<EqpMaintainTemEquipH>();
var db = _repository.AsSugarClient();
foreach (var item in eqpSpotInsTemEquipHsByOne) foreach (var item in eqpSpotInsTemEquipHsByOne)
{ {
@@ -56,7 +57,7 @@ namespace JNPF.TaskScheduler.Listener
if (tobeCreateTemplets != null && tobeCreateTemplets.Count > 0) 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; int index = 1;
foreach (var item in tobeCreateTemplets) foreach (var item in tobeCreateTemplets)
{ {
@@ -67,7 +68,6 @@ namespace JNPF.TaskScheduler.Listener
string code = $"{DateTime.Now.ToString("yyyyMMdd")+(index++).ToString().PadLeft(3,'0')}"; string code = $"{DateTime.Now.ToString("yyyyMMdd")+(index++).ToString().PadLeft(3,'0')}";
tobeCreateList.Add(new EqpMaintainRecordH() tobeCreateList.Add(new EqpMaintainRecordH()
{ {
id = SnowflakeIdHelper.NextId(),
code = code, code = code,
// equip_type_id = item.equip_type_id, // equip_type_id = item.equip_type_id,
equip_id = item.equip_id, equip_id = item.equip_id,
@@ -90,14 +90,14 @@ namespace JNPF.TaskScheduler.Listener
if (tobeCreateList != null && tobeCreateList.Count > 0) if (tobeCreateList != null && tobeCreateList.Count > 0)
{ {
List<string> templetIDs = tobeCreateList.Select(x => x.maintain_tem_equip_id).ToList(); 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<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) foreach (var tobeCreatePlan in tobeCreateList)
{ {
List<EqpMaintainRecordD> spotInsRecordDs = new List<EqpMaintainRecordD>();
List<string> spotInsItems = spotInsTemEquipDs List<string> spotInsItems = spotInsTemEquipDs
.Where(x => x.maintain_tem_equip_id == tobeCreatePlan.maintain_tem_equip_id) .Where(x => x.maintain_tem_equip_id == tobeCreatePlan.maintain_tem_equip_id)
.Select(x => x.maintain_item_id).ToList(); .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<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) catch (Exception e)

View File

@@ -18,17 +18,17 @@ namespace JNPF.TaskScheduler.Listener
// } // }
[SpareTime("0 0,30 * * * ?", "生成点巡检计划", ExecuteType = SpareTimeExecuteTypes.Serial,StartNow = false)] [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("----------------------开始生成点巡检计划----------------------"); Log.Information("----------------------开始生成点巡检计划----------------------");
try try
{ {
List<EqpSpotInsTemEquipH> eqpSpotInsTemEquipHsByOne = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "1"); var db = _repository.CopyNew();
List<EqpSpotInsTemEquipH> eqpSpotInsTemEquipHsByCirculate = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "2"); 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<EqpSpotInsRecordH> tobeCreateList = new List<EqpSpotInsRecordH>();
List<EqpSpotInsTemEquipH> tobeCreateTemplets = new List<EqpSpotInsTemEquipH>(); List<EqpSpotInsTemEquipH> tobeCreateTemplets = new List<EqpSpotInsTemEquipH>();
var db = _repository.AsSugarClient();
foreach (var item in eqpSpotInsTemEquipHsByOne) foreach (var item in eqpSpotInsTemEquipHsByOne)
{ {
@@ -80,7 +80,7 @@ namespace JNPF.TaskScheduler.Listener
if (tobeCreateTemplets != null && tobeCreateTemplets.Count > 0) 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; int index = 1;
foreach (var item in tobeCreateTemplets) foreach (var item in tobeCreateTemplets)
{ {
@@ -114,14 +114,14 @@ namespace JNPF.TaskScheduler.Listener
if (tobeCreateList != null && tobeCreateList.Count > 0) if (tobeCreateList != null && tobeCreateList.Count > 0)
{ {
List<string> templetIDs = tobeCreateList.Select(x => x.spot_ins_tem_equip_id).ToList(); 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<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) foreach (var tobeCreatePlan in tobeCreateList)
{ {
List<EqpSpotInsRecordD> spotInsRecordDs = new List<EqpSpotInsRecordD>();
List<string> spotInsItems = spotInsTemEquipDs List<string> spotInsItems = spotInsTemEquipDs
.Where(x => x.spot_ins_tem_equip_id == tobeCreatePlan.spot_ins_tem_equip_id) .Where(x => x.spot_ins_tem_equip_id == tobeCreatePlan.spot_ins_tem_equip_id)
.Select(x => x.spot_ins_item_id).ToList(); .Select(x => x.spot_ins_item_id).ToList();
@@ -130,7 +130,6 @@ namespace JNPF.TaskScheduler.Listener
{ {
spotInsRecordDs.Add(new EqpSpotInsRecordD() spotInsRecordDs.Add(new EqpSpotInsRecordD()
{ {
id = SnowflakeIdHelper.NextId(),
spot_ins_record_id = tobeCreatePlan.id, spot_ins_record_id = tobeCreatePlan.id,
spot_ins_tem_equip_id = tobeCreatePlan.spot_ins_tem_equip_id, spot_ins_tem_equip_id = tobeCreatePlan.spot_ins_tem_equip_id,
spot_ins_item_id = tobeCreateItem.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<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) catch (Exception e)