mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
系统管理:通知公告支持按机构划分、超管操作公告为内置公告
This commit is contained in:
+1
@@ -94,6 +94,7 @@ public class ErrorCodeConstants {
|
||||
// ========== 通知公告 1-002-008-000 ==========
|
||||
public static final ErrorCode NOTICE_NOT_FOUND = new ErrorCode(1_002_008_001, "当前通知公告不存在");
|
||||
public static final ErrorCode NOTICE_NAME_UNIQE_ERROR = new ErrorCode(1_002_008_002, "公告标题已存在,请编辑后重试");
|
||||
public static final ErrorCode NOTICE_BUILDIN_MODIFY_PERMISSION_ERROR = new ErrorCode(1_002_008_003, "内置通知公告编辑权限不足");
|
||||
|
||||
// ========== 短信渠道 1-002-011-000 ==========
|
||||
public static final ErrorCode SMS_CHANNEL_NOT_EXISTS = new ErrorCode(1_002_011_000, "短信渠道不存在");
|
||||
|
||||
+5
@@ -21,4 +21,9 @@ public class NoticePageReqVO extends PageParam {
|
||||
@CommonStatus
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "组织id")
|
||||
private Long organId;
|
||||
|
||||
@Schema(description = "通知公告来源")
|
||||
private Integer source;
|
||||
}
|
||||
|
||||
+1
@@ -25,6 +25,7 @@ public class NoticeSaveReqVO {
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "公告内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "半生编码")
|
||||
@NotBlank(message = "公告内容不能为空")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
|
||||
+16
@@ -1,7 +1,10 @@
|
||||
package com.cf.imes.module.system.dal.dataobject.notice;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.cf.imes.module.system.enums.notice.NoticeSourceEnum;
|
||||
import com.cf.imes.module.system.enums.notice.NoticeTypeEnum;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
@@ -33,6 +36,14 @@ public class NoticeDO extends BaseDO {
|
||||
* 枚举 {@link NoticeTypeEnum}
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 公告来源
|
||||
* <p>
|
||||
* 枚举 {@link NoticeSourceEnum}
|
||||
*/
|
||||
private NoticeSourceEnum source;
|
||||
|
||||
/**
|
||||
* 公告内容
|
||||
*/
|
||||
@@ -44,4 +55,9 @@ public class NoticeDO extends BaseDO {
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 组织ID
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Long organId;
|
||||
}
|
||||
|
||||
+16
-1
@@ -3,18 +3,33 @@ package com.cf.imes.module.system.dal.mysql.notice;
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.module.system.controller.admin.notice.vo.NoticePageReqVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.notice.NoticeDO;
|
||||
import com.cf.imes.module.system.enums.notice.NoticeSourceEnum;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface NoticeMapper extends BaseMapperX<NoticeDO> {
|
||||
|
||||
default PageResult<NoticeDO> selectPage(NoticePageReqVO reqVO) {
|
||||
if (NoticeSourceEnum.SYSTEM.getSource().equals(reqVO.getSource())) {
|
||||
// 超管只看内置的
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<NoticeDO>()
|
||||
.likeIfPresent(NoticeDO::getTitle, reqVO.getTitle())
|
||||
.eqIfPresent(NoticeDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(NoticeDO::getSource, NoticeSourceEnum.SYSTEM)
|
||||
.orderByDesc(NoticeDO::getId));
|
||||
}
|
||||
// 普通用户查机构下的和内置的
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<NoticeDO>()
|
||||
.likeIfPresent(NoticeDO::getTitle, reqVO.getTitle())
|
||||
.eqIfPresent(NoticeDO::getStatus, reqVO.getStatus())
|
||||
.orderByDesc(NoticeDO::getId));
|
||||
.and(wr -> wr.or(wrapper -> wrapper
|
||||
.eq(NoticeDO::getOrganId, OrganContextHolder.getOrganId())
|
||||
.eq(NoticeDO::getSource, NoticeSourceEnum.CUSTOM))
|
||||
.or(wrapper -> wrapper.eq(NoticeDO::getSource, NoticeSourceEnum.SYSTEM)))
|
||||
.orderByDesc(NoticeDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+53
-5
@@ -1,17 +1,21 @@
|
||||
package com.cf.imes.module.system.service.notice;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.organ.core.aop.OrganIgnore;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.cf.imes.module.system.controller.admin.notice.vo.NoticePageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.notice.vo.NoticeSaveReqVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.notice.NoticeDO;
|
||||
import com.cf.imes.module.system.dal.mysql.notice.NoticeMapper;
|
||||
import com.cf.imes.module.system.enums.ErrorCodeConstants;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.cf.imes.module.system.enums.notice.NoticeSourceEnum;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -30,11 +34,19 @@ public class NoticeServiceImpl implements NoticeService {
|
||||
@Resource
|
||||
private NoticeMapper noticeMapper;
|
||||
|
||||
|
||||
private NoticeServiceImpl getSelf() {
|
||||
return SpringUtil.getBean(getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createNotice(NoticeSaveReqVO createReqVO) {
|
||||
// 标题唯一性校验
|
||||
validateNameExists(createReqVO);
|
||||
NoticeDO notice = BeanUtils.toBean(createReqVO, NoticeDO.class);
|
||||
|
||||
// 超管创建的都是内置公告
|
||||
modifySource(notice);
|
||||
noticeMapper.insert(notice);
|
||||
return notice.getId();
|
||||
}
|
||||
@@ -42,24 +54,32 @@ public class NoticeServiceImpl implements NoticeService {
|
||||
@Override
|
||||
public void updateNotice(NoticeSaveReqVO updateReqVO) {
|
||||
// 校验是否存在
|
||||
validateNoticeExists(updateReqVO.getId());
|
||||
getSelf().validateNoticeExists(updateReqVO.getId());
|
||||
// 标题唯一性校验
|
||||
validateNameExists(updateReqVO);
|
||||
getSelf().validateNameExists(updateReqVO);
|
||||
// 更新通知公告
|
||||
NoticeDO updateObj = BeanUtils.toBean(updateReqVO, NoticeDO.class);
|
||||
// 超管创建的都是内置公告
|
||||
modifySource(updateObj);
|
||||
noticeMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteNotice(Long id) {
|
||||
// 校验是否存在
|
||||
validateNoticeExists(id);
|
||||
getSelf().validateNoticeExists(id);
|
||||
// 删除通知公告
|
||||
noticeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OrganIgnore
|
||||
public PageResult<NoticeDO> getNoticePage(NoticePageReqVO reqVO) {
|
||||
boolean isSuperAdmin = SecurityFrameworkUtils.isSuperAdmin();
|
||||
// 超管查看内置公告
|
||||
if (isSuperAdmin) {
|
||||
reqVO.setSource(NoticeSourceEnum.SYSTEM.getSource());
|
||||
}
|
||||
return noticeMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@@ -68,7 +88,7 @@ public class NoticeServiceImpl implements NoticeService {
|
||||
return noticeMapper.selectById(id);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@OrganIgnore
|
||||
public void validateNoticeExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
@@ -77,6 +97,13 @@ public class NoticeServiceImpl implements NoticeService {
|
||||
if (notice == null) {
|
||||
throw ServiceExceptionUtil.exception(ErrorCodeConstants.NOTICE_NOT_FOUND);
|
||||
}
|
||||
if (!NoticeSourceEnum.SYSTEM.equals(notice.getSource()) && !notice.getOrganId().equals(OrganContextHolder.getOrganId())) {
|
||||
throw ServiceExceptionUtil.exception(ErrorCodeConstants.NOTICE_NOT_FOUND);
|
||||
}
|
||||
// 只有超管可以操作内置公告
|
||||
if (NoticeSourceEnum.SYSTEM.equals(notice.getSource()) && !SecurityFrameworkUtils.isSuperAdmin()) {
|
||||
throw ServiceExceptionUtil.exception(ErrorCodeConstants.NOTICE_BUILDIN_MODIFY_PERMISSION_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,14 +111,35 @@ public class NoticeServiceImpl implements NoticeService {
|
||||
*
|
||||
* @param reqVO
|
||||
*/
|
||||
@OrganIgnore
|
||||
public void validateNameExists(NoticeSaveReqVO reqVO) {
|
||||
boolean isSuperAdmin = SecurityFrameworkUtils.isSuperAdmin();
|
||||
|
||||
Long noticeId = reqVO.getId();
|
||||
LambdaQueryWrapper<NoticeDO> wrapper = new LambdaQueryWrapperX<NoticeDO>().eq(NoticeDO::getTitle, reqVO.getTitle());
|
||||
if (ObjectUtil.isNotNull(noticeId)) {
|
||||
wrapper.ne(NoticeDO::getId, noticeId);
|
||||
}
|
||||
if (isSuperAdmin) {
|
||||
wrapper.eq(NoticeDO::getSource, NoticeSourceEnum.SYSTEM);
|
||||
} else {
|
||||
wrapper.eq(NoticeDO::getOrganId, OrganContextHolder.getOrganId());
|
||||
}
|
||||
if (noticeMapper.exists(wrapper)) {
|
||||
throw exception(NOTICE_NAME_UNIQE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 公告来源赋值
|
||||
*
|
||||
* @param notice
|
||||
*/
|
||||
private void modifySource(NoticeDO notice) {
|
||||
if (SecurityFrameworkUtils.isSuperAdmin()) {
|
||||
notice.setSource(NoticeSourceEnum.SYSTEM);
|
||||
} else {
|
||||
notice.setSource(NoticeSourceEnum.CUSTOM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user