185 lines
7.8 KiB
C#
185 lines
7.8 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.Common.Models.WorkFlow;
|
|
using JNPF.Common.Security;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.WorkFlow.Interfaces.Service;
|
|
using JNPF.WorkFlow.Service;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json.Linq;
|
|
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 EqpRepairOutApplyService : IEqpRepairOutApplyService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarRepository<EqpRepairOutApply> _repository;
|
|
private readonly IUserManager _userManager;
|
|
private readonly FlowTaskService _flowTaskService;
|
|
/// <summary>
|
|
/// flow_templatejson 表的id
|
|
/// </summary>
|
|
private const string flowId = "26414803850262";
|
|
|
|
public EqpRepairOutApplyService(ISqlSugarRepository<EqpRepairOutApply> repository,
|
|
FlowTaskService flowTaskService,
|
|
IUserManager userManager)
|
|
{
|
|
_repository = repository;
|
|
_userManager = userManager;
|
|
_flowTaskService = flowTaskService;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<EqpRepairOutApply> GetInfo(Dictionary<string, string> dic)
|
|
{
|
|
string id = dic["id"];
|
|
EqpRepairApply eqpRepairApply = await _repository.AsSugarClient().Queryable<EqpRepairApply>().SingleAsync(x => x.id == id);
|
|
return await _repository.GetSingleAsync(x => x.repair_apply_id==eqpRepairApply.id);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<string> OutApply(RepairOutApplyInput input)
|
|
{
|
|
|
|
var db = _repository.AsSugarClient();
|
|
string id = string.IsNullOrEmpty(input.id) ? SnowflakeIdHelper.NextId() : input.id;
|
|
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
if (string.IsNullOrEmpty(input.id))
|
|
{
|
|
// await _repository.InsertAsync(new EqpRepairOutApply
|
|
// {
|
|
// id = id,
|
|
// repair_apply_id = input.repair_apply_id,
|
|
// equip_id = input.equip_id,
|
|
// supplier_id = input.supplier_id,
|
|
// estimated_cost = input.estimated_cost,
|
|
// construction_period_requirement = input.construction_period_requirement,
|
|
// out_apply_reason = input.out_apply_reason,
|
|
// remark = input.remark,
|
|
// create_id = _userManager.UserId,
|
|
// create_time = DateTime.Now,
|
|
// approve_status = RepairOutApplyStatus.TOBEAPPROVE,
|
|
// });
|
|
}
|
|
else
|
|
{
|
|
// await _repository.UpdateAsync(x=>new EqpRepairOutApply
|
|
// {
|
|
// repair_apply_id = input.repair_apply_id,
|
|
// equip_id = input.equip_id,
|
|
// supplier_id = input.supplier_id,
|
|
// estimated_cost = input.estimated_cost,
|
|
// construction_period_requirement = input.construction_period_requirement,
|
|
// out_apply_reason = input.out_apply_reason,
|
|
// remark = input.remark,
|
|
// create_id = _userManager.UserId,
|
|
// create_time = DateTime.Now,
|
|
// approve_status = RepairOutApplyStatus.TOBEAPPROVE,
|
|
// },x=>x.id==input.id);
|
|
}
|
|
|
|
await db.Updateable<EqpRepairApply>()
|
|
.SetColumns(x=>x.status == RepairApplyStatus.OUTAPPLYAPPROVE)
|
|
.Where(x=>x.id==input.repair_apply_id).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
});
|
|
|
|
if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
|
|
|
if (result.IsSuccess)
|
|
{
|
|
if (string.IsNullOrEmpty(input.id))
|
|
{
|
|
await _flowTaskService.Create(new FlowTaskSubmitModel()
|
|
{
|
|
flowId = flowId,
|
|
parentId = "0",
|
|
formData = new JObject()
|
|
{
|
|
{"id",id},
|
|
{"repair_apply_id",input.repair_apply_id},
|
|
{"equip_id",input.equip_id},
|
|
{"create_id",_userManager.UserId},
|
|
{"supplier_id",input.supplier_id},
|
|
{"estimated_cost",input.estimated_cost},
|
|
{"construction_period_requirement",input.construction_period_requirement},
|
|
{"out_apply_reason",input.out_apply_reason},
|
|
{"remark",input.remark},
|
|
{"approve_status",RepairOutApplyStatus.TOBEAPPROVE},
|
|
}
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
var entity = await _repository.GetSingleAsync(x=>x.id==input.id);
|
|
if (entity != null)
|
|
{
|
|
|
|
await _flowTaskService.Update("",new FlowTaskSubmitModel()
|
|
{
|
|
flowId = flowId,
|
|
parentId = "0",
|
|
id = entity?.flow_task_id??"",
|
|
formData = new JObject()
|
|
{
|
|
{"id",id},
|
|
{"repair_apply_id",input.repair_apply_id},
|
|
{"equip_id",input.equip_id},
|
|
{"create_id",_userManager.UserId},
|
|
{"supplier_id",input.supplier_id},
|
|
{"estimated_cost",input.estimated_cost},
|
|
{"construction_period_requirement",input.construction_period_requirement},
|
|
{"out_apply_reason",input.out_apply_reason},
|
|
{"remark",input.remark},
|
|
{"approve_status",RepairOutApplyStatus.TOBEAPPROVE},
|
|
}
|
|
|
|
});
|
|
}
|
|
}
|
|
}
|
|
return result.IsSuccess ? "操作成功" : result.ErrorMessage;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<string> Register(RepairApplyOutRegisterInput input)
|
|
{
|
|
|
|
var db = _repository.AsSugarClient();
|
|
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
await _repository.UpdateAsync(x => new EqpRepairOutApply()
|
|
{
|
|
real_supplier_id = input.real_supplier_id,
|
|
cost = input.cost,
|
|
repair_time = input.repair_time,
|
|
repair_take_time = input.repair_take_time,
|
|
repair_remark = input.repair_remark,
|
|
attachment = input.attachment,
|
|
}, x => x.id == input.id);
|
|
|
|
await db.Updateable<EqpRepairApply>().SetColumns(x => x.status == RepairApplyStatus.COMPLETED)
|
|
.Where(x => x.id == input.repair_apply_id).ExecuteCommandAsync();
|
|
});
|
|
if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
|
|
|
return result.IsSuccess ? "登记成功" : result.ErrorMessage;
|
|
}
|
|
|
|
}
|
|
} |