diff --git a/Infrastructure/Helper/FileUtil.cs b/Infrastructure/Helper/FileUtil.cs index 9d3b3aa..1a3c000 100644 --- a/Infrastructure/Helper/FileUtil.cs +++ b/Infrastructure/Helper/FileUtil.cs @@ -21,11 +21,11 @@ namespace Infrastructure int day = date.Day; int hour = date.Hour; - string timeDir = $"{year}/{month}/{day}/{hour}";// date.ToString("yyyyMM/dd/HH/"); + string timeDir = $"{year}{month}{day}";// date.ToString("yyyyMM/dd/HH/"); if (!string.IsNullOrEmpty(path)) { - timeDir = $"{path}/{timeDir}"; + timeDir = $"{path}/{timeDir}/"; } return timeDir; } diff --git a/Infrastructure/Model/SendEmailDto.cs b/Infrastructure/Model/SendEmailDto.cs new file mode 100644 index 0000000..749bbb8 --- /dev/null +++ b/Infrastructure/Model/SendEmailDto.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Infrastructure.Model +{ + public class SendEmailDto + { + public string FileUrl { get; set; } = ""; + public string Subject { get; set; } + public string ToUser { get; set; } + public string Content { get; set; } = ""; + public string HtmlContent { get; set; } + public DateTime AddTime { get; set; } + } +} diff --git a/Infrastructure/OptionsSetting.cs b/Infrastructure/OptionsSetting.cs index 6a876d1..84ef25d 100644 --- a/Infrastructure/OptionsSetting.cs +++ b/Infrastructure/OptionsSetting.cs @@ -27,7 +27,7 @@ namespace Infrastructure { public string From { get; set; } public string Password { get; set; } - public string Host { get; set; } + public string Smtp { get; set; } public int Port { get; set; } } /// diff --git a/README.md b/README.md index 77e1de2..d1368f2 100644 --- a/README.md +++ b/README.md @@ -74,10 +74,10 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e ``` ## ⚡ 近期计划 -- [ ] 参数管理 +- [X] 参数管理 - [ ] 在线用户 - [ ] 文件管理 -- [ ] 邮件发送 +- [X] 邮件发送 - [ ] 集成微信开发 ## 📖 帮助文档 diff --git a/ZR.Admin.WebApi/Controllers/BaseController.cs b/ZR.Admin.WebApi/Controllers/BaseController.cs index 119d7c4..5a318df 100644 --- a/ZR.Admin.WebApi/Controllers/BaseController.cs +++ b/ZR.Admin.WebApi/Controllers/BaseController.cs @@ -22,7 +22,7 @@ namespace ZR.Admin.WebApi.Controllers return Content(jsonStr, "application/json"); } - protected IActionResult ToRespose(ResultCode resultCode, object data = null) + protected IActionResult ToResponse(ResultCode resultCode, object data = null) { string jsonStr = GetJsonStr(GetApiResult(resultCode, data), ""); return Content(jsonStr, "application/json"); @@ -34,13 +34,13 @@ namespace ZR.Admin.WebApi.Controllers /// /// /// - protected IActionResult OutputJson(ApiResult apiResult, string timeFormatStr = "yyyy-MM-dd HH:mm:ss") + protected IActionResult ToResponse(ApiResult apiResult, string timeFormatStr = "yyyy-MM-dd HH:mm:ss") { string jsonStr = GetJsonStr(apiResult, timeFormatStr); return Content(jsonStr, "application/json"); } - protected IActionResult OutputJson(long rows, string timeFormatStr = "yyyy-MM-dd HH:mm:ss") + protected IActionResult ToResponse(long rows, string timeFormatStr = "yyyy-MM-dd HH:mm:ss") { string jsonStr = GetJsonStr(ToJson(rows), timeFormatStr); @@ -97,7 +97,7 @@ namespace ZR.Admin.WebApi.Controllers protected IActionResult CustomError(ResultCode resultCode, string msg = "") { - return OutputJson(GetApiResult(resultCode, msg)); + return ToResponse(GetApiResult(resultCode, msg)); } } } diff --git a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs index d6a4f55..4df2f83 100644 --- a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs @@ -5,6 +5,7 @@ using Mapster; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Hosting; +using Newtonsoft.Json; using SqlSugar; using System; using System.Collections.Generic; @@ -89,7 +90,8 @@ namespace ZR.Admin.WebApi.Controllers var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId); genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId); - + Dictionary options = JsonConvert.DeserializeObject>(genTableInfo.Options); + dto.ParentMenuId = (long)options.GetValueOrDefault("parentMenuId", 0); dto.GenTable = genTableInfo; //生成代码 CodeGeneratorTool.Generate(genTableInfo, dto); @@ -196,7 +198,7 @@ namespace ZR.Admin.WebApi.Controllers } } - return ToRespose(ResultCode.FAIL); + return ToResponse(ResultCode.FAIL); } /// @@ -211,6 +213,7 @@ namespace ZR.Admin.WebApi.Controllers if (genTableDto == null) throw new CustomException("请求参数错误"); var genTable = genTableDto.Adapt().ToUpdate(HttpContext); + genTable.Options = JsonConvert.SerializeObject(new { parentMenuId = genTableDto.ParentMenuId }); int rows = GenTableService.UpdateGenTable(genTable); if (rows > 0) { diff --git a/ZR.Admin.WebApi/Controllers/HomeController.cs b/ZR.Admin.WebApi/Controllers/HomeController.cs index 96bb587..c670ea5 100644 --- a/ZR.Admin.WebApi/Controllers/HomeController.cs +++ b/ZR.Admin.WebApi/Controllers/HomeController.cs @@ -1,12 +1,25 @@ using Infrastructure; using Infrastructure.Attribute; +using Infrastructure.Model; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; +using Newtonsoft.Json; using System; +using ZR.Admin.WebApi.Filters; +using ZR.Common; namespace ZR.Admin.WebApi.Controllers { public class HomeController : BaseController { + private OptionsSetting OptionsSetting; + private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); + + public HomeController(IOptions options) + { + OptionsSetting = options.Value; + } + /// /// 心跳 /// @@ -31,7 +44,7 @@ namespace ZR.Admin.WebApi.Controllers } string key = ConfigUtils.Instance.GetConfig("DbKey"); string encryptTxt = NETCore.Encrypt.EncryptProvider.DESEncrypt(content, key); - return Ok(new { content, encryptTxt }); + return Ok(new { content, encryptTxt }); } /// @@ -49,5 +62,30 @@ namespace ZR.Admin.WebApi.Controllers string encryptTxt = NETCore.Encrypt.EncryptProvider.DESDecrypt(content, key); return Ok(new { content, encryptTxt }); } + + /// + /// 发送邮件 + /// + /// 请求参数接收实体 + /// + [ActionPermissionFilter(Permission = "tool:email:send")] + public IActionResult SendEmail([FromBody] SendEmailDto sendEmailVo) + { + if (sendEmailVo == null || string.IsNullOrEmpty(sendEmailVo.Subject) || string.IsNullOrEmpty(sendEmailVo.ToUser)) + { + return ToResponse(ApiResult.Error($"请求参数不完整")); + } + if (string.IsNullOrEmpty(OptionsSetting.MailOptions.From) || string.IsNullOrEmpty(OptionsSetting.MailOptions.Password)) + { + return ToResponse(ApiResult.Error($"请配置邮箱信息")); + } + MailHelper mailHelper = new MailHelper(OptionsSetting.MailOptions.From, OptionsSetting.MailOptions.Smtp, OptionsSetting.MailOptions.Port, OptionsSetting.MailOptions.Password); + + mailHelper.SendMail(sendEmailVo.ToUser, sendEmailVo.Subject, sendEmailVo.Content, sendEmailVo.FileUrl, sendEmailVo.HtmlContent); + + logger.Info($"发送邮件{JsonConvert.SerializeObject(sendEmailVo)}"); + + return SUCCESS(true); + } } } diff --git a/ZR.Admin.WebApi/Controllers/System/ArticleController.cs b/ZR.Admin.WebApi/Controllers/System/ArticleController.cs index e175c26..0466f31 100644 --- a/ZR.Admin.WebApi/Controllers/System/ArticleController.cs +++ b/ZR.Admin.WebApi/Controllers/System/ArticleController.cs @@ -147,7 +147,7 @@ namespace ZR.Admin.WebApi.Controllers { if (id <= 0) { - return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); + return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } // 删除文章 diff --git a/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs b/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs index a29eccd..55425f6 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs @@ -1,23 +1,169 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; +using SqlSugar; +using Infrastructure; +using Infrastructure.Attribute; +using Infrastructure.Enums; +using Infrastructure.Model; +using Mapster; +using ZR.Model.Dto; +using ZR.Model.Models; +using ZR.Service.Business; +using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; +using ZR.Common; +using ZR.Service.System; +using ZR.Model.System; +using Infrastructure.Extensions; -namespace ZR.Admin.WebApi.Controllers.System +namespace ZR.Admin.WebApi.Controllers { /// - /// 配置文件 + /// 参数配置Controller + /// + /// @author zhaorui + /// @date 2021-09-29 /// [Verify] [Route("system/config")] public class SysConfigController : BaseController { - [HttpGet("list")] - public IActionResult Index() + /// + /// 参数配置接口 + /// + private readonly ISysConfigService _SysConfigService; + + public SysConfigController(ISysConfigService SysConfigService) { - return SUCCESS(1); + _SysConfigService = SysConfigService; + } + + /// + /// 查询参数配置列表 + /// + /// + [HttpGet("list")] + [ActionPermissionFilter(Permission = "system:config:list")] + public IActionResult QuerySysConfig([FromQuery] SysConfigQueryDto parm) + { + //开始拼装查询条件 + var predicate = Expressionable.Create(); + + //TODO 搜索条件 + predicate = predicate.AndIF(!parm.ConfigType.IsEmpty(),m => m.ConfigType == parm.ConfigType); + predicate = predicate.AndIF(!parm.ConfigName.IsEmpty(),m => m.ConfigName.Contains(parm.ConfigType)); + predicate = predicate.AndIF(!parm.ConfigKey.IsEmpty(),m => m.ConfigKey.Contains(parm.ConfigKey)); + predicate = predicate.AndIF(!parm.BeginTime.IsEmpty(),m => m.Create_time >= parm.BeginTime ); + predicate = predicate.AndIF(!parm.BeginTime.IsEmpty(),m => m.Create_time <= parm.EndTime); + + var response = _SysConfigService.GetPages(predicate.ToExpression(), parm); + + return SUCCESS(response); + } + + /// + /// 查询参数配置详情 + /// + /// + /// + [HttpGet("{ConfigId}")] + [ActionPermissionFilter(Permission = "system:config:query")] + public IActionResult GetSysConfig(int ConfigId) + { + var response = _SysConfigService.GetId(ConfigId); + + return SUCCESS(response); + } + + /// + /// 根据参数键名查询参数值 + /// + /// + /// + [HttpGet("configKey/{configKey}")] + public IActionResult GetConfigKey(string configKey) + { + //TODO 增加缓存 + var response = _SysConfigService.Queryable().First(f=> f.ConfigKey == configKey); + + return SUCCESS(response?.ConfigValue); + } + + /// + /// 添加参数配置 + /// + /// + [HttpPost] + [ActionPermissionFilter(Permission = "system:config:add")] + [Log(Title = "参数配置添加", BusinessType = BusinessType.INSERT)] + public IActionResult AddSysConfig([FromBody] SysConfigDto parm) + { + if (parm == null) + { + throw new CustomException("请求参数错误"); + } + //从 Dto 映射到 实体 + var model = parm.Adapt().ToCreate(); + + return SUCCESS(_SysConfigService.Add(model, it => new + { + it.ConfigName, + it.ConfigKey, + it.ConfigValue, + it.ConfigType, + it.Create_by, + it.Create_time, + it.Remark, + })); + } + + /// + /// 更新参数配置 + /// + /// + [HttpPut] + [ActionPermissionFilter(Permission = "system:config:update")] + [Log(Title = "参数配置修改", BusinessType = BusinessType.UPDATE)] + public IActionResult UpdateSysConfig([FromBody] SysConfigDto parm) + { + if (parm == null) + { + throw new CustomException("请求实体不能为空"); + } + //从 Dto 映射到 实体 + var model = parm.Adapt().ToUpdate(HttpContext); + + var response = _SysConfigService.Update(w => w.ConfigId == model.ConfigId, it => new SysConfig() + { + //Update 字段映射 + ConfigName = model.ConfigName, + ConfigKey = model.ConfigKey, + ConfigValue = model.ConfigValue, + ConfigType = model.ConfigType, + Update_by = model.Update_by, + Update_time = model.Update_time, + }); + + return SUCCESS(response); + } + + /// + /// 删除参数配置 + /// + /// + [HttpDelete("{ids}")] + [ActionPermissionFilter(Permission = "system:config:remove")] + [Log(Title = "参数配置删除", BusinessType = BusinessType.DELETE)] + public IActionResult DeleteSysConfig(string ids) + { + int[] idsArr = Tools.SpitIntArrary(ids); + if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } + + var response = _SysConfigService.Delete(idsArr); + + return SUCCESS(response); } } -} +} \ No newline at end of file diff --git a/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs b/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs index dc99ec2..29f1fc8 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs @@ -97,10 +97,10 @@ namespace ZR.Admin.WebApi.Controllers.System { if (UserConstants.NOT_UNIQUE.Equals(DeptService.CheckDeptNameUnique(dept))) { - return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"新增部门{dept.DeptName}失败,部门名称已存在")); + return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"新增部门{dept.DeptName}失败,部门名称已存在")); } dept.Create_by = User.Identity.Name; - return OutputJson(ToJson(DeptService.InsertDept(dept))); + return ToResponse(ToJson(DeptService.InsertDept(dept))); } /// @@ -115,14 +115,14 @@ namespace ZR.Admin.WebApi.Controllers.System { if (UserConstants.NOT_UNIQUE.Equals(DeptService.CheckDeptNameUnique(dept))) { - return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,部门名称已存在")); + return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,部门名称已存在")); } else if (dept.ParentId.Equals(dept.DeptId)) { - return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,上级部门不能是自己")); + return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,上级部门不能是自己")); } dept.Update_by = User.Identity.Name; - return OutputJson(ToJson(DeptService.UpdateDept(dept))); + return ToResponse(ToJson(DeptService.UpdateDept(dept))); } /// @@ -134,13 +134,13 @@ namespace ZR.Admin.WebApi.Controllers.System [Log(Title = "部门管理", BusinessType = BusinessType.DELETE)] public IActionResult Remove(long deptId) { - if (DeptService.GetCount(it => it.ParentId == deptId && it.DelFlag == "0") > 0) + if (DeptService.Queryable().Count(it => it.ParentId == deptId && it.DelFlag == "0") > 0) { - return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"存在下级部门,不允许删除")); + return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"存在下级部门,不允许删除")); } - if (UserService.GetCount(it => it.DeptId == deptId && it.DelFlag == "0") > 0) + if (DeptService.Queryable().Count(it => it.DeptId == deptId && it.DelFlag == "0") > 0) { - return OutputJson(GetApiResult(ResultCode.CUSTOM_ERROR, $"部门存在用户,不允许删除")); + return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"部门存在用户,不允许删除")); } return SUCCESS(DeptService.Delete(deptId)); diff --git a/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs b/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs index d61222c..cee2abf 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs @@ -51,7 +51,7 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:dict:query")] public IActionResult GetInfo(long dictId = 0) { - return SUCCESS(SysDictService.GetFirst(f => f.DictId == dictId)); + return SUCCESS(SysDictService.GetInfo(dictId)); } /// @@ -66,7 +66,7 @@ namespace ZR.Admin.WebApi.Controllers.System { if (UserConstants.NOT_UNIQUE.Equals(SysDictService.CheckDictTypeUnique(dict))) { - return OutputJson(ApiResult.Error($"新增字典'{dict.DictName}'失败,字典类型已存在")); + return ToResponse(ApiResult.Error($"新增字典'{dict.DictName}'失败,字典类型已存在")); } //设置添加人 dict.Create_by = HttpContext.User.Identity.Name; @@ -87,7 +87,7 @@ namespace ZR.Admin.WebApi.Controllers.System { if (UserConstants.NOT_UNIQUE.Equals(SysDictService.CheckDictTypeUnique(dict))) { - return OutputJson(ApiResult.Error($"修改字典'{dict.DictName}'失败,字典类型已存在")); + return ToResponse(ApiResult.Error($"修改字典'{dict.DictName}'失败,字典类型已存在")); } //设置添加人 dict.Update_by = HttpContext.User.Identity.Name; diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index 08afac8..93af7f7 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -125,7 +125,7 @@ namespace ZR.Admin.WebApi.Controllers.System long uid = HttpContext.GetUId(); var menus = sysMenuService.SelectMenuTreeByUserId(uid); - return OutputJson(ToJson(1, sysMenuService.BuildMenus(menus))); + return ToResponse(ToJson(1, sysMenuService.BuildMenus(menus))); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs index aa05eaf..a6a4c29 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs @@ -94,23 +94,23 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:menu:edit")] public IActionResult MenuEdit([FromBody] SysMenu MenuDto) { - if (MenuDto == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (MenuDto == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } //if (UserConstants.NOT_UNIQUE.Equals(sysMenuService.CheckMenuNameUnique(MenuDto))) //{ - // return OutputJson(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,菜单名称已存在")); + // return ToResponse(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,菜单名称已存在")); //} if (UserConstants.YES_FRAME.Equals(MenuDto.isFrame) && !MenuDto.path.StartsWith("http")) { - return OutputJson(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,地址必须以http(s)://开头")); + return ToResponse(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,地址必须以http(s)://开头")); } if (MenuDto.menuId.Equals(MenuDto.parentId)) { - return OutputJson(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,上级菜单不能选择自己")); + return ToResponse(ApiResult.Error($"修改菜单'{MenuDto.menuName}'失败,上级菜单不能选择自己")); } MenuDto.Update_by = User.Identity.Name; int result = sysMenuService.EditMenu(MenuDto); - return OutputJson(result); + return ToResponse(result); } /// @@ -123,20 +123,20 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:menu:add")] public IActionResult MenuAdd([FromBody] SysMenu MenuDto) { - if (MenuDto == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (MenuDto == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } if (UserConstants.NOT_UNIQUE.Equals(sysMenuService.CheckMenuNameUnique(MenuDto))) { - return OutputJson(ApiResult.Error($"新增菜单'{MenuDto.menuName}'失败,菜单名称已存在")); + return ToResponse(ApiResult.Error($"新增菜单'{MenuDto.menuName}'失败,菜单名称已存在")); } if (UserConstants.YES_FRAME.Equals(MenuDto.isFrame) && !MenuDto.path.StartsWith("http")) { - return OutputJson(ApiResult.Error($"新增菜单'{MenuDto.menuName}'失败,地址必须以http(s)://开头")); + return ToResponse(ApiResult.Error($"新增菜单'{MenuDto.menuName}'失败,地址必须以http(s)://开头")); } MenuDto.Create_by = User.Identity.Name; int result = sysMenuService.AddMenu(MenuDto); - return OutputJson(result); + return ToResponse(result); } /// @@ -159,7 +159,7 @@ namespace ZR.Admin.WebApi.Controllers.System } int result = sysMenuService.DeleteMenuById(menuId); - return OutputJson(result); + return ToResponse(result); } /// @@ -172,10 +172,10 @@ namespace ZR.Admin.WebApi.Controllers.System [Log(Title = "保存排序", BusinessType = BusinessType.UPDATE)] public IActionResult ChangeSort([FromBody] MenuDto MenuDto) { - if (MenuDto == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (MenuDto == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } int result = sysMenuService.ChangeSortMenu(MenuDto); - return OutputJson(result); + return ToResponse(result); } } } diff --git a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs index ef3da92..b573aef 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs @@ -36,7 +36,7 @@ namespace ZR.Admin.WebApi.Controllers.System //开始拼装查询条件 var predicate = Expressionable.Create(); predicate = predicate.AndIF(post.Status.IfNotEmpty(), it => it.Status == post.Status); - var list = PostService.GetPages(predicate.ToExpression(), pagerInfo); + var list = PostService.GetPages(predicate.ToExpression(), pagerInfo, s => new { s.PostSort }); return SUCCESS(list); } @@ -71,8 +71,9 @@ namespace ZR.Admin.WebApi.Controllers.System { throw new CustomException($"修改岗位{post.PostName}失败,岗位编码已存在"); } - post.Update_by = User.Identity.Name; - return OutputJson(ToJson(PostService.Add(post))); + + post.Create_by = User.Identity.Name; + return ToResponse(ToJson(PostService.Add(post))); } /// @@ -94,7 +95,7 @@ namespace ZR.Admin.WebApi.Controllers.System throw new CustomException($"修改岗位{post.PostName}失败,岗位编码已存在"); } post.Update_by = User.Identity.Name; - return OutputJson(ToJson(PostService.Update(post))); + return ToResponse(ToJson(PostService.Update(post) ? 1 : 0)); } /// @@ -107,7 +108,7 @@ namespace ZR.Admin.WebApi.Controllers.System [Log(Title = "岗位删除", BusinessType = BusinessType.DELETE)] public IActionResult Delete(int id = 0) { - return OutputJson(ToJson(PostService.Delete(id))); + return ToResponse(ToJson(PostService.Delete(id))); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs index 29890f1..c846d5a 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs @@ -79,12 +79,10 @@ namespace ZR.Admin.WebApi.Controllers.System throw new CustomException(ResultCode.PARAM_ERROR, "请求参数错误"); } //从 Dto 映射到 实体 - var user = userDto.Adapt(); - user.Update_by = User.Identity.Name; - user.Update_time = DateTime.Now; + var user = userDto.Adapt().ToUpdate(HttpContext); int result = UserService.ChangeUser(user); - return OutputJson(result); + return ToResponse(result); } /// @@ -103,11 +101,11 @@ namespace ZR.Admin.WebApi.Controllers.System string newMd5 = NETCore.Encrypt.EncryptProvider.Md5(newPassword); if (user.Password != oldMd5) { - return OutputJson(ApiResult.Error("修改密码失败,旧密码错误")); + return ToResponse(ApiResult.Error("修改密码失败,旧密码错误")); } if (user.Password == newMd5) { - return OutputJson(ApiResult.Error("新密码不能和旧密码相同")); + return ToResponse(ApiResult.Error("新密码不能和旧密码相同")); } if (UserService.ResetPwd(loginUser.UserId, newMd5) > 0) { @@ -116,7 +114,7 @@ namespace ZR.Admin.WebApi.Controllers.System return SUCCESS(1); } - return OutputJson(ApiResult.Error("修改密码异常,请联系管理员")); + return ToResponse(ApiResult.Error("修改密码异常,请联系管理员")); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs b/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs index 7fa72fc..73a12fb 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs @@ -69,17 +69,17 @@ namespace ZR.Admin.WebApi.Controllers.System [Route("edit")] public IActionResult RoleAdd([FromBody] SysRole sysRoleDto) { - if (sysRoleDto == null) return OutputJson(ApiResult.Error(101, "请求参数错误")); + if (sysRoleDto == null) return ToResponse(ApiResult.Error(101, "请求参数错误")); if (UserConstants.NOT_UNIQUE.Equals(sysRoleService.CheckRoleKeyUnique(sysRoleDto))) { - return OutputJson(ApiResult.Error((int)ResultCode.CUSTOM_ERROR, $"新增角色'{sysRoleDto.RoleName}'失败,角色权限已存在")); + return ToResponse(ApiResult.Error((int)ResultCode.CUSTOM_ERROR, $"新增角色'{sysRoleDto.RoleName}'失败,角色权限已存在")); } sysRoleDto.Create_by = User.Identity.Name; long roleId = sysRoleService.InsertRole(sysRoleDto); - return OutputJson(ToJson(roleId)); + return ToResponse(ToJson(roleId)); } /// @@ -95,7 +95,7 @@ namespace ZR.Admin.WebApi.Controllers.System { if (sysRoleDto == null || sysRoleDto.RoleId <= 0 || string.IsNullOrEmpty(sysRoleDto.RoleKey)) { - return OutputJson(ApiResult.Error(101, "请求参数错误")); + return ToResponse(ApiResult.Error(101, "请求参数错误")); } sysRoleService.CheckRoleAllowed(sysRoleDto); var info = sysRoleService.SelectRoleById(sysRoleDto.RoleId); @@ -103,7 +103,7 @@ namespace ZR.Admin.WebApi.Controllers.System { if (UserConstants.NOT_UNIQUE.Equals(sysRoleService.CheckRoleKeyUnique(sysRoleDto))) { - return OutputJson(ApiResult.Error($"编辑角色'{sysRoleDto.RoleName}'失败,角色权限已存在")); + return ToResponse(ApiResult.Error($"编辑角色'{sysRoleDto.RoleName}'失败,角色权限已存在")); } } @@ -115,7 +115,7 @@ namespace ZR.Admin.WebApi.Controllers.System return SUCCESS(upResult); } - return OutputJson(ApiResult.Error($"修改角色'{sysRoleDto.RoleName}'失败,请联系管理员")); + return ToResponse(ApiResult.Error($"修改角色'{sysRoleDto.RoleName}'失败,请联系管理员")); } /// @@ -128,7 +128,7 @@ namespace ZR.Admin.WebApi.Controllers.System [Log(Title = "角色管理", BusinessType = BusinessType.UPDATE)] public IActionResult DataScope([FromBody] SysRole sysRoleDto) { - if (sysRoleDto == null || sysRoleDto.RoleId <= 0) return OutputJson(ApiResult.Error(101, "请求参数错误")); + if (sysRoleDto == null || sysRoleDto.RoleId <= 0) return ToResponse(ApiResult.Error(101, "请求参数错误")); sysRoleDto.Create_by = HttpContextExtension.GetName(HttpContext); //删除角色菜单 @@ -151,7 +151,7 @@ namespace ZR.Admin.WebApi.Controllers.System long[] roleIds = Tools.SpitLongArrary(roleId); int result = sysRoleService.DeleteRoleByRoleId(roleIds); - return OutputJson(ToJson(result)); + return ToResponse(ToJson(result)); } /// @@ -166,7 +166,7 @@ namespace ZR.Admin.WebApi.Controllers.System { int result = sysRoleService.UpdateRoleStatus(roleDto); - return OutputJson(ToJson(result)); + return ToResponse(ToJson(result)); } } } diff --git a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs index e309a41..91f1566 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs @@ -75,7 +75,7 @@ namespace ZR.Admin.WebApi.Controllers.System dic.Add("roleIds", RoleService.SelectUserRoles(userId)); } - return OutputJson(ApiResult.Success(dic)); + return ToResponse(ApiResult.Success(dic)); } /// @@ -88,16 +88,16 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:user:add")] public IActionResult AddUser([FromBody] SysUser user) { - if (user == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (user == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } if (UserConstants.NOT_UNIQUE.Equals(UserService.CheckUserNameUnique(user.UserName))) { - return OutputJson(ApiResult.Error($"新增用户 '{user.UserName}'失败,登录账号已存在")); + return ToResponse(ApiResult.Error($"新增用户 '{user.UserName}'失败,登录账号已存在")); } user.Create_by = User.Identity.Name; user.Password = NETCore.Encrypt.EncryptProvider.Md5(user.Password); - return OutputJson(UserService.InsertUser(user)); + return ToResponse(UserService.InsertUser(user)); } /// @@ -110,12 +110,12 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:user:edit")] public IActionResult UpdateUser([FromBody] SysUser user) { - if (user == null || user.UserId <= 0) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (user == null || user.UserId <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } user.Update_by = User.Identity.Name; int upResult = UserService.UpdateUser(user); - return OutputJson(upResult); + return ToResponse(upResult); } /// @@ -128,10 +128,10 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:user:update")] public IActionResult ChangeStatus([FromBody] SysUser user) { - if (user == null) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (user == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } int result = UserService.ChangeUserStatus(user); - return OutputJson(ToJson(result)); + return ToResponse(ToJson(result)); } /// @@ -144,11 +144,11 @@ namespace ZR.Admin.WebApi.Controllers.System [ActionPermissionFilter(Permission = "system:user:remove")] public IActionResult Remove(int userid = 0) { - if (userid <= 0) { return OutputJson(ApiResult.Error(101, "请求参数错误")); } + if (userid <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } int result = UserService.DeleteUser(userid); - return OutputJson(ToJson(result)); + return ToResponse(ToJson(result)); } /// @@ -164,7 +164,7 @@ namespace ZR.Admin.WebApi.Controllers.System sysUser.Password = NETCore.Encrypt.EncryptProvider.Md5(sysUser.Password); int result = UserService.ResetPwd(sysUser.UserId, sysUser.Password); - return OutputJson(ToJson(result)); + return ToResponse(ToJson(result)); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/TasksController.cs b/ZR.Admin.WebApi/Controllers/System/TasksController.cs index 541ad29..0968dfb 100644 --- a/ZR.Admin.WebApi/Controllers/System/TasksController.cs +++ b/ZR.Admin.WebApi/Controllers/System/TasksController.cs @@ -142,7 +142,7 @@ namespace ZR.Admin.WebApi.Controllers Update_by = User.Identity.Name, Update_time = DateTime.Now }); - if (response > 0) + if (response) { //先暂停原先的任务 var respon = await _schedulerServer.UpdateTaskScheduleAsync(tasksQz, tasksQz.JobGroup); @@ -177,7 +177,7 @@ namespace ZR.Admin.WebApi.Controllers { _tasksQzService.Delete(id); } - return OutputJson(taskResult); + return ToResponse(taskResult); } /// @@ -208,7 +208,7 @@ namespace ZR.Admin.WebApi.Controllers _tasksQzService.Update(tasksQz); } - return OutputJson(taskResult); + return ToResponse(taskResult); } /// @@ -239,7 +239,7 @@ namespace ZR.Admin.WebApi.Controllers _tasksQzService.Update(tasksQz); } - return OutputJson(taskResult); + return ToResponse(taskResult); } /// @@ -264,7 +264,7 @@ namespace ZR.Admin.WebApi.Controllers //_tasksQzService.Update(tasksQz); } - return OutputJson(taskResult); + return ToResponse(taskResult); } } } diff --git a/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs b/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs index 432aad4..916d052 100644 --- a/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs +++ b/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs @@ -61,7 +61,7 @@ namespace ZR.Admin.WebApi.Controllers.System int result = tasksLogService.Delete(jobIdArr); - return OutputJson(ToJson(result, result)); + return ToResponse(ToJson(result, result)); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs index 686be34..a60033d 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs @@ -36,7 +36,7 @@ namespace ZR.Admin.WebApi.Controllers.monitor var list = sysLoginService.GetLoginLog(sysLogininfoDto, pagerInfo); var vMPage = new VMPageResult(list, pagerInfo); - return OutputJson(ToJson(vMPage.TotalNum, vMPage), TIME_FORMAT_FULL_2); + return ToResponse(ToJson(vMPage.TotalNum, vMPage), TIME_FORMAT_FULL_2); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs index e2774b2..437aaa4 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs @@ -36,7 +36,7 @@ namespace ZR.Admin.WebApi.Controllers.monitor var list = sysOperLogService.SelectOperLogList(sysOperLog, pagerInfo); var vMPage = new VMPageResult(list, pagerInfo); - return OutputJson(ToJson(vMPage.TotalNum, vMPage), TIME_FORMAT_FULL_2); + return ToResponse(ToJson(vMPage.TotalNum, vMPage), TIME_FORMAT_FULL_2); } /// diff --git a/ZR.Admin.WebApi/Controllers/UploadController.cs b/ZR.Admin.WebApi/Controllers/UploadController.cs index c05fca5..f1dece4 100644 --- a/ZR.Admin.WebApi/Controllers/UploadController.cs +++ b/ZR.Admin.WebApi/Controllers/UploadController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using System; using System.IO; +using ZR.Admin.WebApi.Filters; using ZR.Common; namespace ZR.Admin.WebApi.Controllers @@ -26,24 +27,28 @@ namespace ZR.Admin.WebApi.Controllers /// /// [HttpPost] + [Verify] + [ActionPermissionFilter(Permission = "system")] public IActionResult SaveFile([FromForm(Name = "file")] IFormFile formFile) { if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传图片不能为空"); string fileExt = Path.GetExtension(formFile.FileName); - string savePath = Path.Combine(WebHostEnvironment.WebRootPath, FileUtil.GetdirPath("uploads")); - - if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } - string fileName = FileUtil.HashFileName(Guid.NewGuid().ToString()).ToLower() + fileExt; - string finalFilePath = Path.Combine(savePath, fileName); + string finalFilePath = Path.Combine(WebHostEnvironment.WebRootPath, FileUtil.GetdirPath("uploads"), fileName); + finalFilePath = finalFilePath.Replace("\\", "/").Replace("//", "/"); + + if (!Directory.Exists(Path.GetDirectoryName(finalFilePath))) + { + Directory.CreateDirectory(Path.GetDirectoryName(finalFilePath)); + } using (var stream = new FileStream(finalFilePath, FileMode.Create)) { formFile.CopyToAsync(stream); } - string accessPath = $"{OptionsSetting.Upload.UploadUrl}/{finalFilePath.Replace("wwwroot", "").Replace("\\", "/")}"; - return OutputJson(ToJson(1, accessPath)); + string accessPath = $"{OptionsSetting.Upload.UploadUrl}/{FileUtil.GetdirPath("uploads").Replace("\\", " /")}{fileName}"; + return ToResponse(ResultCode.SUCCESS, new { accessPath, fullPath = finalFilePath }); } } } diff --git a/ZR.Admin.WebApi/Controllers/business/GendemoController.cs b/ZR.Admin.WebApi/Controllers/business/GendemoController.cs new file mode 100644 index 0000000..33c8a37 --- /dev/null +++ b/ZR.Admin.WebApi/Controllers/business/GendemoController.cs @@ -0,0 +1,146 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using SqlSugar; +using Infrastructure; +using Infrastructure.Attribute; +using Infrastructure.Enums; +using Infrastructure.Model; +using Mapster; +using ZR.Model.Dto; +using ZR.Model.Models; +using ZR.Service.Business; +using ZR.Admin.WebApi.Extensions; +using ZR.Admin.WebApi.Filters; +using ZR.Common; +using Infrastructure.Extensions; + +namespace ZR.Admin.WebApi.Controllers +{ + /// + /// 代码生成演示Controller + /// + /// @author zr + /// @date 2021-10-10 + /// + [Verify] + [Route("business/Gendemo")] + public class GendemoController : BaseController + { + /// + /// 代码生成演示接口 + /// + private readonly IGendemoService _GendemoService; + + public GendemoController(IGendemoService GendemoService) + { + _GendemoService = GendemoService; + } + + /// + /// 查询代码生成演示列表 + /// + /// + [HttpGet("list")] + [ActionPermissionFilter(Permission = "business:gendemo:list")] + public IActionResult QueryGendemo([FromQuery] GendemoQueryDto parm) + { + //开始拼装查询条件 + var predicate = Expressionable.Create(); + + //TODO 搜索条件 + //predicate = predicate.And(m => m.Name.Contains(parm.Name)); + + var response = _GendemoService.GetPages(predicate.ToExpression(), parm); + + return SUCCESS(response); + } + + /// + /// 查询代码生成演示详情 + /// + /// + /// + [HttpGet("{Id}")] + [ActionPermissionFilter(Permission = "business:gendemo:query")] + public IActionResult GetGendemo(int Id) + { + var response = _GendemoService.GetId(Id); + + return SUCCESS(response); + } + + /// + /// 添加代码生成演示 + /// + /// + [HttpPost] + [ActionPermissionFilter(Permission = "business:gendemo:add")] + [Log(Title = "代码生成演示添加", BusinessType = BusinessType.INSERT)] + public IActionResult AddGendemo([FromBody] GendemoDto parm) + { + if (parm == null) + { + throw new CustomException("请求参数错误"); + } + //从 Dto 映射到 实体 + var model = parm.Adapt().ToCreate(HttpContext); + + return SUCCESS(_GendemoService.Add(model, it => new + { + it.Name, + it.Icon, + it.ShowStatus, + it.Sex, + it.Sort, + })); + } + + /// + /// 更新代码生成演示 + /// + /// + [HttpPut] + [ActionPermissionFilter(Permission = "business:gendemo:update")] + [Log(Title = "代码生成演示修改", BusinessType = BusinessType.UPDATE)] + public IActionResult UpdateGendemo([FromBody] GendemoDto parm) + { + if (parm == null) + { + throw new CustomException("请求实体不能为空"); + } + //从 Dto 映射到 实体 + var model = parm.Adapt().ToUpdate(HttpContext); + + var response = _GendemoService.Update(w => w.Id == model.Id, it => new Gendemo() + { + //Update 字段映射 + Name = model.Name, + Icon = model.Icon, + ShowStatus = model.ShowStatus, + Sex = model.Sex, + Sort = model.Sort, + }); + + return SUCCESS(response); + } + + /// + /// 删除代码生成演示 + /// + /// + [HttpDelete("{ids}")] + [ActionPermissionFilter(Permission = "business:gendemo:delete")] + [Log(Title = "代码生成演示删除", BusinessType = BusinessType.DELETE)] + public IActionResult DeleteGendemo(string ids) + { + int[] idsArr = Tools.SpitIntArrary(ids); + if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } + + var response = _GendemoService.Delete(idsArr); + + return SUCCESS(response); + } + } +} \ No newline at end of file diff --git a/ZR.Admin.WebApi/Extensions/EntityExtension.cs b/ZR.Admin.WebApi/Extensions/EntityExtension.cs index 879a258..1ec762a 100644 --- a/ZR.Admin.WebApi/Extensions/EntityExtension.cs +++ b/ZR.Admin.WebApi/Extensions/EntityExtension.cs @@ -57,9 +57,9 @@ namespace ZR.Admin.WebApi.Extensions { types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null); } - if (types.GetProperty("Update_Time") != null) + if (types.GetProperty("Update_time") != null) { - types.GetProperty("Update_Time").SetValue(source, DateTime.Now, null); + types.GetProperty("Update_time").SetValue(source, DateTime.Now, null); } //if (types.GetProperty("UpdateID") != null) //{ diff --git a/ZR.Admin.WebApi/Extensions/TasksExtension.cs b/ZR.Admin.WebApi/Extensions/TasksExtension.cs index d125afa..72b8008 100644 --- a/ZR.Admin.WebApi/Extensions/TasksExtension.cs +++ b/ZR.Admin.WebApi/Extensions/TasksExtension.cs @@ -38,7 +38,7 @@ namespace ZR.Admin.WebApi.Extensions //var _tasksQzService2 = (ISysTasksQzService)services.GetRequiredService(typeof(SysTasksQzService)); ITaskSchedulerServer _schedulerServer = App.GetRequiredService(); - var tasks = _tasksQzService.GetWhere(m => m.IsStart); + var tasks = _tasksQzService.QueryableToList(m => m.IsStart); //程序启动后注册所有定时任务 foreach (var task in tasks) diff --git a/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs b/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs index 88258d7..be6684e 100644 --- a/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs +++ b/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs @@ -54,12 +54,12 @@ namespace ZR.Admin.WebApi.Filters bool isDemoMode = ConfigUtils.Instance.GetAppConfig("DemoMode", false); //演示公开环境屏蔽权限 - string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear" }; + string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "send" }; if (isDemoMode && (denyPerms.Any(f => Permission.ToLower().Contains(f.ToLower())) || Permission.Equals("system"))) { context.Result = new JsonResult(new { code = ResultCode.FORBIDDEN, msg = "演示模式 , 不允许操作" }); } - if (!HasPermi) + if (!HasPermi && !Permission.Equals("system")) { logger.Info($"用户{info.NickName}没有权限访问{context.HttpContext.Request.Path},当前权限[{Permission}]"); context.Result = new JsonResult(new { code = ResultCode.FORBIDDEN, msg = "你没有权限访问" }); diff --git a/ZR.Admin.WebApi/appsettings.json b/ZR.Admin.WebApi/appsettings.json index 4416867..3b2e17c 100644 --- a/ZR.Admin.WebApi/appsettings.json +++ b/ZR.Admin.WebApi/appsettings.json @@ -13,7 +13,7 @@ "urls": "http://localhost:8888", //Ŀurl "sysConfig": { "DBCommandTimeout": 10, - "tokenExpire": 1440,//Jwt tokenʱʱ䣨֣ + "tokenExpire": 1440, //Jwt tokenʱʱ䣨֣ "cors": "http://localhost:8887" //ַ"," }, "DemoMode": false, //Ƿʾģʽ @@ -22,7 +22,7 @@ "UploadDirectory": "/", "UploadUrl": "http://localhost:8888" }, - "ALYUN_OCS": { + "QIQIU_OSS": { "REGIONID": "cn-hangzhou", "KEY": "XX", "SECRET": "XX" @@ -33,5 +33,15 @@ "autoPre": true, //Զȥǰ׺ "author": "zr", "tablePrefix": "live_,sys_" //"ǰ׺ǰ׺öŷָ", + }, + //Ϣ + "MailOptions": { + // + "From": "xxxx@qq.com", + // + "Password": "123456", + //Э + "Smtp": "smtp.qq.com", + "Port": 587 } } diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt index 24973ce..97bb3b0 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt @@ -14,6 +14,7 @@ using {ServicesNamespace}.Business; using {ApiControllerNamespace}.Extensions; using {ApiControllerNamespace}.Filters; using ZR.Common; +using Infrastructure.Extensions; namespace {ApiControllerNamespace}.Controllers { @@ -76,7 +77,7 @@ namespace {ApiControllerNamespace}.Controllers /// [HttpPost] [ActionPermissionFilter(Permission = "{Permission}:add")] - [Log(Title = "{TableDesc}添加", BusinessType = BusinessType.INSERT)] + [Log(Title = "{FunctionName}", BusinessType = BusinessType.INSERT)] public IActionResult Add{ModelName}([FromBody] {ModelName}Dto parm) { if (parm == null) @@ -84,11 +85,11 @@ namespace {ApiControllerNamespace}.Controllers throw new CustomException("请求参数错误"); } //从 Dto 映射到 实体 - var model = parm.Adapt<{ModelName}>().ToCreate(); + var model = parm.Adapt<{ModelName}>().ToCreate(HttpContext); return SUCCESS(_{ModelName}Service.Add(model, it => new { - {InsertColumn} +{InsertColumn} })); } @@ -98,7 +99,7 @@ namespace {ApiControllerNamespace}.Controllers /// [HttpPut] [ActionPermissionFilter(Permission = "{Permission}:update")] - [Log(Title = "{TableDesc}修改", BusinessType = BusinessType.UPDATE)] + [Log(Title = "{FunctionName}", BusinessType = BusinessType.UPDATE)] public IActionResult Update{ModelName}([FromBody] {ModelName}Dto parm) { if (parm == null) @@ -106,12 +107,12 @@ namespace {ApiControllerNamespace}.Controllers throw new CustomException("请求实体不能为空"); } //从 Dto 映射到 实体 - var model = parm.Adapt<{ModelName}>().ToUpdate(); + var model = parm.Adapt<{ModelName}>().ToUpdate(HttpContext); var response = _{ModelName}Service.Update(w => w.{PrimaryKey} == model.{PrimaryKey}, it => new {ModelName}() { //Update 字段映射 - {UpdateColumn} +{UpdateColumn} }); return SUCCESS(response); @@ -123,11 +124,11 @@ namespace {ApiControllerNamespace}.Controllers /// [HttpDelete("{ids}")] [ActionPermissionFilter(Permission = "{Permission}:delete")] - [Log(Title = "{TableDesc}删除", BusinessType = BusinessType.DELETE)] + [Log(Title = "{FunctionName}", BusinessType = BusinessType.DELETE)] public IActionResult Delete{ModelName}(string ids) { int[] idsArr = Tools.SpitIntArrary(ids); - if (idsArr.Length <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); } + if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } var response = _{ModelName}Service.Delete(idsArr); diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/MySqlTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/MySqlTemplate.txt index 1c36b1e..bd6bc5d 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/MySqlTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/MySqlTemplate.txt @@ -1,6 +1,6 @@ -- 菜单 INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark) -VALUES ('{FunctionName}', 0, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', '#', '', sysdate(), '', NULL, '{ModelTypeDesc}菜单'); +VALUES ('{FunctionName}', 0, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', '#', '', sysdate(), '', NULL, '{FunctionName}菜单'); -- 按钮父菜单id SELECT @menuId := LAST_INSERT_ID(); diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt index db312b9..a073a0c 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/RepositoryTemplate.txt @@ -12,7 +12,7 @@ namespace {RepositoriesNamespace} /// @date {DateTime} /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class {ModelTypeName}Repository : BaseRepository + public class {ModelTypeName}Repository : BaseRepository<{ModelTypeName}> { #region 业务逻辑代码 #endregion diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt index c42b2eb..fe7121a 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt @@ -1,12 +1,5 @@ using Infrastructure; using Infrastructure.Attribute; -using Infrastructure.Extensions; -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using ZR.Common; using {ModelsNamespace}.Models; using {IRepositoriesNamespace}; @@ -21,10 +14,10 @@ namespace {ServicesNamespace}.Business [AppService(ServiceType = typeof(I{ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)] public class {ModelTypeName}Service: BaseService<{ModelTypeName}>, I{ModelTypeName}Service { - private readonly {ModelTypeName}Repository _repository; + private readonly {ModelTypeName}Repository _{ModelTypeName}repository; public {ModelTypeName}Service({ModelTypeName}Repository repository) { - _repository = repository; + _{ModelTypeName}repository = repository; } #region 业务逻辑代码 diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt index 3cd128c..45ce4be 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt @@ -1,6 +1,6 @@ -- 菜单 INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark) -VALUES ('{FunctionName}', 0, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', '#', '', GETDATE(), '', NULL, '{ModelTypeDesc}'); +VALUES ('{FunctionName}', {ParentId}, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', '#', '', GETDATE(), '', NULL, '{FunctionName}'); -- 按钮父菜单id declare @menuId int = @@identity @@ -19,5 +19,5 @@ INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isC VALUES ('修改', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:update', '', '', GETDATE(), '', NULL, NULL); GO -SELECT * FROM sys_menu WHERE parentId = @menuId; +SELECT * FROM sys_menu WHERE parentId = {ParentId}; SELECT * FROM sys_menu WHERE menuId = @menuId; \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt index 3d37ec0..29b3edd 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt @@ -38,7 +38,7 @@ export function update{ModelTypeName}(data) { /** * 获取{FunctionName}详情 - * @param {Id} {ModelTypeDesc}Id + * @param {Id} {FunctionName}Id */ export function get{ModelTypeName}(id) { return request({ diff --git a/ZR.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs index f39c2dd..55965b5 100644 --- a/ZR.CodeGenerator/CodeGeneratorTool.cs +++ b/ZR.CodeGenerator/CodeGeneratorTool.cs @@ -53,7 +53,6 @@ namespace ZR.CodeGenerator ReplaceDto replaceDto = new(); replaceDto.ModelTypeName = tableInfo.ClassName;//表名对应C# 实体类名 replaceDto.TableName = tableInfo.TableName;//表名 - replaceDto.TableDesc = tableInfo.TableComment;//表说明描述 replaceDto.Permission = $"{tableInfo.ModuleName}:{tableInfo.ClassName.ToLower()}";//权限 replaceDto.ViewsFileName = FirstLowerCase(replaceDto.ModelTypeName); replaceDto.Author = tableInfo.FunctionAuthor; @@ -78,12 +77,12 @@ namespace ZR.CodeGenerator //编辑字段 if (dbFieldInfo.IsEdit) { - replaceDto.UpdateColumn += $"{dbFieldInfo.CsharpField} = model.{dbFieldInfo.CsharpField}, "; + replaceDto.UpdateColumn += $" {dbFieldInfo.CsharpField} = model.{dbFieldInfo.CsharpField}, \n"; } //新增字段 if (dbFieldInfo.IsInsert) { - replaceDto.InsertColumn += $"it.{dbFieldInfo.CsharpField}, "; + replaceDto.InsertColumn += $" it.{dbFieldInfo.CsharpField}, \n"; } //TODO 查询 //if (dbFieldInfo.IsQuery) @@ -310,8 +309,8 @@ namespace ZR.CodeGenerator .Replace("{ModelName}", replaceDto.ModelTypeName) .Replace("{Permission}", replaceDto.Permission) .Replace("{PrimaryKey}", replaceDto.PKName) - .Replace("{UpdateColumn}", replaceDto.UpdateColumn) - .Replace("{InsertColumn}", replaceDto.InsertColumn) + .Replace("{UpdateColumn}", replaceDto.UpdateColumn.TrimEnd('\n')) + .Replace("{InsertColumn}", replaceDto.InsertColumn.TrimEnd('\n')) .Replace("{ModuleName}", generateDto.GenTable.ModuleName) .Replace("{PKCsharpType}", replaceDto.PKType) .Replace("{Author}", replaceDto.Author) @@ -393,9 +392,9 @@ namespace ZR.CodeGenerator var content = FileHelper.ReadTemplate($"{tempName}.txt") .Replace("{ModelTypeName}", replaceDto.ModelTypeName) .Replace("{Permission}", replaceDto.Permission) - .Replace("{ModelTypeDesc}", replaceDto.TableDesc) .Replace("{ModuleName}", generateDto.GenTable.ModuleName) .Replace("{ViewsFileName}", replaceDto.ViewsFileName) + .Replace("{ParentId}", generateDto.ParentMenuId.ToString()) .Replace("{FunctionName}", generateDto.GenTable.FunctionName); generateDto.GenCodes.Add(new GenCode(8, "sql", fullPath, content)); diff --git a/ZR.CodeGenerator/Model/GenerateDto.cs b/ZR.CodeGenerator/Model/GenerateDto.cs index 9ce7d07..e81020f 100644 --- a/ZR.CodeGenerator/Model/GenerateDto.cs +++ b/ZR.CodeGenerator/Model/GenerateDto.cs @@ -45,6 +45,10 @@ namespace ZR.CodeGenerator.Model /// 代码生成压缩包名称 /// public string ZipFileName { get; set; } + /// + /// 父级菜单id + /// + public long ParentMenuId { get; set; } #endregion } diff --git a/ZR.CodeGenerator/Model/ReplaceDto.cs b/ZR.CodeGenerator/Model/ReplaceDto.cs index 425e63a..caad242 100644 --- a/ZR.CodeGenerator/Model/ReplaceDto.cs +++ b/ZR.CodeGenerator/Model/ReplaceDto.cs @@ -8,13 +8,6 @@ namespace ZR.CodeGenerator.Model { public class ReplaceDto { - //public string ModelsNamespace { get; set; } - //public string DtosNamespace { get; set; } - //public string RepositoriesNamespace { get; set; } - //public string IRepositoriesNamespace { get; set; } - //public string IServicsNamespace { get; set; } - //public string ServicesNamespace { get; set; } - /// /// 主键字段 /// @@ -36,10 +29,6 @@ namespace ZR.CodeGenerator.Model /// public string TableName { get; set; } /// - /// 表描述、说明 - /// - public string TableDesc { get; set; } - /// /// 修改列 /// public string UpdateColumn { get; set; } diff --git a/ZR.CodeGenerator/Service/CodeGeneraterService.cs b/ZR.CodeGenerator/Service/CodeGeneraterService.cs index 1e5612d..b0fcbe7 100644 --- a/ZR.CodeGenerator/Service/CodeGeneraterService.cs +++ b/ZR.CodeGenerator/Service/CodeGeneraterService.cs @@ -33,7 +33,7 @@ namespace ZR.CodeGenerator.Service { tableList = tableList.Where(f => f.Name.ToLower().Contains(tableName.ToLower())).ToList(); } - tableList = tableList.Where(f => !new string[] { "gen", "sys_" }.Contains(f.Name)).ToList(); + //tableList = tableList.Where(f => !new string[] { "gen", "sys_" }.Contains(f.Name)).ToList(); pager.TotalNum = tableList.Count; return tableList.Skip(pager.PageSize * (pager.PageNum - 1)).Take(pager.PageSize).OrderBy(f => f.Name).ToList(); } diff --git a/ZR.Common/MailHelper.cs b/ZR.Common/MailHelper.cs new file mode 100644 index 0000000..c5299a2 --- /dev/null +++ b/ZR.Common/MailHelper.cs @@ -0,0 +1,165 @@ +using MailKit.Net.Smtp; +using MimeKit; +using MimeKit.Text; +using System; +using System.Collections.Generic; +using System.IO; + +namespace ZR.Common +{ + public class MailHelper + { + /// + /// 发送人邮箱 + /// + public string FromEmail { get; set; } = ""; + /// + /// 发送人密码 + /// + public string FromPwd { get; set; } = ""; + /// + /// 发送协议 + /// + public string Smtp { get; set; } = "smtp.qq.com"; + /// + /// 协议端口 + /// + public int Port { get; set; } = 587; + /// + /// 是否使用SSL协议 + /// + public bool UseSsl { get; set; } = false; + public string mailSign = @""; + + public MailHelper(string fromEmail, string smtp, int port, string fromPwd) + { + FromEmail = fromEmail; + Smtp = smtp; + FromPwd = fromPwd; + Port = port; + } + + public MailHelper(string fromEmail, string fromPwd) + { + FromEmail = fromEmail; + FromPwd = fromPwd; + } + + /// + /// 发送一个人 + /// + /// + /// + /// + /// + public void SendMail(string toAddress, string subject, string text, string path = "", string html = "") + { + IEnumerable mailboxes = new List() { + new MailboxAddress(toAddress) + }; + + SendMail(mailboxes, subject, text, path, html); + } + + /// + /// 发送多个邮箱 + /// + /// + /// + /// + /// + public void SendMail(string[] toAddress, string subject, string text, string path = "", string html = "") + { + IList mailboxes = new List() { }; + foreach (var item in toAddress) + { + mailboxes.Add(new MailboxAddress(item)); + } + + SendMail(mailboxes, subject, text, path, html); + } + + /// + /// 发送邮件 + /// + /// + /// + /// + /// + /// 附件url地址 + private void SendMail(IEnumerable toAddress, string subject, string text, string path = "", string html = "") + { + MimeMessage message = new MimeMessage(); + //发件人 + message.From.Add(new MailboxAddress(FromEmail, FromEmail)); + + //收件人 + //message.To.Add(new MailboxAddress(toAddress)); + //IList internets = null; + //internets.Add(new MailboxAddress(toAddress)); + + message.To.AddRange(toAddress); + message.Subject = subject; + message.Date = DateTime.Now; + + //创建附件Multipart + Multipart multipart = new Multipart("mixed"); + + //html内容 + if (!string.IsNullOrEmpty(html)) + { + var Html = new TextPart(TextFormat.Html) + { + Text = html + }; + multipart.Add(Html); + } + //文本内容 + if (!string.IsNullOrEmpty(text)) + { + var plain = new TextPart(TextFormat.Plain) + { + Text = text + "\r\n\n\n" + mailSign + }; + multipart.Add(plain); + } + + //附件 + if (!string.IsNullOrEmpty(path)) + { + MimePart attachment = new MimePart() + { + Content = new MimeContent(File.OpenRead(path), ContentEncoding.Default), + //读取文件,只能用绝对路径 + ContentDisposition = new ContentDisposition(ContentDisposition.Attachment), + ContentTransferEncoding = ContentEncoding.Base64, + //文件名字 + FileName = Path.GetFileName(path) + }; + multipart.Add(attachment); + } + + //赋值邮件内容 + message.Body = multipart; + + //开始发送 + using (var client = new SmtpClient()) + { + client.ServerCertificateValidationCallback = (s, c, h, e) => true; + + //Smtp服务器 + //client.Connect("smtp.qq.com", 587, false); + client.Connect(Smtp, Port, true); + //登录,发送 + //特别说明,对于服务器端的中文相应,Exception中有编码问题,显示乱码了 + client.Authenticate(FromEmail, FromPwd); + + client.Send(message); + //断开 + client.Disconnect(true); + Console.WriteLine($"发送邮件成功{DateTime.Now}"); + } + } + + } +} \ No newline at end of file diff --git a/ZR.Common/ZR.Common.csproj b/ZR.Common/ZR.Common.csproj index bb64769..1e5d7f1 100644 --- a/ZR.Common/ZR.Common.csproj +++ b/ZR.Common/ZR.Common.csproj @@ -1,10 +1,11 @@ - + net5.0 + diff --git a/ZR.Model/Dto/GendemoDto.cs b/ZR.Model/Dto/GendemoDto.cs new file mode 100644 index 0000000..de6932b --- /dev/null +++ b/ZR.Model/Dto/GendemoDto.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using ZR.Model.Dto; +using ZR.Model.Models; + +namespace ZR.Model.Dto +{ + /// + /// 代码生成演示输入对象模型 + /// + public class GendemoDto + { + public int Id { get; set; } + public string Name { get; set; } + public string Icon { get; set; } + public int ShowStatus { get; set; } + public int? Sex { get; set; } + public int? Sort { get; set; } + + } + + /// + /// 代码生成演示查询对象模型 + /// + public class GendemoQueryDto: PagerInfo + { + public string Name { get; set; } + + public DateTime? BeginTime { get; set; } + public DateTime? EndTime { get; set; } + } +} diff --git a/ZR.Model/Models/Gendemo.cs b/ZR.Model/Models/Gendemo.cs new file mode 100644 index 0000000..e2e2556 --- /dev/null +++ b/ZR.Model/Models/Gendemo.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; + +namespace ZR.Model.Models +{ + /// + /// 代码生成演示,数据实体对象 + /// + /// @author zr + /// @date 2021-09-27 + /// + [SqlSugar.SugarTable("gen_demo")] + public class Gendemo + { + /// + /// 描述 :自增id + /// 空值 :False + /// + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + /// + /// 描述 :名称 + /// 空值 :False + /// + public string Name { get; set; } + /// + /// 描述 :图片 + /// 空值 :True + /// + public string Icon { get; set; } + /// + /// 描述 :显示状态 + /// 空值 :False + /// + public int ShowStatus { get; set; } + /// + /// 描述 :添加时间 + /// 空值 :True + /// + public DateTime? AddTime { get; set; } + /// + /// 描述 :用户性别 + /// 空值 :True + /// + public int? Sex { get; set; } + /// + /// 描述 :排序 + /// 空值 :True + /// + public int? Sort { get; set; } + + } +} diff --git a/ZR.Model/System/Dto/GenTableDto.cs b/ZR.Model/System/Dto/GenTableDto.cs index 7820d7b..36986c3 100644 --- a/ZR.Model/System/Dto/GenTableDto.cs +++ b/ZR.Model/System/Dto/GenTableDto.cs @@ -21,6 +21,10 @@ namespace ZR.Model.System.Dto public string FunctionAuthor { get; set; } public string GenType { get; set; } public string Options { get; set; } + /// + /// 上级菜单id + /// + public int ParentMenuId { get; set; } public List Columns { get; set; } } diff --git a/ZR.Model/System/Dto/SysConfigDto.cs b/ZR.Model/System/Dto/SysConfigDto.cs new file mode 100644 index 0000000..02ecefc --- /dev/null +++ b/ZR.Model/System/Dto/SysConfigDto.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using ZR.Model.Dto; +using ZR.Model.Models; + +namespace ZR.Model.Dto +{ + /// + /// 参数配置输入对象模型 + /// + public class SysConfigDto + { + public int ConfigId { get; set; } + public string ConfigName { get; set; } + public string ConfigKey { get; set; } + public string ConfigValue { get; set; } + public string ConfigType { get; set; } + } + + /// + /// 参数配置查询对象模型 + /// + public class SysConfigQueryDto: PagerInfo + { + public string ConfigName { get; set; } + public string ConfigKey { get; set; } + public string ConfigValue { get; set; } + public string ConfigType { get; set; } + public DateTime? BeginTime { get; set; } + public DateTime? EndTime { get; set; } + } +} diff --git a/ZR.Model/System/Generate/GenTable.cs b/ZR.Model/System/Generate/GenTable.cs index 0737c33..d2cd238 100644 --- a/ZR.Model/System/Generate/GenTable.cs +++ b/ZR.Model/System/Generate/GenTable.cs @@ -10,23 +10,64 @@ namespace ZR.Model.System.Generate [SqlSugar.SugarTable("gen_table")] public class GenTable: SysBase { + /// + /// 表id + /// [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public int TableId { get; set; } + /// + /// 表名 + /// public string TableName { get; set; } + /// + /// 表描述 + /// public string TableComment { get; set; } + /// + /// 关联父表的表名 + /// public string SubTableName { get; set; } + /// + /// 本表关联父表的外键名 + /// public string SubTableFkName { get; set; } + /// + /// csharp类名 + /// public string ClassName { get; set; } + /// + /// 使用的模板(crud单表操作 tree树表操作 sub主子表操作) + /// public string TplCategory { get; set; } + /// + /// 基本命名空间前缀 + /// public string BaseNameSpace { get; set; } + /// + /// 生成模块名 + /// public string ModuleName { get; set; } + /// + /// 生成业务名 + /// public string BusinessName { get; set; } + /// + /// 生成功能名 + /// public string FunctionName { get; set; } + /// + /// 生成作者名 + /// public string FunctionAuthor { get; set; } + /// + /// 生成代码方式(0zip压缩包 1自定义路径) + /// public string GenType { get; set; } + /// + /// 其他生成选项 + /// public string Options { get; set; } - /** 表列信息 */ [SqlSugar.SugarColumn(IsIgnore = true)] public List Columns { get; set; } diff --git a/ZR.Model/System/SysConfig.cs b/ZR.Model/System/SysConfig.cs new file mode 100644 index 0000000..073feb4 --- /dev/null +++ b/ZR.Model/System/SysConfig.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ZR.Model.System +{ + /// + /// 参数配置,数据实体对象 + /// + /// @author zhaorui + /// @date 2021-09-29 + /// + [SqlSugar.SugarTable("sys_config")] + public class SysConfig: SysBase + { + /// + /// 描述 : + /// 空值 :False + /// + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int ConfigId { get; set; } + /// + /// 描述 : + /// 空值 :True + /// + public string ConfigName { get; set; } + /// + /// 描述 : + /// 空值 :True + /// + public string ConfigKey { get; set; } + /// + /// 描述 : + /// 空值 :True + /// + public string ConfigValue { get; set; } + /// + /// 描述 : + /// 空值 :True + /// + public string ConfigType { get; set; } + + } +} diff --git a/ZR.Repository/BaseRepository.cs b/ZR.Repository/BaseRepository.cs new file mode 100644 index 0000000..a4d0fab --- /dev/null +++ b/ZR.Repository/BaseRepository.cs @@ -0,0 +1,462 @@ +using Infrastructure; +using Infrastructure.Model; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; +using ZR.Model; + +namespace ZR.Repository +{ + /// + /// + /// + /// + public class BaseRepository : SimpleClient, IBaseRepository where T : class, new() + { + public BaseRepository(ISqlSugarClient dbContext = null, int configId = 0) : base(dbContext) + { + if (dbContext == null) + { + string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin); + string dbKey = ConfigUtils.Instance.GetAppConfig(OptionsSetting.DbKey); + int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.ConnDbType); + if (!string.IsNullOrEmpty(dbKey)) + { + connStr = NETCore.Encrypt.EncryptProvider.DESDecrypt(connStr, dbKey); + } + + var Db = new SqlSugarClient(new List() + { + new ConnectionConfig(){ + ConnectionString = connStr, + DbType = (DbType)dbType, + IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样 + InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息 + ConfigId = 0 + }, + new ConnectionConfig(){ + ConnectionString = "", + DbType = DbType.SqlServer, + IsAutoCloseConnection = true, + InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息 + ConfigId = 1 + }, + }); + + //调式代码 用来打印SQL + Db.GetConnection(0).Aop.OnLogExecuting = (sql, pars) => + { + Console.BackgroundColor = ConsoleColor.Yellow; + Console.WriteLine("【SQL语句】" + sql.ToLower() + "\r\n" + Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); + }; + //出错打印日志 + Db.GetConnection(0).Aop.OnError = (e) => + { + Console.WriteLine($"[执行Sql出错]{e.Message},SQL={e.Sql}"); + Console.WriteLine(); + }; + + Context = Db.GetConnection(configId);//根据类传入的ConfigId自动选择 + } + } + + #region add + /// + /// 插入指定列使用 + /// + /// + /// + /// + /// + public int Add(T parm, Expression> iClumns = null, bool ignoreNull = true) + { + return Context.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand(); + } + /// + /// 插入实体 + /// + /// + /// 默认忽略null列 + /// + public int Add(T t) + { + return Context.Insertable(t).ExecuteCommand(); + } + + public int InsertIgnoreNullColumn(T t) + { + return Context.Insertable(t).IgnoreColumns(true).ExecuteCommand(); + } + + public int InsertIgnoreNullColumn(T t, params string[] columns) + { + return Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand(); + } + + //public int Insert(SqlSugarClient client, T t) + //{ + // return client.Insertable(t).ExecuteCommand(); + //} + + public long InsertBigIdentity(T t) + { + return base.Context.Insertable(t).ExecuteReturnBigIdentity(); + } + + public int Insert(List t) + { + return base.Context.Insertable(t).ExecuteCommand(); + } + + public int InsertIgnoreNullColumn(List t) + { + return base.Context.Insertable(t).IgnoreColumns(true).ExecuteCommand(); + } + + public int InsertIgnoreNullColumn(List t, params string[] columns) + { + return base.Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand(); + } + public int Insert(T parm, Expression> iClumns = null, bool ignoreNull = true) + { + return base.Context.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand(); + } + public DbResult InsertTran(T t) + { + var result = base.Context.Ado.UseTran(() => + { + base.Context.Insertable(t).ExecuteCommand(); + }); + return result; + } + + public DbResult InsertTran(List t) + { + var result = base.Context.Ado.UseTran(() => + { + base.Context.Insertable(t).ExecuteCommand(); + }); + return result; + } + + public T InsertReturnEntity(T t) + { + return base.Context.Insertable(t).ExecuteReturnEntity(); + } + + public T InsertReturnEntity(T t, string sqlWith = SqlWith.UpdLock) + { + return base.Context.Insertable(t).With(sqlWith).ExecuteReturnEntity(); + } + + public bool ExecuteCommand(string sql, object parameters) + { + return base.Context.Ado.ExecuteCommand(sql, parameters) > 0; + } + + public bool ExecuteCommand(string sql, params SugarParameter[] parameters) + { + return base.Context.Ado.ExecuteCommand(sql, parameters) > 0; + } + + public bool ExecuteCommand(string sql, List parameters) + { + return base.Context.Ado.ExecuteCommand(sql, parameters) > 0; + } + + #endregion add + + #region update + + public bool UpdateEntity(T entity, bool ignoreNullColumns = false) + { + return base.Context.Updateable(entity).IgnoreColumns(ignoreNullColumns).ExecuteCommand() > 0; + } + + public bool Update(T entity, Expression> expression) + { + return base.Context.Updateable(entity).Where(expression).ExecuteCommand() > 0; + } + + public bool Update(T entity, Expression> expression, bool ignoreAllNull = false) + { + return base.Context.Updateable(entity).UpdateColumns(expression).IgnoreColumns(ignoreAllNull).ExecuteCommand() > 0; + } + + public bool Update(T entity, Expression> expression, Expression> where) + { + return base.Context.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0; + } + + public bool Update(SqlSugarClient client, T entity, Expression> expression, Expression> where) + { + return client.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0; + } + + /// + /// + /// + /// + /// + /// 默认为true + /// + public bool Update(T entity, List list = null, bool isNull = true) + { + if (list == null) + { + list = new List() + { + "Create_By", + "Create_time" + }; + } + //base.Context.Updateable(entity).IgnoreColumns(c => list.Contains(c)).Where(isNull).ExecuteCommand() + return base.Context.Updateable(entity).IgnoreColumns(isNull).IgnoreColumns(list.ToArray()).ExecuteCommand() > 0; + } + + public bool Update(List entity) + { + var result = base.Context.Ado.UseTran(() => + { + base.Context.Updateable(entity).ExecuteCommand(); + }); + return result.IsSuccess; + } + public bool Update(Expression> where, Expression> columns) + { + return base.Context.Updateable().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand() > 0; + } + #endregion update + + //public DbResult UseTran(Action action) + //{ + // var result = base.Context.Ado.UseTran(() => action()); + // return result; + //} + + //public DbResult UseTran(SqlSugarClient client, Action action) + //{ + // var result = client.Ado.UseTran(() => action()); + // return result; + //} + + //public bool UseTran2(Action action) + //{ + // var result = base.Context.Ado.UseTran(() => action()); + // return result.IsSuccess; + //} + + #region delete + + public bool DeleteExp(Expression> expression) + { + return Context.Deleteable().Where(expression).ExecuteCommand() > 0; + } + + //public bool Delete(PkType[] primaryKeyValues) + //{ + // return base.Context.Deleteable().In(primaryKeyValues).ExecuteCommand() > 0; + //} + + public int Delete(object[] obj) + { + return Context.Deleteable().In(obj).ExecuteCommand(); + } + public int Delete(object id) + { + return Context.Deleteable(id).ExecuteCommand(); + } + public bool DeleteTable() + { + return Context.Deleteable().ExecuteCommand() > 0; + } + + #endregion delete + + #region query + + public bool Any(Expression> expression) + { + return Context.Queryable().Where(expression).Any(); + } + + public ISugarQueryable Queryable() + { + return Context.Queryable(); + } + + public ISugarQueryable Queryable(string tableName, string shortName) + { + return Context.Queryable(tableName, shortName); + } + + public List QueryableToList(Expression> expression) + { + return Context.Queryable().Where(expression).ToList(); + } + + public Task> QueryableToListAsync(Expression> expression) + { + return Context.Queryable().Where(expression).ToListAsync(); + } + + //public string QueryableToJson(string select, Expression> expressionWhere) + //{ + // var query = base.Context.Queryable().Select(select).Where(expressionWhere).ToList(); + // return query.JilToJson(); + //} + + public List QueryableToList(string tableName) + { + return Context.Queryable(tableName).ToList(); + } + + public List QueryableToList(string tableName, Expression> expression) + { + return Context.Queryable(tableName).Where(expression).ToList(); + } + + public (List, int) QueryableToPage(Expression> expression, int pageIndex = 0, int pageSize = 10) + { + int totalNumber = 0; + var list = Context.Queryable().Where(expression).ToPageList(pageIndex, pageSize, ref totalNumber); + return (list, totalNumber); + } + + public (List, int) QueryableToPage(Expression> expression, string order, int pageIndex = 0, int pageSize = 10) + { + int totalNumber = 0; + var list = Context.Queryable().Where(expression).OrderBy(order).ToPageList(pageIndex, pageSize, ref totalNumber); + return (list, totalNumber); + } + + public (List, int) QueryableToPage(Expression> expression, Expression> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10) + { + int totalNumber = 0; + + if (orderBy.Equals("DESC", StringComparison.OrdinalIgnoreCase)) + { + var list = Context.Queryable().Where(expression).OrderBy(orderFiled, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref totalNumber); + return (list, totalNumber); + } + else + { + var list = Context.Queryable().Where(expression).OrderBy(orderFiled, OrderByType.Asc).ToPageList(pageIndex, pageSize, ref totalNumber); + return (list, totalNumber); + } + } + + public List SqlQueryToList(string sql, object obj = null) + { + return Context.Ado.SqlQuery(sql, obj); + } + /// + /// 获得一条数据 + /// + /// Expression> + /// + public T GetFirst(Expression> where) + { + return Context.Queryable().Where(where).First(); + } + + /// + /// 根据主值查询单条数据 + /// + /// 主键值 + /// 泛型实体 + public T GetId(object pkValue) + { + return Context.Queryable().InSingle(pkValue); + } + /// + /// 根据条件查询分页数据 + /// + /// + /// + /// + public PagedInfo GetPages(Expression> where, PagerInfo parm) + { + var source = Context.Queryable().Where(where); + + return source.ToPage(parm); + } + + public PagedInfo GetPages(Expression> where, PagerInfo parm, Expression> order, string orderEnum = "Asc") + { + var source = Context.Queryable().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc); + + return source.ToPage(parm); + } + /// + /// 查询所有数据(无分页,请慎用) + /// + /// + public List GetAll(bool useCache = false, int cacheSecond = 3600) + { + return Context.Queryable().WithCacheIF(useCache, cacheSecond).ToList(); + } + #endregion query + + /// + /// 此方法不带output返回值 + /// var list = new List(); + /// list.Add(new SugarParameter(ParaName, ParaValue)); input + /// + /// + /// + /// + //public DataTable UseStoredProcedureToDataTable(string procedureName, List parameters) + //{ + // return base.Context.Ado.UseStoredProcedure().GetDataTable(procedureName, parameters); + //} + + /// + /// 带output返回值 + /// var list = new List(); + /// list.Add(new SugarParameter(ParaName, ParaValue, true)); output + /// list.Add(new SugarParameter(ParaName, ParaValue)); input + /// + /// + /// + /// + //public (DataTable, List) UseStoredProcedureToTuple(string procedureName, List parameters) + //{ + // var result = (base.Context.Ado.UseStoredProcedure().GetDataTable(procedureName, parameters), parameters); + // return result; + //} + + //public string QueryableToJson(string select, Expression> expressionWhere) + //{ + // throw new NotImplementedException(); + //} + } + + public static class QueryableExtension + { + /// + /// 读取列表 + /// + /// + /// + /// + /// + public static PagedInfo ToPage(this ISugarQueryable source, PagerInfo parm) + { + var page = new PagedInfo(); + var total = source.Count(); + page.TotalCount = total; + page.PageSize = parm.PageSize; + page.PageIndex = parm.PageNum; + + //page.DataSource = source.OrderByIF(!string.IsNullOrEmpty(parm.Sort), $"{parm.OrderBy} {(parm.Sort == "descending" ? "desc" : "asc")}").ToPageList(parm.PageNum, parm.PageSize); + page.Result = source.ToPageList(parm.PageNum, parm.PageSize); + return page; + } + + } +} diff --git a/ZR.Repository/DbProvider/SugarDbContext.cs b/ZR.Repository/DbProvider/SugarDbContext.cs deleted file mode 100644 index 69fee4e..0000000 --- a/ZR.Repository/DbProvider/SugarDbContext.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Infrastructure; -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace ZR.Repository.DbProvider -{ - /// - /// SqlSugar ORM - /// - public class SugarDbContext - { - public SqlSugarClient Db; //用来处理事务多表查询和复杂的操作 - - /// - /// 使用SugarSql获取连接对象 - /// 构造方法有问题 - /// - /// - public SugarDbContext() - { - string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin); - string dbKey = ConfigUtils.Instance.GetAppConfig(OptionsSetting.DbKey); - int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.ConnDbType); - if (!string.IsNullOrEmpty(dbKey)) - { - connStr = NETCore.Encrypt.EncryptProvider.DESDecrypt(connStr, dbKey); - } - - Db = new SqlSugarClient(new List() - { - new ConnectionConfig(){ - ConnectionString = connStr, - DbType = (DbType)dbType, - IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样 - InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息 - ConfigId = 0 - }, - }); - - //调式代码 用来打印SQL - Db.Aop.OnLogExecuting = (sql, pars) => - { - Console.BackgroundColor = ConsoleColor.Yellow; - Console.WriteLine("【SQL语句】" + sql.ToLower() + "\r\n" + Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); - }; - //出错打印日志 - Db.Aop.OnError = (e) => - { - Console.WriteLine($"[执行Sql出错]{e.Message},SQL={e.Sql}"); - Console.WriteLine(); - }; - } - } -} diff --git a/ZR.Repository/IBaseRepository.cs b/ZR.Repository/IBaseRepository.cs new file mode 100644 index 0000000..719eda4 --- /dev/null +++ b/ZR.Repository/IBaseRepository.cs @@ -0,0 +1,165 @@ +using Infrastructure.Model; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Data; +using System.Dynamic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using ZR.Model; + +namespace ZR.Repository +{ + public interface IBaseRepository where T : class, new() + { + #region add + int Add(T parm, Expression> iClumns = null, bool ignoreNull = true); + int Add(T t); + + int InsertIgnoreNullColumn(T t); + + int InsertIgnoreNullColumn(T t, params string[] columns); + + //int Insert(SqlSugarClient client, T t); + + long InsertBigIdentity(T t); + + int Insert(List t); + int Insert(T parm, Expression> iClumns = null, bool ignoreNull = true); + + int InsertIgnoreNullColumn(List t); + + int InsertIgnoreNullColumn(List t, params string[] columns); + + DbResult InsertTran(T t); + + DbResult InsertTran(List t); + + T InsertReturnEntity(T t); + + T InsertReturnEntity(T t, string sqlWith = SqlWith.UpdLock); + + bool ExecuteCommand(string sql, object parameters); + + bool ExecuteCommand(string sql, params SugarParameter[] parameters); + + bool ExecuteCommand(string sql, List parameters); + + #endregion add + + #region update + + bool UpdateEntity(T entity, bool ignoreNullColumns = false); + + bool Update(T entity, Expression> expression); + + /// + /// 只更新表达式的值 + /// + /// + /// + /// + bool Update(T entity, Expression> expression, bool ignoreAllNull = false); + + bool Update(T entity, Expression> expression, Expression> where); + + bool Update(SqlSugarClient client, T entity, Expression> expression, Expression> where); + + /// + /// + /// + /// T + /// 忽略更新 + /// Null不更新 + /// + bool Update(T entity, List list = null, bool isNull = true); + + bool Update(List entity); + bool Update(Expression> where, Expression> columns); + + #endregion update + + //DbResult UseTran(Action action); + + //DbResult UseTran(SqlSugarClient client, Action action); + + //bool UseTran2(Action action); + + #region delete + + bool DeleteExp(Expression> expression); + + //bool Delete(PkType[] primaryKeyValues); + int Delete(object[] obj); + int Delete(object id); + bool DeleteTable(); + + #endregion delete + + #region query + /// + /// 根据条件查询分页数据 + /// + /// + /// + /// + PagedInfo GetPages(Expression> where, PagerInfo parm); + + PagedInfo GetPages(Expression> where, PagerInfo parm, Expression> order, string orderEnum = "Asc"); + + bool Any(Expression> expression); + + ISugarQueryable Queryable(); + List GetAll(bool useCache = false, int cacheSecond = 3600); + + //ISugarQueryable Queryable(string tableName, string shortName); + + //ISugarQueryable Queryable() where T1 : class where T2 : new(); + + List QueryableToList(Expression> expression); + + Task> QueryableToListAsync(Expression> expression); + + //string QueryableToJson(string select, Expression> expressionWhere); + + List QueryableToList(string tableName); + + List QueryableToList(string tableName, Expression> expression); + + (List, int) QueryableToPage(Expression> expression, int pageIndex = 0, int pageSize = 10); + + (List, int) QueryableToPage(Expression> expression, string order, int pageIndex = 0, int pageSize = 10); + + (List, int) QueryableToPage(Expression> expression, Expression> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10); + + //(List, int) QueryableToPage(Expression> expression, Bootstrap.BootstrapParams bootstrap); + + List SqlQueryToList(string sql, object obj = null); + /// + /// 获得一条数据 + /// + /// Expression> + /// + T GetFirst(Expression> where); + T GetId(object pkValue); + + /// + /// 获得一条数据 + /// + /// string + /// + //T GetFirst(string parm); + + #endregion query + + #region Procedure + + //DataTable UseStoredProcedureToDataTable(string procedureName, List parameters); + + //(DataTable, List) UseStoredProcedureToTuple(string procedureName, List parameters); + + #endregion Procedure + } +} diff --git a/ZR.Repository/Interceptor/SqlLogInterceptorAttribute.cs b/ZR.Repository/Interceptor/SqlLogInterceptorAttribute.cs deleted file mode 100644 index fe569de..0000000 --- a/ZR.Repository/Interceptor/SqlLogInterceptorAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -using AspectCore.DynamicProxy; -using System.Threading.Tasks; -using ZR.Repository.DbProvider; - -namespace ZR.Repository.Interceptor -{ - - public class SqlLogInterceptorAttribute : AbstractInterceptorAttribute - { - public override Task Invoke(AspectContext context, AspectDelegate next) - { - global::System.Console.WriteLine(""); - return next(context); - } - } -} diff --git a/ZR.Repository/Repositories/GendemoRepository.cs b/ZR.Repository/Repositories/GendemoRepository.cs new file mode 100644 index 0000000..1d1c8c6 --- /dev/null +++ b/ZR.Repository/Repositories/GendemoRepository.cs @@ -0,0 +1,20 @@ +using System; +using Infrastructure.Attribute; +using ZR.Repository.System; +using ZR.Model.Models; + +namespace ZR.Repository +{ + /// + /// 代码生成演示仓储接口的实现 + /// + /// @author zr + /// @date 2021-09-27 + /// + [AppService(ServiceLifetime = LifeTime.Transient)] + public class GendemoRepository : BaseRepository + { + #region 业务逻辑代码 + #endregion + } +} \ No newline at end of file diff --git a/ZR.Repository/System/BaseRepository.cs b/ZR.Repository/System/BaseRepository.cs deleted file mode 100644 index cd7a790..0000000 --- a/ZR.Repository/System/BaseRepository.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Infrastructure.Attribute; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using ZR.Repository.DbProvider; - -namespace ZR.Repository.System -{ - public class BaseRepository : SugarDbContext - { - protected void PrintLog() - { - //调式代码 用来打印SQL - Db.Aop.OnLogExecuting = (sql, pars) => - { - Console.WriteLine("【SQL语句】" + sql.ToLower() + "\r\n" + Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); - }; - } - } -} diff --git a/ZR.Repository/System/GenTableRepository.cs b/ZR.Repository/System/GenTableRepository.cs new file mode 100644 index 0000000..0ce1970 --- /dev/null +++ b/ZR.Repository/System/GenTableRepository.cs @@ -0,0 +1,93 @@ +using Infrastructure.Attribute; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZR.Model.System.Generate; + +namespace ZR.Repository.System +{ + [AppService(ServiceLifetime = LifeTime.Transient)] + public class GenTableRepository : BaseRepository + { + + } + [AppService(ServiceLifetime = LifeTime.Transient)] + public class GenTableColumnRepository : BaseRepository + { + /// + /// 根据表id批量删除表字段 + /// + /// + /// + public int DeleteGenTableColumn(long[] tableId) + { + return Context.Deleteable().Where(f => tableId.Contains(f.TableId)).ExecuteCommand(); + } + + /// + /// 根据表名删除字段 + /// + /// + /// + public int DeleteGenTableColumnByTableName(string tableName) + { + return Context.Deleteable().Where(f => f.TableName == tableName).ExecuteCommand(); + } + + /// + /// 获取表所有字段 + /// + /// + /// + public List GenTableColumns(long tableId) + { + return Context.Queryable().Where(f => f.TableId == tableId).OrderBy(x => x.Sort).ToList(); + } + + /// + /// 插入表字段 + /// + /// + /// + public int InsertGenTableColumn(List tableColumn) + { + return Context.Insertable(tableColumn).IgnoreColumns(x => new { x.Remark }).ExecuteCommand(); + } + + /// + /// 批量更新表字段 + /// + /// + /// + public int UpdateGenTableColumn(List tableColumn) + { + foreach (var item in tableColumn) + { + Context.Updateable() + .Where(f => f.TableId == item.TableId) + .SetColumns(it => new GenTableColumn() + { + ColumnComment = item.ColumnComment, + CsharpField = item.CsharpField, + CsharpType = item.CsharpType, + IsQuery = item.IsQuery, + IsEdit = item.IsEdit, + IsInsert = item.IsInsert, + IsList = item.IsList, + QueryType = item.QueryType, + HtmlType = item.HtmlType, + IsRequired = item.IsRequired, + Sort = item.Sort, + Update_time = DateTime.Now, + DictType = item.DictType + }) + .Where(f => f.ColumnId == item.ColumnId) + .ExecuteCommand(); + } + + return 1; + } + } +} diff --git a/ZR.Repository/System/SysConfigRepository.cs b/ZR.Repository/System/SysConfigRepository.cs new file mode 100644 index 0000000..4f391e0 --- /dev/null +++ b/ZR.Repository/System/SysConfigRepository.cs @@ -0,0 +1,21 @@ +using System; +using Infrastructure.Attribute; +using ZR.Repository.System; +using ZR.Model.Models; +using ZR.Model.System; + +namespace ZR.Repository +{ + /// + /// 参数配置仓储接口的实现 + /// + /// @author zhaorui + /// @date 2021-09-29 + /// + [AppService(ServiceLifetime = LifeTime.Transient)] + public class SysConfigRepository : BaseRepository + { + #region 业务逻辑代码 + #endregion + } +} \ No newline at end of file diff --git a/ZR.Repository/System/SysDeptRepository.cs b/ZR.Repository/System/SysDeptRepository.cs index 4935ec2..b41871a 100644 --- a/ZR.Repository/System/SysDeptRepository.cs +++ b/ZR.Repository/System/SysDeptRepository.cs @@ -8,7 +8,7 @@ namespace ZR.Repository.System /// 部门管理 /// [AppService(ServiceLifetime= LifeTime.Transient)] - public class SysDeptRepository : BaseRepository + public class SysDeptRepository : BaseRepository { /// /// @@ -19,12 +19,12 @@ namespace ZR.Repository.System { string sql = "select * from sys_dept where find_in_set(@deptId, ancestors)"; - return Db.SqlQueryable(sql).AddParameters(new { @deptId = deptId }).ToList(); + return Context.SqlQueryable(sql).AddParameters(new { @deptId = deptId }).ToList(); } public int UdateDeptChildren(SysDept dept) { - return Db.Updateable(dept).UpdateColumns(it => new { it.Ancestors }).ExecuteCommand(); + return Context.Updateable(dept).UpdateColumns(it => new { it.Ancestors }).ExecuteCommand(); } } } diff --git a/ZR.Repository/System/SysDictDataRepository.cs b/ZR.Repository/System/SysDictDataRepository.cs index 6cdf0c6..a6db1d3 100644 --- a/ZR.Repository/System/SysDictDataRepository.cs +++ b/ZR.Repository/System/SysDictDataRepository.cs @@ -9,7 +9,7 @@ namespace ZR.Repository.System /// 字典数据 /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysDictDataRepository : BaseRepository + public class SysDictDataRepository : BaseRepository { /// /// 字典类型数据搜索 @@ -18,7 +18,7 @@ namespace ZR.Repository.System /// public List SelectDictDataList(SysDictData dictData) { - return Db.Queryable() + return Context.Queryable() .WhereIF(!string.IsNullOrEmpty(dictData.DictLabel), it => it.DictLabel.Contains(dictData.DictLabel)) .WhereIF(!string.IsNullOrEmpty(dictData.Status), it => it.Status == dictData.Status) .WhereIF(!string.IsNullOrEmpty(dictData.DictType), it => it.DictType == dictData.DictType) @@ -32,7 +32,7 @@ namespace ZR.Repository.System /// public List SelectDictDataByType(string dictType) { - return Db.Queryable().Where(f => f.Status == "0" && f.DictType == dictType) + return Context.Queryable().Where(f => f.Status == "0" && f.DictType == dictType) .OrderBy(it => it.DictSort) .ToList(); } @@ -44,8 +44,7 @@ namespace ZR.Repository.System /// public long InsertDictData(SysDictData dict) { - var result = Db.Insertable(dict).IgnoreColumns(it => new { dict.Update_by }) - .ExecuteReturnIdentity(); + var result = InsertReturnBigIdentity(dict); return result; } @@ -56,7 +55,7 @@ namespace ZR.Repository.System /// public long UpdateDictData(SysDictData dict) { - return Db.Updateable() + return Context.Updateable() .SetColumns(t => new SysDictData() { Remark = dict.Remark, @@ -64,7 +63,9 @@ namespace ZR.Repository.System DictSort = dict.DictSort, DictLabel = dict.DictLabel, DictValue = dict.DictValue, - Status = dict.Status + Status = dict.Status, + CssClass = dict.CssClass, + ListClass = dict.ListClass }) .Where(f => f.DictCode == dict.DictCode).ExecuteCommand(); } @@ -76,7 +77,7 @@ namespace ZR.Repository.System /// public int DeleteDictDataByIds(long[] dictCodes) { - return Db.Deleteable().In(dictCodes).ExecuteCommand(); + return Delete(dictCodes); } /// @@ -88,7 +89,7 @@ namespace ZR.Repository.System public int UpdateDictDataType(string old_dictType, string new_dictType) { //只更新DictType字段根据where条件 - return Db.Updateable() + return Context.Updateable() .SetColumns(t => new SysDictData() { DictType = new_dictType }) .Where(f => f.DictType == old_dictType) .ExecuteCommand(); diff --git a/ZR.Repository/System/SysDictRepository.cs b/ZR.Repository/System/SysDictRepository.cs index e01de1b..b792879 100644 --- a/ZR.Repository/System/SysDictRepository.cs +++ b/ZR.Repository/System/SysDictRepository.cs @@ -10,7 +10,7 @@ namespace ZR.Repository.System /// 字典 /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysDictRepository : BaseRepository + public class SysDictRepository : BaseRepository { /// /// 查询字段类型列表 @@ -20,7 +20,7 @@ namespace ZR.Repository.System public List SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager) { var totalNum = 0; - var list = Db + var list = Context .Queryable() .WhereIF(!string.IsNullOrEmpty(dictType.DictName), it => it.DictName.Contains(dictType.DictName)) .WhereIF(!string.IsNullOrEmpty(dictType.Status), it => it.Status == dictType.Status) @@ -37,7 +37,7 @@ namespace ZR.Repository.System /// public int DeleteDictTypeByIds(long[] id) { - return Db.Deleteable().In(id).ExecuteCommand(); + return Context.Deleteable().In(id).ExecuteCommand(); } /// @@ -47,7 +47,7 @@ namespace ZR.Repository.System /// public int UpdateDictType(SysDictType dictType) { - return Db.Updateable(dictType).IgnoreColumns(it => new { dictType.Create_by }).ExecuteCommand(); + return Context.Updateable(dictType).IgnoreColumns(it => new { dictType.Create_by }).ExecuteCommand(); } } } diff --git a/ZR.Repository/System/SysLogininfoRepository.cs b/ZR.Repository/System/SysLogininfoRepository.cs index f91a88d..53c023c 100644 --- a/ZR.Repository/System/SysLogininfoRepository.cs +++ b/ZR.Repository/System/SysLogininfoRepository.cs @@ -8,7 +8,7 @@ using ZR.Model.System; namespace ZR.Repository.System { [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysLogininfoRepository : BaseRepository + public class SysLogininfoRepository : BaseRepository { /// /// 查询登录日志 @@ -19,7 +19,7 @@ namespace ZR.Repository.System public List GetLoginLog(SysLogininfor logininfoDto, PagerInfo pager) { int totalCount = 0; - var list = Db.Queryable() + var list = Context.Queryable() .Where(it => it.loginTime >= logininfoDto.BeginTime && it.loginTime <= logininfoDto.EndTime) .WhereIF(logininfoDto.ipaddr.IfNotEmpty(), f => f.ipaddr == logininfoDto.ipaddr) .WhereIF(logininfoDto.userName.IfNotEmpty(), f => f.userName.Contains(logininfoDto.userName)) @@ -38,7 +38,7 @@ namespace ZR.Repository.System /// public void AddLoginInfo(SysLogininfor sysLogininfor) { - int result = Db.Insertable(sysLogininfor) + int result = Context.Insertable(sysLogininfor) .IgnoreColumns(it => new { it.Create_by, it.Create_time, it.Remark }) .ExecuteReturnIdentity(); } @@ -50,7 +50,7 @@ namespace ZR.Repository.System { string sql = "truncate table sys_logininfor"; - Db.Ado.ExecuteCommand(sql); + Context.Ado.ExecuteCommand(sql); } /// @@ -60,7 +60,7 @@ namespace ZR.Repository.System /// public int DeleteLogininforByIds(long[] ids) { - return Db.Deleteable().In(ids).ExecuteCommand(); + return Context.Deleteable().In(ids).ExecuteCommand(); } /// @@ -70,7 +70,7 @@ namespace ZR.Repository.System /// public SysUser Login(LoginBodyDto user) { - return Db.Queryable().First(it => it.UserName == user.Username && it.Password == user.Password); + return Context.Queryable().First(it => it.UserName == user.Username && it.Password == user.Password); } /// @@ -81,7 +81,8 @@ namespace ZR.Repository.System /// public void UpdateLoginInfo(LoginBodyDto user, long userId) { - Db.Updateable(new SysUser() { LoginIP = user.LoginIP, LoginDate = Db.GetDate(), UserId = userId }) + var db = Context; + db.Updateable(new SysUser() { LoginIP = user.LoginIP, LoginDate = db.GetDate(), UserId = userId }) .UpdateColumns(it => new { it.LoginIP, it.LoginDate }) .ExecuteCommand(); } diff --git a/ZR.Repository/System/SysMenuRepository.cs b/ZR.Repository/System/SysMenuRepository.cs index 3fafa0b..8086698 100644 --- a/ZR.Repository/System/SysMenuRepository.cs +++ b/ZR.Repository/System/SysMenuRepository.cs @@ -12,7 +12,7 @@ namespace ZR.Repository.System /// 系统菜单 /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysMenuRepository : BaseRepository + public class SysMenuRepository : BaseRepository { /// /// 获取所有菜单(菜单管理) @@ -20,7 +20,7 @@ namespace ZR.Repository.System /// public List SelectMenuList(SysMenu menu) { - return Db.Queryable() + return Context.Queryable() .WhereIF(!string.IsNullOrEmpty(menu.menuName), it => it.menuName.Contains(menu.menuName)) .WhereIF(!string.IsNullOrEmpty(menu.visible), it => it.visible == menu.visible) .WhereIF(!string.IsNullOrEmpty(menu.status), it => it.status == menu.status) @@ -36,7 +36,7 @@ namespace ZR.Repository.System /// public List SelectMenuListByUserId(SysMenu sysMenu, long userId) { - return Db.Queryable((menu, roleMenu, userRole, role) => new JoinQueryInfos( + return Context.Queryable((menu, roleMenu, userRole, role) => new JoinQueryInfos( JoinType.Left, menu.menuId == roleMenu.Menu_id, JoinType.Left, roleMenu.Role_id == userRole.RoleId, JoinType.Left, userRole.RoleId == role.RoleId @@ -60,7 +60,7 @@ namespace ZR.Repository.System { var menuTypes = new string[] { "M", "C" }; - return Db.Queryable() + return Context.Queryable() .Where(f => f.status == "0" && menuTypes.Contains(f.menuType)) .OrderBy(it => new { it.parentId, it.orderNum }).ToList(); } @@ -73,7 +73,7 @@ namespace ZR.Repository.System public List SelectMenuTreeByRoleIds(List roleIds) { var menuTypes = new string[] { "M", "C"}; - return Db.Queryable((menu, roleMenu) => new JoinQueryInfos( + return Context.Queryable((menu, roleMenu) => new JoinQueryInfos( JoinType.Left, menu.menuId == roleMenu.Menu_id )) .Where((menu, roleMenu) => roleIds.Contains(roleMenu.Role_id) && menuTypes.Contains(menu.menuType) && menu.status == "0") @@ -90,7 +90,7 @@ namespace ZR.Repository.System /// public SysMenu SelectMenuById(int menuId) { - return Db.Queryable().Where(it => it.menuId == menuId).Single(); + return Context.Queryable().Where(it => it.menuId == menuId).Single(); } /// @@ -100,6 +100,7 @@ namespace ZR.Repository.System /// public int AddMenu(SysMenu menu) { + var Db = Context; menu.Create_time = Db.GetDate(); menu.menuId = Db.Insertable(menu).ExecuteReturnIdentity(); return 1; @@ -112,7 +113,7 @@ namespace ZR.Repository.System /// public int EditMenu(SysMenu menu) { - return Db.Updateable(menu).ExecuteCommand(); + return Context.Updateable(menu).ExecuteCommand(); } /// @@ -122,7 +123,7 @@ namespace ZR.Repository.System /// public int DeleteMenuById(int menuId) { - return Db.Deleteable().Where(it => it.menuId == menuId).ExecuteCommand(); + return Context.Deleteable().Where(it => it.menuId == menuId).ExecuteCommand(); } /// @@ -132,7 +133,7 @@ namespace ZR.Repository.System /// public int ChangeSortMenu(MenuDto menuDto) { - var result = Db.Updateable(new SysMenu() { menuId = menuDto.MenuId, orderNum = menuDto.orderNum }) + var result = Context.Updateable(new SysMenu() { menuId = menuDto.MenuId, orderNum = menuDto.orderNum }) .UpdateColumns(it => new { it.orderNum }).ExecuteCommand(); return result; } @@ -144,7 +145,7 @@ namespace ZR.Repository.System /// public List SelectMenuPermsByUserId(long userId) { - return Db.Queryable((m, rm, ur, r) => new JoinQueryInfos( + return Context.Queryable((m, rm, ur, r) => new JoinQueryInfos( JoinType.Left, m.menuId == rm.Menu_id, JoinType.Left, rm.Role_id == ur.RoleId, JoinType.Left, ur.RoleId == r.RoleId @@ -161,7 +162,7 @@ namespace ZR.Repository.System /// public SysMenu CheckMenuNameUnique(SysMenu menu) { - return Db.Queryable() + return Context.Queryable() .Where(it => it.menuName == menu.menuName && it.parentId == menu.parentId).Single(); } @@ -172,7 +173,7 @@ namespace ZR.Repository.System /// public int HasChildByMenuId(long menuId) { - return Db.Queryable().Where(it => it.parentId == menuId).Count(); + return Context.Queryable().Where(it => it.parentId == menuId).Count(); } #region RoleMenu @@ -184,7 +185,7 @@ namespace ZR.Repository.System /// public int CheckMenuExistRole(long menuId) { - return Db.Queryable().Where(it => it.Menu_id == menuId).Count(); + return Context.Queryable().Where(it => it.Menu_id == menuId).Count(); } #endregion diff --git a/ZR.Repository/System/SysOperLogRepository.cs b/ZR.Repository/System/SysOperLogRepository.cs index 9c47b11..7953394 100644 --- a/ZR.Repository/System/SysOperLogRepository.cs +++ b/ZR.Repository/System/SysOperLogRepository.cs @@ -8,7 +8,7 @@ using ZR.Model.System; namespace ZR.Repository.System { [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysOperLogRepository : BaseRepository + public class SysOperLogRepository : BaseRepository { /// /// 查询操作日志 @@ -19,7 +19,7 @@ namespace ZR.Repository.System public List GetSysOperLog(SysOperLogDto sysOper, PagerInfo pagerInfo) { int totalCount = 0; - var list = Db.Queryable() + var list = Context.Queryable() .Where(it => it.operTime >= sysOper.BeginTime && it.operTime <= sysOper.EndTime) .WhereIF(sysOper.Title.IfNotEmpty(), it => it.title.Contains(sysOper.Title)) .WhereIF(sysOper.operName.IfNotEmpty(), it => it.operName.Contains(sysOper.operName)) @@ -38,7 +38,7 @@ namespace ZR.Repository.System /// public void AddSysOperLog(SysOperLog sysOperLog) { - Db.Insertable(sysOperLog).ExecuteCommandAsync(); + Context.Insertable(sysOperLog).ExecuteCommandAsync(); } /// @@ -47,7 +47,7 @@ namespace ZR.Repository.System public void ClearOperLog() { string sql = "truncate table sys_oper_log"; - Db.Ado.ExecuteCommand(sql); + Context.Ado.ExecuteCommand(sql); } /// @@ -57,7 +57,7 @@ namespace ZR.Repository.System /// public int DeleteOperLogByIds(long[] operIds) { - return Db.Deleteable().In(operIds).ExecuteCommand(); + return Context.Deleteable().In(operIds).ExecuteCommand(); } /// @@ -67,7 +67,7 @@ namespace ZR.Repository.System /// public SysOperLog SelectOperLogById(long operId) { - return Db.Queryable().InSingle(operId); + return Context.Queryable().InSingle(operId); } } } diff --git a/ZR.Repository/System/SysPostRepository.cs b/ZR.Repository/System/SysPostRepository.cs new file mode 100644 index 0000000..cc12aa0 --- /dev/null +++ b/ZR.Repository/System/SysPostRepository.cs @@ -0,0 +1,15 @@ +using Infrastructure.Attribute; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZR.Model.System; + +namespace ZR.Repository.System +{ + [AppService(ServiceLifetime = LifeTime.Transient)] + public class SysPostRepository : BaseRepository + { + } +} diff --git a/ZR.Repository/System/SysRoleRepository.cs b/ZR.Repository/System/SysRoleRepository.cs index fc2480d..2a70a10 100644 --- a/ZR.Repository/System/SysRoleRepository.cs +++ b/ZR.Repository/System/SysRoleRepository.cs @@ -9,7 +9,7 @@ namespace ZR.Repository.System /// 角色操作类 /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysRoleRepository : BaseRepository + public class SysRoleRepository : BaseRepository { /// /// 根据条件分页查询角色数据 @@ -17,7 +17,7 @@ namespace ZR.Repository.System /// public List SelectRoleList(SysRole sysRole) { - return Db.Queryable() + return Context.Queryable() .Where(role => role.DelFlag == "0") .WhereIF(!string.IsNullOrEmpty(sysRole.RoleName), role => role.RoleName.Contains(sysRole.RoleName)) .WhereIF(!string.IsNullOrEmpty(sysRole.Status), role => role.Status == sysRole.Status) @@ -33,7 +33,7 @@ namespace ZR.Repository.System /// public List SelectRolePermissionByUserId(long userId) { - return Db.Queryable() + return Context.Queryable() .Where(role => role.DelFlag == "0") .Where(it => SqlFunc.Subqueryable().Where(s => s.UserId == userId).Any()) .OrderBy(role => role.RoleSort) @@ -46,7 +46,7 @@ namespace ZR.Repository.System /// public List SelectRoleAll() { - return Db.Queryable().OrderBy(it => it.RoleSort).ToList(); + return Context.Queryable().OrderBy(it => it.RoleSort).ToList(); } /// @@ -56,7 +56,7 @@ namespace ZR.Repository.System /// public SysRole SelectRoleById(long roleId) { - return Db.Queryable().InSingle(roleId); + return Context.Queryable().InSingle(roleId); } /// @@ -66,7 +66,7 @@ namespace ZR.Repository.System /// public int DeleteRoleByRoleIds(long[] roleId) { - return Db.Deleteable().In(roleId).ExecuteCommand(); + return Context.Deleteable().In(roleId).ExecuteCommand(); } /// @@ -76,7 +76,7 @@ namespace ZR.Repository.System /// public List SelectUserRoleListByUserId(long userId) { - return Db.Queryable((ur, r) => new SqlSugar.JoinQueryInfos( + return Context.Queryable((ur, r) => new SqlSugar.JoinQueryInfos( SqlSugar.JoinType.Left, ur.RoleId == r.RoleId )).Where((ur, r) => ur.UserId == userId) .Select((ur, r) => r).ToList(); @@ -91,7 +91,7 @@ namespace ZR.Repository.System /// public List SelectRoleMenuByRoleId(long roleId) { - return Db.Queryable().Where(it => it.Role_id == roleId).ToList(); + return Context.Queryable().Where(it => it.Role_id == roleId).ToList(); } /// @@ -101,7 +101,7 @@ namespace ZR.Repository.System /// public int AddRoleMenu(List sysRoleMenus) { - return Db.Insertable(sysRoleMenus).ExecuteCommand(); + return Context.Insertable(sysRoleMenus).ExecuteCommand(); } /// @@ -111,7 +111,7 @@ namespace ZR.Repository.System /// public int DeleteRoleMenuByRoleId(long roleId) { - return Db.Deleteable().Where(it => it.Role_id == roleId).ExecuteCommand(); + return Context.Deleteable().Where(it => it.Role_id == roleId).ExecuteCommand(); } #endregion @@ -123,8 +123,8 @@ namespace ZR.Repository.System /// public long InsertRole(SysRole sysRole) { - sysRole.Create_time = Db.GetDate(); - return Db.Insertable(sysRole).ExecuteReturnBigIdentity(); + sysRole.Create_time = Context.GetDate(); + return Context.Insertable(sysRole).ExecuteReturnBigIdentity(); } /// @@ -134,7 +134,7 @@ namespace ZR.Repository.System /// public int UpdateSysRole(SysRole sysRole) { - var db = Db; + var db = Context; sysRole.Update_time = db.GetDate(); return db.Updateable() @@ -156,7 +156,7 @@ namespace ZR.Repository.System /// public int UpdateRoleStatus(SysRole role) { - return Db.Updateable(role).UpdateColumns(t => new { t.Status }).ExecuteCommand(); + return Context.Updateable(role).UpdateColumns(t => new { t.Status }).ExecuteCommand(); } /// @@ -166,7 +166,7 @@ namespace ZR.Repository.System /// public SysRole CheckRoleKeyUnique(string roleKey) { - return Db.Queryable().Where(it => it.RoleKey == roleKey).Single(); + return Context.Queryable().Where(it => it.RoleKey == roleKey).Single(); } /// @@ -176,7 +176,7 @@ namespace ZR.Repository.System /// public SysRole CheckRoleNameUnique(string roleName) { - return Db.Queryable().Where(it => it.RoleName == roleName).Single(); + return Context.Queryable().Where(it => it.RoleName == roleName).Single(); } } } diff --git a/ZR.Repository/System/SysUserPostRepository.cs b/ZR.Repository/System/SysUserPostRepository.cs index 73ffb91..af85023 100644 --- a/ZR.Repository/System/SysUserPostRepository.cs +++ b/ZR.Repository/System/SysUserPostRepository.cs @@ -9,7 +9,7 @@ namespace ZR.Repository.System /// 用户岗位 /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysUserPostRepository : BaseRepository + public class SysUserPostRepository : BaseRepository { /// /// 获取用户岗位 @@ -18,7 +18,7 @@ namespace ZR.Repository.System /// public List SelectPostsByUserId(long userId) { - return Db.Queryable((p, up) => new JoinQueryInfos( + return Context.Queryable((p, up) => new JoinQueryInfos( JoinType.Left, up.PostId == p.PostId )).Where((p, up) => up.UserId == userId) .Select().ToList(); diff --git a/ZR.Repository/System/SysUserRepository.cs b/ZR.Repository/System/SysUserRepository.cs index 754edcd..c9e8e8c 100644 --- a/ZR.Repository/System/SysUserRepository.cs +++ b/ZR.Repository/System/SysUserRepository.cs @@ -10,7 +10,7 @@ namespace ZR.Repository.System /// 用户管理 /// [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysUserRepository : BaseRepository + public class SysUserRepository : BaseRepository { /// /// 根据条件分页查询用户列表 @@ -25,7 +25,7 @@ namespace ZR.Repository.System left join sys_dept d on u.deptId = d.deptId WHERE u.delFlag = '0' "; int totalCount = 0; - var list = Db.SqlQueryable(sql) + var list = Context.SqlQueryable(sql) .WhereIF(!string.IsNullOrEmpty(user.UserName), it => it.UserName.Contains(user.UserName)) .WhereIF(!string.IsNullOrEmpty(user.Status), it => it.Status == user.Status) .WhereIF(user.BeginTime != DateTime.MinValue && user.BeginTime != null, it => it.Create_time >= user.BeginTime) @@ -44,7 +44,7 @@ namespace ZR.Repository.System /// public SysUser SelectUserById(long userId) { - return Db.Queryable().Where(f => f.UserId == userId).First(); + return Context.Queryable().Where(f => f.UserId == userId).First(); } /// @@ -54,7 +54,7 @@ namespace ZR.Repository.System /// public int CheckUserNameUnique(string userName) { - return Db.Queryable().Where(it => it.UserName == userName).Count(); + return Context.Queryable().Where(it => it.UserName == userName).Count(); } /// @@ -65,7 +65,7 @@ namespace ZR.Repository.System public int AddUser(SysUser sysUser) { sysUser.Create_time = DateTime.Now; - return Db.Insertable(sysUser).ExecuteReturnIdentity(); + return Context.Insertable(sysUser).ExecuteReturnIdentity(); } /// @@ -76,7 +76,7 @@ namespace ZR.Repository.System /// public int ResetPwd(long userid, string password) { - return Db.Updateable(new SysUser() { UserId = userid, Password = password }) + return Context.Updateable(new SysUser() { UserId = userid, Password = password }) .UpdateColumns(it => new { it.Password }).ExecuteCommand(); } @@ -87,7 +87,7 @@ namespace ZR.Repository.System /// public int ChangeUserStatus(SysUser user) { - return Db.Updateable(user).UpdateColumns(t => new { t.Status }) + return Context.Updateable(user).UpdateColumns(t => new { t.Status }) .ExecuteCommand(); } @@ -98,7 +98,7 @@ namespace ZR.Repository.System /// public int DeleteUser(long userid) { - return Db.Updateable(new SysUser() { UserId = userid, DelFlag = "2" }) + return Context.Updateable(new SysUser() { UserId = userid, DelFlag = "2" }) .UpdateColumns(t => t.DelFlag) .ExecuteCommand(); } @@ -110,7 +110,7 @@ namespace ZR.Repository.System /// public int UpdateUser(SysUser user) { - return Db.Updateable(user) + return Context.Updateable(user) //.SetColumns(t => new SysUser() //{ // UserName = user.UserName, @@ -136,7 +136,7 @@ namespace ZR.Repository.System /// public int UpdatePhoto(SysUser user) { - return Db.Updateable() + return Context.Updateable() .SetColumns(t => new SysUser() { Avatar = user.Avatar diff --git a/ZR.Repository/System/SysUserRoleRepository.cs b/ZR.Repository/System/SysUserRoleRepository.cs index f63d296..4f80eed 100644 --- a/ZR.Repository/System/SysUserRoleRepository.cs +++ b/ZR.Repository/System/SysUserRoleRepository.cs @@ -6,7 +6,7 @@ using ZR.Model.System; namespace ZR.Repository.System { [AppService(ServiceLifetime = LifeTime.Transient)] - public class SysUserRoleRepository : BaseRepository + public class SysUserRoleRepository : BaseRepository { /// /// 删除用户角色 @@ -15,7 +15,7 @@ namespace ZR.Repository.System /// public int DeleteUserRoleByUserId(int userId) { - return Db.Deleteable().Where(it => it.UserId == userId).ExecuteCommand(); + return Context.Deleteable().Where(it => it.UserId == userId).ExecuteCommand(); } /// @@ -26,7 +26,7 @@ namespace ZR.Repository.System /// public int DeleteRoleUserByUserIds(long roleId, List userIds) { - return Db.Deleteable().Where(it => it.RoleId == roleId && userIds.Contains(it.UserId)) + return Context.Deleteable().Where(it => it.RoleId == roleId && userIds.Contains(it.UserId)) .ExecuteCommand(); } @@ -37,7 +37,7 @@ namespace ZR.Repository.System /// public int AddUserRole(List sysUsers) { - return Db.Insertable(sysUsers).ExecuteCommand(); + return Context.Insertable(sysUsers).ExecuteCommand(); } /// @@ -47,7 +47,7 @@ namespace ZR.Repository.System /// public int DeleteUserRoleByRoleId(int roleId) { - return Db.Deleteable().In(roleId).ExecuteCommand(); + return Context.Deleteable().In(roleId).ExecuteCommand(); } /// @@ -57,7 +57,7 @@ namespace ZR.Repository.System /// public int CountUserRoleByRoleId(long roleId) { - return Db.Queryable().Where(it => it.RoleId == roleId).Count(); + return Context.Queryable().Where(it => it.RoleId == roleId).Count(); } /// @@ -67,7 +67,7 @@ namespace ZR.Repository.System /// public List GetSysUsersByRoleId(long roleId) { - return Db.Queryable((t1, u) => new JoinQueryInfos( + return Context.Queryable((t1, u) => new JoinQueryInfos( JoinType.Left, t1.UserId == u.UserId)) .Where((t1, u) => t1.RoleId == roleId && u.DelFlag == "0") .Select((t1, u) => u) diff --git a/ZR.Service/BaseService.cs b/ZR.Service/BaseService.cs index 8eb83d0..9f79143 100644 --- a/ZR.Service/BaseService.cs +++ b/ZR.Service/BaseService.cs @@ -1,11 +1,4 @@ -using Infrastructure.Attribute; -using Infrastructure.Model; -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using ZR.Model; -using ZR.Repository.DbProvider; +using ZR.Repository; namespace ZR.Service { @@ -13,313 +6,284 @@ namespace ZR.Service /// 基础服务定义 /// /// - public class BaseService : SugarDbContext, IBaseService where T : class, new() + public class BaseService : BaseRepository, IBaseService where T : class, new() { - #region 事务 + //#region 添加操作 + ///// + ///// 添加一条数据 + ///// + ///// T + ///// + //public int Add(T parm) + //{ + // return Add(parm);// Context.Insertable(parm).RemoveDataCache().ExecuteCommand(); + //} - /// - /// 启用事务 - /// - public void BeginTran() - { - Db.Ado.BeginTran(); - } + ///// + ///// 添加 + ///// + ///// + ///// 插入列 + ///// 忽略null列 + ///// + //public int Add(T parm, Expression> iClumns = null, bool ignoreNull = true) + //{ + // return Add(parm); + //} - /// - /// 提交事务 - /// - public void CommitTran() - { - Db.Ado.CommitTran(); - } + ///// + ///// 批量添加数据 + ///// + ///// List + ///// + //public int Add(List parm) + //{ + // return 1;// Context.Insertable(parm).RemoveDataCache().ExecuteCommand(); + //} - /// - /// 回滚事务 - /// - public void RollbackTran() - { - Db.Ado.RollbackTran(); - } + ///// + ///// 添加或更新数据,不推荐使用了 + ///// + ///// List + ///// + //public T Saveable(T parm, Expression> uClumns = null, Expression> iColumns = null) + //{ + // var command = Context.Saveable(parm); - #endregion + // if (uClumns != null) + // { + // command = command.UpdateIgnoreColumns(uClumns); + // } - #region 添加操作 - /// - /// 添加一条数据 - /// - /// T - /// - public int Add(T parm) - { - return Db.Insertable(parm).RemoveDataCache().ExecuteCommand(); - } + // if (iColumns != null) + // { + // command = command.InsertIgnoreColumns(iColumns); + // } - /// - /// 添加 - /// - /// - /// 插入列 - /// 忽略null列 - /// - public int Add(T parm, Expression> iClumns = null, bool ignoreNull = true) - { - return Db.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand(); - } + // return command.ExecuteReturnEntity(); + //} - /// - /// 批量添加数据 - /// - /// List - /// - public int Add(List parm) - { - return Db.Insertable(parm).RemoveDataCache().ExecuteCommand(); - } + ///// + ///// 批量添加或更新数据 + ///// + ///// List + ///// + //public List Saveable(List parm, Expression> uClumns = null, Expression> iColumns = null) + //{ + // var command = Context.Saveable(parm); - /// - /// 添加或更新数据,不推荐使用了 - /// - /// List - /// - public T Saveable(T parm, Expression> uClumns = null, Expression> iColumns = null) - { - var command = Db.Saveable(parm); + // if (uClumns != null) + // { + // command = command.UpdateIgnoreColumns(uClumns); + // } - if (uClumns != null) - { - command = command.UpdateIgnoreColumns(uClumns); - } + // if (iColumns != null) + // { + // command = command.InsertIgnoreColumns(iColumns); + // } - if (iColumns != null) - { - command = command.InsertIgnoreColumns(iColumns); - } + // return command.ExecuteReturnList(); + //} + //#endregion - return command.ExecuteReturnEntity(); - } + //#region 查询操作 - /// - /// 批量添加或更新数据 - /// - /// List - /// - public List Saveable(List parm, Expression> uClumns = null, Expression> iColumns = null) - { - var command = Db.Saveable(parm); + ///// + ///// 根据条件查询数据是否存在 + ///// + ///// 条件表达式树 + ///// + //public bool Any(Expression> where) + //{ + // return true;// base.Context.Any(where); + //} - if (uClumns != null) - { - command = command.UpdateIgnoreColumns(uClumns); - } + ///// + ///// 根据条件合计字段 + ///// + ///// 条件表达式树 + ///// + //public TResult Sum(Expression> where, Expression> field) + //{ + // return base.Context.Queryable().Where(where).Sum(field); + //} - if (iColumns != null) - { - command = command.InsertIgnoreColumns(iColumns); - } + ///// + ///// 根据主值查询单条数据 + ///// + ///// 主键值 + ///// 泛型实体 + ////public T GetId(object pkValue) + ////{ + //// return base.Context.Queryable().InSingle(pkValue); + ////} - return command.ExecuteReturnList(); - } - #endregion + ///// + ///// 根据主键查询多条数据 + ///// + ///// + ///// + //public List GetIn(object[] ids) + //{ + // return Context.Queryable().In(ids).ToList(); + //} - #region 查询操作 + ///// + ///// 根据条件取条数 + ///// + ///// 条件表达式树 + ///// + //public int GetCount(Expression> where) + //{ + // return Context.Queryable().Count(where); - /// - /// 根据条件查询数据是否存在 - /// - /// 条件表达式树 - /// - public bool Any(Expression> where) - { - return Db.Queryable().Any(where); - } + //} - /// - /// 根据条件合计字段 - /// - /// 条件表达式树 - /// - public TResult Sum(Expression> where, Expression> field) - { - return Db.Queryable().Where(where).Sum(field); - } + ///// + ///// 查询所有数据(无分页,请慎用) + ///// + ///// + //public List GetAll(bool useCache = false, int cacheSecond = 3600) + //{ + // return Context.Queryable().WithCacheIF(useCache, cacheSecond).ToList(); + //} - /// - /// 根据主值查询单条数据 - /// - /// 主键值 - /// 泛型实体 - public T GetId(object pkValue) - { - return Db.Queryable().InSingle(pkValue); - } + ///// + ///// 获得一条数据 + ///// + ///// Expression> + ///// + //public T GetFirst2(Expression> where) + //{ + // return base.GetFirst(where);// Context.Queryable().Where(where).First(); + //} - /// - /// 根据主键查询多条数据 - /// - /// - /// - public List GetIn(object[] ids) - { - return Db.Queryable().In(ids).ToList(); - } + ///// + ///// 获得一条数据 + ///// + ///// string + ///// + ////public T GetFirst(string parm) + ////{ + //// return Context.Queryable().Where(parm).First(); + ////} - /// - /// 根据条件取条数 - /// - /// 条件表达式树 - /// - public int GetCount(Expression> where) - { - return Db.Queryable().Count(where); + ///// + ///// 根据条件查询分页数据 + ///// + ///// + ///// + ///// + //public PagedInfo GetPages(Expression> where, PagerInfo parm) + //{ + // var source = Context.Queryable().Where(where); - } + // return source.ToPage(parm); + //} - /// - /// 查询所有数据(无分页,请慎用) - /// - /// - public List GetAll(bool useCache = false, int cacheSecond = 3600) - { - return Db.Queryable().WithCacheIF(useCache, cacheSecond).ToList(); - } + //public PagedInfo GetPages(Expression> where, PagerInfo parm, Expression> order, string orderEnum = "Asc") + //{ + // var source = Context.Queryable().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc); - /// - /// 获得一条数据 - /// - /// Expression> - /// - public T GetFirst(Expression> where) - { - return Db.Queryable().Where(where).First(); - } - - /// - /// 获得一条数据 - /// - /// string - /// - public T GetFirst(string parm) - { - return Db.Queryable().Where(parm).First(); - } - - - /// - /// 根据条件查询分页数据 - /// - /// - /// - /// - public PagedInfo GetPages(Expression> where, PagerInfo parm) - { - var source = Db.Queryable().Where(where); - - return source.ToPage(parm); - } - - public PagedInfo GetPages(Expression> where, PagerInfo parm, Expression> order, string orderEnum = "Asc") - { - var source = Db.Queryable().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc); - - return source.ToPage(parm); - } + // return source.ToPage(parm); + //} /// /// 根据条件查询数据 /// /// 条件表达式树 /// - public List GetWhere(Expression> where, bool useCache = false, int cacheSecond = 3600) - { - var query = Db.Queryable().Where(where).WithCacheIF(useCache, cacheSecond); - return query.ToList(); - } + // public List GetWhere(Expression> where, bool useCache = false, int cacheSecond = 3600) + // { + // var query = Context.Queryable().Where(where).WithCacheIF(useCache, cacheSecond); + // return query.ToList(); + // } - /// - /// 根据条件查询数据 - /// - /// 条件表达式树 - /// - public List GetWhere(Expression> where, Expression> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600) - { - var query = Db.Queryable().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc).WithCacheIF(useCache, cacheSecond); - return query.ToList(); - } + // /// + ///// 根据条件查询数据 + ///// + ///// 条件表达式树 + ///// + // public List GetWhere(Expression> where, Expression> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600) + // { + // var query = Context.Queryable().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc).WithCacheIF(useCache, cacheSecond); + // return query.ToList(); + // } - #endregion + // #endregion - #region 修改操作 + //#region 修改操作 - /// - /// 修改一条数据 - /// - /// T - /// - public int Update(T parm) - { - return Db.Updateable(parm).RemoveDataCache().ExecuteCommand(); - } + /////// + /////// 修改一条数据 + /////// + /////// T + /////// + ////public int Update(T parm) + ////{ + //// return Context.Updateable(parm).RemoveDataCache().ExecuteCommand(); + ////} - /// - /// 批量修改 - /// - /// T - /// - public int Update(List parm) - { - return Db.Updateable(parm).RemoveDataCache().ExecuteCommand(); - } + /////// + /////// 批量修改 + /////// + /////// T + /////// + ////public int Update(List parm) + ////{ + //// return Context.Updateable(parm).RemoveDataCache().ExecuteCommand(); + ////} - /// - /// 按查询条件更新 - /// - /// - /// - /// - public int Update(Expression> where, Expression> columns) - { - return Db.Updateable().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand(); - } + /////// + /////// 按查询条件更新 + /////// + /////// + /////// + /////// + ////public int Update(Expression> where, Expression> columns) + ////{ + //// return Context.Updateable().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand(); + ////} - #endregion + //#endregion - #region 删除操作 + //#region 删除操作 - /// - /// 删除一条或多条数据 - /// - /// string - /// - public int Delete(object id) - { - return Db.Deleteable(id).RemoveDataCache().ExecuteCommand(); - } + /////// + /////// 删除一条或多条数据 + /////// + /////// string + /////// + ////public int Delete(object id) + ////{ + //// return Context.Deleteable(id).RemoveDataCache().ExecuteCommand(); + ////} - /// - /// 删除一条或多条数据 - /// - /// string - /// - public int Delete(object[] ids) - { - return Db.Deleteable().In(ids).RemoveDataCache().ExecuteCommand(); - } + /////// + /////// 删除一条或多条数据 + /////// + /////// string + /////// + ////public int Delete(object[] ids) + ////{ + //// return Context.Deleteable().In(ids).RemoveDataCache().ExecuteCommand(); + ////} - /// - /// 根据条件删除一条或多条数据 - /// - /// 过滤条件 - /// - public int Delete(Expression> where) - { - return Db.Deleteable().Where(where).RemoveDataCache().ExecuteCommand(); - } + /////// + /////// 根据条件删除一条或多条数据 + /////// + /////// 过滤条件 + /////// + ////public int Delete(Expression> where) + ////{ + //// return Context.Deleteable().Where(where).RemoveDataCache().ExecuteCommand(); + ////} - public int DeleteTable() - { - return Db.Deleteable().RemoveDataCache().ExecuteCommand(); - } - #endregion + //public int DeleteTable() + //{ + // return Context.Deleteable().RemoveDataCache().ExecuteCommand(); + //} + //#endregion } } diff --git a/ZR.Service/Business/GendemoService.cs b/ZR.Service/Business/GendemoService.cs new file mode 100644 index 0000000..e86a392 --- /dev/null +++ b/ZR.Service/Business/GendemoService.cs @@ -0,0 +1,33 @@ +using Infrastructure; +using Infrastructure.Attribute; +using Infrastructure.Extensions; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using ZR.Common; +using ZR.Model.Models; +using ZR.Repository; + +namespace ZR.Service.Business +{ + /// + /// 代码生成演示Service业务层处理 + /// + /// @author zr + /// @date 2021-09-27 + /// + [AppService(ServiceType = typeof(IGendemoService), ServiceLifetime = LifeTime.Transient)] + public class GendemoService: BaseService, IGendemoService + { + private readonly GendemoRepository _repository; + public GendemoService(GendemoRepository repository) + { + _repository = repository; + } + #region 业务逻辑代码 + + #endregion + } +} \ No newline at end of file diff --git a/ZR.Service/Business/IBusService/IGendemoService.cs b/ZR.Service/Business/IBusService/IGendemoService.cs new file mode 100644 index 0000000..7e0454c --- /dev/null +++ b/ZR.Service/Business/IBusService/IGendemoService.cs @@ -0,0 +1,15 @@ +using System; +using ZR.Model.Models; + +namespace ZR.Service.Business +{ + /// + /// 代码生成演示service接口 + /// + /// @author zr + /// @date 2021-09-27 + /// + public interface IGendemoService: IBaseService + { + } +} diff --git a/ZR.Service/Business/IBusService/ISysConfigService.cs b/ZR.Service/Business/IBusService/ISysConfigService.cs new file mode 100644 index 0000000..182b403 --- /dev/null +++ b/ZR.Service/Business/IBusService/ISysConfigService.cs @@ -0,0 +1,16 @@ +using System; +using ZR.Model.Models; +using ZR.Model.System; + +namespace ZR.Service.System +{ + /// + /// 参数配置service接口 + /// + /// @author zhaorui + /// @date 2021-09-29 + /// + public interface ISysConfigService: IBaseService + { + } +} diff --git a/ZR.Service/Extensions/QueryableExtension.cs b/ZR.Service/Extensions/QueryableExtension.cs index 1bf1a23..d87b195 100644 --- a/ZR.Service/Extensions/QueryableExtension.cs +++ b/ZR.Service/Extensions/QueryableExtension.cs @@ -11,31 +11,6 @@ namespace ZR.Service { public static class QueryableExtension { - /// - /// 读取列表 - /// - /// - /// - /// - /// - /// - //public static async Task> ToPageAsync(this ISugarQueryable source, PageParm parm) - //{ - // var page = new PagedInfo(); - // var total = await source.CountAsync(); - // page.TotalCount = total; - // page.TotalPages = total / parm.PageSize; - - // if (total % parm.PageSize > 0) - // page.TotalPages++; - - // page.PageSize = parm.PageSize; - // page.PageIndex = parm.PageIndex; - - // page.DataSource = await source.OrderByIF(!string.IsNullOrEmpty(parm.Sort), $"{parm.OrderBy} {(parm.Sort == "descending" ? "desc" : "asc")}").ToPageListAsync(parm.PageIndex, parm.PageSize); - // return page; - //} - /// /// 读取列表 /// @@ -49,11 +24,6 @@ namespace ZR.Service var page = new PagedInfo(); var total = source.Count(); page.TotalCount = total; - //page.TotalPage = total / parm.PageSize; - - //if (total % parm.PageSize > 0) - // page.TotalPages++; - page.PageSize = parm.PageSize; page.PageIndex = parm.PageNum; diff --git a/ZR.Service/IBaseService.cs b/ZR.Service/IBaseService.cs index 38d2065..3e0b4ba 100644 --- a/ZR.Service/IBaseService.cs +++ b/ZR.Service/IBaseService.cs @@ -3,6 +3,7 @@ using SqlSugar; using System; using System.Collections.Generic; using System.Linq.Expressions; +using ZR.Repository; namespace ZR.Service { @@ -10,221 +11,199 @@ namespace ZR.Service /// 基础服务定义 /// /// - public interface IBaseService where T : class + public interface IBaseService : IBaseRepository where T : class, new() { - - #region 事务 - - /// - /// 启用事务 - /// - void BeginTran(); - - - /// - /// 提交事务 - /// - void CommitTran(); - - - /// - /// 回滚事务 - /// - void RollbackTran(); - - #endregion - #region 添加操作 /// /// 添加一条数据 /// /// /// - int Add(T parm); + //int Add(T parm); - int Add(T parm, Expression> iClumns = null, bool ignoreNull = false); + //int Add(T parm, Expression> iClumns = null, bool ignoreNull = false); - /// - /// 批量添加数据 - /// - /// List - /// - int Add(List parm); + ///// + ///// 批量添加数据 + ///// + ///// List + ///// + //int Add(List parm); - /// - /// 添加或更新数据 - /// - /// - /// - T Saveable(T parm, Expression> uClumns = null, Expression> iColumns = null); + ///// + ///// 添加或更新数据 + ///// + ///// + ///// + //T Saveable(T parm, Expression> uClumns = null, Expression> iColumns = null); - /// - /// 批量添加或更新数据 - /// - /// List - /// - List Saveable(List parm, Expression> uClumns = null, Expression> iColumns = null); + ///// + ///// 批量添加或更新数据 + ///// + ///// List + ///// + //List Saveable(List parm, Expression> uClumns = null, Expression> iColumns = null); - #endregion + //#endregion - #region 查询操作 + //#region 查询操作 - /// - /// 根据条件查询数据是否存在 - /// - /// 条件表达式树 - /// - bool Any(Expression> where); + ///// + ///// 根据条件查询数据是否存在 + ///// + ///// 条件表达式树 + ///// + //bool Any(Expression> where); - /// - /// 根据条件合计字段 - /// - /// 条件表达式树 - /// - TResult Sum(Expression> where, Expression> field); + ///// + ///// 根据条件合计字段 + ///// + ///// 条件表达式树 + ///// + //TResult Sum(Expression> where, Expression> field); - /// - /// 根据主值查询单条数据 - /// - /// 主键值 - /// 泛型实体 - T GetId(object pkValue); + ///// + ///// 根据主值查询单条数据 + ///// + ///// 主键值 + ///// 泛型实体 + //T GetId(object pkValue); - /// - /// 根据主键查询多条数据 - /// - /// - /// - List GetIn(object[] ids); + ///// + ///// 根据主键查询多条数据 + ///// + ///// + ///// + //List GetIn(object[] ids); - /// - /// 根据条件取条数 - /// - /// 条件表达式树 - /// - int GetCount(Expression> where); + ///// + ///// 根据条件取条数 + ///// + ///// 条件表达式树 + ///// + //int GetCount(Expression> where); - /// - /// 查询所有数据(无分页,请慎用) - /// - /// - List GetAll(bool useCache = false, int cacheSecond = 3600); + ///// + ///// 查询所有数据(无分页,请慎用) + ///// + ///// + //List GetAll(bool useCache = false, int cacheSecond = 3600); - /// - /// 获得一条数据 - /// - /// Expression> - /// - T GetFirst(Expression> where); + ///// + ///// 获得一条数据 + ///// + ///// Expression> + ///// + //T GetFirst(Expression> where); - /// - /// 获得一条数据 - /// - /// string - /// - T GetFirst(string parm); + ///// + ///// 获得一条数据 + ///// + ///// string + ///// + //T GetFirst(string parm); - /// - /// 根据条件查询分页数据 - /// - /// - /// - /// - PagedInfo GetPages(Expression> where, Model.PagerInfo parm); + ///// + ///// 根据条件查询分页数据 + ///// + ///// + ///// + ///// + //PagedInfo GetPages(Expression> where, Model.PagerInfo parm); - /// - /// 根据条件查询分页 - /// - /// - /// - /// - /// - /// - PagedInfo GetPages(Expression> where, Model.PagerInfo parm, Expression> order, string orderEnum = "Asc"); + ///// + ///// 根据条件查询分页 + ///// + ///// + ///// + ///// + ///// + ///// + //PagedInfo GetPages(Expression> where, Model.PagerInfo parm, Expression> order, string orderEnum = "Asc"); - /// - /// 根据条件查询数据 - /// - /// 条件表达式树 - /// - List GetWhere(Expression> where, bool useCache = false, int cacheSecond = 3600); + ///// + ///// 根据条件查询数据 + ///// + ///// 条件表达式树 + ///// + ////List GetWhere(Expression> where, bool useCache = false, int cacheSecond = 3600); - /// - /// 根据条件查询数据 - /// - /// 条件表达式树 - /// - List GetWhere(Expression> where, Expression> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600); + /////// + /////// 根据条件查询数据 + /////// + /////// 条件表达式树 + /////// + ////List GetWhere(Expression> where, Expression> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600); - #endregion + //#endregion - #region 修改操作 + //#region 修改操作 - /// - /// 修改一条数据 - /// - /// T - /// - int Update(T parm); + ///// + ///// 修改一条数据 + ///// + ///// T + ///// + //int Update(T parm); - /// - /// 批量修改 - /// - /// T - /// - int Update(List parm); + ///// + ///// 批量修改 + ///// + ///// T + ///// + //int Update(List parm); - /// - /// 按查询条件更新 - /// - /// - /// - /// - int Update(Expression> where, Expression> columns); + ///// + ///// 按查询条件更新 + ///// + ///// + ///// + ///// + //int Update(Expression> where, Expression> columns); - #endregion + //#endregion - #region 删除操作 + //#region 删除操作 - /// - /// 删除一条或多条数据 - /// - /// string - /// - int Delete(object id); + ///// + ///// 删除一条或多条数据 + ///// + ///// string + ///// + //int Delete(object id); - /// - /// 删除一条或多条数据 - /// - /// string - /// - int Delete(object[] ids); + ///// + ///// 删除一条或多条数据 + ///// + ///// string + ///// + //int Delete(object[] ids); - /// - /// 根据条件删除一条或多条数据 - /// - /// 过滤条件 - /// - int Delete(Expression> where); - - /// - /// 清空表 - /// - /// - int DeleteTable(); + ///// + ///// 根据条件删除一条或多条数据 + ///// + ///// 过滤条件 + ///// + //int Delete(Expression> where); + + ///// + ///// 清空表 + ///// + ///// + //int DeleteTable(); #endregion } diff --git a/ZR.Service/System/GenTableService.cs b/ZR.Service/System/GenTableService.cs index 782324e..f38f3cc 100644 --- a/ZR.Service/System/GenTableService.cs +++ b/ZR.Service/System/GenTableService.cs @@ -1,11 +1,13 @@ using Infrastructure.Attribute; using Infrastructure.Extensions; using Infrastructure.Model; +using Newtonsoft.Json; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using ZR.Model.System.Generate; +using ZR.Repository.System; using ZR.Service.System.IService; namespace ZR.Service.System @@ -14,12 +16,14 @@ namespace ZR.Service.System /// 代码生成表 /// [AppService(ServiceType = typeof(IGenTableService), ServiceLifetime = LifeTime.Transient)] - public class GenTableService : BaseService, IGenTableService + public class GenTableService : IGenTableService { - public IGenTableColumnService GenTableColumnService; - public GenTableService(IGenTableColumnService genTableColumnService) + private GenTableRepository GenTableRepository; + private IGenTableColumnService GenTableColumnService; + public GenTableService(IGenTableColumnService genTableColumnService, GenTableRepository genTableRepository) { GenTableColumnService = genTableColumnService; + GenTableRepository = genTableRepository; } /// @@ -29,7 +33,7 @@ namespace ZR.Service.System /// public int DeleteGenTableByIds(long[] tableIds) { - Db.Deleteable().Where(f => tableIds.Contains(f.TableId)).ExecuteCommand(); + GenTableRepository.Delete(f => tableIds.Contains(f.TableId)); return GenTableColumnService.DeleteGenTableColumn(tableIds); } @@ -40,7 +44,7 @@ namespace ZR.Service.System /// public int DeleteGenTableByTbName(string tableName) { - return Db.Deleteable().Where(f => f.TableName == tableName).ExecuteCommand(); + return GenTableRepository.Delete(f => f.TableName == tableName) ? 1 : 0; } /// @@ -50,7 +54,7 @@ namespace ZR.Service.System /// public GenTable GetGenTableInfo(long tableId) { - return GetId(tableId); + return GenTableRepository.GetById(tableId); } /// @@ -64,7 +68,7 @@ namespace ZR.Service.System var predicate = Expressionable.Create(); predicate = predicate.AndIF(genTable.TableName.IfNotEmpty(), it => it.TableName.Contains(genTable.TableName)); - return GetPages(predicate.ToExpression(), pagerInfo); + return GenTableRepository.GetPages(predicate.ToExpression(), pagerInfo); } /// @@ -74,13 +78,12 @@ namespace ZR.Service.System /// public int ImportGenTable(GenTable table) { - var db = Db; - table.Create_time = db.GetDate(); + table.Create_time = DateTime.Now; //导入前删除现有表 //DeleteGenTableByIds(new long[] { table.TableId }); DeleteGenTableByTbName(table.TableName); - return db.Insertable(table).IgnoreColumns(ignoreNullColumn: true).ExecuteReturnIdentity(); + return GenTableRepository.Context.Insertable(table).IgnoreColumns(ignoreNullColumn: true).ExecuteReturnIdentity(); } /// @@ -95,7 +98,7 @@ namespace ZR.Service.System public int UpdateGenTable(GenTable genTable) { - var db = Db; + var db = GenTableRepository.Context; genTable.Update_time = db.GetDate(); return db.Updateable(genTable).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } @@ -105,8 +108,14 @@ namespace ZR.Service.System /// 代码生成表列 /// [AppService(ServiceType = typeof(IGenTableColumnService), ServiceLifetime = LifeTime.Transient)] - public class GenTableColumnService : BaseService, IGenTableColumnService + public class GenTableColumnService : IGenTableColumnService { + + private GenTableColumnRepository GetTableColumnRepository; + public GenTableColumnService(GenTableColumnRepository genTableColumnRepository) + { + GetTableColumnRepository = genTableColumnRepository; + } /// /// 删除表字段 /// @@ -114,7 +123,7 @@ namespace ZR.Service.System /// public int DeleteGenTableColumn(long tableId) { - return DeleteGenTableColumn(new long[] { tableId }); + return GetTableColumnRepository.DeleteGenTableColumn(new long[] { tableId }); } /// /// 根据表id批量删除表字段 @@ -123,7 +132,7 @@ namespace ZR.Service.System /// public int DeleteGenTableColumn(long[] tableId) { - return Db.Deleteable().Where(f => tableId.Contains(f.TableId)).ExecuteCommand(); + return GetTableColumnRepository.DeleteGenTableColumn(tableId); } /// @@ -133,7 +142,7 @@ namespace ZR.Service.System /// public int DeleteGenTableColumnByTableName(string tableName) { - return Db.Deleteable().Where(f => f.TableName == tableName).ExecuteCommand(); + return GetTableColumnRepository.DeleteGenTableColumnByTableName(tableName); } /// @@ -143,7 +152,7 @@ namespace ZR.Service.System /// public List GenTableColumns(long tableId) { - return Db.Queryable().Where(f => f.TableId == tableId).OrderBy(x => x.Sort).ToList(); + return GetTableColumnRepository.GenTableColumns(tableId); } /// @@ -153,7 +162,7 @@ namespace ZR.Service.System /// public int InsertGenTableColumn(List tableColumn) { - return Db.Insertable(tableColumn).IgnoreColumns(x => new { x.Remark }).ExecuteCommand(); + return GetTableColumnRepository.InsertGenTableColumn(tableColumn); } /// @@ -163,31 +172,7 @@ namespace ZR.Service.System /// public int UpdateGenTableColumn(List tableColumn) { - foreach (var item in tableColumn) - { - Db.Updateable() - .Where(f => f.TableId == item.TableId) - .SetColumns(it => new GenTableColumn() - { - ColumnComment = item.ColumnComment, - CsharpField = item.CsharpField, - CsharpType = item.CsharpType, - IsQuery = item.IsQuery, - IsEdit = item.IsEdit, - IsInsert = item.IsInsert, - IsList = item.IsList, - QueryType = item.QueryType, - HtmlType = item.HtmlType, - IsRequired = item.IsRequired, - Sort = item.Sort, - Update_time = DateTime.Now, - DictType = item.DictType - }) - .Where(f => f.ColumnId == item.ColumnId) - .ExecuteCommand(); - } - - return 1; + return GetTableColumnRepository.UpdateGenTableColumn(tableColumn); } } } diff --git a/ZR.Service/System/IService/ISysDeptService.cs b/ZR.Service/System/IService/ISysDeptService.cs index 4e90491..7a381f6 100644 --- a/ZR.Service/System/IService/ISysDeptService.cs +++ b/ZR.Service/System/IService/ISysDeptService.cs @@ -8,13 +8,13 @@ namespace ZR.Service.System.IService { public interface ISysDeptService : IBaseService { - public List GetSysDepts(SysDept dept); - public string CheckDeptNameUnique(SysDept dept); - public int InsertDept(SysDept dept); - public int UpdateDept(SysDept dept); - public void UpdateDeptChildren(long deptId, string newAncestors, string oldAncestors); - public List GetChildrenDepts(List depts, long deptId); - public List BuildDeptTree(List depts); - public List BuildDeptTreeSelect(List depts); + List GetSysDepts(SysDept dept); + string CheckDeptNameUnique(SysDept dept); + int InsertDept(SysDept dept); + int UpdateDept(SysDept dept); + void UpdateDeptChildren(long deptId, string newAncestors, string oldAncestors); + List GetChildrenDepts(List depts, long deptId); + List BuildDeptTree(List depts); + List BuildDeptTreeSelect(List depts); } } diff --git a/ZR.Service/System/IService/ISysDictDataService.cs b/ZR.Service/System/IService/ISysDictDataService.cs index d048b1a..7d57d66 100644 --- a/ZR.Service/System/IService/ISysDictDataService.cs +++ b/ZR.Service/System/IService/ISysDictDataService.cs @@ -5,7 +5,7 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysDictDataService : IBaseService + public interface ISysDictDataService { public List SelectDictDataList(SysDictData dictData); public List SelectDictDataByType(string dictType); diff --git a/ZR.Service/System/IService/ISysDictService.cs b/ZR.Service/System/IService/ISysDictService.cs index 6d99e7a..a6bd282 100644 --- a/ZR.Service/System/IService/ISysDictService.cs +++ b/ZR.Service/System/IService/ISysDictService.cs @@ -8,7 +8,7 @@ namespace ZR.Service.System.IService /// /// /// - public interface ISysDictService: IBaseService + public interface ISysDictService { public List SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager); @@ -39,5 +39,12 @@ namespace ZR.Service.System.IService /// /// public int UpdateDictType(SysDictType sysDictType); + + /// + /// 获取字典信息 + /// + /// + /// + SysDictType GetInfo(long dictId); } } diff --git a/ZR.Service/System/IService/ISysFileService.cs b/ZR.Service/System/IService/ISysFileService.cs index f223bff..99daf07 100644 --- a/ZR.Service/System/IService/ISysFileService.cs +++ b/ZR.Service/System/IService/ISysFileService.cs @@ -3,7 +3,7 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysFileService : IBaseService + public interface ISysFileService { } } diff --git a/ZR.Service/System/IService/ISysMenuService.cs b/ZR.Service/System/IService/ISysMenuService.cs index 8928c4e..90aea34 100644 --- a/ZR.Service/System/IService/ISysMenuService.cs +++ b/ZR.Service/System/IService/ISysMenuService.cs @@ -6,7 +6,7 @@ using ZR.Model.Vo.System; namespace ZR.Service.System.IService { - public interface ISysMenuService: IBaseService + public interface ISysMenuService { public List SelectMenuList(long userId); diff --git a/ZR.Service/System/IService/ISysOperLogService.cs b/ZR.Service/System/IService/ISysOperLogService.cs index 0029904..7f9eb76 100644 --- a/ZR.Service/System/IService/ISysOperLogService.cs +++ b/ZR.Service/System/IService/ISysOperLogService.cs @@ -6,7 +6,7 @@ using ZR.Service.System; namespace ZR.Service.System.IService { - public interface ISysOperLogService : IBaseService + public interface ISysOperLogService { public void InsertOperlog(SysOperLog operLog); diff --git a/ZR.Service/System/IService/ISysPostService.cs b/ZR.Service/System/IService/ISysPostService.cs index 9cd098b..e8d0abf 100644 --- a/ZR.Service/System/IService/ISysPostService.cs +++ b/ZR.Service/System/IService/ISysPostService.cs @@ -2,10 +2,11 @@ using System.Collections.Generic; using System.Text; using ZR.Model.System; +using ZR.Repository; namespace ZR.Service.System.IService { - public interface ISysPostService: IBaseService + public interface ISysPostService : IBaseService { string CheckPostNameUnique(SysPost sysPost); string CheckPostCodeUnique(SysPost sysPost); diff --git a/ZR.Service/System/IService/ISysRoleService.cs b/ZR.Service/System/IService/ISysRoleService.cs index 6f039fd..f4f2bcc 100644 --- a/ZR.Service/System/IService/ISysRoleService.cs +++ b/ZR.Service/System/IService/ISysRoleService.cs @@ -6,7 +6,7 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysRoleService: IBaseService + public interface ISysRoleService { /// /// 根据条件分页查询角色数据 diff --git a/ZR.Service/System/IService/ISysTasksLogService.cs b/ZR.Service/System/IService/ISysTasksLogService.cs index 48dbff4..cf0f16e 100644 --- a/ZR.Service/System/IService/ISysTasksLogService.cs +++ b/ZR.Service/System/IService/ISysTasksLogService.cs @@ -1,4 +1,5 @@ using ZR.Model.System; +using ZR.Repository; namespace ZR.Service.System.IService { diff --git a/ZR.Service/System/IService/ISysTasksQzService.cs b/ZR.Service/System/IService/ISysTasksQzService.cs index 69931d0..e7e0257 100644 --- a/ZR.Service/System/IService/ISysTasksQzService.cs +++ b/ZR.Service/System/IService/ISysTasksQzService.cs @@ -7,7 +7,8 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysTasksQzService: IBaseService + public interface ISysTasksQzService : IBaseService { + //SysTasksQz GetId(object id); } } diff --git a/ZR.Service/System/IService/ISysUserPostService.cs b/ZR.Service/System/IService/ISysUserPostService.cs index 0514047..193dfdd 100644 --- a/ZR.Service/System/IService/ISysUserPostService.cs +++ b/ZR.Service/System/IService/ISysUserPostService.cs @@ -3,12 +3,13 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysUserPostService: IBaseService + public interface ISysUserPostService { public void InsertUserPost(SysUser user); public List GetUserPostsByUserId(long userId); public string GetPostsStrByUserId(long userId); + int Delete(long userId); } } diff --git a/ZR.Service/System/IService/ISysUserService.cs b/ZR.Service/System/IService/ISysUserService.cs index f49e926..4f56323 100644 --- a/ZR.Service/System/IService/ISysUserService.cs +++ b/ZR.Service/System/IService/ISysUserService.cs @@ -8,7 +8,7 @@ using ZR.Model.System; namespace ZR.Service.System.IService { - public interface ISysUserService : IBaseService + public interface ISysUserService { public List SelectUserList(SysUser user, PagerInfo pager); diff --git a/ZR.Service/System/SysConfigService.cs b/ZR.Service/System/SysConfigService.cs new file mode 100644 index 0000000..8684572 --- /dev/null +++ b/ZR.Service/System/SysConfigService.cs @@ -0,0 +1,35 @@ +using Infrastructure; +using Infrastructure.Attribute; +using Infrastructure.Extensions; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using ZR.Common; +using ZR.Model.Models; +using ZR.Model.System; +using ZR.Repository; + +namespace ZR.Service.System +{ + /// + /// 参数配置Service业务层处理 + /// + /// @author zhaorui + /// @date 2021-09-29 + /// + [AppService(ServiceType = typeof(ISysConfigService), ServiceLifetime = LifeTime.Transient)] + public class SysConfigService: BaseService, ISysConfigService + { + private readonly SysConfigRepository _SysConfigrepository; + public SysConfigService(SysConfigRepository repository) + { + _SysConfigrepository = repository; + } + + #region 业务逻辑代码 + + #endregion + } +} \ No newline at end of file diff --git a/ZR.Service/System/SysDeptService.cs b/ZR.Service/System/SysDeptService.cs index a99c541..c2b56aa 100644 --- a/ZR.Service/System/SysDeptService.cs +++ b/ZR.Service/System/SysDeptService.cs @@ -40,7 +40,7 @@ namespace ZR.Service.System predicate = predicate.AndIF(dept.DeptName.IfNotEmpty(), it => it.DeptName.Contains(dept.DeptName)); predicate = predicate.AndIF(dept.Status.IfNotEmpty(), it => it.Status == dept.Status); - var response = GetWhere(predicate.ToExpression()); + var response = DeptRepository.GetList(predicate.ToExpression()); return response; } @@ -53,7 +53,7 @@ namespace ZR.Service.System public string CheckDeptNameUnique(SysDept dept) { long deptId = dept.DeptId == 0 ? -1L : dept.DeptId; - SysDept info = GetFirst(it => it.DeptName == dept.DeptName && it.ParentId == dept.ParentId); + SysDept info = DeptRepository.GetFirst(it => it.DeptName == dept.DeptName && it.ParentId == dept.ParentId); if (info != null && info.DeptId != deptId) { return UserConstants.NOT_UNIQUE; @@ -68,7 +68,7 @@ namespace ZR.Service.System /// public int InsertDept(SysDept dept) { - SysDept info = GetFirst(it => it.DeptId == dept.ParentId); + SysDept info = DeptRepository.GetSingle(it => it.DeptId == dept.ParentId); //如果父节点不为正常状态,则不允许新增子节点 if (!UserConstants.DEPT_NORMAL.Equals(info.Status)) { @@ -76,7 +76,7 @@ namespace ZR.Service.System } dept.Ancestors = info.Ancestors + "," + dept.ParentId; - return Add(dept); + return DeptRepository.Add(dept); } /// @@ -86,8 +86,8 @@ namespace ZR.Service.System /// public int UpdateDept(SysDept dept) { - SysDept newParentDept = GetFirst(it => it.ParentId == dept.ParentId); - SysDept oldDept = GetFirst(m => m.DeptId == dept.DeptId); + SysDept newParentDept = DeptRepository.GetFirst(it => it.ParentId == dept.ParentId); + SysDept oldDept = DeptRepository.GetFirst(m => m.DeptId == dept.DeptId); if (newParentDept != null && oldDept != null) { string newAncestors = newParentDept.Ancestors + "," + newParentDept.DeptId; @@ -95,7 +95,7 @@ namespace ZR.Service.System dept.Ancestors = newAncestors; UpdateDeptChildren(dept.DeptId, newAncestors, oldAncestors); } - int result = Update(dept); + int result = DeptRepository.Context.Updateable(dept).ExecuteCommand(); if (UserConstants.DEPT_NORMAL.Equals(dept.Status)) { // 如果该部门是启用状态,则启用该部门的所有上级部门 @@ -111,7 +111,7 @@ namespace ZR.Service.System private void UpdateParentDeptStatus(SysDept dept) { string updateBy = dept.Update_by; - dept = GetFirst(it => it.DeptId == dept.DeptId); + dept = DeptRepository.GetFirst(it => it.DeptId == dept.DeptId); dept.Update_by = updateBy; //DeptRepository.UpdateParentDeptStatus(dept); } @@ -129,12 +129,10 @@ namespace ZR.Service.System foreach (var child in children) { child.Ancestors = child.Ancestors.Replace(oldAncestors, newAncestors); - - if (child.DeptId.Equals(deptId)) - { - Saveable(child, it => new { it.Ancestors }); - //DeptRepository.UdateDeptChildren(child); - } + } + if (children.Count > 0) + { + //DeptRepository.UdateDeptChildren(child); } } diff --git a/ZR.Service/System/SysDictDataService.cs b/ZR.Service/System/SysDictDataService.cs index 92c7a01..2c698c8 100644 --- a/ZR.Service/System/SysDictDataService.cs +++ b/ZR.Service/System/SysDictDataService.cs @@ -10,7 +10,7 @@ using ZR.Service.System.IService; namespace ZR.Service.System { [AppService(ServiceType = typeof(ISysDictDataService), ServiceLifetime = LifeTime.Transient)] - public class SysDictDataService: BaseService, ISysDictDataService + public class SysDictDataService: ISysDictDataService { private readonly SysDictDataRepository SysDictDataRepository; @@ -37,7 +37,7 @@ namespace ZR.Service.System public List SelectDictDataByType(string dictType) { string CK = $"SelectDictDataByType_{dictType}"; - if (!(CacheHelper.GetCache(CK) is List list)) + if (CacheHelper.GetCache(CK) is not List list) { list = SysDictDataRepository.SelectDictDataByType(dictType); CacheHelper.SetCache(CK, list, 30); @@ -55,7 +55,7 @@ namespace ZR.Service.System string CK = $"SelectDictDataByCode_{dictCode}"; if (CacheHelper.GetCache(CK) is not SysDictData list) { - list = GetFirst(f => f.DictCode == dictCode); + list = SysDictDataRepository.GetFirst(f => f.DictCode == dictCode); CacheHelper.SetCache(CK, list, 5); } return list; @@ -78,7 +78,9 @@ namespace ZR.Service.System /// public long UpdateDictData(SysDictData dict) { - return SysDictDataRepository.UpdateDictData(dict); + var result = SysDictDataRepository.UpdateDictData(dict); + CacheHelper.Remove($"SelectDictDataByCode_{dict.DictCode}"); + return result; } /// diff --git a/ZR.Service/System/SysDictService.cs b/ZR.Service/System/SysDictService.cs index cf8c849..96a3395 100644 --- a/ZR.Service/System/SysDictService.cs +++ b/ZR.Service/System/SysDictService.cs @@ -13,14 +13,14 @@ namespace ZR.Service.System /// 字典类型 /// [AppService(ServiceType = typeof(ISysDictService), ServiceLifetime = LifeTime.Transient)] - public class SysDictService : BaseService, ISysDictService + public class SysDictService : ISysDictService { - private SysDictRepository sysDictRepository; + private SysDictRepository DictRepository; private SysDictDataRepository DictDataRepository; public SysDictService(SysDictRepository sysDictRepository, SysDictDataRepository dictDataRepository) { - this.sysDictRepository = sysDictRepository; + this.DictRepository = sysDictRepository; this.DictDataRepository = dictDataRepository; } @@ -31,7 +31,7 @@ namespace ZR.Service.System /// public List SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager) { - return sysDictRepository.SelectDictTypeList(dictType, pager); + return DictRepository.SelectDictTypeList(dictType, pager); } /// @@ -41,7 +41,7 @@ namespace ZR.Service.System /// public string CheckDictTypeUnique(SysDictType dictType) { - SysDictType sysDictType = GetFirst(f => f.DictType == dictType.DictType); + SysDictType sysDictType = DictRepository.GetFirst(f => f.DictType == dictType.DictType); if (sysDictType != null && sysDictType.DictId != dictType.DictId) { return UserConstants.NOT_UNIQUE; @@ -58,13 +58,13 @@ namespace ZR.Service.System { foreach (var dictId in dictIds) { - SysDictType dictType = GetFirst(x => x.DictId == dictId); - if (GetCount(f => f.DictType == dictType.DictType) > 0) + SysDictType dictType = DictRepository.GetFirst(x => x.DictId == dictId); + if (DictRepository.Count(f => f.DictType == dictType.DictType) > 0) { throw new CustomException($"{dictType.DictName}已分配,不能删除"); } } - int count = sysDictRepository.DeleteDictTypeByIds(dictIds); + int count = DictRepository.DeleteDictTypeByIds(dictIds); //if (count > 0) //{ // DictUtils.clearDictCache(); @@ -79,7 +79,7 @@ namespace ZR.Service.System /// public long InsertDictType(SysDictType sysDictType) { - return Saveable(sysDictType, iColumns: it => new { sysDictType.Update_by }).DictId; + return DictRepository.InsertReturnBigIdentity(sysDictType); } /// @@ -89,13 +89,23 @@ namespace ZR.Service.System /// public int UpdateDictType(SysDictType sysDictType) { - SysDictType oldDict = GetFirst(x => x.DictId == sysDictType.DictId); + SysDictType oldDict = DictRepository.GetFirst(x => x.DictId == sysDictType.DictId); if (sysDictType.DictType != oldDict.DictType) { //同步修改 dict_data表里面的DictType值 DictDataRepository.UpdateDictDataType(oldDict.DictType, sysDictType.DictType); } - return sysDictRepository.UpdateDictType(sysDictType); + return DictRepository.UpdateDictType(sysDictType); + } + + /// + /// 获取字典信息 + /// + /// + /// + public SysDictType GetInfo(long dictId) + { + return DictRepository.GetFirst(f => f.DictId == dictId); } } } diff --git a/ZR.Service/System/SysFileService.cs b/ZR.Service/System/SysFileService.cs index 5098a88..7a0741d 100644 --- a/ZR.Service/System/SysFileService.cs +++ b/ZR.Service/System/SysFileService.cs @@ -8,7 +8,7 @@ namespace ZR.Service.System /// 文件管理 /// [AppService(ServiceType = typeof(ISysFileService), ServiceLifetime = LifeTime.Transient)] - public class SysFileService: BaseService, ISysFileService + public class SysFileService : ISysFileService { } diff --git a/ZR.Service/System/SysMenuService.cs b/ZR.Service/System/SysMenuService.cs index 780a468..cbc39c6 100644 --- a/ZR.Service/System/SysMenuService.cs +++ b/ZR.Service/System/SysMenuService.cs @@ -15,7 +15,7 @@ namespace ZR.Service /// 菜单 /// [AppService(ServiceType = typeof(ISysMenuService), ServiceLifetime = LifeTime.Transient)] - public class SysMenuService: BaseService, ISysMenuService + public class SysMenuService: ISysMenuService { public SysMenuRepository MenuRepository; public ISysRoleService SysRoleService; diff --git a/ZR.Service/System/SysOperLogService.cs b/ZR.Service/System/SysOperLogService.cs index 80a5f5f..043ba8c 100644 --- a/ZR.Service/System/SysOperLogService.cs +++ b/ZR.Service/System/SysOperLogService.cs @@ -13,7 +13,7 @@ namespace ZR.Service.System /// 操作日志 /// [AppService(ServiceType = typeof(ISysOperLogService), ServiceLifetime = LifeTime.Transient)] - public class SysOperLogService: BaseService, ISysOperLogService + public class SysOperLogService : ISysOperLogService { public SysOperLogRepository sysOperLogRepository; diff --git a/ZR.Service/System/SysPostService.cs b/ZR.Service/System/SysPostService.cs index 39808a5..5a5e977 100644 --- a/ZR.Service/System/SysPostService.cs +++ b/ZR.Service/System/SysPostService.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; using System.Text; using ZR.Model.System; +using ZR.Repository; +using ZR.Repository.System; using ZR.Service.System.IService; namespace ZR.Service.System @@ -13,6 +15,12 @@ namespace ZR.Service.System [AppService(ServiceType = typeof(ISysPostService), ServiceLifetime = LifeTime.Transient)] public class SysPostService : BaseService, ISysPostService { + public SysPostRepository PostRepository; + public SysPostService(SysPostRepository postRepository) + { + PostRepository = postRepository; + } + /// /// 校验岗位编码是否唯一 /// @@ -20,7 +28,7 @@ namespace ZR.Service.System /// public string CheckPostCodeUnique(SysPost post) { - SysPost info = GetFirst(it => it.PostCode.Equals(post.PostCode)); + SysPost info = PostRepository.GetFirst(it => it.PostCode.Equals(post.PostCode)); if (info != null && info.PostId != post.PostId) { return UserConstants.NOT_UNIQUE; @@ -35,7 +43,7 @@ namespace ZR.Service.System /// public string CheckPostNameUnique(SysPost post) { - SysPost info = GetFirst(it => it.PostName.Equals(post.PostName)); + SysPost info = PostRepository.GetFirst(it => it.PostName.Equals(post.PostName)); if (info != null && info.PostId != post.PostId) { return UserConstants.NOT_UNIQUE; diff --git a/ZR.Service/System/SysRoleService.cs b/ZR.Service/System/SysRoleService.cs index c42b5fd..94b82f4 100644 --- a/ZR.Service/System/SysRoleService.cs +++ b/ZR.Service/System/SysRoleService.cs @@ -15,7 +15,7 @@ namespace ZR.Service /// 角色 /// [AppService(ServiceType = typeof(ISysRoleService), ServiceLifetime = LifeTime.Transient)] - public class SysRoleService: BaseService, ISysRoleService + public class SysRoleService: ISysRoleService { private SysRoleRepository SysRoleRepository; private ISysUserRoleService SysUserRoleService; diff --git a/ZR.Service/System/SysTasksLogService.cs b/ZR.Service/System/SysTasksLogService.cs index 25f56e4..7b7ae0d 100644 --- a/ZR.Service/System/SysTasksLogService.cs +++ b/ZR.Service/System/SysTasksLogService.cs @@ -1,12 +1,13 @@ using Infrastructure.Attribute; using System; using ZR.Model.System; +using ZR.Repository; using ZR.Service.System.IService; namespace ZR.Service.System { [AppService(ServiceLifetime = LifeTime.Transient, ServiceType = typeof(ISysTasksLogService))] - public class SysTasksLogService : BaseService, ISysTasksLogService + public class SysTasksLogService : BaseRepository, ISysTasksLogService { private ISysTasksQzService _tasksQzService; public SysTasksLogService(ISysTasksQzService tasksQzService) diff --git a/ZR.Service/System/SysUserPostService.cs b/ZR.Service/System/SysUserPostService.cs index c312d31..78c4fa4 100644 --- a/ZR.Service/System/SysUserPostService.cs +++ b/ZR.Service/System/SysUserPostService.cs @@ -13,10 +13,9 @@ namespace ZR.Service.System /// 用户岗位 /// [AppService(ServiceType = typeof(ISysUserPostService), ServiceLifetime = LifeTime.Transient)] - public class SysUserPostService : BaseService, ISysUserPostService + public class SysUserPostService : ISysUserPostService { - public SysUserPostRepository UserPostRepository; - + private SysUserPostRepository UserPostRepository; public SysUserPostService(SysUserPostRepository userPostRepository) { UserPostRepository = userPostRepository; @@ -34,7 +33,7 @@ namespace ZR.Service.System { list.Add(new SysUserPost() { PostId = item, UserId = user.UserId }); } - Add(list); + UserPostRepository.Insert(list); } @@ -45,7 +44,7 @@ namespace ZR.Service.System /// public List GetUserPostsByUserId(long userId) { - var list = GetWhere(f => f.UserId == userId); + var list = UserPostRepository.GetList(f => f.UserId == userId); return list.Select(x => x.PostId).ToList(); } @@ -59,5 +58,10 @@ namespace ZR.Service.System var list = UserPostRepository.SelectPostsByUserId(userId); return string.Join(',', list.Select(x => x.PostName)); } + + public int Delete(long userId) + { + return UserPostRepository.Delete(x => x.UserId == userId) ? 1: 0 ; + } } } diff --git a/ZR.Service/System/SysUserService.cs b/ZR.Service/System/SysUserService.cs index 23b972e..919d494 100644 --- a/ZR.Service/System/SysUserService.cs +++ b/ZR.Service/System/SysUserService.cs @@ -11,7 +11,7 @@ using ZR.Service.System.IService; namespace ZR.Service { [AppService(ServiceType = typeof(ISysUserService), ServiceLifetime = LifeTime.Transient)] - public class SysUserService : BaseService, ISysUserService + public class SysUserService : ISysUserService { private readonly SysUserRepository UserRepository; private readonly ISysRoleService RoleService; @@ -101,7 +101,7 @@ namespace ZR.Service UserRoleService.InsertUserRole(user); } // 删除用户与岗位关联 - UserPostService.Delete(it => it.UserId == user.UserId); + UserPostService.Delete(user.UserId); // 新增用户与岗位管理 UserPostService.InsertUserPost(user); return UserRepository.UpdateUser(user); diff --git a/ZR.Vue/.env.development b/ZR.Vue/.env.development index b6be2a4..2028595 100644 --- a/ZR.Vue/.env.development +++ b/ZR.Vue/.env.development @@ -1,11 +1,9 @@ +# 关于此文件说明 必须以VUE_APP开头 # 开发环境配置 ENV = 'development' # ZR管理系统/开发环境 VUE_APP_BASE_API = 'http://localhost:8888/' -# 路由懒加载 -VUE_CLI_BABEL_TRANSPILE_MODULES = true - # 路由前缀 -VUE_ROUTER_PREFIX = '/' +VUE_APP_ROUTER_PREFIX = '' diff --git a/ZR.Vue/.env.production b/ZR.Vue/.env.production index 08c684f..dc272e2 100644 --- a/ZR.Vue/.env.production +++ b/ZR.Vue/.env.production @@ -5,4 +5,4 @@ ENV = 'production' VUE_APP_BASE_API = '/prod-api' # 路由前缀 -VUE_ROUTER_PREFIX = '/' +VUE_APP_ROUTER_PREFIX = '' diff --git a/ZR.Vue/package.json b/ZR.Vue/package.json index fce507a..798a711 100644 --- a/ZR.Vue/package.json +++ b/ZR.Vue/package.json @@ -44,7 +44,6 @@ "vue-count-to": "1.0.13", "vue-cropper": "0.4.9", "vue-router": "3.0.2", - "vue-splitpane": "1.0.4", "vuedraggable": "2.20.0", "vuex": "3.1.0" }, @@ -58,7 +57,7 @@ "babel-eslint": "10.1.0", "babel-jest": "23.6.0", "babel-plugin-dynamic-import-node": "2.3.3", - "chalk": "2.4.2", + "chalk": "4.1.0", "chokidar": "2.1.5", "connect": "3.6.6", "eslint": "6.7.2", @@ -69,7 +68,6 @@ "lint-staged": "8.1.5", "node-sass": "4.14.1", "plop": "2.3.0", - "qs": "^6.9.4", "runjs": "4.3.2", "sass-loader": "8.0.2", "script-ext-html-webpack-plugin": "2.1.3", diff --git a/ZR.Vue/src/api/common.js b/ZR.Vue/src/api/common.js index 51044b3..b106f3b 100644 --- a/ZR.Vue/src/api/common.js +++ b/ZR.Vue/src/api/common.js @@ -8,3 +8,16 @@ export function upload(data) { headers: { "Content-Type": "multipart/form-data" }, }) } + +/** + * 发送邮件 + * @param {*} data + * @returns + */ +export function sendEmail(data) { + return request({ + url: '/home/SendEmail', + method: 'POST', + data: data, + }) +} diff --git a/ZR.Vue/src/api/gendemo.js b/ZR.Vue/src/api/gendemo.js new file mode 100644 index 0000000..394e903 --- /dev/null +++ b/ZR.Vue/src/api/gendemo.js @@ -0,0 +1,59 @@ +import request from '@/utils/request' + +/** + * 代码生成演示分页查询 + * @param {查询条件} data + */ +export function listGendemo(query) { + return request({ + url: 'business/Gendemo/list', + method: 'get', + params: query, + }) +} + +/** + * 新增代码生成演示 + * @param data + */ +export function addGendemo(data) { + return request({ + url: 'business/Gendemo', + method: 'post', + data: data, + }) +} + +/** + * 修改代码生成演示 + * @param data + */ +export function updateGendemo(data) { + return request({ + url: 'business/Gendemo', + method: 'PUT', + data: data, + }) +} + +/** + * 获取代码生成演示详情 + * @param {Id} 代码生成演示Id + */ +export function getGendemo(id) { + return request({ + url: 'business/Gendemo/' + id, + method: 'get' + }) +} + +/** + * 删除 + * @param {主键} pid + */ +export function delGendemo(pid) { + return request({ + url: 'business/Gendemo/' + pid, + method: 'delete' + }) +} diff --git a/ZR.Vue/src/api/system/config.js b/ZR.Vue/src/api/system/config.js new file mode 100644 index 0000000..3633ba1 --- /dev/null +++ b/ZR.Vue/src/api/system/config.js @@ -0,0 +1,69 @@ +import request from '@/utils/request' + +// 查询参数列表 +export function listConfig(query) { + return request({ + url: '/system/config/list', + method: 'get', + params: query + }) +} + +// 查询参数详细 +export function getConfig(configId) { + return request({ + url: '/system/config/' + configId, + method: 'get' + }) +} + +// 根据参数键名查询参数值 +export function getConfigKey(configKey) { + return request({ + url: '/system/config/configKey/' + configKey, + method: 'get' + }) +} + +// 新增参数配置 +export function addConfig(data) { + return request({ + url: '/system/config', + method: 'post', + data: data + }) +} + +// 修改参数配置 +export function updateConfig(data) { + return request({ + url: '/system/config', + method: 'put', + data: data + }) +} + +// 删除参数配置 +export function delConfig(configId) { + return request({ + url: '/system/config/' + configId, + method: 'delete' + }) +} + +// 刷新参数缓存 +export function refreshCache() { + return request({ + url: '/system/config/refreshCache', + method: 'delete' + }) +} + +// 导出参数 +// export function exportConfig(query) { +// return request({ +// url: '/system/config/export', +// method: 'get', +// params: query +// }) +// } diff --git a/ZR.Vue/src/assets/image/dark.svg b/ZR.Vue/src/assets/image/dark.svg new file mode 100644 index 0000000..f646bd7 --- /dev/null +++ b/ZR.Vue/src/assets/image/dark.svg @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ZR.Vue/src/assets/image/light.svg b/ZR.Vue/src/assets/image/light.svg new file mode 100644 index 0000000..ab7cc08 --- /dev/null +++ b/ZR.Vue/src/assets/image/light.svg @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ZR.Vue/src/assets/styles/sidebar.scss b/ZR.Vue/src/assets/styles/sidebar.scss index 17381fc..2e68730 100644 --- a/ZR.Vue/src/assets/styles/sidebar.scss +++ b/ZR.Vue/src/assets/styles/sidebar.scss @@ -3,22 +3,26 @@ .main-container { min-height: 100%; transition: margin-left .28s; - margin-left: $sideBarWidth; + margin-left: $base-sidebar-width; position: relative; } .sidebar-container { + -webkit-transition: width .28s; transition: width 0.28s; - width: $sideBarWidth !important; - background-color: $menuBg; + width: $base-sidebar-width !important; + background-color: $base-menu-background; height: 100%; position: fixed; - font-size: 0; + font-size: 0px; top: 0; bottom: 0; left: 0; z-index: 1001; overflow: hidden; + // 有改动 + -webkit-box-shadow: 2px 0 14px rgba(0,21,41 , .10); + box-shadow: 2px 0 14px rgba(0,21,41 , .10); // reset element-ui css .horizontal-collapse-transition { @@ -30,7 +34,7 @@ } .el-scrollbar__bar.is-vertical { - right: 0; + right: 0px; } .el-scrollbar { @@ -63,25 +67,39 @@ width: 100% !important; } + .el-menu-item, .el-submenu__title { + overflow: hidden !important; + text-overflow: ellipsis !important; + white-space: nowrap !important; + } + // menu hover .submenu-title-noDropdown, .el-submenu__title { &:hover { - background-color: $menuHover !important; + background-color: rgba(0, 0, 0, 0.06) !important; } } - .is-active>.el-submenu__title { - color: $subMenuActiveText !important; + & .theme-dark .is-active > .el-submenu__title { + color: $base-menu-color-active !important; } & .nest-menu .el-submenu>.el-submenu__title, & .el-submenu .el-menu-item { - min-width: $sideBarWidth !important; - background-color: $subMenuBg !important; + min-width: $base-sidebar-width !important; &:hover { - background-color: $subMenuHover !important; + background-color: rgba(0, 0, 0, 0.06) !important; + } + } + + & .theme-dark .nest-menu .el-submenu>.el-submenu__title, + & .theme-dark .el-submenu .el-menu-item { + background-color: $base-sub-menu-background !important; + + &:hover { + background-color: $base-sub-menu-hover !important; } } } @@ -118,9 +136,6 @@ margin-left: 20px; } - .el-submenu__icon-arrow { - display: none; - } } } @@ -140,25 +155,25 @@ } .el-menu--collapse .el-menu .el-submenu { - min-width: $sideBarWidth !important; + min-width: $base-sidebar-width !important; } // mobile responsive .mobile { .main-container { - margin-left: 0; + margin-left: 0px; } .sidebar-container { transition: transform .28s; - width: $sideBarWidth !important; + width: $base-sidebar-width !important; } &.hideSidebar { .sidebar-container { pointer-events: none; transition-duration: 0.3s; - transform: translate3d(-$sideBarWidth, 0, 0); + transform: translate3d(-$base-sidebar-width, 0, 0); } } } @@ -184,7 +199,7 @@ .el-menu-item { &:hover { // you can use $subMenuHover - background-color: $menuHover !important; + background-color: rgba(0, 0, 0, 0.06) !important; } } diff --git a/ZR.Vue/src/assets/styles/variables.scss b/ZR.Vue/src/assets/styles/variables.scss index 5688f25..86ae632 100644 --- a/ZR.Vue/src/assets/styles/variables.scss +++ b/ZR.Vue/src/assets/styles/variables.scss @@ -8,28 +8,35 @@ $tiffany: #4AB7BD; $yellow:#FEC171; $panGreen: #30B08F; -// sidebar -$menuText:#bfcbd9; -$menuActiveText:#409EFF; -$subMenuActiveText:#f4f4f5; // https://github.com/ElemeFE/element/issues/12951 +// 默认菜单主题风格 +$base-menu-color:#bfcbd9; +$base-menu-color-active:#f4f4f5; +$base-menu-background:#304156; +$base-logo-title-color: #ffffff; -$menuBg:#304156; -$menuHover:#263445; +$base-menu-light-color:rgba(0,0,0,.70); +$base-menu-light-background:#ffffff; +$base-logo-light-title-color: #001529; -$subMenuBg:#1f2d3d; -$subMenuHover:#001528; +$base-sub-menu-background:#1f2d3d; +$base-sub-menu-hover:#001528; -$sideBarWidth: 200px; + + +$base-sidebar-width: 200px; // the :export directive is the magic sauce for webpack // https://www.bluematador.com/blog/how-to-share-variables-between-js-and-sass :export { - menuText: $menuText; - menuActiveText: $menuActiveText; - subMenuActiveText: $subMenuActiveText; - menuBg: $menuBg; - menuHover: $menuHover; - subMenuBg: $subMenuBg; - subMenuHover: $subMenuHover; - sideBarWidth: $sideBarWidth; + menuColor: $base-menu-color; + menuLightColor: $base-menu-light-color; + menuColorActive: $base-menu-color-active; + menuBackground: $base-menu-background; + menuLightBackground: $base-menu-light-background; + subMenuBackground: $base-sub-menu-background; + subMenuHover: $base-sub-menu-hover; + sideBarWidth: $base-sidebar-width; + logoTitleColor: $base-logo-title-color; + logoLightTitleColor: $base-logo-light-title-color } + diff --git a/ZR.Vue/src/components/DictData/index.js b/ZR.Vue/src/components/DictData/index.js new file mode 100644 index 0000000..c2a0359 --- /dev/null +++ b/ZR.Vue/src/components/DictData/index.js @@ -0,0 +1,21 @@ +import Vue from 'vue' +import DataDict from '@/utils/dict' +import { getDicts as getDicts } from '@/api/system/dict/data' + +function install() { + Vue.use(DataDict, { + metas: { + '*': { + labelField: 'dictLabel', + valueField: 'dictValue', + request(dictMeta) { + return getDicts(dictMeta.type).then(res => res.data) + }, + }, + }, + }) +} + +export default { + install, +} \ No newline at end of file diff --git a/ZR.Vue/src/components/DictTag/index.vue b/ZR.Vue/src/components/DictTag/index.vue new file mode 100644 index 0000000..ed4712d --- /dev/null +++ b/ZR.Vue/src/components/DictTag/index.vue @@ -0,0 +1,39 @@ + + + + diff --git a/ZR.Vue/src/components/ThemePicker/index.vue b/ZR.Vue/src/components/ThemePicker/index.vue index bf13c28..d8f9d1e 100644 --- a/ZR.Vue/src/components/ThemePicker/index.vue +++ b/ZR.Vue/src/components/ThemePicker/index.vue @@ -42,6 +42,7 @@ export default { methods: { async setTheme(val) { + console.log('%c setTheme Color','color:' + val) const oldVal = this.chalk ? this.theme : ORIGINAL_THEME if (typeof val !== 'string') return const themeCluster = this.getThemeCluster(val.replace('#', '')) diff --git a/ZR.Vue/src/components/TopNav/index.vue b/ZR.Vue/src/components/TopNav/index.vue index 8cc019e..32358ef 100644 --- a/ZR.Vue/src/components/TopNav/index.vue +++ b/ZR.Vue/src/components/TopNav/index.vue @@ -8,7 +8,7 @@ - +