|
|
|
@ -0,0 +1,135 @@
|
|
|
|
|
using GDZZ.Core;
|
|
|
|
|
using Furion.DependencyInjection;
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using GDZZ.Application.Entity;
|
|
|
|
|
using GDZZ.Application.Help;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace GDZZ.Application
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 附件管理服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings("Application",Name = "Annex", Order = 1)]
|
|
|
|
|
public class AnnexService : IAnnexService, IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<Annex> _rep;
|
|
|
|
|
private readonly UploadFileOptions _options;
|
|
|
|
|
public AnnexService(SqlSugarRepository<Annex> rep, IOptions<UploadFileOptions> options)
|
|
|
|
|
{
|
|
|
|
|
this._options = options.Value;
|
|
|
|
|
_rep = rep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询附件管理
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/Annex/page")]
|
|
|
|
|
public async Task<dynamic> Page([FromQuery] AnnexInput input)
|
|
|
|
|
{
|
|
|
|
|
var entities = await _rep.AsQueryable()
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.FileName), u => u.FileName == input.FileName)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.FileSize), u => u.FileSize == input.FileSize)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.FileUrl), u => u.FileUrl == input.FileUrl)
|
|
|
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
|
|
|
return entities.XnPagedResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 增加附件管理
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <param name="FileName"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/Mini/Annex/add")]
|
|
|
|
|
public async Task<Annex> Add(IFormFile file,string FileName)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var entity = await this._rep.AsQueryable().Where(x => x.CreatedUserId == UserManager.UserId).FirstAsync();
|
|
|
|
|
var fileInfo =await Utils.UploadFile(file, this._options.Default.path, FileLocation.LOCAL);
|
|
|
|
|
if (fileInfo == null)
|
|
|
|
|
throw new Exception("文件上传失败!");
|
|
|
|
|
entity.FileName = FileName;
|
|
|
|
|
entity.FileSize = file.Length.ToString();
|
|
|
|
|
entity.FileUrl = fileInfo.FileUrl;
|
|
|
|
|
//查询
|
|
|
|
|
|
|
|
|
|
if(entity != null )
|
|
|
|
|
{
|
|
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
}
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取附件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/Mini/Annex/GetAnnex")]
|
|
|
|
|
public async Task<dynamic> GetAnnex()
|
|
|
|
|
{
|
|
|
|
|
return await _rep.Where(x=>x.CreatedUserId == UserManager.UserId).FirstAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除附件管理
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/Annex/delete")]
|
|
|
|
|
public async Task Delete(DeleteAnnexInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
|
|
|
|
await _rep.DeleteAsync(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新附件管理
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/Annex/edit")]
|
|
|
|
|
public async Task Update(UpdateAnnexInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<Annex>();
|
|
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取附件管理
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/Annex/detail")]
|
|
|
|
|
public async Task<Annex> Get([FromQuery] QueryeAnnexInput input)
|
|
|
|
|
{
|
|
|
|
|
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取附件管理列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/Annex/list")]
|
|
|
|
|
public async Task<dynamic> List([FromQuery] AnnexInput input)
|
|
|
|
|
{
|
|
|
|
|
return await _rep.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|