费用代码导入

usertest
cjy 3 months ago
parent 520503eb8f
commit 0834b3421c

@ -0,0 +1,37 @@
using DS.Module.Core;
using FluentValidation;
using SqlSugar;
namespace DS.WMS.Core.Code.Dtos;
/// <summary>
/// 费用代码导入请求实体
/// </summary>
public class FeeCodeExcelImportReq
{
/// <summary>
/// 费用代码 录入费用是作为检索
/// </summary>
public string Code { get; set; }
/// <summary>
/// 费用名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 费用英文名称
/// </summary>
public string EnName { get; set; }
/// <summary>
/// 默认币别
/// </summary>
public string DefaultCurrency { get; set; }
/// <summary>
/// 默认计费标准代码
/// </summary>
public string DefaultUnit { get; set; }
}

@ -63,7 +63,7 @@ public class CodePort: BaseModel<long>
/// <summary>
/// EDI代码
/// </summary>
[SugarColumn(ColumnDescription = "EDI代码", Length = 5,IsNullable = true)]
[SugarColumn(ColumnDescription = "EDI代码", Length = 10,IsNullable = true)]
public string EdiCode { get; set; }
/// <summary>

@ -4,6 +4,7 @@ using DS.Module.UserModule;
using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.Code.Interface;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.Op.Entity;
using Microsoft.AspNetCore.Http;

@ -23,7 +23,7 @@ public class FeeCode : BaseModel<long>
/// <summary>
/// 费用英文名称
/// </summary>
[SugarColumn(ColumnDescription = "费用英文名称", Length = 50)]
[SugarColumn(ColumnDescription = "费用英文名称", Length = 50, IsNullable = true)]
public string EnName { get; set; }
/// <summary>
/// 币别Id

@ -1,6 +1,7 @@
using DS.Module.Core;
using DS.WMS.Core.Fee.Dtos;
using DS.WMS.Core.Sys.Dtos;
using Microsoft.AspNetCore.Http;
namespace DS.WMS.Core.Fee.Interface;
@ -27,4 +28,12 @@ public interface IFeeCodeService
/// <param name="id"></param>
/// <returns></returns>
DataResult<FeeCodeRes> GetFeeCodeInfo(string id);
/// <summary>
/// 按Excel导入费用信息
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public Task<DataResult<string>> ImportFeeCodeByExcel(IFormFile file);
}

@ -9,6 +9,9 @@ using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using Mapster;
using DS.Module.Core.Extensions;
using DS.WMS.Core.Code.Dtos;
using Microsoft.AspNetCore.Http;
using MiniExcelLibs;
namespace DS.WMS.Core.Fee.Method
{
@ -94,5 +97,77 @@ namespace DS.WMS.Core.Fee.Method
.First();
return DataResult<FeeCodeRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
}
/// <summary>
/// 按Excel导入费用信息
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public async Task<DataResult<string>> ImportFeeCodeByExcel(IFormFile file)
{
//未上传文件
if (file == null || file.Length == 0)
{
return await Task.FromResult(DataResult<string>.Failed("请上传Excel!"));
}
var formFile = file;
//DataResult<string> api_Result = new Api_Result<string>();
//获取文件名
var fileName = formFile.FileName;
// 获取文件后缀
var fileExtension = Path.GetExtension(fileName);
// 判断后缀是否是xlsx或者xls
if (fileExtension != ".xlsx" && fileExtension != ".xls")
{
return DataResult<string>.Failed("文件格式错误");
}
var length = formFile.Length;
if (length > 1024 * 1024 * 10)
{
return DataResult<string>.Failed("文件大小不能超过10M");
}
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
// MemoryStream 内存流 在内存当中创建一个流(开辟空间)
using (var stream = new MemoryStream())
{
//将文件写入内存流
formFile.CopyTo(stream);
//将流的位置归零
stream.Position = 0;
//将内存流转成List集合
var list = await stream.QueryAsync<FeeCodeExcelImportReq>();
var fees = new List<FeeCode>();
foreach (var item in list)
{
var unit = string.Empty;
var unitName = string.Empty;
if (item.DefaultUnit == "TEU")
{
unit = "TEU";
unitName = "箱型";
}
else if (item.DefaultUnit == "BILL")
{
unit = "P";
unitName = "单票";
}
var fee = new FeeCode()
{
Name = item.Name,
EnName = item.EnName,
Code = item.Code,
DefaultCurrency = item.DefaultCurrency.IsNull() ? "CNY": item.DefaultCurrency,
IsSea = true,
DefaultUnit = unit,
DefaultUnitName = unitName,
};
fees.Add(fee);
}
await tenantDb.Insertable(fees).ExecuteCommandAsync();
return await Task.FromResult(DataResult<string>.Failed("导入成功!", MultiLanguageConst.DataImportSuccess));
}
}
}
}

@ -62,5 +62,18 @@ namespace DS.WMS.FeeApi.Controllers
var res = _invokeService.GetFeeCodeInfo(id);
return res;
}
/// <summary>
/// 按Excel导入费用代码信息
/// </summary>
/// <param name="file">Excel文件</param>
/// <returns></returns>
[HttpPost]
[Route("ImportFeeCodeByExcel")]
public async Task<DataResult<string>> ImportFeeCodeByExcel(IFormFile file)
{
var res = await _invokeService.ImportFeeCodeByExcel(file);
return res;
}
}
}

Loading…
Cancel
Save