121 lines
5.9 KiB
C#
121 lines
5.9 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.Common.Security;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.EquipMgr.Entities;
|
|
using Tnb.EquipMgr.Entities.Dto;
|
|
using Tnb.EquipMgr.Interfaces;
|
|
|
|
namespace Tnb.EquipMgr
|
|
{
|
|
/// <summary>
|
|
/// 点巡检模板管理
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
public class EqpSpotInsTemService : IEqpSpotInsTemService, IDynamicApiController, ITransient
|
|
{
|
|
private const string ModuleId = "26123080740885";
|
|
private readonly ISqlSugarRepository<EqpSpotInsTemH> _repository;
|
|
private readonly IUserManager _userManager;
|
|
|
|
public EqpSpotInsTemService(ISqlSugarRepository<EqpSpotInsTemH> repository,
|
|
IUserManager userManager)
|
|
{
|
|
_repository = repository;
|
|
_userManager = userManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据模板id发布到设备
|
|
/// </summary>
|
|
[HttpPost]
|
|
public async Task<string> Publish(SpotInsTemPublishInput input)
|
|
{
|
|
ISqlSugarClient db = _repository.AsSugarClient();
|
|
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
EqpSpotInsTemH eqpSpotInsTemH = await _repository.GetSingleAsync(x => x.id == input.id);
|
|
List<EqpSpotInsTemD> eqpSpotInsTemDs = await db.Queryable<EqpSpotInsTemD>().Where(x => x.spot_ins_tem_id == input.id).ToListAsync();
|
|
|
|
if (input.equipIds != null && input.equipIds.Length > 0)
|
|
{
|
|
List<EqpSpotInsTemEquipH> insertEqpSpotInsTemEquipHs = new();
|
|
List<EqpSpotInsTemEquipD> insertEqpSpotInsTemEquipDs = new();
|
|
foreach (string equipId in input.equipIds)
|
|
{
|
|
string id = SnowflakeIdHelper.NextId();
|
|
string code = $"{DateTime.Now.ToString("yyyyMMdd") + equipId}";
|
|
EqpSpotInsTemEquipH eqpSpotInsTemEquipH = new()
|
|
{
|
|
id = id,
|
|
code = code,
|
|
name = eqpSpotInsTemH.name + equipId,
|
|
plan_cycle = eqpSpotInsTemH.plan_cycle,
|
|
plan_cycle_unit = eqpSpotInsTemH.plan_cycle_unit,
|
|
plan_run_notice = eqpSpotInsTemH.plan_run_notice,
|
|
plan_delay = eqpSpotInsTemH.plan_delay,
|
|
start_time = eqpSpotInsTemH.start_time,
|
|
is_start = eqpSpotInsTemH.is_start.ToString(),
|
|
is_repeat = eqpSpotInsTemH.is_repeat.ToString(),
|
|
is_send = eqpSpotInsTemH.is_send,
|
|
spot_ins_tem_id = input.id,
|
|
equip_id = equipId,
|
|
remark = eqpSpotInsTemH.remark,
|
|
plan_run_notice_unit = eqpSpotInsTemH.plan_run_notice_unit,
|
|
plan_delay_unit = eqpSpotInsTemH.plan_delay_unit,
|
|
repeat_post_info_user_id = eqpSpotInsTemH.repeat_post_info_user_id,
|
|
send_post_info_user_id = eqpSpotInsTemH.send_post_info_user_id,
|
|
send_post_id = eqpSpotInsTemH.send_post_id,
|
|
org_id = eqpSpotInsTemH.org_id,
|
|
create_id = _userManager.UserId,
|
|
create_time = DateTime.Now,
|
|
duty_user_id= eqpSpotInsTemH.duty_user_id,
|
|
repeat_user_id= eqpSpotInsTemH.repeat_user_id
|
|
};
|
|
insertEqpSpotInsTemEquipHs.Add(eqpSpotInsTemEquipH);
|
|
|
|
if (eqpSpotInsTemDs != null && eqpSpotInsTemDs.Count > 0)
|
|
{
|
|
foreach (EqpSpotInsTemD eqpSpotInsTem in eqpSpotInsTemDs)
|
|
{
|
|
EqpSpotInsTemEquipD eqpSpotInsTemEquipD = new()
|
|
{
|
|
id = SnowflakeIdHelper.NextId(),
|
|
spot_ins_item_id = eqpSpotInsTem?.spot_ins_item_id ?? "",
|
|
spot_ins_tem_equip_id = id,
|
|
};
|
|
insertEqpSpotInsTemEquipDs.Add(eqpSpotInsTemEquipD);
|
|
}
|
|
}
|
|
|
|
EqpSpotInsTemEquipH oldSpotInsTemEquipH = await db.Queryable<EqpSpotInsTemEquipH>().Where(x => x.spot_ins_tem_id == input.id && x.equip_id == equipId).FirstAsync();
|
|
_ = await db.Deleteable<EqpSpotInsTemEquipH>().Where(x => x.spot_ins_tem_id == input.id && x.equip_id == equipId).ExecuteCommandAsync();
|
|
if (oldSpotInsTemEquipH != null)
|
|
{
|
|
_ = await db.Deleteable<EqpSpotInsTemEquipD>().Where(x => x.spot_ins_tem_equip_id == oldSpotInsTemEquipH.id).ExecuteCommandAsync();
|
|
}
|
|
}
|
|
|
|
if (insertEqpSpotInsTemEquipHs != null && insertEqpSpotInsTemEquipHs.Count > 0)
|
|
{
|
|
_ = await db.Insertable(insertEqpSpotInsTemEquipHs).ExecuteCommandAsync();
|
|
}
|
|
|
|
if (insertEqpSpotInsTemEquipDs != null && insertEqpSpotInsTemEquipDs.Count > 0)
|
|
{
|
|
_ = await db.Insertable(insertEqpSpotInsTemEquipDs).ExecuteCommandAsync();
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "发布成功" : result.ErrorMessage;
|
|
}
|
|
}
|
|
} |