146 lines
5.7 KiB
C#
146 lines
5.7 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys;
|
|
using JNPF.VisualDev.Interfaces;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
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]")]
|
|
[OverideVisualDev(ModuleId)]
|
|
public class EqpMaintainRecordService : IOverideVisualDevService, IEqpMaintainRecordService, IDynamicApiController, ITransient
|
|
{
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
private const string ModuleId = "26304609081109";
|
|
private readonly ISqlSugarRepository<EqpMaintainRecordH> _repository;
|
|
private readonly IVisualDevService _visualDevService;
|
|
private readonly IRunService _runService;
|
|
private readonly IUserManager _userManager;
|
|
|
|
public EqpMaintainRecordService(ISqlSugarRepository<EqpMaintainRecordH> repository,
|
|
IRunService runService,
|
|
IUserManager userManager,
|
|
IVisualDevService visualDevService)
|
|
{
|
|
_repository = repository;
|
|
_visualDevService = visualDevService;
|
|
_runService = runService;
|
|
_userManager = userManager;
|
|
// OverideFuncs.UpdateAsync = ExecuteSpotIns;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行设备保养计划
|
|
/// </summary>
|
|
/// <param name="pageInput"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> ExecuteMaintain(SpotInsRecordExecuteInput input)
|
|
{
|
|
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
|
{
|
|
EqpMaintainRecordH eqpSpotInsRecordH = _repository.GetSingle(x=>x.id==input.id);
|
|
string status = "";
|
|
if (eqpSpotInsRecordH.is_repeat == "1")
|
|
{
|
|
status = SpotInsRecordExecutionStatus.TOBECHECK;
|
|
}
|
|
else
|
|
{
|
|
status = SpotInsRecordExecutionStatus.COMPLETED;
|
|
}
|
|
await _repository.UpdateAsync(x => new EqpMaintainRecordH()
|
|
{
|
|
result = input.result,
|
|
attachment = input.attachment,
|
|
result_remark = input.result_remark,
|
|
status = status,
|
|
execute_time = DateTime.Now,
|
|
execute_user_id = _userManager.UserId
|
|
}, x => x.id == input.id);
|
|
|
|
foreach (var item in input.details)
|
|
{
|
|
await _repository.AsSugarClient().Updateable<EqpMaintainRecordD>()
|
|
.SetColumns(x=>x.result==item["result"])
|
|
.SetColumns(x=>x.maintain_descrip==item["maintain_descrip"])
|
|
.Where(x=>x.id==item["id"])
|
|
.ExecuteCommandAsync();
|
|
}
|
|
|
|
|
|
});
|
|
|
|
if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
|
return result.IsSuccess ? "执行成功" : result.ErrorMessage;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取设备保养计划复核信息
|
|
/// </summary>
|
|
/// <param name="dic"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<MaintainRecordRepeatOutput> GetMaintainRecordRepeatInfo(Dictionary<string, string> dic)
|
|
{
|
|
string id = dic["id"];
|
|
EqpMaintainRecordH eqpSpotInsRecordH = await _repository.GetSingleAsync(x => x.id == id);
|
|
List<EqpMaintainRecordD> eqpSpotInsRecordDs = await _repository.AsSugarClient().Queryable<EqpMaintainRecordD>()
|
|
.Where(x => x.maintain_record_id == id).ToListAsync();
|
|
MaintainRecordRepeatOutput output = new MaintainRecordRepeatOutput()
|
|
{
|
|
model = eqpSpotInsRecordH,
|
|
details = eqpSpotInsRecordDs,
|
|
};
|
|
return output;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 复核设备保养计划
|
|
/// </summary>
|
|
/// <param name="pageInput"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<string> RepeatMaintain(MaintainRecordRepeatInput input)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
|
|
foreach (var item in input.details)
|
|
{
|
|
await db.Updateable<EqpMaintainRecordD>()
|
|
.SetColumns(x => x.repeat_descrip == item["repeat_descrip"])
|
|
.SetColumns(x => x.repeat_result == item["repeat_result"])
|
|
.Where(x => x.id == item["id"]).ExecuteCommandAsync();
|
|
}
|
|
|
|
await _repository.UpdateAsync(x => new EqpMaintainRecordH()
|
|
{
|
|
repeat_result = input.repeat_result,
|
|
repeat_remark = input.repeat_remark,
|
|
repeat_user_id = _userManager.UserId,
|
|
repeat_time = DateTime.Now,
|
|
status = SpotInsRecordExecutionStatus.COMPLETED
|
|
}, x => x.id == input.id);
|
|
});
|
|
|
|
if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
|
return result.IsSuccess ? "复核成功" : result.ErrorMessage;
|
|
}
|
|
}
|
|
} |