学工发布通知功能代码
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package com.srs.routine.domain;
|
||||
import com.srs.common.annotation.Excel;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.*;
|
||||
import com.srs.common.core.domain.BaseEntity;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 通知管理对象 cph_msg
|
||||
*
|
||||
* @author srs
|
||||
* @date 2025-07-30
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@ApiModel(value = "NotificationManagement对象" , description = "通知管理")
|
||||
@TableName("cph_msg")
|
||||
public class NotificationManagement extends BaseEntity{
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
@ApiModelProperty("${column.columnComment}")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
@Excel(name = "${comment}" , readConverterExp = "$column.readConverterExp()")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 发送人用户id
|
||||
*/
|
||||
@ApiModelProperty("发送人用户id")
|
||||
@TableField("sender")
|
||||
@Excel(name = "发送人用户id")
|
||||
private Long sender;
|
||||
|
||||
/**
|
||||
* 收信人用户id
|
||||
*/
|
||||
@ApiModelProperty("收信人用户id")
|
||||
@TableField("receiver")
|
||||
private Long receiver;
|
||||
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
@ApiModelProperty("消息内容")
|
||||
@TableField("content")
|
||||
@Excel(name = "消息内容")
|
||||
private String content;
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.srs.routine.domain.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 发送通知DTO
|
||||
*
|
||||
* @author srs
|
||||
* @date 2025-07-30
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "SendNotificationDto", description = "发送通知数据传输对象")
|
||||
public class SendNotificationDto {
|
||||
|
||||
@ApiModelProperty("发送人用户ID")
|
||||
private Long senderId;
|
||||
|
||||
@ApiModelProperty("选中的年级ID列表")
|
||||
private List<String> selectedGrades;
|
||||
|
||||
@ApiModelProperty("通知内容")
|
||||
private String content;
|
||||
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
package com.srs.routine.mapper;
|
||||
import java.util.List;
|
||||
import com.srs.comprehensive.domain.SrsGrade;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.srs.routine.domain.NotificationManagement;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 通知管理Mapper接口
|
||||
*
|
||||
* @author srs
|
||||
* @date 2025-07-30
|
||||
*/
|
||||
public interface NotificationManagementMapper extends BaseMapper<NotificationManagement> {
|
||||
/**
|
||||
* 查询通知管理
|
||||
*
|
||||
* @param id 通知管理主键
|
||||
* @return 通知管理
|
||||
*/
|
||||
public NotificationManagement selectNotificationManagementById(Long id);
|
||||
|
||||
/**
|
||||
* 查询通知管理列表
|
||||
*
|
||||
* @param notificationManagement 通知管理
|
||||
* @return 通知管理集合
|
||||
*/
|
||||
List<NotificationManagement> selectNotificationManagementList(NotificationManagement notificationManagement);
|
||||
|
||||
/**
|
||||
* 新增通知管理
|
||||
*
|
||||
* @param notificationManagement 通知管理
|
||||
* @return 结果
|
||||
*/
|
||||
int insertNotificationManagement(NotificationManagement notificationManagement);
|
||||
|
||||
/**
|
||||
* 修改通知管理
|
||||
*
|
||||
* @param notificationManagement 通知管理
|
||||
* @return 结果
|
||||
*/
|
||||
int updateNotificationManagement(NotificationManagement notificationManagement);
|
||||
|
||||
/**
|
||||
* 删除通知管理
|
||||
*
|
||||
* @param id 通知管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteNotificationManagementById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除通知管理
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteNotificationManagementByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 查询年级列表
|
||||
*
|
||||
* @return 年级列表
|
||||
*/
|
||||
List<SrsGrade> selectGradeList();
|
||||
|
||||
/**
|
||||
* 根据年级ID列表查询学生用户ID
|
||||
*
|
||||
* @param gradeIds 年级ID列表
|
||||
* @return 学生用户ID列表
|
||||
*/
|
||||
List<Long> selectStudentIdsByGrades(@Param("gradeIds") List<String> gradeIds);
|
||||
|
||||
/**
|
||||
* 根据学号查询用户ID
|
||||
*
|
||||
* @param stuNo 学号
|
||||
* @return 用户ID
|
||||
*/
|
||||
Long selectUserIdByStuNo(@Param("stuNo") String stuNo);
|
||||
|
||||
/**
|
||||
* 批量插入通知记录
|
||||
*
|
||||
* @param notifications 通知记录列表
|
||||
* @return 结果
|
||||
*/
|
||||
int batchInsertNotification(@Param("list") List<NotificationManagement> notifications);
|
||||
|
||||
/**
|
||||
* 查询当前用户发送的通知列表
|
||||
*
|
||||
* @param notificationManagement 通知管理
|
||||
* @param senderId 发送人ID
|
||||
* @return 通知管理集合
|
||||
*/
|
||||
List<NotificationManagement> selectNotificationManagementListBySender(@Param("notification") NotificationManagement notificationManagement, @Param("senderId") Long senderId);
|
||||
}
|
@@ -0,0 +1,104 @@
|
||||
package com.srs.routine.service;
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.srs.routine.domain.NotificationManagement;
|
||||
import com.srs.routine.domain.dto.SendNotificationDto;
|
||||
import com.srs.comprehensive.domain.SrsGrade;
|
||||
|
||||
/**
|
||||
* 通知管理Service接口
|
||||
*
|
||||
* @author srs
|
||||
* @date 2025-07-30
|
||||
*/
|
||||
public interface INotificationManagementService extends IService<NotificationManagement> {
|
||||
/**
|
||||
* 查询通知管理
|
||||
*
|
||||
* @param id 通知管理主键
|
||||
* @return 通知管理
|
||||
*/
|
||||
public NotificationManagement selectNotificationManagementById(Long id);
|
||||
|
||||
/**
|
||||
* 查询通知管理列表
|
||||
*
|
||||
* @param notificationManagement 通知管理
|
||||
* @return 通知管理集合
|
||||
*/
|
||||
List<NotificationManagement> selectNotificationManagementList(NotificationManagement notificationManagement);
|
||||
|
||||
/**
|
||||
* 新增通知管理
|
||||
*
|
||||
* @param notificationManagement 通知管理
|
||||
* @return 结果
|
||||
*/
|
||||
int insertNotificationManagement(NotificationManagement notificationManagement);
|
||||
|
||||
/**
|
||||
* 修改通知管理
|
||||
*
|
||||
* @param notificationManagement 通知管理
|
||||
* @return 结果
|
||||
*/
|
||||
int updateNotificationManagement(NotificationManagement notificationManagement);
|
||||
|
||||
/**
|
||||
* 批量删除通知管理
|
||||
*
|
||||
* @param ids 需要删除的通知管理主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteNotificationManagementByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除通知管理信息
|
||||
*
|
||||
* @param id 通知管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteNotificationManagementById(Long id);
|
||||
|
||||
/**
|
||||
* 获取年级列表
|
||||
*
|
||||
* @return 年级列表
|
||||
*/
|
||||
List<SrsGrade> getGradeList();
|
||||
|
||||
/**
|
||||
* 按年级发送通知
|
||||
*
|
||||
* @param sendNotificationDto 发送通知DTO
|
||||
* @return 结果
|
||||
*/
|
||||
int sendNotificationByGrades(SendNotificationDto sendNotificationDto);
|
||||
|
||||
/**
|
||||
* 根据年级获取学生用户ID列表
|
||||
*
|
||||
* @param gradeIds 年级ID列表
|
||||
* @return 学生用户ID列表
|
||||
*/
|
||||
List<Long> getStudentIdsByGrades(List<String> gradeIds);
|
||||
|
||||
/**
|
||||
* 根据学号查询用户ID
|
||||
*
|
||||
* @param stuNo 学号
|
||||
* @return 用户ID
|
||||
*/
|
||||
Long getUserIdByStuNo(String stuNo);
|
||||
|
||||
|
||||
/**
|
||||
* 查询当前用户发送的通知列表
|
||||
*
|
||||
* @param notificationManagement 通知管理
|
||||
* @return 通知管理集合
|
||||
*/
|
||||
List<NotificationManagement> selectNotificationManagementListBySender(NotificationManagement notificationManagement);
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,182 @@
|
||||
package com.srs.routine.service.impl;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import com.srs.common.utils.DateUtils;
|
||||
import com.srs.common.utils.SecurityUtils;
|
||||
import com.srs.routine.domain.NotificationManagement;
|
||||
import com.srs.comprehensive.domain.SrsGrade;
|
||||
import com.srs.routine.domain.dto.SendNotificationDto;
|
||||
import com.srs.routine.mapper.NotificationManagementMapper;
|
||||
import com.srs.routine.service.INotificationManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 通知管理Service业务层处理
|
||||
*
|
||||
* @author srs
|
||||
* @date 2025-07-30
|
||||
*/
|
||||
@Service
|
||||
public class NotificationManagementServiceImpl extends ServiceImpl<NotificationManagementMapper,NotificationManagement> implements INotificationManagementService {
|
||||
@Autowired
|
||||
private NotificationManagementMapper notificationManagementMapper;
|
||||
|
||||
/**
|
||||
* 查询通知管理
|
||||
*
|
||||
* @param id 通知管理主键
|
||||
* @return 通知管理
|
||||
*/
|
||||
@Override
|
||||
public NotificationManagement selectNotificationManagementById(Long id) {
|
||||
return notificationManagementMapper.selectNotificationManagementById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询通知管理列表
|
||||
*
|
||||
* @param notificationManagement 通知管理
|
||||
* @return 通知管理
|
||||
*/
|
||||
@Override
|
||||
public List<NotificationManagement> selectNotificationManagementList(NotificationManagement notificationManagement) {
|
||||
return notificationManagementMapper.selectNotificationManagementList(notificationManagement);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增通知管理
|
||||
*
|
||||
* @param notificationManagement 通知管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertNotificationManagement(NotificationManagement notificationManagement) {
|
||||
notificationManagement.setCreateTime(DateUtils.getNowDate());
|
||||
return notificationManagementMapper.insertNotificationManagement(notificationManagement);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改通知管理
|
||||
*
|
||||
* @param notificationManagement 通知管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateNotificationManagement(NotificationManagement notificationManagement) {
|
||||
notificationManagement.setUpdateTime(DateUtils.getNowDate());
|
||||
return notificationManagementMapper.updateNotificationManagement(notificationManagement);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除通知管理
|
||||
*
|
||||
* @param ids 需要删除的通知管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteNotificationManagementByIds(Long[] ids) {
|
||||
return notificationManagementMapper.deleteNotificationManagementByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除通知管理信息
|
||||
*
|
||||
* @param id 通知管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteNotificationManagementById(Long id) {
|
||||
return notificationManagementMapper.deleteNotificationManagementById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年级列表
|
||||
*
|
||||
* @return 年级列表
|
||||
*/
|
||||
@Override
|
||||
public List<SrsGrade> getGradeList() {
|
||||
return notificationManagementMapper.selectGradeList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按年级发送通知
|
||||
*
|
||||
* @param sendNotificationDto 发送通知DTO
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int sendNotificationByGrades(SendNotificationDto sendNotificationDto) {
|
||||
// 获取当前登录用户ID作为发送人
|
||||
Long senderId = SecurityUtils.getUserId();
|
||||
if (sendNotificationDto.getSenderId() != null) {
|
||||
senderId = sendNotificationDto.getSenderId();
|
||||
}
|
||||
|
||||
// 根据年级获取学生用户ID列表
|
||||
List<Long> studentIds = getStudentIdsByGrades(sendNotificationDto.getSelectedGrades());
|
||||
|
||||
if (studentIds == null || studentIds.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 批量构建通知记录
|
||||
final Long finalSenderId = senderId;
|
||||
List<NotificationManagement> notifications = studentIds.stream()
|
||||
.map(studentId -> {
|
||||
NotificationManagement notification = new NotificationManagement();
|
||||
notification.setSender(finalSenderId);
|
||||
notification.setReceiver(studentId);
|
||||
notification.setContent(sendNotificationDto.getContent());
|
||||
notification.setCreateTime(DateUtils.getNowDate());
|
||||
return notification;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 批量插入
|
||||
return notificationManagementMapper.batchInsertNotification(notifications);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据年级获取学生用户ID列表
|
||||
*
|
||||
* @param gradeIds 年级ID列表
|
||||
* @return 学生用户ID列表
|
||||
*/
|
||||
@Override
|
||||
public List<Long> getStudentIdsByGrades(List<String> gradeIds) {
|
||||
return notificationManagementMapper.selectStudentIdsByGrades(gradeIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据学号查询用户ID
|
||||
*
|
||||
* @param stuNo 学号
|
||||
* @return 用户ID
|
||||
*/
|
||||
@Override
|
||||
public Long getUserIdByStuNo(String stuNo) {
|
||||
return notificationManagementMapper.selectUserIdByStuNo(stuNo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询当前用户发送的通知列表
|
||||
*
|
||||
* @param notificationManagement 通知管理
|
||||
* @return 通知管理集合
|
||||
*/
|
||||
@Override
|
||||
public List<NotificationManagement> selectNotificationManagementListBySender(NotificationManagement notificationManagement) {
|
||||
// 获取当前登录用户ID
|
||||
Long senderId = SecurityUtils.getUserId();
|
||||
return notificationManagementMapper.selectNotificationManagementListBySender(notificationManagement, senderId);
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user