From 254c49e6767982229ca638ce502e27e373a5224c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Sat, 11 Jun 2022 18:58:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../System/CommonLangController.cs | 50 ++++--------------- ZR.Service/System/CommonLangService.cs | 42 ++++++++++++++-- .../ICommonLangService.cs | 4 +- 3 files changed, 50 insertions(+), 46 deletions(-) rename ZR.Service/System/{ISystemService => IService}/ICommonLangService.cs (75%) diff --git a/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs b/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs index a777d5f..6b03095 100644 --- a/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs +++ b/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs @@ -6,14 +6,13 @@ using Infrastructure.Model; using Mapster; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using System; using System.Collections.Generic; using ZR.Admin.WebApi.Filters; using ZR.Common; using ZR.Model; using ZR.Model.Dto; using ZR.Model.Models; -using ZR.Service.System.ISystemService; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers { @@ -45,8 +44,10 @@ namespace ZR.Admin.WebApi.Controllers { if (parm.ShowMode == 2) { - PagedInfo pagedInfo = new(); - pagedInfo.Result = _CommonLangService.GetListToPivot(parm); + PagedInfo pagedInfo = new() + { + Result = _CommonLangService.GetListToPivot(parm) + }; return SUCCESS(pagedInfo); } @@ -60,34 +61,11 @@ namespace ZR.Admin.WebApi.Controllers /// [HttpGet("list/{lang}")] [AllowAnonymous] - public IActionResult QueryCommonLangs() + public IActionResult QueryCommonLangs(string lang) { - var msgList = _CommonLangService.GetLangList(new CommonLangQueryDto() { LangCode = "zh-cn" }); - var msgListEn = _CommonLangService.GetLangList(new CommonLangQueryDto() { LangCode = "en" }); - var msgListTw = _CommonLangService.GetLangList(new CommonLangQueryDto() { LangCode = "zh-tw" }); - Dictionary dic = new(); - Dictionary dicEn = new(); - Dictionary dicTw = new(); - SetLang(msgList, dic); - SetLang(msgListEn, dicEn); - SetLang(msgListTw, dicTw); - return SUCCESS(new - { - en = dicEn, - cn = dic, - tw = dicTw - }); - } + var msgList = _CommonLangService.GetLangList(new CommonLangQueryDto() { LangCode = lang }); - private static void SetLang(List msgList, Dictionary dic) - { - foreach (var item in msgList) - { - if (!dic.ContainsKey(item.LangKey)) - { - dic.Add(item.LangKey, item.LangName); - } - } + return SUCCESS(_CommonLangService.SetLang(msgList)); } /// @@ -137,17 +115,9 @@ namespace ZR.Admin.WebApi.Controllers throw new CustomException("请求实体不能为空"); } - List langs = new(); - foreach (var item in parm.LangList) - { - langs.Add(new CommonLang() { Addtime = DateTime.Now, LangKey = parm.LangKey, LangCode = item.LangCode, LangName = item.LangName }); - } - var storage = _CommonLangService.Storageable(langs).WhereColumns(it => new { it.LangKey, it.LangCode }).ToStorage(); + _CommonLangService.StorageCommonLang(parm); - long r = storage.AsInsertable.ExecuteReturnSnowflakeId();//执行插入 - storage.AsUpdateable.UpdateColumns(it => new { it.LangName }).ExecuteCommand();//执行修改 - - return ToResponse(r); + return ToResponse(1); } /// diff --git a/ZR.Service/System/CommonLangService.cs b/ZR.Service/System/CommonLangService.cs index 818442d..4abe031 100644 --- a/ZR.Service/System/CommonLangService.cs +++ b/ZR.Service/System/CommonLangService.cs @@ -1,12 +1,13 @@ using Infrastructure.Attribute; using SqlSugar; +using System; using System.Collections.Generic; using System.Linq; using ZR.Model; using ZR.Model.Dto; using ZR.Model.Models; using ZR.Repository; -using ZR.Service.System.ISystemService; +using ZR.Service.System.IService; namespace ZR.Service.System { @@ -40,7 +41,6 @@ namespace ZR.Service.System //搜索条件查询语法参考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 >= DateTime.Now.AddDays(-1)); predicate = predicate.AndIF(parm.BeginAddtime != null, it => it.Addtime >= parm.BeginAddtime && it.Addtime <= parm.EndAddtime); var response = _CommonLangrepository .Queryable() @@ -62,7 +62,6 @@ namespace ZR.Service.System //搜索条件查询语法参考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 >= DateTime.Now.AddDays(-1)); predicate = predicate.AndIF(parm.BeginAddtime != null, it => it.Addtime >= parm.BeginAddtime && it.Addtime <= parm.EndAddtime); var response = _CommonLangrepository .Queryable() @@ -79,14 +78,47 @@ namespace ZR.Service.System //搜索条件查询语法参考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 >= DateTime.Now.AddDays(-1)); - //predicate = predicate.AndIF(parm.BeginAddtime != null, it => it.Addtime >= parm.BeginAddtime && it.Addtime <= parm.EndAddtime); var response = _CommonLangrepository .Queryable() .Where(predicate.ToExpression()) .ToList(); return response; } + + public void StorageCommonLang(CommonLangDto parm) + { + List langs = new(); + foreach (var item in parm.LangList) + { + langs.Add(new CommonLang() + { + Addtime = DateTime.Now, + LangKey = parm.LangKey, + LangCode = item.LangCode, + LangName = item.LangName, + }); + } + var storage = _CommonLangrepository.Storageable(langs) + .WhereColumns(it => new { it.LangKey, it.LangCode }) + .ToStorage(); + + storage.AsInsertable.ExecuteReturnSnowflakeIdList();//执行插入 + storage.AsUpdateable.UpdateColumns(it => new { it.LangName }).ExecuteCommand();//执行修改 + } + + public Dictionary SetLang(List msgList) + { + Dictionary dic = new(); + + foreach (var item in msgList) + { + if (!dic.ContainsKey(item.LangKey)) + { + dic.Add(item.LangKey, item.LangName); + } + } + return dic; + } #endregion } } \ No newline at end of file diff --git a/ZR.Service/System/ISystemService/ICommonLangService.cs b/ZR.Service/System/IService/ICommonLangService.cs similarity index 75% rename from ZR.Service/System/ISystemService/ICommonLangService.cs rename to ZR.Service/System/IService/ICommonLangService.cs index 67c6351..b8a3f5f 100644 --- a/ZR.Service/System/ISystemService/ICommonLangService.cs +++ b/ZR.Service/System/IService/ICommonLangService.cs @@ -4,7 +4,7 @@ using ZR.Model.Dto; using ZR.Model.Models; using System.Collections.Generic; -namespace ZR.Service.System.ISystemService +namespace ZR.Service.System.IService { /// /// 多语言配置service接口 @@ -17,5 +17,7 @@ namespace ZR.Service.System.ISystemService PagedInfo GetList(CommonLangQueryDto parm); List GetLangList(CommonLangQueryDto parm); dynamic GetListToPivot(CommonLangQueryDto parm); + void StorageCommonLang(CommonLangDto parm); + Dictionary SetLang(List msgList); } }