瀏覽代碼

Update Notice公告通知优化

Yue 3 月之前
父節點
當前提交
d2a3045862

+ 9 - 0
SERVER/ChickenFarmV3/vb-modules/vb-system/src/main/java/cn/vber/system/controller/system/SysNoticeController.java

@@ -142,4 +142,13 @@ public class SysNoticeController extends BaseController {
 
         return R.ok(list);
     }
+
+    @PostMapping("/removeRead/{messageId}")
+    public R<Void> removeRead(@PathVariable String messageId) {
+        return toAjax(noticeService.removeRead(LoginHelper.getUserId(), messageId));
+    }
+    @PostMapping("/removeReadAll")
+    public R<Void> removeReadAll() {
+        return toAjax(noticeService.removeReadAll(LoginHelper.getUserId()));
+    }
 }

+ 4 - 0
SERVER/ChickenFarmV3/vb-modules/vb-system/src/main/java/cn/vber/system/service/ISysNoticeService.java

@@ -93,4 +93,8 @@ public interface ISysNoticeService {
     TableDataInfo<SysNoticeVo> selectPageMyNoticeList(SysNoticeBo notice, PageQuery pageQuery);
 
     int readAll(Long userId);
+
+    int removeRead(Long userId, String messageId);
+
+    int removeReadAll(Long userId);
 }

+ 23 - 1
SERVER/ChickenFarmV3/vb-modules/vb-system/src/main/java/cn/vber/system/service/impl/SysNoticeServiceImpl.java

@@ -208,7 +208,11 @@ public class SysNoticeServiceImpl implements ISysNoticeService, NoticeService {
 
         List<SysNotice> list = baseMapper.selectList(new LambdaQueryWrapper<SysNotice>()
                 .eq(SysNotice::getStatus, "0")
-                .apply("notice_id NOT IN (SELECT message_id FROM sys_notice_status WHERE user_id=" + userId + " AND status='1')")
+                .apply("status = '0' AND (" +
+                        "notice_type='1' AND notice_id  IN (SELECT message_id FROM sys_notice_status WHERE user_id=" + userId + " AND status='0') " +
+                        "or " +
+                        "notice_type='2' AND notice_id NOt IN (SELECT message_id FROM sys_notice_status WHERE user_id=" + userId + " AND status!='0')" +
+                        ")")
                 .orderByDesc(SysNotice::getCreateTime));
         List<SysMessageVo> msgList = new ArrayList<>();
         for (SysNotice notice : list) {
@@ -228,6 +232,8 @@ public class SysNoticeServiceImpl implements ISysNoticeService, NoticeService {
     @Override
     public TableDataInfo<SysNoticeVo> selectPageMyNoticeList(SysNoticeBo notice, PageQuery pageQuery) {
         Long userId = LoginHelper.getUserId();
+
+        //
         LambdaQueryWrapper<SysNotice> lqw = new LambdaQueryWrapper<SysNotice>()
                 .eq(SysNotice::getStatus, "0")
                 .orderByDesc(SysNotice::getCreateTime);
@@ -322,6 +328,22 @@ public class SysNoticeServiceImpl implements ISysNoticeService, NoticeService {
         return count;
     }
 
+    @Override
+    public int removeRead(Long userId, String messageId) {
+        return noticeStatusMapper.update(new LambdaUpdateWrapper<SysNoticeStatus>()
+                .eq(SysNoticeStatus::getUserId, userId)
+                .eq(SysNoticeStatus::getMessageId, messageId)
+                .set(SysNoticeStatus::getStatus, "2"));
+    }
+
+    @Override
+    public int removeReadAll(Long userId) {
+       return noticeStatusMapper.update(new LambdaUpdateWrapper<SysNoticeStatus>()
+                .eq(SysNoticeStatus::getUserId, userId)
+                .eq(SysNoticeStatus::getStatus, "1")
+                .set(SysNoticeStatus::getStatus, "2"));
+    }
+
     @Override
     @Transactional
     public Long savePushNotice(String noticeTitle, String noticeType, String noticeContent, List<Long> userIds) {

+ 3 - 2
SERVER/ChickenFarmV3/vb-modules/vb-system/src/main/resources/mapper/system/SysNoticeMapper.xml

@@ -28,8 +28,9 @@
             n.create_by,
             n.create_time,
             IFNULL(s.read_status, '0') AS read_status
-        FROM sys_notice n
-        LEFT JOIN (select message_id,status as read_status FROM sys_notice_status WHERE user_id = #{userId}) s ON n.notice_id = s.message_id
+        FROM  sys_notice as n JOIN
+        (select message_id,status as read_status,user_id FROM sys_notice_status WHERE (status ='0 'or status='1') and user_id = #{userId}) as s
+            ON n.notice_id = s.message_id
         ${ew.customSqlSegment}
     </select>
 

+ 10 - 0
UI/VB.VUE/src/api/system/_notice.ts

@@ -66,6 +66,16 @@ class noticeApi {
 			url: `/system/notice/getAllMessage/${limit}`
 		})
 	}
+	removeRead = (messageId: string) => {
+		return Rs.post({
+			url: `/system/notice/removeRead/${messageId}`
+		})
+	}
+	removeReadAll = () => {
+		return Rs.post({
+			url: `/system/notice/removeReadAll`
+		})
+	}
 }
 
 export default noticeApi

+ 14 - 4
UI/VB.VUE/src/stores/_notice.ts

@@ -55,13 +55,13 @@ export const useNoticeStore = defineStore("noticeStore", () => {
 				// 	router.push({ path: "/redirect/" + old.data.routerPath, query: old.data.params })
 				// }
 				if (old.read) {
-					jump(old.data)
+					jump(old.data, messageType)
 					return
 				}
 
 				apis.system.noticeApi.read(messageId, messageType).then(() => {
 					message.msgSuccess("消息已阅读")
-					jump(old.data)
+					jump(old.data, messageType)
 				})
 			}
 			old.read = true
@@ -69,17 +69,27 @@ export const useNoticeStore = defineStore("noticeStore", () => {
 	}
 
 	function readNotice(data) {
+		if (data.readStatus == "1") {
+			const temp = JSON.parse(data.noticeContent)
+			jump(temp, data.noticeType)
+			return
+		}
 		apis.system.noticeApi.read(data.noticeId, data.noticeType).then(() => {
 			message.msgSuccess("消息已阅读")
 			try {
 				const temp = JSON.parse(data.noticeContent)
-				jump(temp)
+				jump(temp, data.noticeType)
 			} catch (error) {
 				console.log("error", error)
 			}
 		})
 	}
-	function jump(data: any) {
+	function jump(data: any, noticeType) {
+		if (noticeType === "2") {
+			router.push({ path: "/my/notice" })
+			return
+		}
+
 		switch (data.businessType) {
 			case "device_repair":
 				router.push({ path: "/workOrder/needReceive" })

+ 61 - 6
UI/VB.VUE/src/views/my/notice.vue

@@ -11,7 +11,7 @@ const opts = reactive({
 		{ field: "noticeType", name: "公告通知类型", visible: true, width: 130 },
 		{ field: "readStatus", name: "是否阅读", visible: true, width: 100 },
 		{ field: "createTime", name: "公告通知时间", visible: true, width: 190 },
-		{ field: "actions", name: `操作`, width: 60 }
+		{ field: "actions", name: `操作`, width: 80 }
 	],
 	queryParams: {
 		noticeTitle: "",
@@ -57,8 +57,18 @@ const opts = reactive({
 		// }
 	] as any,
 	permission: "",
-	handleFuns: {},
-	customBtns: [],
+	handleFuns: {
+		handleRemoveAll
+	},
+	customBtns: [
+		{
+			key: "handleRemoveAll",
+			name: "删除全部已读",
+			icon: "bi bi-dash-square",
+			btnClass: "btn btn-light-danger",
+			disabledFun: () => false
+		}
+	],
 	tableListFun: apis.system.noticeApi.listMyNotice
 })
 const { queryParams } = toRefs(opts)
@@ -71,8 +81,34 @@ function handleQuery(query?: any) {
 function resetQuery() {
 	//
 }
+const detailData = ref()
 function handleRead(row: any) {
-	appStore.noticeStore.readNotice(row)
+	if (row.noticeType == "1") {
+		appStore.noticeStore.readNotice(row)
+	} else {
+		detailData.value = row
+		if (row.readStatus == "1") {
+			modalRef.value.show()
+			return
+		}
+		apis.system.noticeApi.read(row.noticeId, row.noticeType).then(() => {
+			modalRef.value.show()
+			handleQuery()
+		})
+	}
+}
+function handleRemove(row: any) {
+	apis.system.noticeApi.removeRead(row.noticeId).then(() => {
+		message.msgSuccess("删除成功")
+		handleQuery()
+	})
+}
+
+function handleRemoveAll() {
+	apis.system.noticeApi.removeReadAll().then(() => {
+		message.msgSuccess("全部已读删除成功")
+		handleQuery()
+	})
 }
 
 function init() {}
@@ -112,15 +148,34 @@ onMounted(init)
 				<DictTag type="sys_notice_read_status" :value="row.readStatus"></DictTag>
 			</template>
 			<template #actions="{ row }">
-				<vb-tooltip v-if="row.readStatus == '0'" content="阅读" placement="top">
+				<vb-tooltip content="阅读" placement="top">
 					<el-button link type="primary" @click="handleRead(row)">
 						<template #icon>
 							<VbIcon icon-name="book" icon-type="duotone" class="fs-3"></VbIcon>
 						</template>
 					</el-button>
 				</vb-tooltip>
-				<span v-else>-</span>
+				<vb-tooltip v-if="row.readStatus == '1'" content="删除" placement="top">
+					<el-button link type="danger" @click="handleRemove(row)">
+						<template #icon>
+							<VbIcon icon-name="trash-square" icon-type="duotone" class="fs-3"></VbIcon>
+						</template>
+					</el-button>
+				</vb-tooltip>
 			</template>
 		</VbDataTable>
+		<VbModal
+			v-model:modal="modalRef"
+			title="公告详情"
+			:confirm-btn="false"
+			:close-btn-class="'btn btn-danger'"
+			append-to-body>
+			<template #body>
+				<div v-if="detailData" class="d-flex flex-column">
+					<div class="fw-bold text-center my-3">{{ detailData.noticeTitle }}</div>
+					<div v-html="detailData.noticeContent"></div>
+				</div>
+			</template>
+		</VbModal>
 	</div>
 </template>

+ 3 - 3
UI/VB.VUE/src/views/system/notice/index.vue

@@ -225,11 +225,11 @@ onMounted(init)
 					</el-col>
 					<el-col :span="24">
 						<el-form-item label="公告内容">
-							<!-- <vb-editor v-model="form.noticeContent" :min-height="192" /> -->
-							<el-input
+							<vb-editor v-model="form.noticeContent" :min-height="192" />
+							<!-- <el-input
 								v-model="form.noticeContent"
 								type="textarea"
-								placeholder="请输入公告内容"></el-input>
+								placeholder="请输入公告内容"></el-input> -->
 						</el-form-item>
 					</el-col>
 				</el-row>