diff --git a/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs b/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs
index 7e3680d..092546c 100644
--- a/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs
+++ b/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs
@@ -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);
}
+ ///
+ /// 删除多语言配置
+ ///
+ ///
+ [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);
+ }
+
///
/// 导出多语言配置
///
@@ -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 });
}
+ ///
+ /// 导入
+ ///
+ ///
+ ///
+ [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 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));
+ }
+
+ ///
+ /// 多语言设置导入模板下载
+ ///
+ ///
+ [HttpGet("importTemplate")]
+ [Log(Title = "多语言设置模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
+ [AllowAnonymous]
+ public IActionResult ImportTemplateExcel()
+ {
+ var result = DownloadImportTemplate(new List() { }, "lang");
+ return ExportExcel(result.Item2, result.Item1);
+ }
}
}
\ No newline at end of file
diff --git a/ZR.Admin.WebApi/wwwroot/ImportTemplate/lang.xlsx b/ZR.Admin.WebApi/wwwroot/ImportTemplate/lang.xlsx
new file mode 100644
index 0000000..66de938
Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/ImportTemplate/lang.xlsx differ
diff --git a/ZR.Admin.WebApi/wwwroot/data.xlsx b/ZR.Admin.WebApi/wwwroot/data.xlsx
index bb86189..a35adec 100644
Binary files a/ZR.Admin.WebApi/wwwroot/data.xlsx and b/ZR.Admin.WebApi/wwwroot/data.xlsx differ
diff --git a/ZR.Service/System/CommonLangService.cs b/ZR.Service/System/CommonLangService.cs
index 7e56122..21d8fec 100644
--- a/ZR.Service/System/CommonLangService.cs
+++ b/ZR.Service/System/CommonLangService.cs
@@ -1,7 +1,6 @@
using Infrastructure.Attribute;
using SqlSugar;
using System;
-using System.Collections.Generic;
using System.Linq;
using ZR.Model;
using ZR.Model.Dto;
@@ -29,10 +28,8 @@ namespace ZR.Service.System
///
public PagedInfo GetList(CommonLangQueryDto parm)
{
- //开始拼装查询条件
var predicate = Expressionable.Create();
- //搜索条件查询语法参考Sqlsugar
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.LangCode), it => it.LangCode == parm.LangCode);
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.LangKey), it => it.LangKey.Contains(parm.LangKey));
predicate = predicate.AndIF(parm.BeginAddtime != null, it => it.Addtime >= parm.BeginAddtime && it.Addtime <= parm.EndAddtime);
@@ -49,10 +46,8 @@ namespace ZR.Service.System
///
public dynamic GetListToPivot(CommonLangQueryDto parm)
{
- //开始拼装查询条件
var predicate = Expressionable.Create();
- //搜索条件查询语法参考Sqlsugar
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.LangCode), it => it.LangCode == parm.LangCode);
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.LangKey), it => it.LangKey.Contains(parm.LangKey));
predicate = predicate.AndIF(parm.BeginAddtime != null, it => it.Addtime >= parm.BeginAddtime && it.Addtime <= parm.EndAddtime);
@@ -64,10 +59,8 @@ namespace ZR.Service.System
public List GetLangList(CommonLangQueryDto parm)
{
- //开始拼装查询条件
var predicate = Expressionable.Create();
- //搜索条件查询语法参考Sqlsugar
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.LangCode), it => it.LangCode == parm.LangCode);
//predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.LangKey), it => it.LangKey.Contains(parm.LangKey));
var response = Queryable()
@@ -110,6 +103,33 @@ namespace ZR.Service.System
}
return dic;
}
+
+ ///
+ /// 导入多语言设置
+ ///
+ ///
+ public (string, object, object) ImportCommonLang(List list)
+ {
+ var x = Storageable(list)
+ .WhereColumns(it => new { it.LangKey, it.LangCode })
+ .ToStorage();
+ x.AsInsertable.ExecuteReturnSnowflakeIdList();//插入可插入部分;
+ x.AsUpdateable.UpdateColumns(it => new { it.LangName }).ExecuteCommand();
+
+ string msg = $"插入{x.InsertList.Count} 更新{x.UpdateList.Count} 错误数据{x.ErrorList.Count} 不计算数据{x.IgnoreList.Count} 删除数据{x.DeleteList.Count} 总共{x.TotalList.Count}";
+
+ //输出错误信息
+ foreach (var item in x.ErrorList)
+ {
+ Console.WriteLine("错误" + item.StorageMessage);
+ }
+ foreach (var item in x.IgnoreList)
+ {
+ Console.WriteLine("忽略" + item.StorageMessage);
+ }
+
+ return (msg, x.ErrorList, x.IgnoreList);
+ }
#endregion
}
}
\ No newline at end of file
diff --git a/ZR.Service/System/IService/ICommonLangService.cs b/ZR.Service/System/IService/ICommonLangService.cs
index b8a3f5f..5af554a 100644
--- a/ZR.Service/System/IService/ICommonLangService.cs
+++ b/ZR.Service/System/IService/ICommonLangService.cs
@@ -3,6 +3,7 @@ using ZR.Model;
using ZR.Model.Dto;
using ZR.Model.Models;
using System.Collections.Generic;
+using JinianNet.JNTemplate;
namespace ZR.Service.System.IService
{
@@ -19,5 +20,7 @@ namespace ZR.Service.System.IService
dynamic GetListToPivot(CommonLangQueryDto parm);
void StorageCommonLang(CommonLangDto parm);
Dictionary SetLang(List msgList);
+
+ (string, object, object) ImportCommonLang(List list);
}
}