1. notice module
This commit is contained in:
2026-02-12 15:09:31 +08:00
parent 5344c76cac
commit a6782b4fa1
4 changed files with 6 additions and 61 deletions

View File

@@ -23,7 +23,10 @@
<select id="selectUserNoticePage" resultMap="userNoticeResultMap">
select * from user_notice where is_deleted = 0
select *
from user_notice
where is_deleted = 0
and notice_type in (0, 1, 2)
</select>
<select id="selectAppSystemNoticeVOList" resultType="org.springblade.modules.api.vo.CommonUserNoticeApiVO">

View File

@@ -39,9 +39,8 @@ import java.io.Serial;
@Data
@EqualsAndHashCode(callSuper = true)
public class CommonUserNoticeVO extends CommonUserNoticeEntity {
@Serial
private static final long serialVersionUID = 1L;
private Integer noticeRange;
}

View File

@@ -25,7 +25,6 @@
*/
package org.springblade.modules.common.service;
import jakarta.validation.Valid;
import org.springblade.modules.api.vo.CommonUserNoticeApiVO;
import org.springblade.modules.api.vo.CommonUserNoticeDetailApiVO;
import org.springblade.modules.common.pojo.entity.CommonUserNoticeEntity;
@@ -51,8 +50,7 @@ public interface ICommonUserNoticeService extends BaseService<CommonUserNoticeEn
*/
IPage<CommonUserNoticeVO> selectUserNoticePage(IPage<CommonUserNoticeVO> page, CommonUserNoticeVO userNotice);
boolean saveUserNotice(@Valid CommonUserNoticeVO userNotice);
boolean saveUserNotice(CommonUserNoticeVO userNotice);
IPage<CommonUserNoticeApiVO> selectAppUserNoticeApiPage(IPage<CommonUserNoticeApiVO> page, CommonUserNoticeApiVO vo);

View File

@@ -36,7 +36,6 @@ import org.springblade.modules.common.pojo.entity.CommonUserNoticeEntity;
import org.springblade.modules.common.pojo.vo.CommonUserNoticeVO;
import org.springblade.modules.common.mapper.CommonUserNoticeMapper;
import org.springblade.modules.common.service.ICommonUserNoticeService;
import org.springblade.modules.system.pojo.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -44,7 +43,6 @@ import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -68,60 +66,7 @@ public class CommonUserNoticeServiceImpl extends BaseServiceImpl<CommonUserNotic
@Transactional(rollbackFor = RuntimeException.class)
@Override
public boolean saveUserNotice(CommonUserNoticeVO userNotice) {
Assert.notNull(userNotice.getNoticeType(), "通知类型不能为空");
Assert.notNull(userNotice.getTitle(), "标题不能为空");
Assert.notNull(userNotice.getContent(), "内容不能为空");
if (userNotice.getNoticeRange() == 0) {
User user = userService.getById(userNotice.getUserId());
Assert.notNull(user, "用户不存在");
return save(
new CommonUserNoticeEntity()
.setUserId(userNotice.getUserId())
.setTitle(userNotice.getTitle())
.setContent(userNotice.getContent())
.setNoticeType(userNotice.getNoticeType())
.setHasRead(0)
);
} else if (userNotice.getNoticeRange() == 1) {
long count = userService.count(
Wrappers.lambdaQuery(User.class)
.eq(User::getUserType, 2)
);
// 向上取整
long pageNun = (count + PAGE_SIZE - 1) / PAGE_SIZE;
List<CommonUserNoticeEntity> noticeList = new ArrayList<>();
for (int i = 0; i < pageNun; i++) {
List<Long> userIdList = userService.list(
Wrappers.lambdaQuery(User.class)
.eq(User::getUserType, 2)
.orderByAsc(User::getId)
.last("limit " + PAGE_SIZE + " offset " + i * PAGE_SIZE)
).stream().map(User::getId).toList();
userIdList.forEach(userId -> {
noticeList.add(
new CommonUserNoticeEntity()
.setUserId(userId)
.setTitle(userNotice.getTitle())
.setContent(userNotice.getContent())
.setNoticeType(userNotice.getNoticeType())
.setHasRead(0)
);
});
if (!saveBatch(noticeList)) {
throw new RuntimeException("批量保存用户通知失败");
} else {
noticeList.clear();
}
}
} else {
throw new RuntimeException("通知范围错误");
}
return Boolean.TRUE;
}