148 lines
7.2 KiB
C#
148 lines
7.2 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;
|
|
using Tnb.EquipMgr.Entities.Dto;
|
|
using Tnb.EquipMgr.Entities;
|
|
|
|
namespace Tnb.MoldMgr
|
|
{
|
|
/// <summary>
|
|
/// 模具保养检模板管理
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
public class ToolMaintainTemService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarRepository<ToolMaintainTemH> _repository;
|
|
private readonly IUserManager _userManager;
|
|
|
|
public ToolMaintainTemService(ISqlSugarRepository<ToolMaintainTemH> repository,
|
|
IUserManager userManager)
|
|
{
|
|
_repository = repository;
|
|
_userManager = userManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据模板id发布到设备
|
|
/// </summary>
|
|
[HttpPost]
|
|
public async Task<string> Publish(ToolTemPublishInput input)
|
|
{
|
|
ISqlSugarClient db = _repository.AsSugarClient();
|
|
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
ToolMaintainTemH ToolMaintainTemH = await _repository.GetSingleAsync(x => x.id == input.id);
|
|
List<ToolMaintainTemD> ToolMaintainTemDs = await db.Queryable<ToolMaintainTemD>().Where(x => x.maintain_tem_id == input.id).ToListAsync();
|
|
|
|
if (input.moldIds != null && input.moldIds.Length > 0)
|
|
{
|
|
List<ToolMaintainTemMoldH> insertToolMaintainTemMoldHs = new();
|
|
List<ToolMaintainTemMoldD> insertToolMaintainTemMoldDs = new();
|
|
foreach (string moldId in input.moldIds)
|
|
{
|
|
string id = SnowflakeIdHelper.NextId();
|
|
string code = $"{DateTime.Now.ToString("yyyyMMdd") + moldId}";
|
|
ToolMaintainTemMoldH ToolMaintainTemMoldH = new()
|
|
{
|
|
id = id,
|
|
code = code,
|
|
name = ToolMaintainTemH.name + moldId,
|
|
plan_cycle = ToolMaintainTemH.plan_cycle,
|
|
plan_cycle_unit = ToolMaintainTemH.plan_cycle_unit,
|
|
plan_run_notice = ToolMaintainTemH.plan_run_notice,
|
|
plan_delay = ToolMaintainTemH.plan_delay,
|
|
start_time = ToolMaintainTemH.start_time,
|
|
is_start = ToolMaintainTemH.is_start.ToString(),
|
|
is_repeat = ToolMaintainTemH.is_repeat.ToString(),
|
|
is_send = ToolMaintainTemH.is_send,
|
|
maintain_tem_id = input.id,
|
|
mold_id = moldId,
|
|
remark = ToolMaintainTemH.remark,
|
|
plan_run_notice_unit = ToolMaintainTemH.plan_run_notice_unit,
|
|
plan_delay_unit = ToolMaintainTemH.plan_delay_unit,
|
|
repeat_post_info_user_id = ToolMaintainTemH.repeat_post_info_user_id,
|
|
send_post_info_user_id = ToolMaintainTemH.send_post_info_user_id,
|
|
send_post_id = ToolMaintainTemH.send_post_id,
|
|
org_id = ToolMaintainTemH.org_id,
|
|
create_id = _userManager.UserId,
|
|
create_time = DateTime.Now,
|
|
duty_user_id= ToolMaintainTemH.duty_user_id,
|
|
repeat_user_id= ToolMaintainTemH.repeat_user_id
|
|
};
|
|
insertToolMaintainTemMoldHs.Add(ToolMaintainTemMoldH);
|
|
|
|
if (ToolMaintainTemDs != null && ToolMaintainTemDs.Count > 0)
|
|
{
|
|
foreach (ToolMaintainTemD ToolMaintainTem in ToolMaintainTemDs)
|
|
{
|
|
ToolMaintainTemMoldD ToolMaintainTemMoldD = new()
|
|
{
|
|
id = SnowflakeIdHelper.NextId(),
|
|
maintain_item_id = ToolMaintainTem.maintain_item_id,
|
|
maintain_tem_mold_id = id,
|
|
};
|
|
insertToolMaintainTemMoldDs.Add(ToolMaintainTemMoldD);
|
|
}
|
|
}
|
|
|
|
ToolMaintainTemMoldH oldMaintainTemMoldH = await db.Queryable<ToolMaintainTemMoldH>().Where(x => x.maintain_tem_id == input.id && x.mold_id == moldId).FirstAsync();
|
|
_ = await db.Deleteable<ToolMaintainTemMoldH>().Where(x => x.maintain_tem_id == input.id && x.mold_id == moldId).ExecuteCommandAsync();
|
|
if (oldMaintainTemMoldH != null)
|
|
{
|
|
_ = await db.Deleteable<ToolMaintainTemMoldD>().Where(x => x.maintain_tem_mold_id == oldMaintainTemMoldH.id).ExecuteCommandAsync();
|
|
}
|
|
}
|
|
|
|
if (insertToolMaintainTemMoldHs != null && insertToolMaintainTemMoldHs.Count > 0)
|
|
{
|
|
_ = await db.Insertable(insertToolMaintainTemMoldHs).ExecuteCommandAsync();
|
|
}
|
|
|
|
if (insertToolMaintainTemMoldDs != null && insertToolMaintainTemMoldDs.Count > 0)
|
|
{
|
|
_ = await db.Insertable(insertToolMaintainTemMoldDs).ExecuteCommandAsync();
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "发布成功" : result.ErrorMessage;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task Stop(Dictionary<string, string> parameters)
|
|
{
|
|
string id = parameters["id"];
|
|
var db = _repository.AsSugarClient();
|
|
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
await db.Updateable<ToolMaintainTemMoldH>()
|
|
.SetColumns(x => x.is_start == "0")
|
|
.Where(x => x.id == id)
|
|
.ExecuteCommandAsync();
|
|
List<string> ids = await _repository.AsSugarClient().Queryable<ToolMoldMaintainRecordH>()
|
|
.Where(x => x.maintain_tem_mold_id == id && x.status == SpotInsRecordExecutionStatus.TOBEEXECUTED)
|
|
.Select(x => x.id).ToListAsync();
|
|
_ = await _repository.AsSugarClient().Deleteable<ToolMoldMaintainRecordH>()
|
|
.Where(x => x.maintain_tem_mold_id == id && x.status == SpotInsRecordExecutionStatus.TOBEEXECUTED).ExecuteCommandAsync();
|
|
|
|
_ = await _repository.AsSugarClient().Deleteable<ToolMoldMaintainRecordD>()
|
|
.Where(x => ids.Contains(x.maintain_record_id)).ExecuteCommandAsync();
|
|
|
|
});
|
|
|
|
if (!result.IsSuccess)
|
|
{
|
|
throw Oops.Oh(ErrorCode.COM1008);
|
|
}
|
|
}
|
|
}
|
|
} |