多语言设置新增导入

This commit is contained in:
不做码农
2023-08-02 18:43:11 +08:00
parent 66a8d5793d
commit 78a743d6b7
5 changed files with 90 additions and 8 deletions

View File

@@ -1,8 +1,10 @@
using Infrastructure.Extensions;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.Dto;
using ZR.Model.Models;
using ZR.Service.System.IService;
namespace ZR.Admin.WebApi.Controllers
@@ -128,6 +130,25 @@ namespace ZR.Admin.WebApi.Controllers
return ToResponse(response);
}
/// <summary>
/// 删除多语言配置
/// </summary>
/// <returns></returns>
[HttpDelete("ByKey")]
[ActionPermissionFilter(Permission = "system:lang:delete")]
[Log(Title = "多语言配置", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteCommonLangByKey(string langkey)
{
if (langkey.IsEmpty()) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _CommonLangService
.Deleteable()
.EnableDiffLogEvent()
.Where(f => f.LangKey == langkey)
.ExecuteCommand();
return ToResponse(response);
}
/// <summary>
/// 导出多语言配置
/// </summary>
@@ -138,11 +159,49 @@ namespace ZR.Admin.WebApi.Controllers
public IActionResult Export([FromQuery] CommonLangQueryDto parm)
{
parm.PageSize = 10000;
var list = _CommonLangService.GetList(parm).Result;
var list = _CommonLangService.GetListToPivot(parm);
string sFileName = ExportExcel(list, "CommonLang", "多语言配置");
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
}
/// <summary>
/// 导入
/// </summary>
/// <param name="formFile"></param>
/// <returns></returns>
[HttpPost("importData")]
[Log(Title = "多语言设置导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)]
[ActionPermissionFilter(Permission = "system:lang:import")]
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
{
List<CommonLang> list = new();
using (var stream = formFile.OpenReadStream())
{
var rows = stream.Query(startCell: "A2").ToList();
foreach (var item in rows)
{
list.Add(new CommonLang() { LangCode = "zh-cn", LangKey = item.A, LangName = item.B, Addtime = DateTime.Now });
list.Add(new CommonLang() { LangCode = "en", LangKey = item.A, LangName = item.C, Addtime = DateTime.Now });
list.Add(new CommonLang() { LangCode = "zh-tw", LangKey = item.A, LangName = item.D, Addtime = DateTime.Now });
}
}
return SUCCESS(_CommonLangService.ImportCommonLang(list));
}
/// <summary>
/// 多语言设置导入模板下载
/// </summary>
/// <returns></returns>
[HttpGet("importTemplate")]
[Log(Title = "多语言设置模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
[AllowAnonymous]
public IActionResult ImportTemplateExcel()
{
var result = DownloadImportTemplate(new List<CommonLang>() { }, "lang");
return ExportExcel(result.Item2, result.Item1);
}
}
}