From 84d1e706db2517b50b22f1f19bf6104394645057 Mon Sep 17 00:00:00 2001 From: samisgod <21gh@163.com> Date: Wed, 15 Dec 2021 16:12:22 +0800 Subject: [PATCH] SysNotice Implement --- .../Controllers/System/SysNoticeController.cs | 150 +++++++++++++++++- ZR.Model/System/Dto/SysNoticeDto.cs | 32 ++++ ZR.Model/System/SysNotice.cs | 48 ++++++ ZR.Repository/System/SysNoticeRepository.cs | 20 +++ .../System/IService/ISysNoticeService.cs | 15 ++ ZR.Service/System/SysNoticeService.cs | 29 ++++ ZR.Vue/src/views/system/notice/index.vue | 40 ++--- document/admin-sqlserver-表字段说明导入.sql | Bin 108670 -> 113344 bytes document/admin-sqlserver.sql | Bin 113514 -> 117700 bytes 9 files changed, 312 insertions(+), 22 deletions(-) create mode 100644 ZR.Model/System/Dto/SysNoticeDto.cs create mode 100644 ZR.Model/System/SysNotice.cs create mode 100644 ZR.Repository/System/SysNoticeRepository.cs create mode 100644 ZR.Service/System/IService/ISysNoticeService.cs create mode 100644 ZR.Service/System/SysNoticeService.cs diff --git a/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs b/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs index 4608c15..2b4b911 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs @@ -3,16 +3,158 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Infrastructure; +using Infrastructure.Attribute; +using Infrastructure.Enums; +using Infrastructure.Model; +using Mapster; +using SqlSugar; +using ZR.Admin.WebApi.Extensions; +using ZR.Admin.WebApi.Filters; +using ZR.Common; +using ZR.Model.Dto; +using ZR.Model.Models; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System { [Route("system/notice")] public class SysNoticeController : BaseController { - [HttpGet("list")] - public IActionResult Index() + /// + /// 通知公告表接口 + /// + private readonly ISysNoticeService _SysNoticeService; + + public SysNoticeController(ISysNoticeService SysNoticeService) { - return SUCCESS(null); + _SysNoticeService = SysNoticeService; + } + + /// + /// 查询通知公告表列表 + /// + /// + [HttpGet("list")] + [ActionPermissionFilter(Permission = "system:sysnotice:list")] + public IActionResult QuerySysNotice([FromQuery] SysNoticeQueryDto parm) + { + //开始拼装查询条件 + var predicate = Expressionable.Create(); + + //搜索条件查询语法参考Sqlsugar + predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.NoticeTitle), m => m.NoticeTitle.Contains(parm.NoticeTitle)); + predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.NoticeType), m => m.NoticeType == parm.NoticeType); + predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.CreateBy), m => m.Create_by.Contains(parm.CreateBy) || m.Update_by.Contains(parm.CreateBy)); + var response = _SysNoticeService.GetPages(predicate.ToExpression(), parm); + return SUCCESS(response); + } + + /// + /// 查询通知公告表详情 + /// + /// + /// + [HttpGet("{NoticeId}")] + [ActionPermissionFilter(Permission = "system:sysnotice:query")] + public IActionResult GetSysNotice(int NoticeId) + { + var response = _SysNoticeService.GetFirst(x => x.NoticeId == NoticeId); + + return SUCCESS(response); + } + + /// + /// 添加通知公告表 + /// + /// + [HttpPost] + [ActionPermissionFilter(Permission = "system:sysnotice:add")] + [Log(Title = "通知公告表", BusinessType = BusinessType.INSERT)] + public IActionResult AddSysNotice([FromBody] SysNoticeDto parm) + { + if (parm == null) + { + throw new CustomException("请求参数错误"); + } + //从 Dto 映射到 实体 + var model = parm.Adapt().ToCreate(HttpContext); + model.Create_by = User.Identity.Name; + model.Create_time = DateTime.Now; + + return SUCCESS(_SysNoticeService.Insert(model, it => new + { + it.NoticeTitle, + it.NoticeType, + it.NoticeContent, + it.Status, + it.Remark, + it.Create_by, + it.Create_time + })); + } + + /// + /// 更新通知公告表 + /// + /// + [HttpPut] + [ActionPermissionFilter(Permission = "system:sysnotice:update")] + [Log(Title = "通知公告表", BusinessType = BusinessType.UPDATE)] + public IActionResult UpdateSysNotice([FromBody] SysNoticeDto parm) + { + if (parm == null) + { + throw new CustomException("请求实体不能为空"); + } + //从 Dto 映射到 实体 + var model = parm.Adapt().ToUpdate(HttpContext); + + var response = _SysNoticeService.Update(w => w.NoticeId == model.NoticeId, it => new SysNotice() + { + //Update 字段映射 + NoticeTitle = model.NoticeTitle, + NoticeType = model.NoticeType, + NoticeContent = model.NoticeContent, + Status = model.Status, + Remark = model.Remark, + Update_by = User.Identity.Name, + Update_time = DateTime.Now + }); + + return SUCCESS(response); + } + + /// + /// 删除通知公告表 + /// + /// + [HttpDelete("{ids}")] + [ActionPermissionFilter(Permission = "system:sysnotice:delete")] + [Log(Title = "通知公告表", BusinessType = BusinessType.DELETE)] + public IActionResult DeleteSysNotice(string ids) + { + int[] idsArr = Tools.SpitIntArrary(ids); + if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } + + var response = _SysNoticeService.Delete(idsArr); + + return SUCCESS(response); + } + + /// + /// 通知公告表导出 + /// + /// + [Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "通知公告表")] + [HttpGet("export")] + [ActionPermissionFilter(Permission = "system:sysnotice:export")] + public IActionResult Export() + { + var list = _SysNoticeService.GetAll(); + + string sFileName = ExportExcel(list, "SysNotice", "通知公告表"); + return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName }); } } -} +} \ No newline at end of file diff --git a/ZR.Model/System/Dto/SysNoticeDto.cs b/ZR.Model/System/Dto/SysNoticeDto.cs new file mode 100644 index 0000000..7ceb563 --- /dev/null +++ b/ZR.Model/System/Dto/SysNoticeDto.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using ZR.Model.Dto; +using ZR.Model.Models; + +namespace ZR.Model.Dto +{ + /// + /// 通知公告表输入对象 + /// + public class SysNoticeDto + { + public int NoticeId { get; set; } + public string NoticeTitle { get; set; } + public string NoticeType { get; set; } + public string NoticeContent { get; set; } + public string Status { get; set; } + public string Remark { get; set; } + } + + /// + /// 通知公告表查询对象 + /// + public class SysNoticeQueryDto : PagerInfo + { + public string NoticeTitle { get; set; } + public string NoticeType { get; set; } + public string CreateBy { get; set; } + } +} diff --git a/ZR.Model/System/SysNotice.cs b/ZR.Model/System/SysNotice.cs new file mode 100644 index 0000000..47facb7 --- /dev/null +++ b/ZR.Model/System/SysNotice.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using SqlSugar; +using ZR.Model.System; + +namespace ZR.Model.Models +{ + /// + /// 通知公告表,数据实体对象 + /// + /// @author zr + /// @date 2021-12-15 + /// + [SugarTable("sys_notice")] + [Tenant(0)] + public class SysNotice : SysBase + { + /// + /// 描述 : 公告ID + /// 空值 : true + /// + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "notice_id")] + public int NoticeId { get; set; } + /// + /// 描述 : 公告标题 + /// 空值 : true + /// + [SugarColumn(ColumnName = "notice_title")] + public string NoticeTitle { get; set; } + /// + /// 描述 : 公告类型 (1通知 2公告) + /// 空值 : true + /// + [SugarColumn(ColumnName = "notice_type")] + public string NoticeType { get; set; } + /// + /// 描述 : 公告内容 + /// 空值 : true + /// + [SugarColumn(ColumnName = "notice_content")] + public string NoticeContent { get; set; } + /// + /// 描述 : 公告状态 (0正常 1关闭) + /// 空值 : true + /// + public string Status { get; set; } + } +} \ No newline at end of file diff --git a/ZR.Repository/System/SysNoticeRepository.cs b/ZR.Repository/System/SysNoticeRepository.cs new file mode 100644 index 0000000..d6ccd5c --- /dev/null +++ b/ZR.Repository/System/SysNoticeRepository.cs @@ -0,0 +1,20 @@ +using System; +using Infrastructure.Attribute; +using ZR.Repository.System; +using ZR.Model.Models; + +namespace ZR.Repository.System +{ + /// + /// 通知公告表仓储 + /// + /// @author zr + /// @date 2021-12-15 + /// + [AppService(ServiceLifetime = LifeTime.Transient)] + public class SysNoticeRepository : BaseRepository + { + #region 业务逻辑代码 + #endregion + } +} \ No newline at end of file diff --git a/ZR.Service/System/IService/ISysNoticeService.cs b/ZR.Service/System/IService/ISysNoticeService.cs new file mode 100644 index 0000000..9bdc748 --- /dev/null +++ b/ZR.Service/System/IService/ISysNoticeService.cs @@ -0,0 +1,15 @@ +using System; +using ZR.Model.Models; + +namespace ZR.Service.System.IService +{ + /// + /// 通知公告表service接口 + /// + /// @author zr + /// @date 2021-12-15 + /// + public interface ISysNoticeService: IBaseService + { + } +} diff --git a/ZR.Service/System/SysNoticeService.cs b/ZR.Service/System/SysNoticeService.cs new file mode 100644 index 0000000..bbe5d28 --- /dev/null +++ b/ZR.Service/System/SysNoticeService.cs @@ -0,0 +1,29 @@ +using Infrastructure; +using Infrastructure.Attribute; +using ZR.Model.Models; +using ZR.Repository; +using ZR.Repository.System; +using ZR.Service.System.IService; + +namespace ZR.Service.System +{ + /// + /// 通知公告表Service业务层处理 + /// + /// @author zr + /// @date 2021-12-15 + /// + [AppService(ServiceType = typeof(ISysNoticeService), ServiceLifetime = LifeTime.Transient)] + public class SysNoticeService : BaseService, ISysNoticeService + { + private readonly SysNoticeRepository _SysNoticerepository; + public SysNoticeService(SysNoticeRepository repository) : base(repository) + { + _SysNoticerepository = repository; + } + + #region 业务逻辑代码 + + #endregion + } +} \ No newline at end of file diff --git a/ZR.Vue/src/views/system/notice/index.vue b/ZR.Vue/src/views/system/notice/index.vue index 05f9735..da9775c 100644 --- a/ZR.Vue/src/views/system/notice/index.vue +++ b/ZR.Vue/src/views/system/notice/index.vue @@ -13,21 +13,21 @@ - 搜索 + 搜索 重置 - 新增 + 新增 - 修改 + 修改 - 删除 + 删除 @@ -37,8 +37,16 @@ - - + + + + + +