using JNPF.Common.Configuration; using JNPF.Common.Const; using JNPF.Common.Core.Manager; using JNPF.Common.Core.Manager.Files; using JNPF.Common.Extension; using JNPF.Common.Manager; using JNPF.Common.Models; using JNPF.Common.Models.WorkFlow; using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.WorkFlow.Entitys; using JNPF.WorkFlow.Entitys.Dto.WorkFlowForm.LeaveApply; using JNPF.WorkFlow.Interfaces.Service; using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; namespace JNPF.WorkFlow.WorkFlowForm; /// /// 请假申请 /// 版 本:V3.2 /// 版 权:拓通智联科技有限公司(http://www.tuotong-tech.com) /// 日 期:2021-06-01. /// [ApiDescriptionSettings(Tag = "WorkflowForm", Name = "LeaveApply", Order = 516)] [Route("api/workflow/Form/[controller]")] public class LeaveApplyService : ILeaveApplyService, IDynamicApiController, ITransient { private readonly ISqlSugarRepository _sqlSugarRepository; private readonly ICacheManager _cacheManager; private readonly IFileManager _fileManager; private readonly IUserManager _userManager; public LeaveApplyService( ISqlSugarRepository sqlSugarRepository, ICacheManager cacheManager, IFileManager fileManager, IUserManager userManager) { _sqlSugarRepository = sqlSugarRepository; _cacheManager = cacheManager; _fileManager = fileManager; _userManager = userManager; } #region GET /// /// 信息. /// /// 主键值 /// [HttpGet("{id}")] public async Task GetInfo(string id) { return (await _sqlSugarRepository.GetFirstAsync(x => x.Id == id)).Adapt(); } #endregion #region POST /// /// 保存. /// /// 表单信息. /// 表单信息. /// [HttpPost("{id}")] public async Task Save(string id, [FromBody] LeaveApplyInput input) { input.id = id; var entity = input.Adapt(); entity.Id = id; if (_sqlSugarRepository.IsAny(x => x.Id == id)) { await _sqlSugarRepository.UpdateAsync(entity); if (entity.FileJson.IsNotEmptyOrNull() && entity.FileJson.IsNotEmptyOrNull()) { foreach (var item in entity.FileJson.ToList()) { if (item.IsNotEmptyOrNull() && item.FileType == "delete") { await _fileManager.DeleteFile(Path.Combine(FileVariable.SystemFilePath, item.FileName)); } } } } else { await _sqlSugarRepository.InsertAsync(entity); _cacheManager.Del(string.Format("{0}{1}_{2}", CommonConst.CACHEKEYBILLRULE, _userManager.TenantId, _userManager.UserId + "WF_LeaveApplyNo")); } } #endregion }