优化通知公告

This commit is contained in:
不做码农 2023-06-01 15:06:41 +08:00
parent 538dde51a8
commit 68d43240e7
9 changed files with 162 additions and 160 deletions

View File

@ -45,7 +45,7 @@ namespace ZR.Admin.WebApi.Controllers.System
{
var predicate = Expressionable.Create<SysNotice>();
predicate = predicate.And(m => m.Status == "0");
predicate = predicate.And(m => m.Status == 0);
var response = _SysNoticeService.GetPages(predicate.ToExpression(), parm);
return SUCCESS(response);
}
@ -61,9 +61,9 @@ namespace ZR.Admin.WebApi.Controllers.System
var predicate = Expressionable.Create<SysNotice>();
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(parm.NoticeType != null, 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));
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.Status), m => m.Status == parm.Status);
predicate = predicate.AndIF(parm.Status != null, m => m.Status == parm.Status);
var response = _SysNoticeService.GetPages(predicate.ToExpression(), parm);
return SUCCESS(response);
}
@ -88,14 +88,9 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <returns></returns>
[HttpPost]
[ActionPermissionFilter(Permission = "system:notice:add")]
[Log(Title = "知公", BusinessType = BusinessType.INSERT)]
[Log(Title = "发布通告", BusinessType = BusinessType.INSERT)]
public IActionResult AddSysNotice([FromBody] SysNoticeDto parm)
{
if (parm == null)
{
throw new CustomException("请求参数错误");
}
//从 Dto 映射到 实体
var modal = parm.Adapt<SysNotice>().ToCreate(HttpContext);
modal.Create_by = HttpContext.GetName();
modal.Create_time = DateTime.Now;
@ -120,19 +115,13 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <returns></returns>
[HttpPut]
[ActionPermissionFilter(Permission = "system:notice:update")]
[Log(Title = "通知公告表", BusinessType = BusinessType.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);
model.Update_by = HttpContext.GetName();
var response = _SysNoticeService.Update(w => w.NoticeId == model.NoticeId, it => new SysNotice()
{
//Update 字段映射
NoticeTitle = model.NoticeTitle,
NoticeType = model.NoticeType,
NoticeContent = model.NoticeContent,
@ -150,7 +139,7 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <returns></returns>
[HttpPut("send/{NoticeId}")]
[ActionPermissionFilter(Permission = "system:notice:update")]
[Log(Title = "通知公告", BusinessType = BusinessType.OTHER)]
[Log(Title = "发送通知公告", BusinessType = BusinessType.OTHER)]
public IActionResult SendNotice(int NoticeId = 0)
{
if (NoticeId <= 0)
@ -158,7 +147,7 @@ namespace ZR.Admin.WebApi.Controllers.System
throw new CustomException("请求实体不能为空");
}
var response = _SysNoticeService.GetFirst(x => x.NoticeId == NoticeId);
if (response != null && response.Status == "0")
if (response != null && response.Status == 0)
{
_hubContext.Clients.All.SendAsync(HubsConstant.ReceiveNotice, response.NoticeTitle, response.NoticeContent);
}
@ -171,7 +160,7 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "system:notice:delete")]
[Log(Title = "通知公告", BusinessType = BusinessType.DELETE)]
[Log(Title = "通知公告", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteSysNotice(string ids)
{
int[] idsArr = Tools.SpitIntArrary(ids);
@ -181,20 +170,5 @@ namespace ZR.Admin.WebApi.Controllers.System
return SUCCESS(response);
}
/// <summary>
/// 通知公告表导出
/// </summary>
/// <returns></returns>
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "通知公告表")]
[HttpGet("export")]
[ActionPermissionFilter(Permission = "system:notice:export")]
public IActionResult Export()
{
var list = _SysNoticeService.GetAll();
string sFileName = ExportExcel(list, "SysNotice", "通知公告表");
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
}
}
}

View File

@ -1,3 +1,5 @@
using System.ComponentModel.DataAnnotations;
namespace ZR.Model.System.Dto
{
/// <summary>
@ -6,10 +8,11 @@ namespace ZR.Model.System.Dto
public class SysNoticeDto
{
public int NoticeId { get; set; }
[Required]
public string NoticeTitle { get; set; }
public string NoticeType { get; set; }
public int NoticeType { get; set; }
public string NoticeContent { get; set; }
public string Status { get; set; }
public int Status { get; set; }
public string Remark { get; set; }
}
@ -19,8 +22,8 @@ namespace ZR.Model.System.Dto
public class SysNoticeQueryDto : PagerInfo
{
public string NoticeTitle { get; set; }
public string NoticeType { get; set; }
public int? NoticeType { get; set; }
public string CreateBy { get; set; }
public string Status { get; set; }
public int? Status { get; set; }
}
}

View File

@ -26,7 +26,7 @@ namespace ZR.Model.System
/// 公告类型 (1通知 2公告)
/// </summary>
[SugarColumn(ColumnName = "notice_type")]
public string NoticeType { get; set; }
public int NoticeType { get; set; }
/// <summary>
/// 公告内容
/// </summary>
@ -35,6 +35,6 @@ namespace ZR.Model.System
/// <summary>
/// 公告状态 (0正常 1关闭)
/// </summary>
public string Status { get; set; }
public int Status { get; set; }
}
}

View File

@ -28,7 +28,7 @@ namespace ZR.Service.System
var predicate = Expressionable.Create<SysNotice>();
//搜索条件查询语法参考Sqlsugar
predicate = predicate.And(m => m.Status == "0");
predicate = predicate.And(m => m.Status == 0);
return GetList(predicate.ToExpression());
}

View File

@ -23,13 +23,28 @@
<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" plain 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" plain 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>
@ -58,15 +73,20 @@
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-bell" @click="handleNotice(scope.row)" v-hasPermi="['system:notice:edit']">通知</el-button>
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:notice:edit']">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:notice:remove']">删除
<el-button size="mini" type="text" icon="el-icon-bell" @click="handleNotice(scope.row)" v-hasPermi="['system:notice:edit']"
>通知</el-button
>
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:notice:edit']"
>修改</el-button
>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:notice:remove']"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
<!-- 添加或修改公告对话框 -->
<el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
@ -80,14 +100,14 @@
<el-col :span="12">
<el-form-item label="公告类型" prop="noticeType">
<el-select v-model="form.noticeType" placeholder="请选择公告类型">
<el-option v-for="dict in typeOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
<el-option v-for="dict in typeOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="parseInt(dict.dictValue)"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="状态">
<el-radio-group v-model="form.status">
<el-radio v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictValue">{{dict.dictLabel}}</el-radio>
<el-radio v-for="dict in statusOptions" :key="dict.dictValue" :label="parseInt(dict.dictValue)">{{ dict.dictLabel }}</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
@ -115,10 +135,10 @@ import {
updateNotice,
sendNotice,
// exportNotice,
} from "@/api/system/notice";
} from '@/api/system/notice'
export default {
name: "notice",
name: 'notice',
data() {
return {
//
@ -136,7 +156,7 @@ export default {
//
noticeList: [],
//
title: "",
title: '',
//
open: false,
//
@ -155,38 +175,34 @@ export default {
form: {},
//
rules: {
noticeTitle: [
{ required: true, message: "公告标题不能为空", trigger: "blur" },
],
noticeType: [
{ required: true, message: "公告类型不能为空", trigger: "change" },
],
noticeTitle: [{ required: true, message: '公告标题不能为空', trigger: 'blur' }],
noticeType: [{ required: true, message: '公告类型不能为空', trigger: 'change' }],
},
};
}
},
created() {
this.getList();
this.getDicts("sys_notice_status").then((response) => {
this.statusOptions = response.data;
});
this.getDicts("sys_notice_type").then((response) => {
this.typeOptions = response.data;
});
this.getList()
this.getDicts('sys_notice_status').then((response) => {
this.statusOptions = response.data
})
this.getDicts('sys_notice_type').then((response) => {
this.typeOptions = response.data
})
},
methods: {
/** 查询公告列表 */
getList() {
this.loading = true;
this.loading = true
listNotice(this.queryParams).then((res) => {
this.noticeList = res.data.result;
this.total = res.data.totalNum;
this.loading = false;
});
this.noticeList = res.data.result
this.total = res.data.totalNum
this.loading = false
})
},
//
cancel() {
this.open = false;
this.reset();
this.open = false
this.reset()
},
//
reset() {
@ -195,93 +211,89 @@ export default {
noticeTitle: undefined,
noticeType: undefined,
noticeContent: undefined,
status: "0",
};
this.resetForm("form");
status: 0,
}
this.resetForm('form')
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
this.resetForm('queryForm')
this.handleQuery()
},
//
handleSelectionChange(selection) {
this.ids = selection.map((item) => item.noticeId);
this.single = selection.length != 1;
this.multiple = !selection.length;
this.ids = selection.map((item) => item.noticeId)
this.single = selection.length != 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加公告";
this.reset()
this.open = true
this.title = '添加公告'
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const noticeId = row.noticeId || this.ids;
this.reset()
const noticeId = row.noticeId || this.ids
getNotice(noticeId).then((response) => {
this.form = response.data;
this.open = true;
this.title = "修改公告";
});
this.form = response.data
this.open = true
this.title = '修改公告'
})
},
//
handleNotice(row) {
const noticeId = row.noticeId || this.ids;
sendNotice(noticeId).then(res => {
this.msgSuccess("发送通知成功");
});
const noticeId = row.noticeId || this.ids
sendNotice(noticeId).then((res) => {
this.msgSuccess('发送通知成功')
})
},
/** 提交按钮 */
submitForm: function () {
this.$refs["form"].validate((valid) => {
this.$refs['form'].validate((valid) => {
if (valid) {
if (this.form.noticeId != undefined) {
updateNotice(this.form).then((response) => {
if (!response.data) {
this.msgError("修改失败");
return;
this.msgError('修改失败')
return
}
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
this.msgSuccess('修改成功')
this.open = false
this.getList()
})
} else {
addNotice(this.form).then((response) => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
this.msgSuccess('新增成功')
this.open = false
this.getList()
})
}
}
});
})
},
/** 删除按钮操作 */
handleDelete(row) {
const noticeIds = row.noticeId || this.ids;
this.$confirm(
'是否确认删除公告编号为"' + noticeIds + '"的数据项?',
"警告",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}
)
const noticeIds = row.noticeId || this.ids
this.$confirm('是否确认删除公告编号为"' + noticeIds + '"的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(function () {
return delNotice(noticeIds);
return delNotice(noticeIds)
})
.then(() => {
this.getList();
this.msgSuccess("删除成功");
});
this.getList()
this.msgSuccess('删除成功')
})
},
},
};
}
</script>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -35,38 +35,52 @@ CREATE TABLE `sys_tasks` (
-- ----------------------------
-- Table structure for sys_tasks_log
-- ----------------------------
DROP TABLE IF EXISTS `sys_tasks_log`;
DROP TABLE
IF
EXISTS `sys_tasks_log`;
CREATE TABLE `sys_tasks_log` (
`jobLogId` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '任务日志ID',
`jobId` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务id',
`jobName` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务名称',
`jobGroup` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务组名',
`jobMessage` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '日志信息',
`status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '执行状态0正常 1失败',
`exception` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '异常信息',
`createTime` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`invokeTarget` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '调用目标',
`elapsed` double(10, 0) NULL DEFAULT NULL COMMENT '作业用时',
PRIMARY KEY (`jobLogId`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 198 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '定时任务调度日志表' ROW_FORMAT = Dynamic;
`jobLogId` BIGINT ( 20 ) NOT NULL AUTO_INCREMENT COMMENT '任务日志ID',
`jobId` VARCHAR ( 20 ) CHARACTER
SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务id',
`jobName` VARCHAR ( 64 ) CHARACTER
SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务名称',
`jobGroup` VARCHAR ( 64 ) CHARACTER
SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务组名',
`jobMessage` VARCHAR ( 500 ) CHARACTER
SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '日志信息',
`status` CHAR ( 1 ) CHARACTER
SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '执行状态0正常 1失败',
`exception` VARCHAR ( 2000 ) CHARACTER
SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '异常信息',
`createTime` DATETIME ( 0 ) NULL DEFAULT NULL COMMENT '创建时间',
`invokeTarget` VARCHAR ( 200 ) CHARACTER
SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '调用目标',
`elapsed` DOUBLE ( 10, 0 ) NULL DEFAULT NULL COMMENT '作业用时',
PRIMARY KEY ( `jobLogId` ) USING BTREE
) ENGINE = INNODB AUTO_INCREMENT = 198 CHARACTER
SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '定时任务调度日志表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- 通知公告表
-- ----------------------------
drop table if exists sys_notice;
create table sys_notice (
notice_id int(4) not null auto_increment comment '公告ID',
notice_title varchar(50) not null comment '公告标题',
notice_type char(1) not null comment '公告类型1通知 2公告',
notice_content varchar(500) default null comment '公告内容',
status char(1) default '0' comment '公告状态0正常 1关闭',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
remark varchar(255) default null comment '备注',
primary key (notice_id)
) engine=innodb auto_increment=10 comment = '通知公告表';
DROP TABLE
IF
EXISTS sys_notice;
CREATE TABLE sys_notice (
notice_id INT ( 4 ) NOT NULL auto_increment COMMENT '公告ID',
notice_title VARCHAR ( 50 ) CHARACTER
SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '公告标题',
notice_type INT NOT NULL COMMENT '公告类型1通知 2公告',
notice_content TEXT CHARACTER
SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '公告内容',
`status` INT DEFAULT 0 COMMENT '公告状态0正常 1关闭',
create_by VARCHAR ( 64 ) DEFAULT '' COMMENT '创建者',
create_time DATETIME COMMENT '创建时间',
update_by VARCHAR ( 64 ) DEFAULT '' COMMENT '更新者',
update_time DATETIME COMMENT '更新时间',
remark VARCHAR ( 255 ) CHARACTER
SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注',
PRIMARY KEY ( notice_id )
) ENGINE = INNODB auto_increment = 1 COMMENT = '通知公告表';
-- ----------------------------

View File

@ -683,9 +683,9 @@ DROP TABLE IF EXISTS "public"."sys_notice";
CREATE TABLE "public"."sys_notice" (
"notice_id" int4 NOT NULL DEFAULT nextval('sys_noticeid_seq'::regclass),
"notice_title" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"notice_type" char(1) COLLATE "pg_catalog"."default" NOT NULL,
"notice_type" int4 NOT NULL,
"notice_content" varchar(500) COLLATE "pg_catalog"."default",
"status" char(1) COLLATE "pg_catalog"."default",
"status" int4,
"create_by" varchar(64) COLLATE "pg_catalog"."default",
"create_time" timestamp(6),
"update_by" varchar(64) COLLATE "pg_catalog"."default",

View File

@ -31,7 +31,6 @@ CREATE TABLE sys_tasks
requestMethod VARCHAR(10) --
)
GO
GO
if OBJECT_ID(N'sys_tasks_log',N'U') is not NULL DROP TABLE sys_tasks_log
GO
/**定时任务调度日志表*/
@ -55,9 +54,9 @@ GO
CREATE TABLE [dbo].[sys_notice](
[notice_id] [int] NOT NULL PRIMARY KEY IDENTITY(1,1),
[notice_title] [varchar](100) NULL,
[notice_type] [char](1) NULL,
[notice_type] int NULL,
[notice_content] [text] NULL,
[status] [char](1) NULL,
[status] int NULL,
[create_by] [varchar](64) NULL,
[create_time] [datetime] NULL,
[update_by] [varchar](64) NULL,