diff --git a/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs b/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs new file mode 100644 index 0000000..04a89b0 --- /dev/null +++ b/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs @@ -0,0 +1,233 @@ +using Infrastructure; +using Infrastructure.Attribute; +using Infrastructure.Enums; +using Infrastructure.Model; +using Mapster; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using ZR.Admin.WebApi.Extensions; +using ZR.Admin.WebApi.Filters; +using ZR.Common; +using ZR.Model; +using ZR.Model.Dto; +using ZR.Model.Models; +using ZR.Service.System.ISystemService; + +namespace ZR.Admin.WebApi.Controllers +{ + /// + /// 多语言配置Controller + /// + /// @author zr + /// @date 2022-05-06 + /// + [Verify] + [Route("system/CommonLang")] + public class CommonLangController : BaseController + { + /// + /// 多语言配置接口 + /// + private readonly ICommonLangService _CommonLangService; + + public CommonLangController(ICommonLangService CommonLangService) + { + _CommonLangService = CommonLangService; + } + + /// + /// 查询多语言配置列表 + /// + /// + /// + [HttpGet("list")] + [ActionPermissionFilter(Permission = "system:lang:list")] + public IActionResult QueryCommonLang([FromQuery] CommonLangQueryDto parm) + { + if (parm.ShowMode == 2) + { + PagedInfo pagedInfo = new(); + pagedInfo.Result = _CommonLangService.GetListToPivot(parm); + + return SUCCESS(pagedInfo); + } + + return SUCCESS(_CommonLangService.GetList(parm)); + } + + /// + /// 查询多语言配置列表 + /// + /// + [HttpGet("list/{lang}")] + [AllowAnonymous] + public IActionResult QueryCommonLangs() + { + 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 + }); + } + + private static void SetLang(List msgList, Dictionary dic) + { + foreach (var item in msgList) + { + if (!dic.ContainsKey(item.LangKey)) + { + dic.Add(item.LangKey, item.LangName); + } + } + } + + /// + /// 查询多语言配置详情 + /// + /// + /// + [HttpGet("{Id}")] + [ActionPermissionFilter(Permission = "system:lang:query")] + public IActionResult GetCommonLang(long Id) + { + var response = _CommonLangService.GetFirst(x => x.Id == Id); + var modal = response.Adapt(); + if (modal != null) + { + var list = _CommonLangService.GetList(f => f.LangKey == modal.LangKey); + modal.LangName = list.Find(f => f.LangCode == "zh-cn")?.LangName; + modal.LangNameEn = list.Find(f => f.LangCode == "en")?.LangName; + modal.LangNameTw = list.Find(f => f.LangCode == "zh-tw")?.LangName; + } + return SUCCESS(modal); + } + + /// + /// 查询多语言配置详情 + /// + /// + /// + [HttpGet("key/{langKey}")] + [ActionPermissionFilter(Permission = "system:lang:query")] + public IActionResult GetCommonLangByKey(string langKey) + { + var response = _CommonLangService.GetList(x => x.LangKey == langKey); + + return SUCCESS(response); + } + /// + /// 添加多语言配置 + /// + /// + [HttpPost] + [ActionPermissionFilter(Permission = "system:lang:add")] + [Log(Title = "多语言配置", BusinessType = BusinessType.INSERT)] + public IActionResult AddCommonLang([FromBody] CommonLangDto parm) + { + if (parm == null) + { + throw new CustomException("请求参数错误"); + } + + //从 Dto 映射到 实体 + var modal = parm.Adapt().ToCreate(HttpContext); + var list = _CommonLangService.GetList(f => f.LangKey == modal.LangKey); + modal.Addtime = DateTime.Now; + modal.LangCode = "zh-cn"; + modal.LangName = parm.LangName; + if (!list.Any(f => f.LangCode == modal.LangCode)) + { + _CommonLangService.InsertReturnSnowflakeId(modal); + } + modal.LangCode = "zh-tw"; + modal.LangName = parm.LangNameTw; + if (!list.Any(f => f.LangCode == modal.LangCode)) + { + _CommonLangService.InsertReturnSnowflakeId(modal); + } + modal.LangCode = "en"; + modal.LangName = parm.LangNameEn; + if (!list.Any(f => f.LangCode == modal.LangCode)) + { + _CommonLangService.InsertReturnSnowflakeId(modal); + } + return ToResponse(1); + } + + /// + /// 更新多语言配置 + /// + /// + [HttpPut] + [ActionPermissionFilter(Permission = "system:lang:edit")] + [Log(Title = "多语言配置", BusinessType = BusinessType.UPDATE)] + public IActionResult UpdateCommonLang([FromBody] CommonLangDto parm) + { + if (parm == null) + { + throw new CustomException("请求实体不能为空"); + } + //从 Dto 映射到 实体 + var modal = parm.Adapt().ToUpdate(HttpContext); + var list = _CommonLangService.GetList(f => f.LangKey == modal.LangKey); + + List langs = new(); + langs.Add(new CommonLang() { Addtime = DateTime.Now, LangCode = "zh-cn", LangKey = modal.LangKey, LangName = parm.LangName }); + langs.Add(new CommonLang() { Addtime = DateTime.Now, LangCode = "zh-tw", LangKey = modal.LangKey, LangName = parm.LangNameTw }); + langs.Add(new CommonLang() { Addtime = DateTime.Now, LangCode = "en", LangKey = modal.LangKey, LangName = parm.LangNameEn }); + var storage = _CommonLangService.Storageable(langs).WhereColumns(it => new { it.LangKey, it.LangCode }).ToStorage(); + + long r = storage.AsInsertable.ExecuteReturnSnowflakeId();//执行插入 + storage.AsUpdateable.UpdateColumns(it => new { it.LangName }).ExecuteCommand();//执行修改 + + return ToResponse(r); + } + + /// + /// 删除多语言配置 + /// + /// + [HttpDelete("{ids}")] + [ActionPermissionFilter(Permission = "system:lang:delete")] + [Log(Title = "多语言配置", BusinessType = BusinessType.DELETE)] + public IActionResult DeleteCommonLang(string ids) + { + long[] idsArr = Tools.SpitLongArrary(ids); + if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } + + var response = _CommonLangService.Delete(idsArr); + + return ToResponse(response); + } + + /// + /// 导出多语言配置 + /// + /// + [Log(Title = "多语言配置", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)] + [HttpGet("export")] + [ActionPermissionFilter(Permission = "system:lang:export")] + public IActionResult Export([FromQuery] CommonLangQueryDto parm) + { + parm.PageSize = 10000; + var list = _CommonLangService.GetList(parm).Result; + + string sFileName = ExportExcel(list, "CommonLang", "多语言配置"); + return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName }); + } + + } +} \ No newline at end of file diff --git a/ZR.Admin.WebApi/appsettings.json b/ZR.Admin.WebApi/appsettings.json index bbead78..0421a75 100644 --- a/ZR.Admin.WebApi/appsettings.json +++ b/ZR.Admin.WebApi/appsettings.json @@ -12,13 +12,13 @@ }, "conn_zrAdmin_type": 1, //MySql = 0, SqlServer = 1 "conn_bus_type": 1, - "urls": "http://localhost:8888", //Ŀurl + "urls": "http://localhost:8888", //ĿurlĶ˿ǰ˶ӦdevServerҲҪ޸ "corsUrls": "http://localhost:8887", //ַǰĿǰ˷뵥Ҫã"," "JwtSettings": { "Issuer": "ZRAdmin.NET", "Audience": "ZRAdmin.NET", "SecretKey": "SecretKey-ZRADMIN.NET-20210101", - "Expire": 30 + "Expire": 30//jwt¼ʱ䣨֣ }, "DemoMode": false, //Ƿʾģʽ "DbKey": "", //ݿkey diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt index eb25c9d..acf31de 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt @@ -1,26 +1,22 @@ -using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Infrastructure; +using Infrastructure; using Infrastructure.Attribute; using Infrastructure.Enums; using Infrastructure.Model; using Mapster; +using Microsoft.AspNetCore.Mvc; using ${options.ModelsNamespace}.Dto; using ${options.ModelsNamespace}.Models; using ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service; using ${options.ApiControllerNamespace}.Extensions; using ${options.ApiControllerNamespace}.Filters; -using ZR.Common; -using Infrastructure.Extensions; -using System.Linq; +using ${options.BaseNamespace}.Common; namespace ${options.ApiControllerNamespace}.Controllers { /// /// ${genTable.functionName}Controller - /// + /// + /// @tableName ${genTable.TableName} /// @author ${replaceDto.Author} /// @date ${replaceDto.AddTime} /// @@ -97,14 +93,8 @@ $if(replaceDto.ShowBtnAdd) //从 Dto 映射到 实体 var modal = parm.Adapt<${replaceDto.ModelTypeName}>().ToCreate(HttpContext); - var response = _${replaceDto.ModelTypeName}Service.Insert(modal, it => new - { -$foreach(item in genTable.Columns) -$if((item.IsInsert)) - it.$item.CsharpField, -$end -${end} - }); + var response = _${replaceDto.ModelTypeName}Service.Add${replaceDto.ModelTypeName}(modal); + return ToResponse(response); } $end diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt index 310864d..a0c2451 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt @@ -19,5 +19,6 @@ namespace ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNam $if(genTable.TplCategory == "tree") List<${replaceDto.ModelTypeName}> GetTreeList(${replaceDto.ModelTypeName}QueryDto parm); $end + int Add${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm); } } diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt index 566d9b8..9c9236a 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt @@ -23,7 +23,7 @@ $if(replaceDto.ShowBtnExport) [EpplusTableColumn(Header = "$if(item.ColumnComment == "")${item.CsharpField}${else}${item.ColumnComment}${end}"$if(item.CsharpType == "DateTime"), NumberFormat = "yyyy-MM-dd HH:mm:ss"$end)] $end $if(item.IsPk || item.IsIncrement) - [SqlSugar.SugarColumn(IsPrimaryKey = ${item.IsPk.ToString().ToLower()}, IsIdentity = ${item.IsIncrement.ToString().ToLower()}$if(item.CsharpField.ToLower() != item.ColumnName.ToLower()), ColumnName = "$item.ColumnName"$end)] + [SugarColumn(IsPrimaryKey = ${item.IsPk.ToString().ToLower()}, IsIdentity = ${item.IsIncrement.ToString().ToLower()}$if(item.CsharpField.ToLower() != item.ColumnName.ToLower()), ColumnName = "$item.ColumnName"$end)] $elseif(item.CsharpField.ToLower() != item.ColumnName.ToLower()) [SugarColumn(ColumnName = "$item.ColumnName")] $end @@ -35,5 +35,15 @@ $if(genTable.TplCategory == "tree") [SugarColumn(IsIgnore = true)] public List<${replaceDto.ModelTypeName}> Children { get; set; } $end + +$if(genTable.TplCategory == "subNav" && genTable.SubTable != null) + [Navigate(NavigateType.Dynamic, null)] //自定义关系映射 + public ${genTable.SubTable.ClassName} Sub { get; set; } +$end + +$if(genTable.TplCategory == "subNavMore" && genTable.SubTable != null) + [Navigate(NavigateType.Dynamic, null)] //自定义关系映射 + public List<${genTable.SubTable.ClassName}> Sub { get; set; } +$end } } \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt index b3e2add..219b23b 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt @@ -1,13 +1,13 @@ -using Infrastructure; +using System; +using SqlSugar; +using System.Collections.Generic; +using Infrastructure; using Infrastructure.Attribute; using ${options.ModelsNamespace}; using ${options.ModelsNamespace}.Dto; using ${options.ModelsNamespace}.Models; using ${options.IRepositoriesNamespace}; using ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service; -using System; -using SqlSugar; -using System.Collections.Generic; namespace ${options.ServicesNamespace}.${options.SubNamespace} { @@ -20,10 +20,10 @@ namespace ${options.ServicesNamespace}.${options.SubNamespace} [AppService(ServiceType = typeof(I${replaceDto.ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)] public class ${replaceDto.ModelTypeName}Service : BaseService<${replaceDto.ModelTypeName}>, I${replaceDto.ModelTypeName}Service { - private readonly ${replaceDto.ModelTypeName}Repository _${replaceDto.ModelTypeName}repository; + private readonly ${replaceDto.ModelTypeName}Repository _${replaceDto.ModelTypeName}Repository; public ${replaceDto.ModelTypeName}Service(${replaceDto.ModelTypeName}Repository repository) { - _${replaceDto.ModelTypeName}repository = repository; + _${replaceDto.ModelTypeName}Repository = repository; } #region 业务逻辑代码 @@ -51,15 +51,17 @@ $elseif(column.CsharpType == "int" || column.CsharpType == "long") $end $end $end -$if(genTable.SortField != "" && genTable.SortField != null) - var response = _${replaceDto.ModelTypeName}repository - .GetPages(predicate.ToExpression(), parm, it => it.${genTable.SortField}, "${genTable.SortType}"); -$else - var response = _${replaceDto.ModelTypeName}repository + var response = _${replaceDto.ModelTypeName}Repository .Queryable() +$if(genTable.SubTableName != "" && genTable.SubTableName != null) + .Includes(it => it.Sub.MappingField(z => z.${genTable.SubTableFkName}, () => it.${replaceDto.PKName})) +$end +$if(genTable.SortField != "" && genTable.SortField != null) + .OrderBy("${genTable.SortField} ${genTable.SortType}") +$end .Where(predicate.ToExpression()) .ToPage(parm); -$end + return response; } @@ -85,12 +87,29 @@ $end $end $end - var response = _${replaceDto.ModelTypeName}repository.Queryable().Where(predicate.ToExpression()) + var response = _${replaceDto.ModelTypeName}Repository.Queryable().Where(predicate.ToExpression()) .ToTree(it => it.Children, it => it.${genTable.TreeParentCode}, 0); return response; } $end + /// + /// 添加${genTable.FunctionName} + /// + /// + /// + public int Add${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm) + { + var response = _${replaceDto.ModelTypeName}Repository.Insert(parm, it => new + { +${foreach(item in genTable.Columns)} +$if((item.IsInsert)) + it.$item.CsharpField, +$end +${end} + }); + return response; + } #endregion } } \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt index 28199bf..f744b87 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt @@ -1,10 +1,10 @@