mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-02 10:57:10 +08:00
refactor: 优化通知公告部分代码
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import top.continew.starter.core.enums.BaseEnum;
|
||||
|
||||
/**
|
||||
* 公告通知范围枚举
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/8/20 10:55
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum NoticeScopeEnum implements BaseEnum<Integer> {
|
||||
|
||||
/**
|
||||
* 所有人
|
||||
*/
|
||||
ALL(1, "所有人"),
|
||||
|
||||
/**
|
||||
* 指定用户
|
||||
*/
|
||||
USER(2, "指定用户"),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
}
|
@@ -34,6 +34,7 @@ public interface NoticeMapper extends BaseMapper<NoticeDO> {
|
||||
/**
|
||||
* 查询仪表盘公告列表
|
||||
*
|
||||
* @param userId 用户 ID
|
||||
* @return 仪表盘公告列表
|
||||
*/
|
||||
List<DashboardNoticeResp> selectDashboardList(@Param("userId") Long userId);
|
||||
|
@@ -68,8 +68,8 @@ public class UserQuery implements Serializable {
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 用户 IDS
|
||||
* 用户 ID 列表
|
||||
*/
|
||||
@Schema(description = "用户 ID数组", example = "[1,2,3]")
|
||||
@Schema(description = "用户 ID 列表", example = "[1,2,3]")
|
||||
private List<Long> userIds;
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import top.continew.admin.system.enums.NoticeScopeEnum;
|
||||
import top.continew.starter.extension.crud.model.req.BaseReq;
|
||||
|
||||
import java.io.Serial;
|
||||
@@ -80,9 +81,9 @@ public class NoticeReq extends BaseReq {
|
||||
/**
|
||||
* 通知范围
|
||||
*/
|
||||
@Schema(description = "通知范围(1.所有人 2.指定用户)", example = "1")
|
||||
@Schema(description = "通知范围", example = "2")
|
||||
@NotNull(message = "通知范围不能为空")
|
||||
private Integer noticeScope;
|
||||
private NoticeScopeEnum noticeScope;
|
||||
|
||||
/**
|
||||
* 指定用户
|
||||
|
@@ -20,6 +20,7 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.system.enums.NoticeScopeEnum;
|
||||
import top.continew.starter.extension.crud.model.resp.BaseDetailResp;
|
||||
|
||||
import java.io.Serial;
|
||||
@@ -78,8 +79,8 @@ public class NoticeDetailResp extends BaseDetailResp {
|
||||
/**
|
||||
* 通知范围
|
||||
*/
|
||||
@Schema(description = "通知范围(1.所有人 2.指定用户)", example = "1")
|
||||
private Integer noticeScope;
|
||||
@Schema(description = "通知范围", example = "2")
|
||||
private NoticeScopeEnum noticeScope;
|
||||
|
||||
/**
|
||||
* 指定用户
|
||||
|
@@ -128,13 +128,6 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
return pageResp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserResp> list(UserQuery query, SortQuery sortQuery) {
|
||||
QueryWrapper<UserDO> queryWrapper = this.buildQueryWrapper(query);
|
||||
List<UserDetailResp> entityList = baseMapper.selectUserList(queryWrapper);
|
||||
return BeanUtil.copyToList(entityList, UserResp.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeAdd(UserReq req) {
|
||||
final String errorMsgTemplate = "新增失败,[{}] 已存在";
|
||||
|
@@ -5,27 +5,14 @@
|
||||
<select id="selectDashboardList"
|
||||
resultType="top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp">
|
||||
SELECT
|
||||
id,
|
||||
title,
|
||||
type
|
||||
FROM
|
||||
sys_notice
|
||||
WHERE
|
||||
( effective_time IS NULL OR NOW() > effective_time )
|
||||
AND (
|
||||
terminate_time IS NULL
|
||||
OR terminate_time > NOW())
|
||||
id, title, type
|
||||
FROM sys_notice
|
||||
WHERE (effective_time IS NULL OR NOW() > effective_time)
|
||||
AND (terminate_time IS NULL OR terminate_time > NOW())
|
||||
<if test="userId != null">
|
||||
AND ( notice_scope = 1
|
||||
OR (
|
||||
notice_scope = 2 AND
|
||||
<!--转化为字符串类型,因为存储的也是字符串类型-->
|
||||
JSON_EXTRACT(notice_users, "$[0]") = CAST(#{userId} AS CHAR)
|
||||
))
|
||||
AND (notice_scope = 1 OR (notice_scope = 2 AND JSON_EXTRACT(notice_users, "$[0]") = CAST(#{userId} AS CHAR)))
|
||||
</if>
|
||||
ORDER BY
|
||||
sort ASC,
|
||||
effective_time DESC
|
||||
LIMIT 5;
|
||||
ORDER BY sort ASC, effective_time DESC
|
||||
LIMIT 5
|
||||
</select>
|
||||
</mapper>
|
Reference in New Issue
Block a user