191 lines
8.2 KiB
C#
191 lines
8.2 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.Systems.Entitys.Permission;
|
|
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>
|
|
/// <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);
|
|
|
|
if (input != null && input.details != null)
|
|
{
|
|
foreach (var item in input.details)
|
|
{
|
|
await _repository.AsSugarClient().Updateable<EqpMaintainRecordD>()
|
|
.SetColumns(x=>x.result==item["result"])
|
|
.SetColumnsIF(item.ContainsKey("maintain_descrip"),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>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<string> RepeatMaintain(MaintainRecordRepeatInput input)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
|
|
if (input != null && input.details != null)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
|
|
if (input != null)
|
|
{
|
|
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;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> GetMaintainRecordList(EquipQueryInput input)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
Dictionary<string, string>? queryJson = new Dictionary<string, string>();
|
|
if (!string.IsNullOrEmpty(input.queryJson))
|
|
{
|
|
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson);
|
|
}
|
|
var result = await db.Queryable<EqpMaintainRecordH>()
|
|
.LeftJoin<EqpEquipment>((a,b)=>a.equip_id==b.id)
|
|
.LeftJoin<UserEntity>((a,b,c)=>a.execute_user_id==c.Id)
|
|
.LeftJoin<UserEntity>((a,b,c,d)=>a.repeat_user_id==d.Id)
|
|
.Where(a=>a.equip_id==input.equip_id)
|
|
.Select((a,b,c,d) => new EquipMaintainRecordQueryOutput
|
|
{
|
|
id = a.id,
|
|
attachment = a.attachment,
|
|
create_time = a.create_time==null ? null : a.create_time.Value.ToString("yyyy-MM-dd HH:mm"),
|
|
equip_id = b.code,
|
|
equip_id_id = a.equip_id,
|
|
repeat_remark = a.repeat_remark,
|
|
repeat_result = a.repeat_result=="1"?"合格":"不合格",
|
|
repeat_time = a.repeat_time==null ? null : a.repeat_time.Value.ToString("yyyy-MM-dd HH:mm"),
|
|
repeat_user_id = d.RealName,
|
|
result = a.result=="1"?"合格":"不合格",
|
|
result_remark = a.result_remark,
|
|
maintain_tem_equip_id = a.maintain_tem_equip_id,
|
|
execute_time = a.execute_time==null ? null : a.execute_time.Value.ToString("yyyy-MM-dd HH:mm"),
|
|
execute_user_id = c.RealName,
|
|
status = SqlFunc.IF(a.status.Equals("1")).Return("待执行").ElseIF(a.status.Equals("2")).Return("待复核").ElseIF(a.status.Equals("3")).Return("已完成").End("")
|
|
}).ToPagedListAsync(input.currentPage, input.pageSize);
|
|
|
|
return PageResult<EquipMaintainRecordQueryOutput>.SqlSugarPageResult(result);
|
|
}
|
|
}
|
|
} |