优化
This commit is contained in:
69
BasicData/Tnb.BasicData/BasStandardTimeService.cs
Normal file
69
BasicData/Tnb.BasicData/BasStandardTimeService.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Systems.Interfaces.Permission;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData.Entities;
|
||||
|
||||
namespace Tnb.BasicData
|
||||
{
|
||||
/// <summary>
|
||||
/// 标准工时
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
public class BasStandardTimeService : IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarRepository<BasStandardTime> _repository;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IOrganizeService _organizeService;
|
||||
|
||||
public BasStandardTimeService(
|
||||
ISqlSugarRepository<BasStandardTime> repository,
|
||||
IOrganizeService organizeService,
|
||||
IUserManager userManager
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_organizeService = organizeService;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<dynamic?> SaveDate(BasStandardTime input)
|
||||
{
|
||||
var db = _repository.AsSugarClient();
|
||||
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
||||
{
|
||||
if (input.enabled != null && input.enabled == 1)
|
||||
{
|
||||
await db.Updateable<BasStandardTime>()
|
||||
.SetColumns(x => x.enabled == 0)
|
||||
.Where(x => x.process_id == input.process_id)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
if (input.id != null && !input.id.IsEmpty())
|
||||
{
|
||||
input.modify_id = _userManager.UserId;
|
||||
input.modify_time = DateTime.Now;
|
||||
await _repository.UpdateAsync(input);
|
||||
}
|
||||
else
|
||||
{
|
||||
input.id = SnowflakeIdHelper.NextId();
|
||||
input.create_time = DateTime.Now;
|
||||
input.create_id = _userManager.UserId;
|
||||
await db.Insertable(input).ExecuteCommandAsync();
|
||||
}
|
||||
});
|
||||
|
||||
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : (dynamic)(result.IsSuccess ? "保存成功" : result.ErrorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user