✨多语言设置新增导入
This commit is contained in:
parent
66a8d5793d
commit
78a743d6b7
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
ZR.Admin.WebApi/wwwroot/ImportTemplate/lang.xlsx
Normal file
BIN
ZR.Admin.WebApi/wwwroot/ImportTemplate/lang.xlsx
Normal file
Binary file not shown.
Binary file not shown.
@ -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
|
||||
/// <returns></returns>
|
||||
public PagedInfo<CommonLang> GetList(CommonLangQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<CommonLang>();
|
||||
|
||||
//搜索条件查询语法参考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
|
||||
/// <returns></returns>
|
||||
public dynamic GetListToPivot(CommonLangQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<CommonLang>();
|
||||
|
||||
//搜索条件查询语法参考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<CommonLang> GetLangList(CommonLangQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<CommonLang>();
|
||||
|
||||
//搜索条件查询语法参考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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入多语言设置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public (string, object, object) ImportCommonLang(List<CommonLang> 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
|
||||
}
|
||||
}
|
||||
@ -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<string, object> SetLang(List<CommonLang> msgList);
|
||||
|
||||
(string, object, object) ImportCommonLang(List<CommonLang> list);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user