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 { /// /// 标准工时 /// [ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)] [Route("api/[area]/[controller]/[action]")] public class BasStandardTimeService : IDynamicApiController, ITransient { private readonly ISqlSugarRepository _repository; private readonly IUserManager _userManager; private readonly IOrganizeService _organizeService; public BasStandardTimeService( ISqlSugarRepository repository, IOrganizeService organizeService, IUserManager userManager ) { _repository = repository; _organizeService = organizeService; _userManager = userManager; } [HttpPost] public async Task SaveDate(BasStandardTime input) { var db = _repository.AsSugarClient(); DbResult result = await db.Ado.UseTranAsync(async () => { if (input.enabled != null && input.enabled == 1) { await db.Updateable() .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); } } }