181 lines
6.7 KiB
C#
181 lines
6.7 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.Common.Security;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.Systems.Entitys.Permission;
|
|
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]")]
|
|
public class EqpRepairApplyService : IEqpRepairApplyService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarRepository<EqpRepairApply> _repository;
|
|
private readonly IUserManager _userManager;
|
|
|
|
public EqpRepairApplyService(ISqlSugarRepository<EqpRepairApply> repository,
|
|
IUserManager userManager)
|
|
{
|
|
_repository = repository;
|
|
_userManager = userManager;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<string> Repeal(Dictionary<string, string> dic)
|
|
{
|
|
string id = dic["id"];
|
|
await _repository.UpdateAsync(x => new EqpRepairApply()
|
|
{
|
|
status = RepairApplyStatus.REPEAL
|
|
}, x => x.id == id);
|
|
return "作废成功";
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<string> Close(Dictionary<string, string> dic)
|
|
{
|
|
string id = dic["id"];
|
|
await _repository.UpdateAsync(x => new EqpRepairApply()
|
|
{
|
|
status = RepairApplyStatus.CLOSE
|
|
}, x => x.id == id);
|
|
return "关闭成功";
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<string> Assign(Dictionary<string, string> dic)
|
|
{
|
|
string id = dic["id"];
|
|
string repairerId = dic["repairerId"];
|
|
await _repository.UpdateAsync(x => new EqpRepairApply()
|
|
{
|
|
repairer_id = repairerId,
|
|
status = RepairApplyStatus.TOBERECEIVED,
|
|
}, x => x.id == id);
|
|
return "指派成功";
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<string> Receive(Dictionary<string, string> dic)
|
|
{
|
|
string id = dic["id"];
|
|
await _repository.UpdateAsync(x => new EqpRepairApply()
|
|
{
|
|
status = RepairApplyStatus.RECEIVED,
|
|
}, x => x.id == id);
|
|
return "接收成功";
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<string> Refuse(Dictionary<string, string> dic)
|
|
{
|
|
string id = dic["id"];
|
|
string reason = dic["reason"];
|
|
var db = _repository.AsSugarClient();
|
|
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
await _repository.UpdateAsync(x => new EqpRepairApply()
|
|
{
|
|
status = RepairApplyStatus.REFUSE,
|
|
}, x => x.id == id);
|
|
EqpRepairRefuse eqpRepairRefuse = new EqpRepairRefuse()
|
|
{
|
|
repair_apply_id = id,
|
|
reason = reason,
|
|
create_id = _userManager.UserId,
|
|
create_time = DateTime.Now,
|
|
org_id = _userManager.GetUserInfo().Result.organizeId
|
|
};
|
|
await db.Insertable<EqpRepairRefuse>(eqpRepairRefuse).ExecuteCommandAsync();
|
|
});
|
|
if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
|
return "拒绝成功";
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<EqpRepairApply> GetInfo(Dictionary<string, string> dic)
|
|
{
|
|
string id = dic["id"];
|
|
return await _repository.GetSingleAsync(x => x.id == id);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<string> Register(RepairApplyRegisterInput input)
|
|
{
|
|
string status = input.is_out_apply==1 ? RepairApplyStatus.TOBEOUTAPPLY : RepairApplyStatus.COMPLETED;
|
|
|
|
await _repository.UpdateAsync(x => new EqpRepairApply()
|
|
{
|
|
fault_id = input.fault_id,
|
|
is_complete = input.is_complete,
|
|
complete_time = input.complete_time,
|
|
repair_take_time = input.repair_take_time,
|
|
is_halt = input.is_halt,
|
|
halt_take_time = input.halt_take_time,
|
|
repair_description = input.repair_description,
|
|
repair_img = input.repair_img,
|
|
is_out_apply = input.is_out_apply,
|
|
status = status,
|
|
}, x => x.id == input.id);
|
|
|
|
return "登记成功";
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<RepairApplyDetailOutput> GetRepairApplyDetail(Dictionary<string, string> dic)
|
|
{
|
|
string id = dic["id"];
|
|
|
|
EqpRepairApply eqpRepairApply = await _repository.GetSingleAsync(x => x.id == id);
|
|
EqpRepairOutApply eqpRepairOutApply = await _repository.AsSugarClient().Queryable<EqpRepairOutApply>().FirstAsync(x=>x.repair_apply_id==id);
|
|
|
|
return new RepairApplyDetailOutput()
|
|
{
|
|
eqpRepairApply = eqpRepairApply,
|
|
eqpRepairOutApply = eqpRepairOutApply,
|
|
};
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> GetRepairRecordList(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<EqpRepairApply>()
|
|
.LeftJoin<UserEntity>((a,b)=>a.apply_user_id==b.Id)
|
|
.LeftJoin<UserEntity>((a,b,c)=>a.repairer_id==c.Id)
|
|
.Where(a=>a.equip_id==input.equip_id)
|
|
.Select((a,b,c) => new EquipRepairRecordQueryOutput
|
|
{
|
|
id = a.id,
|
|
equip_id = a.equip_id,
|
|
code = a.code,
|
|
name = a.name,
|
|
apply_user_id =b.RealName,
|
|
is_ugent = a.is_ugent==1 ? "是" : "否",
|
|
description = a.description,
|
|
repair_description = a.repair_description,
|
|
complete_time = a.complete_time==null ? null : a.complete_time.Value.ToString("yyyy-MM-dd HH:mm"),
|
|
repairer_id = c.RealName
|
|
}).ToPagedListAsync(input.currentPage, input.pageSize);
|
|
|
|
return PageResult<EquipRepairRecordQueryOutput>.SqlSugarPageResult(result);
|
|
}
|
|
}
|
|
} |