feat 本地上传
This commit is contained in:
@@ -8,7 +8,6 @@ namespace Dlhis.Canteen.Order.Request
|
||||
/// <summary>
|
||||
/// 成本中心
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "成本中心号不能为空")]
|
||||
public string CostId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -8,7 +8,6 @@ namespace Dlhis.Canteen.Order.Request
|
||||
/// <summary>
|
||||
/// 成本中心
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "成本中心号不能为空")]
|
||||
public string CostId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,9 +3,12 @@ using Dlhis.Canteen.Order.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.Core.DataAccess.Entity;
|
||||
using Kurisu.Core.User.Abstractions;
|
||||
using Kurisu.SqlSugar.Attributes;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
@@ -81,6 +84,7 @@ public class BalanceService : IBalanceService
|
||||
.WhereIF(!request.UserCode.IsEmpty(), record => record.UserCode == request.UserCode)
|
||||
.WhereIF(!request.DepartmentNo.IsEmpty(), record => record.DepartmentNo == request.DepartmentNo)
|
||||
.WhereIF(!request.OriginTenantId.IsEmpty(), record => record.OriginTenantId == request.OriginTenantId)
|
||||
.WhereIF(!request.CostId.IsEmpty(), record => record.CostId == request.CostId)
|
||||
.WhereIF(request.StartDatetime.HasValue, record => record.CostDateTime >= request.StartDatetime)
|
||||
.WhereIF(request.EndDatetime.HasValue, record => record.CostDateTime <= request.EndDatetime)
|
||||
.Where(record => record.Type == BalanceRecordTypeEnumType.Out)
|
||||
@@ -519,27 +523,41 @@ public class BalanceService : IBalanceService
|
||||
throw new UserFriendlyException("操作失败,请重试");
|
||||
}
|
||||
|
||||
|
||||
private async Task<Dictionary<string, string>> GetShiftCode()
|
||||
[IgnoreTenant]
|
||||
public async Task<Dictionary<string, string>> GetShiftCode()
|
||||
{
|
||||
|
||||
var shiftCodeDict = new Dictionary<string, string>();
|
||||
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
|
||||
try
|
||||
{
|
||||
var shiftCodeDict = new Dictionary<string, string>();
|
||||
|
||||
var shifts = await _dbContext.Queryable<CanteenBusinessShiftEntity>().ToListAsync();
|
||||
//guid
|
||||
var breakfastCode = shifts.Where(x=>x.CustomCode == "shift-breakfast").Select(x => x.Code).First().ToString();
|
||||
var shifts = await _dbContext.Queryable<CanteenBusinessShiftEntity>().ToListAsync();
|
||||
//guid
|
||||
var breakfastCode = shifts.Where(x => x.CustomCode == "shift-breakfast").Select(x => x.Code).First().ToString();
|
||||
|
||||
var lunchCode = shifts.Where(x => x.CustomCode == "shift-lunch").Select(x => x.Code).First().ToString();
|
||||
var lunchCode = shifts.Where(x => x.CustomCode == "shift-lunch").Select(x => x.Code).First().ToString();
|
||||
|
||||
var dinnerCode = shifts.Where(x => x.CustomCode == "shift-dinner").Select(x => x.Code).First().ToString();
|
||||
var dinnerCode = shifts.Where(x => x.CustomCode == "shift-dinner").Select(x => x.Code).First().ToString();
|
||||
|
||||
var lateNightCode = shifts.Where(x => x.CustomCode == "shift-midnightsnack").Select(x => x.Code).First().ToString();
|
||||
var lateNightCode = shifts.Where(x => x.CustomCode == "shift-midnightsnack").Select(x => x.Code).First().ToString();
|
||||
|
||||
shiftCodeDict.Add("Breakfast", breakfastCode.ToString());
|
||||
shiftCodeDict.Add("Lunch", lunchCode.ToString());
|
||||
shiftCodeDict.Add("Dinner", dinnerCode.ToString());
|
||||
shiftCodeDict.Add("LateNight", lateNightCode.ToString());
|
||||
shiftCodeDict.Add("Breakfast", breakfastCode.ToString());
|
||||
shiftCodeDict.Add("Lunch", lunchCode.ToString());
|
||||
shiftCodeDict.Add("Dinner", dinnerCode.ToString());
|
||||
shiftCodeDict.Add("LateNight", lateNightCode.ToString());
|
||||
|
||||
return shiftCodeDict;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"生成{DeviceTaskEnumType.UploadRecord.GetDescription()}任务失败:" + ex.Message);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dbContext.Client.QueryFilter.Restore();
|
||||
}
|
||||
|
||||
return shiftCodeDict;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,18 +22,18 @@ public class ApkFIileController : ControllerBase
|
||||
_apkFIileService = apkFIileService;
|
||||
}
|
||||
/// <summary>
|
||||
/// 文件上传
|
||||
/// minlo文件上传
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[HttpPost("minlo")]
|
||||
public async Task<ApkFileResponse> FormSingleFileUpload([FromForm] ApkRequest request)
|
||||
{
|
||||
return await _apkFIileService.FormSingleFileUpload(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件下载
|
||||
/// minlo文件下载
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
@@ -44,6 +44,28 @@ public class ApkFIileController : ControllerBase
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 本地文件上传
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("local")]
|
||||
[RequestSizeLimit(100_000_000)]
|
||||
|
||||
public async Task<ApkFileResponse> FormLocalFileUpload([FromForm] ApkRequest request)
|
||||
{
|
||||
return await _apkFIileService.FormLocalFileUpload(request);
|
||||
}
|
||||
/// <summary>
|
||||
/// 本地文件下载
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("local")]
|
||||
public IActionResult FormLocalDownloadFile(string filePath)
|
||||
{
|
||||
return _apkFIileService.FormLocalDownloadFile(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Minio;
|
||||
|
||||
@@ -17,6 +18,10 @@ namespace Dlhis.Common.Packs
|
||||
.WithCredentials("Zbjj05OFtR19e5TJopQU", "UMXtNdZhufhAAyYJ3XND4cEgZNUsgOWtbUzksizK")
|
||||
.Build();
|
||||
services.AddSingleton(minioClient);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,11 @@ namespace Dlhis.Common.Response
|
||||
{
|
||||
public class ApkFileResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地址
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Dlhis.Common.Request;
|
||||
using Dlhis.Common.Response;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Common.Services;
|
||||
|
||||
@@ -17,6 +18,19 @@ namespace Dlhis.Common.Services;
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<string> RequestDownloadFile(string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// 本地上传
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<ApkFileResponse> FormLocalFileUpload(ApkRequest request);
|
||||
/// <summary>
|
||||
/// 本地下载
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <returns></returns>
|
||||
IActionResult FormLocalDownloadFile(string filePath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using Dlhis.Common.Response;
|
||||
using Dlhis.Entity.Common;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Common.Services.Implements;
|
||||
|
||||
@@ -62,6 +63,96 @@ public class ApkFIileService : IApkFIileService
|
||||
{
|
||||
return await _minioService.MinloDownloadLinkAsync(fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 本地文件上传
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ApkFileResponse> FormLocalFileUpload(ApkRequest request)
|
||||
{
|
||||
//上传
|
||||
var completeFilePath = FormSingleFileUpload(request.formFile);
|
||||
if (completeFilePath == "No file uploaded")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//更新数据库
|
||||
var 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 = completeFilePath,
|
||||
VersionCode = request.VersionCode,
|
||||
UpdateMessage = request.UpdateMessage,
|
||||
};
|
||||
await _dbContext.InsertAsync(info);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Url = completeFilePath;
|
||||
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;
|
||||
|
||||
}
|
||||
public string FormSingleFileUpload(IFormFile formFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filePath = "D:\\apk\\";
|
||||
|
||||
// 创建存储文件夹
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
|
||||
if (formFile != null && formFile.Length > 0)
|
||||
{
|
||||
// 保存的文件名称
|
||||
var saveName = Path.GetFileName(formFile.FileName);
|
||||
|
||||
// 文件保存
|
||||
using (var fs = File.Create(Path.Combine(filePath, saveName)))
|
||||
{
|
||||
formFile.CopyTo(fs);
|
||||
fs.Flush();
|
||||
}
|
||||
|
||||
// 完整的文件路径
|
||||
var completeFilePath = Path.Combine(filePath, saveName);
|
||||
return completeFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "No file uploaded";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return $"Error uploading file: {ex.Message}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 本地下载
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <returns></returns>
|
||||
public IActionResult FormLocalDownloadFile(string filePath)
|
||||
{
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
return new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user