68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
using Dlhis.Common.Request;
|
|
using Dlhis.Common.Response;
|
|
using Dlhis.Entity.Common;
|
|
using Kurisu.SqlSugar.Services;
|
|
using Mapster;
|
|
|
|
namespace Dlhis.Common.Services.Implements;
|
|
|
|
public class ApkFIileService : IApkFIileService
|
|
{
|
|
private readonly IMinioService _minioService;
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public ApkFIileService(IMinioService minioService, IDbContext dbContext)
|
|
{
|
|
_minioService = minioService;
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 文件上传
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public async Task<ApkFileResponse> FormSingleFileUpload(ApkRequest request)
|
|
{
|
|
//上传
|
|
var fileUrl = await _minioService.MinloUploadFileAsync(request);
|
|
|
|
string fileName = request.formFile.FileName;
|
|
|
|
//更新数据库
|
|
var entity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
|
|
if (entity == null)
|
|
{
|
|
var info = new ApkFileEntity
|
|
{
|
|
Name = fileName,
|
|
Url = fileUrl,
|
|
VersionCode = request.VersionCode,
|
|
UpdateMessage = request.UpdateMessage,
|
|
};
|
|
await _dbContext.InsertAsync(info);
|
|
}
|
|
else
|
|
{
|
|
entity.Url = fileUrl;
|
|
entity.VersionCode = request.VersionCode;
|
|
entity.UpdateMessage = request.UpdateMessage;
|
|
await _dbContext.UpdateAsync(entity);
|
|
}
|
|
var newEntity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
|
|
var res = newEntity.Adapt<ApkFileResponse>();
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 文件下载
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<string> RequestDownloadFile(string fileName)
|
|
{
|
|
return await _minioService.MinloDownloadLinkAsync(fileName);
|
|
}
|
|
}
|
|
|
|
|