455 lines
20 KiB
C#
455 lines
20 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.JsonSerialization;
|
|
using JNPF.Systems.Entitys.Permission;
|
|
using JNPF.Systems.Entitys.System;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Interfaces;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using SQLitePCL;
|
|
using SqlSugar;
|
|
using Tnb.BasicData;
|
|
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 EqpRepairApplyService : IEqpRepairApplyService, IOverideVisualDevService, IDynamicApiController, ITransient
|
|
{
|
|
private const string ModuleId = "26165698078741";
|
|
private readonly ISqlSugarRepository<EqpRepairApply> _repository;
|
|
private readonly IVisualDevService _visualDevService;
|
|
private readonly IRunService _runService;
|
|
private readonly IBillRullService _billRuleService;
|
|
private readonly IUserManager _userManager;
|
|
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
|
|
public EqpRepairApplyService(ISqlSugarRepository<EqpRepairApply> repository,
|
|
IVisualDevService visualDevService,
|
|
IRunService runService,
|
|
IBillRullService billRullService,
|
|
IUserManager userManager)
|
|
{
|
|
_repository = repository;
|
|
_visualDevService = visualDevService;
|
|
_runService = runService;
|
|
_userManager = userManager;
|
|
_billRuleService = billRullService;
|
|
OverideFuncs.CreateAsync = Create;
|
|
}
|
|
|
|
private async Task<dynamic> Create(VisualDevModelDataCrInput input)
|
|
{
|
|
if (!input.data.ContainsKey("create_time"))
|
|
{
|
|
input.data.Add("create_time", DateTime.Now);
|
|
}
|
|
else if (string.IsNullOrEmpty((string)input.data["create_time"]))
|
|
{
|
|
input.data["create_time"] = DateTime.Now;
|
|
}
|
|
|
|
if (!input.data.ContainsKey("create_id"))
|
|
{
|
|
input.data.Add("create_id", _userManager.UserId);
|
|
}
|
|
else if (string.IsNullOrEmpty((string)input.data["create_id"]))
|
|
{
|
|
input.data["create_id"] = _userManager.UserId;
|
|
}
|
|
|
|
if (!input.data.ContainsKey("apply_user_id"))
|
|
{
|
|
input.data.Add("apply_user_id", _userManager.UserId);
|
|
}
|
|
else if (string.IsNullOrEmpty((string)input.data["apply_user_id"]))
|
|
{
|
|
input.data["apply_user_id"] = _userManager.UserId;
|
|
}
|
|
|
|
if (!input.data.ContainsKey("org_id"))
|
|
{
|
|
input.data.Add("org_id", _userManager.GetUserInfo().Result.organizeId);
|
|
}
|
|
else if (string.IsNullOrEmpty((string)input.data["org_id"]))
|
|
{
|
|
input.data["org_id"] = _userManager.GetUserInfo().Result.organizeId;
|
|
}
|
|
|
|
if (!input.data.ContainsKey("code"))
|
|
{
|
|
input.data.Add("code", await _billRuleService.GetBillNumber(CodeTemplateConst.EQPREPAIR_CODE));
|
|
}
|
|
else if (string.IsNullOrEmpty((string)input.data["code"]))
|
|
{
|
|
input.data["code"] = await _billRuleService.GetBillNumber(CodeTemplateConst.EQPREPAIR_CODE);
|
|
}
|
|
|
|
EqpRepairApply eqpRepairApply = new();
|
|
|
|
eqpRepairApply.code = (string)input.data["code"];
|
|
eqpRepairApply.name = (string)input.data["name"];
|
|
eqpRepairApply.equip_id = (string)input.data["equip_id"];
|
|
eqpRepairApply.expect_complete_time = input.data["expect_complete_time"] != null && input.data["expect_complete_time"].ToString() != "" ? DateTimeOffset.FromUnixTimeSeconds(((long)input.data["expect_complete_time"]) / 1000).ToLocalTime().DateTime : null;
|
|
eqpRepairApply.is_ugent = (int?)(long)input.data["is_ugent"];
|
|
eqpRepairApply.attachment = input.data.ContainsKey("attachment") ? JsonConvert.SerializeObject(input.data["attachment"]) : null;
|
|
eqpRepairApply.apply_user_id = (string)input.data["apply_user_id"];
|
|
eqpRepairApply.create_id = (string)input.data["create_id"];
|
|
eqpRepairApply.create_time = DateTime.Now;
|
|
eqpRepairApply.org_id = (string)input.data["org_id"];
|
|
eqpRepairApply.remark = input.data.ContainsKey("remark") ? (string)input.data["remark"] : "";
|
|
eqpRepairApply.description = input.data.ContainsKey("description") ? (string)input.data["description"] : "";
|
|
eqpRepairApply.status = RepairApplyStatus.TOBEEXECUTED;
|
|
|
|
_ = await _repository.InsertAsync(eqpRepairApply);
|
|
|
|
// VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
|
// await _runService.Create(templateEntity, input);
|
|
return await Task.FromResult(true);
|
|
}
|
|
|
|
[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"];
|
|
EqpRepairApply eqpRepairApply = await _repository.GetSingleAsync(x => x.id == id);
|
|
if (eqpRepairApply.status is RepairApplyStatus.TOBEEXECUTED or
|
|
RepairApplyStatus.REFUSE)
|
|
{
|
|
_ = await _repository.UpdateAsync(x => new EqpRepairApply()
|
|
{
|
|
repairer_id = repairerId,
|
|
status = RepairApplyStatus.TOBERECEIVED,
|
|
}, x => x.id == id);
|
|
return "指派成功";
|
|
}
|
|
else
|
|
{
|
|
throw Oops.Bah("状态错误");
|
|
}
|
|
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<string> Receive(Dictionary<string, string> dic)
|
|
{
|
|
// string id = dic["id"];
|
|
// EqpRepairApply eqpRepairApply = await _repository.GetSingleAsync(x => x.id == id);
|
|
// if (eqpRepairApply.status == RepairApplyStatus.TOBERECEIVED)
|
|
// {
|
|
// if (_userManager.UserId == eqpRepairApply.repairer_id)
|
|
// {
|
|
// _ = await _repository.UpdateAsync(x => new EqpRepairApply()
|
|
// {
|
|
// status = RepairApplyStatus.RECEIVED,
|
|
// }, x => x.id == id);
|
|
// return "接收成功";
|
|
// }
|
|
// else
|
|
// {
|
|
// throw Oops.Bah("该任务没有指派给您,无法接收");
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// throw Oops.Bah("状态错误");
|
|
// }
|
|
|
|
string id = dic["id"];
|
|
EqpRepairApply eqpRepairApply = await _repository.GetSingleAsync(x => x.id == id);
|
|
if (eqpRepairApply.status == RepairApplyStatus.TOBEEXECUTED)
|
|
{
|
|
if (await _repository.AsSugarClient().Queryable<UserRelationEntity>().AnyAsync(x => x.UserId == _userManager.UserId && x.ObjectId == "26586914497557"))
|
|
{
|
|
_ = await _repository.UpdateAsync(x => new EqpRepairApply()
|
|
{
|
|
repairer_id = _userManager.UserId,
|
|
status = RepairApplyStatus.RECEIVED,
|
|
receive_time = DateTime.Now,
|
|
}, x => x.id == id);
|
|
return "接收成功";
|
|
}else
|
|
{
|
|
throw Oops.Bah("不是设备管理部的,无法接收");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
throw Oops.Bah("状态错误");
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<string> Refuse(Dictionary<string, string> dic)
|
|
{
|
|
string id = dic["id"];
|
|
string reason = dic["reason"];
|
|
ISqlSugarClient db = _repository.AsSugarClient();
|
|
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
EqpRepairApply eqpRepairApply = await _repository.GetSingleAsync(x => x.id == id);
|
|
if (eqpRepairApply.status == RepairApplyStatus.TOBERECEIVED)
|
|
{
|
|
if (_userManager.UserId == eqpRepairApply.repairer_id)
|
|
{
|
|
_ = await _repository.UpdateAsync(x => new EqpRepairApply()
|
|
{
|
|
status = RepairApplyStatus.REFUSE,
|
|
}, x => x.id == id);
|
|
EqpRepairRefuse eqpRepairRefuse = new()
|
|
{
|
|
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();
|
|
}
|
|
else
|
|
{
|
|
throw Oops.Bah("该任务没有指派给您,无法拒绝");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw Oops.Bah("状态错误");
|
|
}
|
|
|
|
});
|
|
return !result.IsSuccess ? throw Oops.Oh(result.ErrorMessage) : "拒绝成功";
|
|
}
|
|
|
|
[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)
|
|
{
|
|
|
|
EqpRepairApply eqpRepairApply = await _repository.GetSingleAsync(x => x.id == input.id);
|
|
if (eqpRepairApply.status == RepairApplyStatus.RECEIVED)
|
|
{
|
|
if (_userManager.UserId == eqpRepairApply.repairer_id)
|
|
{
|
|
// string status = input.is_out_apply == 1 ? RepairApplyStatus.TOBEOUTAPPLY : RepairApplyStatus.COMPLETED;
|
|
string status = input.is_out_apply == 1 ? RepairApplyStatus.TOBEOUTAPPLY : RepairApplyStatus.REPEATCHECKING;
|
|
_ = 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 "登记成功";
|
|
}
|
|
else
|
|
{
|
|
throw Oops.Bah("您不是责任人");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw Oops.Bah("状态错误");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<RepairApplyDetailOutput> GetRepairApplyDetail(Dictionary<string, string> dic)
|
|
{
|
|
string id = dic["id"];
|
|
var db = _repository.AsSugarClient();
|
|
EqpRepairApply eqpRepairApply = await _repository.GetSingleAsync(x => x.id == id);
|
|
EqpRepairOutApply eqpRepairOutApply = await db.Queryable<EqpRepairOutApply>().FirstAsync(x => x.repair_apply_id == id);
|
|
|
|
EqpFault eqpFault = await db.Queryable<EqpFault>().SingleAsync(x => x.id == eqpRepairApply.fault_id);
|
|
eqpRepairApply.fault_name = eqpFault != null ? eqpFault.fault_name : "";
|
|
return new RepairApplyDetailOutput()
|
|
{
|
|
eqpRepairApply = eqpRepairApply,
|
|
eqpRepairOutApply = eqpRepairOutApply,
|
|
};
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> GetRepairRecordList(EquipQueryInput input)
|
|
{
|
|
ISqlSugarClient db = _repository.AsSugarClient();
|
|
Dictionary<string, string>? queryJson = new();
|
|
if (!string.IsNullOrEmpty(input.queryJson))
|
|
{
|
|
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson);
|
|
}
|
|
SqlSugarPagedList<EquipRepairRecordQueryOutput> 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)
|
|
.OrderByDescending(a => a.create_time)
|
|
.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(DbTimeFormat.MM),
|
|
repairer_id = c.RealName
|
|
}).ToPagedListAsync(input.currentPage, input.pageSize);
|
|
|
|
return PageResult<EquipRepairRecordQueryOutput>.SqlSugarPageResult(result);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> GetPadRepairList(PadRepairListInput input)
|
|
{
|
|
|
|
DateTime? start_time = input.start_time;
|
|
DateTime? end_time = input.end_time;
|
|
List<string> statusList = new();
|
|
if (!string.IsNullOrEmpty(input.status))
|
|
{
|
|
switch (input.status)
|
|
{
|
|
case "1":
|
|
statusList.Add(RepairApplyStatus.TOBEEXECUTED);
|
|
statusList.Add(RepairApplyStatus.REFUSE);
|
|
break;
|
|
case "2":
|
|
statusList.Add(RepairApplyStatus.TOBERECEIVED);
|
|
statusList.Add(RepairApplyStatus.RECEIVED);
|
|
statusList.Add(RepairApplyStatus.OUTAPPLYAPPROVE);
|
|
statusList.Add(RepairApplyStatus.APPROVEPASS);
|
|
statusList.Add(RepairApplyStatus.APPROVENOTPASS);
|
|
statusList.Add(RepairApplyStatus.TOBEOUTAPPLY);
|
|
break;
|
|
case "3":
|
|
statusList.Add(RepairApplyStatus.COMPLETED);
|
|
statusList.Add(RepairApplyStatus.CLOSE);
|
|
statusList.Add(RepairApplyStatus.REPEAL);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(input.sidx))
|
|
{
|
|
input.sidx = "a.create_time";
|
|
input.sort = "desc";
|
|
}
|
|
else
|
|
{
|
|
input.sidx = "a." + input.sidx;
|
|
}
|
|
|
|
ISqlSugarClient db = _repository.AsSugarClient();
|
|
SqlSugarPagedList<PadRepairListOutput> 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)
|
|
.LeftJoin<EqpEquipment>((a, b, c, d) => a.equip_id == d.id)
|
|
.LeftJoin<DictionaryTypeEntity>((a, b, c, d, e) => e.EnCode == DictConst.RepairStatus)
|
|
.LeftJoin<DictionaryDataEntity>((a, b, c, d, e, f) => e.Id == f.DictionaryTypeId && a.status == f.EnCode)
|
|
.WhereIF(!string.IsNullOrEmpty(input.equip_info), (a, b, c, d) => d.code.Contains(input.equip_info) || d.name.Contains(input.equip_info))
|
|
.WhereIF(!string.IsNullOrEmpty(input.status), (a, b, c, d) => statusList.Contains(a.status))
|
|
.WhereIF(input.status == "3" && start_time != null, a => a.complete_time != null && a.complete_time >= start_time)
|
|
.WhereIF(input.status == "3" && end_time != null, a => a.complete_time != null && a.complete_time <= end_time)
|
|
.OrderBy($"{input.sidx} {input.sort}")
|
|
.Select((a, b, c, d, e, f) => new PadRepairListOutput
|
|
{
|
|
id = a.id,
|
|
equip_id = d.code + "/" + d.name,
|
|
equip_id_id = a.equip_id,
|
|
code = a.code,
|
|
name = a.name,
|
|
apply_user_id = b.RealName,
|
|
apply_user_id_id = b.Id,
|
|
is_ugent = a.is_ugent == 1 ? "是" : "否",
|
|
description = a.description,
|
|
create_time = a.create_time == null ? "" : a.create_time.Value.ToString(DbTimeFormat.SS),
|
|
complete_time = a.complete_time == null ? "" : a.complete_time.Value.ToString(DbTimeFormat.SS),
|
|
expect_complete_time = a.expect_complete_time == null ? "" : a.expect_complete_time.Value.ToString(DbTimeFormat.SS),
|
|
repairer_id = c.RealName,
|
|
repairer_id_id = c.Id,
|
|
remark = a.remark,
|
|
status = f.FullName,
|
|
attachment=a.attachment
|
|
}).ToPagedListAsync(input?.currentPage ?? 1, input?.pageSize ?? 50);
|
|
|
|
return PageResult<PadRepairListOutput>.SqlSugarPageResult(result);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<string> Repeat(RepairApplyRepeatInput input)
|
|
{
|
|
|
|
EqpRepairApply eqpRepairApply = await _repository.GetSingleAsync(x => x.id == input.id);
|
|
if (eqpRepairApply.status == RepairApplyStatus.REPEATCHECKING)
|
|
{
|
|
string status = input.repeat_result=="1" ? RepairApplyStatus.COMPLETED : RepairApplyStatus.TOBEEXECUTED;
|
|
await _repository.AsSugarClient().Updateable<EqpRepairApply>()
|
|
.SetColumns(x => x.repeat_result == input.repeat_result)
|
|
.SetColumns(x => x.repeat_descrip == input.repeat_descrip)
|
|
.SetColumns(x => x.status == status)
|
|
.Where(x => x.id == input.id).ExecuteCommandAsync();
|
|
return "复核成功";
|
|
}
|
|
else
|
|
{
|
|
throw Oops.Bah("状态错误");
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
} |