using JNPF.Common.Core.Manager; using JNPF.Common.Enums; using JNPF.Common.Filter; using JNPF.Common.Models; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.FriendlyException; using JNPF.Logging; using JNPF.Systems.Common; using JNPF.Systems.Entitys.Permission; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using SqlSugar; using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Entities.Dto; using Tnb.EquipMgr.Interfaces; namespace Tnb.EquipMgr { /// /// 设备保养计划执行管理 /// [ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)] [Route("api/[area]/[controller]/[action]")] public class EqpEquipFileService : IEqpEquipFileService, IDynamicApiController, ITransient { private readonly ISqlSugarRepository _repository; private readonly IUserManager _userManager; private readonly FileService _fileService; public EqpEquipFileService(ISqlSugarRepository repository, FileService fileService, IUserManager userManager) { _repository = repository; _userManager = userManager; _fileService = fileService; } [HttpPost] public async Task Upload([FromForm] string equip_id,[FromForm] string file_type, [FromForm] ChunkModel input) { string msg; try { FileControlsModel attachment = await _fileService.Uploader("annexpic", input); EqpEquipFile eqpEquipFile = new() { file_name = input.file.FileName, equip_id = equip_id, create_id = _userManager.UserId, create_time = DateTime.Now, attachment = JsonConvert.SerializeObject(attachment), file_ext = attachment.fileExtension, file_type = file_type, org_id = _userManager.GetUserInfo().Result.organizeId, }; _ = await _repository.InsertAsync(eqpEquipFile); msg = "上传成功"; } catch (Exception e) { Log.Error(e.Message); throw Oops.Oh(ErrorCode.D8001); } return msg; } [HttpPost] public async Task GetEquipFileList(EquipQueryInput input) { ISqlSugarClient db = _repository.AsSugarClient(); Dictionary? queryJson = new(); if (!string.IsNullOrEmpty(input.queryJson)) { queryJson = JsonConvert.DeserializeObject>(input.queryJson); } SqlSugarPagedList result = await db.Queryable() .LeftJoin((a, b) => a.create_id == b.Id) .LeftJoin((a, b, c) => a.modify_id == c.Id) .LeftJoin((a, b, c, d) => a.equip_id == d.id) .Where((a, b, c, d) => a.equip_id == input.equip_id) .WhereIF(queryJson != null && queryJson.ContainsKey("file_name"), (a, b, c, d) => a.file_name.Contains(queryJson!["file_name"])) .WhereIF(queryJson != null && queryJson.ContainsKey("file_type"), (a, b, c, d) => a.file_type==queryJson!["file_type"]) .Select((a, b, c, d) => new EquipFileQueryOutput { id = a.id, attachment = a.attachment, create_id = b.RealName, create_id_id = a.create_id, create_time = a.create_time == null ? null : a.create_time.Value.ToString("yyyy-MM-dd"), equip_id = d.name, equip_id_id = a.equip_id, file_ext = a.file_ext, file_type = a.file_type, file_name = a.file_name, }).ToPagedListAsync(input.currentPage, input.pageSize); return PageResult.SqlSugarPageResult(result); } } }