SysNotice Implement

This commit is contained in:
samisgod 2021-12-15 16:12:22 +08:00 committed by 不做码农
parent 93dd3b0826
commit 84d1e706db
9 changed files with 312 additions and 22 deletions

View File

@ -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()
/// <summary>
/// 通知公告表接口
/// </summary>
private readonly ISysNoticeService _SysNoticeService;
public SysNoticeController(ISysNoticeService SysNoticeService)
{
return SUCCESS(null);
_SysNoticeService = SysNoticeService;
}
/// <summary>
/// 查询通知公告表列表
/// </summary>
/// <returns></returns>
[HttpGet("list")]
[ActionPermissionFilter(Permission = "system:sysnotice:list")]
public IActionResult QuerySysNotice([FromQuery] SysNoticeQueryDto parm)
{
//开始拼装查询条件
var predicate = Expressionable.Create<SysNotice>();
//搜索条件查询语法参考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);
}
/// <summary>
/// 查询通知公告表详情
/// </summary>
/// <param name="NoticeId"></param>
/// <returns></returns>
[HttpGet("{NoticeId}")]
[ActionPermissionFilter(Permission = "system:sysnotice:query")]
public IActionResult GetSysNotice(int NoticeId)
{
var response = _SysNoticeService.GetFirst(x => x.NoticeId == NoticeId);
return SUCCESS(response);
}
/// <summary>
/// 添加通知公告表
/// </summary>
/// <returns></returns>
[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<SysNotice>().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
}));
}
/// <summary>
/// 更新通知公告表
/// </summary>
/// <returns></returns>
[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<SysNotice>().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);
}
/// <summary>
/// 删除通知公告表
/// </summary>
/// <returns></returns>
[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);
}
/// <summary>
/// 通知公告表导出
/// </summary>
/// <returns></returns>
[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 });
}
}
}
}

View File

@ -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
{
/// <summary>
/// 通知公告表输入对象
/// </summary>
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; }
}
/// <summary>
/// 通知公告表查询对象
/// </summary>
public class SysNoticeQueryDto : PagerInfo
{
public string NoticeTitle { get; set; }
public string NoticeType { get; set; }
public string CreateBy { get; set; }
}
}

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using SqlSugar;
using ZR.Model.System;
namespace ZR.Model.Models
{
/// <summary>
/// 通知公告表,数据实体对象
///
/// @author zr
/// @date 2021-12-15
/// </summary>
[SugarTable("sys_notice")]
[Tenant(0)]
public class SysNotice : SysBase
{
/// <summary>
/// 描述 : 公告ID
/// 空值 : true
/// </summary>
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "notice_id")]
public int NoticeId { get; set; }
/// <summary>
/// 描述 : 公告标题
/// 空值 : true
/// </summary>
[SugarColumn(ColumnName = "notice_title")]
public string NoticeTitle { get; set; }
/// <summary>
/// 描述 : 公告类型 (1通知 2公告)
/// 空值 : true
/// </summary>
[SugarColumn(ColumnName = "notice_type")]
public string NoticeType { get; set; }
/// <summary>
/// 描述 : 公告内容
/// 空值 : true
/// </summary>
[SugarColumn(ColumnName = "notice_content")]
public string NoticeContent { get; set; }
/// <summary>
/// 描述 : 公告状态 (0正常 1关闭)
/// 空值 : true
/// </summary>
public string Status { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using System;
using Infrastructure.Attribute;
using ZR.Repository.System;
using ZR.Model.Models;
namespace ZR.Repository.System
{
/// <summary>
/// 通知公告表仓储
///
/// @author zr
/// @date 2021-12-15
/// </summary>
[AppService(ServiceLifetime = LifeTime.Transient)]
public class SysNoticeRepository : BaseRepository<SysNotice>
{
#region
#endregion
}
}

View File

@ -0,0 +1,15 @@
using System;
using ZR.Model.Models;
namespace ZR.Service.System.IService
{
/// <summary>
/// 通知公告表service接口
///
/// @author zr
/// @date 2021-12-15
/// </summary>
public interface ISysNoticeService: IBaseService<SysNotice>
{
}
}

View File

@ -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
{
/// <summary>
/// 通知公告表Service业务层处理
///
/// @author zr
/// @date 2021-12-15
/// </summary>
[AppService(ServiceType = typeof(ISysNoticeService), ServiceLifetime = LifeTime.Transient)]
public class SysNoticeService : BaseService<SysNotice>, ISysNoticeService
{
private readonly SysNoticeRepository _SysNoticerepository;
public SysNoticeService(SysNoticeRepository repository) : base(repository)
{
_SysNoticerepository = repository;
}
#region
#endregion
}
}

View File

@ -13,21 +13,21 @@
</el-select>
</el-form-item>
<el-form-item>
<el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:notice:add']">新增</el-button>
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:notice:add']">新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="success" icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['system:notice:edit']">修改
<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['system:notice:edit']">修改
</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['system:notice:remove']">删除
<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['system:notice:remove']">删除
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
@ -37,8 +37,16 @@
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="序号" align="center" prop="noticeId" width="100" />
<el-table-column label="公告标题" align="center" prop="noticeTitle" :show-overflow-tooltip="true" />
<el-table-column label="公告类型" align="center" prop="noticeType" :formatter="typeFormat" width="100" />
<el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" width="100" />
<el-table-column label="公告类型" align="center" prop="noticeType" width="100">
<template slot-scope="scope">
<dict-tag :options="typeOptions" :value="scope.row.noticeType" />
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status" width="100">
<template slot-scope="scope">
<dict-tag :options="statusOptions" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="创建者" align="center" prop="createBy" width="100" />
<el-table-column label="创建时间" align="center" prop="createTime" width="100">
<template slot-scope="scope">
@ -164,20 +172,12 @@ export default {
/** 查询公告列表 */
getList() {
this.loading = true;
listNotice(this.queryParams).then((response) => {
this.noticeList = response.rows;
this.total = response.total;
listNotice(this.queryParams).then((res) => {
this.noticeList = res.data.result;
this.total = res.data.totalNum;
this.loading = false;
});
},
//
statusFormat(row, column) {
return this.selectDictLabel(this.statusOptions, row.status);
},
//
typeFormat(row, column) {
return this.selectDictLabel(this.typeOptions, row.noticeType);
},
//
cancel() {
this.open = false;
@ -232,6 +232,10 @@ export default {
if (valid) {
if (this.form.noticeId != undefined) {
updateNotice(this.form).then((response) => {
if (!response.data) {
this.msgError("修改失败");
return;
}
this.msgSuccess("修改成功");
this.open = false;
this.getList();
@ -268,4 +272,4 @@ export default {
},
},
};
</script>
</script>

Binary file not shown.