Merge branch 'dev' of ssh://git.tuotong-tech.com:9105/tnb/tnb.server into dev
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.Logging;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using SqlSugar;
|
||||
using Tnb.EquipMgr.Entities;
|
||||
|
||||
namespace JNPF.TaskScheduler.Listener
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成设备保养计划
|
||||
/// </summary>
|
||||
public class GenerateMaintainPlanTimeWorker : ISpareTimeWorker
|
||||
{
|
||||
private ISqlSugarRepository<EqpMaintainTemEquipH> _repository => App.GetService<ISqlSugarRepository<EqpMaintainTemEquipH>>();
|
||||
// public GenerateSpotInspectionPlanTimeWorker(ISqlSugarRepository<EqpMaintainTemEquipH> repository)
|
||||
// {
|
||||
// _repository = repository;
|
||||
// }
|
||||
|
||||
[SpareTime("0 0 0 * * ?", "生成设备保养计划", ExecuteType = SpareTimeExecuteTypes.Serial,StartNow = false)]
|
||||
public 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");
|
||||
List<EqpMaintainRecordH> tobeCreateList = new List<EqpMaintainRecordH>();
|
||||
List<EqpMaintainTemEquipH> tobeCreateTemplets = new List<EqpMaintainTemEquipH>();
|
||||
var db = _repository.AsSugarClient();
|
||||
|
||||
foreach (var item in eqpSpotInsTemEquipHsByOne)
|
||||
{
|
||||
if (item.start_time.AddDays((double)item.plan_cycle).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
|
||||
{
|
||||
tobeCreateTemplets.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (eqpSpotInsTemEquipHsByCirculate != null && eqpSpotInsTemEquipHsByCirculate.Count > 0)
|
||||
{
|
||||
|
||||
//整除表示一个周期到了
|
||||
foreach (var item in eqpSpotInsTemEquipHsByCirculate)
|
||||
{
|
||||
TimeSpan ts1 = new TimeSpan(Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")).Ticks);
|
||||
TimeSpan ts2 = new TimeSpan(Convert.ToDateTime(item.start_time.ToString("yyyy-MM-dd")).Ticks);
|
||||
TimeSpan ts3 = ts1.Subtract(ts2).Duration();
|
||||
if (ts3.TotalDays * 10 % (10 * (double)item.plan_cycle)==0)
|
||||
{
|
||||
tobeCreateTemplets.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tobeCreateTemplets != null && tobeCreateTemplets.Count > 0)
|
||||
{
|
||||
List<EqpEquipment> equipments = db.Queryable<EqpEquipment>().Where(x => x.life==Tnb.EquipMgr.EquipmentLife.ENABLE).ToList();
|
||||
int index = 1;
|
||||
foreach (var item in tobeCreateTemplets)
|
||||
{
|
||||
//只有启用设备才生成计划
|
||||
if (equipments.FirstOrDefault(x => x.id == item.equip_id) == null)
|
||||
continue;
|
||||
|
||||
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,
|
||||
maintain_tem_equip_id = item.id,
|
||||
plan_run_notice = item.plan_run_notice,
|
||||
plan_run_notice_unit = item.plan_run_notice_unit,
|
||||
plan_delay = item.plan_delay,
|
||||
plan_delay_unit = item.plan_delay_unit,
|
||||
send_post_info_user_id = item.send_post_info_user_id,
|
||||
is_repeat = item.is_repeat,
|
||||
repeat_post_info_user_id = item.repeat_post_info_user_id,
|
||||
is_send = item.is_send,
|
||||
create_time = DateTime.Now,
|
||||
status = Tnb.EquipMgr.SpotInsRecordExecutionStatus.TOBEEXECUTED
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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<string> spotInsItemIDs = spotInsTemEquipDs.Select(x => x.maintain_item_id).ToList();
|
||||
List<EqpMaintainItem> spotCheckItems = db.Queryable<EqpMaintainItem>().Where(x => spotInsItemIDs.Contains(x.id)).ToList();
|
||||
|
||||
|
||||
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();
|
||||
List<EqpMaintainItem> tobeCreateItems = spotCheckItems.Where(x => spotInsItems.Contains(x.id)).ToList();
|
||||
foreach (var tobeCreateItem in tobeCreateItems)
|
||||
{
|
||||
spotInsRecordDs.Add(new EqpMaintainRecordD()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId(),
|
||||
maintain_record_id = tobeCreatePlan.id,
|
||||
maintain_tem_equip_id = tobeCreatePlan.maintain_tem_equip_id,
|
||||
maintain_item_id = tobeCreateItem.id,
|
||||
code = tobeCreateItem.code,
|
||||
name = tobeCreateItem.name,
|
||||
maintain_type = tobeCreateItem.maintain_type,
|
||||
maintain_content = tobeCreateItem.maintain_content,
|
||||
descrip = tobeCreateItem.descrip,
|
||||
remark = tobeCreateItem.remark
|
||||
});
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
Log.Error(e.Message);
|
||||
}
|
||||
|
||||
|
||||
Log.Information("----------------------结束生成设备保养计划----------------------");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace JNPF.TaskScheduler.Listener
|
||||
// _repository = repository;
|
||||
// }
|
||||
|
||||
//[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)
|
||||
{
|
||||
Log.Information("----------------------开始生成点巡检计划----------------------");
|
||||
|
||||
Reference in New Issue
Block a user