完善了之前的通知管理功能,支持对发送的通知的批量更改和删除;在学生证补办模块增加了完成制作功能。

This commit is contained in:
MDSMO
2025-08-11 15:25:53 +08:00
parent 28383d3a94
commit dd51721e4e
20 changed files with 510 additions and 178 deletions

View File

@@ -6,10 +6,8 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import com.srs.common.core.domain.BaseEntity;
/**
* 通知管理对象 cph_msg
* 通知管理对象 srs_notification
*
* @author srs
* @date 2025-07-30
@@ -20,40 +18,63 @@ import com.srs.common.core.domain.BaseEntity;
@AllArgsConstructor
@Builder
@ApiModel(value = "NotificationManagement对象" , description = "通知管理")
@TableName("cph_msg")
@TableName("srs_notification")
public class NotificationManagement extends BaseEntity{
private static final long serialVersionUID=1L;
private static final long serialVersionUID=1L;
/**
* $column.columnComment
* 通知ID
*/
@ApiModelProperty("${column.columnComment}")
@ApiModelProperty("通知ID")
@TableId(value = "id", type = IdType.AUTO)
@Excel(name = "${comment}" , readConverterExp = "$column.readConverterExp()")
@Excel(name = "通知ID")
private Long id;
/**
* 发送人用户id
* 通知标题
*/
@ApiModelProperty("发送人用户id")
@ApiModelProperty("通知标题")
@TableField("title")
@Excel(name = "通知标题")
private String title;
/**
* 通知内容
*/
@ApiModelProperty("通知内容")
@TableField("content")
@Excel(name = "通知内容")
private String content;
/**
* 年级ID列表以逗号分隔
*/
@ApiModelProperty("年级ID列表以逗号分隔")
@TableField("grade_ids")
@Excel(name = "年级ID列表")
private String gradeIds;
/**
* 年级名称
*/
@ApiModelProperty("年级名称")
@TableField("gradeName")
@Excel(name = "年级名称")
private String gradeName;
/**
* 发送人用户ID
*/
@ApiModelProperty("发送人用户ID")
@TableField("sender")
@Excel(name = "发送人用户id")
@Excel(name = "发送人用户ID")
private Long sender;
/**
* 收人用户id
* 收人用户ID用于cph_msg表
*/
@ApiModelProperty("人用户id")
@ApiModelProperty("收人用户ID")
@TableField("receiver")
private Long receiver;
/**
* 消息内容
*/
@ApiModelProperty("消息内容")
@TableField("content")
@Excel(name = "消息内容")
private String content;
}

View File

@@ -22,6 +22,9 @@ public class SendNotificationDto {
@ApiModelProperty("选中的年级ID列表")
private List<String> selectedGrades;
@ApiModelProperty("通知标题")
private String title;
@ApiModelProperty("通知内容")
private String content;

View File

@@ -76,15 +76,15 @@ public interface NotificationManagementMapper extends BaseMapper<NotificationMan
List<Long> selectStudentIdsByGrades(@Param("gradeIds") List<String> gradeIds);
/**
* 根据学号查询用户ID
* 根据年级ID列表查询学生学号列表
*
* @param stuNo 学号
* @return 用户ID
* @param gradeIds 年级ID列表
* @return 学生学号列表
*/
Long selectUserIdByStuNo(@Param("stuNo") String stuNo);
List<String> selectStudentNosByGrades(@Param("gradeIds") List<String> gradeIds);
/**
* 批量插入通知记录
* 批量插入通知记录到cph_msg表
*
* @param notifications 通知记录列表
* @return 结果
@@ -99,4 +99,23 @@ public interface NotificationManagementMapper extends BaseMapper<NotificationMan
* @return 通知管理集合
*/
List<NotificationManagement> selectNotificationManagementListBySender(@Param("notification") NotificationManagement notificationManagement, @Param("senderId") Long senderId);
/**
* 批量删除cph_msg表数据
*
* @param notificationList 通知列表
* @return 结果
*/
int batchDeleteCphMsg(@Param("list") List<NotificationManagement> notificationList);
/**
* 批量更新cph_msg表数据
*
* @param oldList 原数据列表
* @param newList 新数据列表
* @return 结果
*/
int batchUpdateCphMsg(@Param("oldList") List<NotificationManagement> oldList, @Param("newList") List<NotificationManagement> newList);
}

View File

@@ -63,4 +63,14 @@ public interface RtStuMultiLevelReviewMapper extends BaseMapper<RtStuMultiLevelR
* @return 结果
*/
int deleteRtStuMultiLevelReviewByIds(Long[] ids);
/**
* 更新审核信息并同时更新学生证补办状态
*
* @param rtStuMultiLevelReview 审核信息
* @return 结果
*/
int updateRtStuMultiLevelReviewWithStuIdReissue(RtStuMultiLevelReview rtStuMultiLevelReview);
}

View File

@@ -76,21 +76,12 @@ public interface INotificationManagementService extends IService<NotificationMan
int sendNotificationByGrades(SendNotificationDto sendNotificationDto);
/**
* 根据年级获取学生用户ID列表
* 根据年级获取学生学号列表
*
* @param gradeIds 年级ID列表
* @return 学生用户ID列表
* @return 学生学号列表
*/
List<Long> getStudentIdsByGrades(List<String> gradeIds);
/**
* 根据学号查询用户ID
*
* @param stuNo 学号
* @return 用户ID
*/
Long getUserIdByStuNo(String stuNo);
List<String> getStudentNosByGrades(List<String> gradeIds);
/**
* 查询当前用户发送的通知列表
@@ -99,6 +90,4 @@ public interface INotificationManagementService extends IService<NotificationMan
* @return 通知管理集合
*/
List<NotificationManagement> selectNotificationManagementListBySender(NotificationManagement notificationManagement);
}

View File

@@ -70,5 +70,13 @@ public interface IRtStuIdReissueService extends IService<RtStuIdReissue> {
*/
StuInfoReturnVo getStuInfo(String stuNo);
/**
* 完成制作
*
* @param id 学生证补办主键
* @return 结果
*/
int completedRtStuIdReissue(Long id);
}

View File

@@ -61,4 +61,15 @@ public interface IRtStuMultiLevelReviewService extends IService<RtStuMultiLevelR
* @return 结果
*/
int deleteRtStuMultiLevelReviewById(Long id);
/**
* 更新审核信息并同时更新学生证补办状态
*
* @param rtStuMultiLevelReview 审核信息
* @return 结果
*/
int updateRtStuMultiLevelReviewWithStuIdReissue(RtStuMultiLevelReview rtStuMultiLevelReview);
}

View File

@@ -1,8 +1,10 @@
package com.srs.routine.service.impl;
import java.util.List;
import java.util.stream.Collectors;
import java.util.ArrayList;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.SecurityUtils;
import com.srs.common.utils.WeChatUtil;
import com.srs.routine.domain.NotificationManagement;
import com.srs.comprehensive.domain.SrsGrade;
import com.srs.routine.domain.dto.SendNotificationDto;
@@ -11,9 +13,7 @@ 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;
import org.springframework.transaction.annotation.Transactional;
/**
* 通知管理Service业务层处理
@@ -26,6 +26,9 @@ public class NotificationManagementServiceImpl extends ServiceImpl<NotificationM
@Autowired
private NotificationManagementMapper notificationManagementMapper;
@Autowired
public WeChatUtil weChatUtil;
/**
* 查询通知管理
*
@@ -41,7 +44,7 @@ public class NotificationManagementServiceImpl extends ServiceImpl<NotificationM
* 查询通知管理列表
*
* @param notificationManagement 通知管理
* @return 通知管理
* @return 通知管理集合
*/
@Override
public List<NotificationManagement> selectNotificationManagementList(NotificationManagement notificationManagement) {
@@ -57,6 +60,7 @@ public class NotificationManagementServiceImpl extends ServiceImpl<NotificationM
@Override
public int insertNotificationManagement(NotificationManagement notificationManagement) {
notificationManagement.setCreateTime(DateUtils.getNowDate());
notificationManagement.setCreateBy(SecurityUtils.getUsername());
return notificationManagementMapper.insertNotificationManagement(notificationManagement);
}
@@ -67,9 +71,35 @@ public class NotificationManagementServiceImpl extends ServiceImpl<NotificationM
* @return 结果
*/
@Override
@Transactional
public int updateNotificationManagement(NotificationManagement notificationManagement) {
// 获取修改前的通知信息
NotificationManagement originalNotification = selectNotificationManagementById(notificationManagement.getId());
// 更新srs_notification表
notificationManagement.setUpdateTime(DateUtils.getNowDate());
return notificationManagementMapper.updateNotificationManagement(notificationManagement);
notificationManagement.setUpdateBy(SecurityUtils.getUsername());
int result = notificationManagementMapper.updateNotificationManagement(notificationManagement);
// 如果更新成功同步更新cph_msg表数据
if (result > 0 && originalNotification != null) {
// 构建更新条件:根据原内容、发送人和创建时间匹配
List<NotificationManagement> updateList = new ArrayList<>();
updateList.add(originalNotification);
// 构建新数据用于更新
List<NotificationManagement> newList = new ArrayList<>();
NotificationManagement newMsg = new NotificationManagement();
newMsg.setContent(notificationManagement.getContent());
newMsg.setSender(notificationManagement.getSender());
newMsg.setCreateTime(originalNotification.getCreateTime()); // 保持原创建时间不变
newList.add(newMsg);
// 批量更新cph_msg表
notificationManagementMapper.batchUpdateCphMsg(updateList, newList);
}
return result;
}
/**
@@ -79,7 +109,22 @@ public class NotificationManagementServiceImpl extends ServiceImpl<NotificationM
* @return 结果
*/
@Override
@Transactional
public int deleteNotificationManagementByIds(Long[] ids) {
// 先删除相关的cph_msg表数据
List<NotificationManagement> notifications = new ArrayList<>();
for (Long id : ids) {
NotificationManagement notification = selectNotificationManagementById(id);
if (notification != null) {
notifications.add(notification);
}
}
if (!notifications.isEmpty()) {
notificationManagementMapper.batchDeleteCphMsg(notifications);
}
// 删除srs_notification表数据
return notificationManagementMapper.deleteNotificationManagementByIds(ids);
}
@@ -90,7 +135,17 @@ public class NotificationManagementServiceImpl extends ServiceImpl<NotificationM
* @return 结果
*/
@Override
@Transactional
public int deleteNotificationManagementById(Long id) {
// 先删除相关的cph_msg表数据
NotificationManagement notification = selectNotificationManagementById(id);
if (notification != null) {
List<NotificationManagement> notifications = new ArrayList<>();
notifications.add(notification);
notificationManagementMapper.batchDeleteCphMsg(notifications);
}
// 删除srs_notification表数据
return notificationManagementMapper.deleteNotificationManagementById(id);
}
@@ -111,60 +166,58 @@ public class NotificationManagementServiceImpl extends ServiceImpl<NotificationM
* @return 结果
*/
@Override
@Transactional
public int sendNotificationByGrades(SendNotificationDto sendNotificationDto) {
// 获取当前登录用户ID作为发送人
Long senderId = SecurityUtils.getUserId();
if (sendNotificationDto.getSenderId() != null) {
senderId = sendNotificationDto.getSenderId();
// 1. 先插入srs_notification表
NotificationManagement notification = new NotificationManagement();
notification.setTitle(sendNotificationDto.getTitle());
notification.setContent(sendNotificationDto.getContent());
notification.setGradeIds(String.join(",", sendNotificationDto.getSelectedGrades()));
notification.setSender(SecurityUtils.getUserId());
notification.setCreateTime(DateUtils.getNowDate());
notification.setCreateBy(SecurityUtils.getUsername());
int result = notificationManagementMapper.insertNotificationManagement(notification);
// 2. 如果插入成功向cph_msg表插入学生通知记录
if (result > 0) {
// 根据年级获取学生用户ID列表
List<Long> studentIds = notificationManagementMapper.selectStudentIdsByGrades(sendNotificationDto.getSelectedGrades());
if (studentIds != null && !studentIds.isEmpty()) {
// 使用srs_notification表的create_time确保两个表的时间一致
java.util.Date notificationCreateTime = notification.getCreateTime();
// 批量构建cph_msg记录
List<NotificationManagement> cphMsgList = studentIds.stream()
.map(studentId -> {
NotificationManagement msg = new NotificationManagement();
msg.setSender(SecurityUtils.getUserId());
msg.setReceiver(studentId);
msg.setContent(sendNotificationDto.getContent());
msg.setCreateTime(notificationCreateTime);
return msg;
})
.collect(Collectors.toList());
// 批量插入cph_msg表
int i= notificationManagementMapper.batchInsertNotification(cphMsgList);
// 如果插入成功,发送企业微信消息
if (i > 0) {
//根据年级获取学生学号列表
List<String> studentNos = getStudentNosByGrades(sendNotificationDto.getSelectedGrades());
if (studentNos != null && !studentNos.isEmpty()) {
// 批量发送企业微信消息
sendWeChatMessagesBatch(studentNos, sendNotificationDto.getContent());
}
}
return i;
}
}
// 根据年级获取学生用户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);
return result;
}
/**
* 根据年级获取学生用户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);
}
/**
* 查询当前用户发送的通知列表
*
@@ -177,6 +230,34 @@ public class NotificationManagementServiceImpl extends ServiceImpl<NotificationM
Long senderId = SecurityUtils.getUserId();
return notificationManagementMapper.selectNotificationManagementListBySender(notificationManagement, senderId);
}
/**
* 批量发送企业微信消息
*
* @param studentNos 学生学号列表
* @param content 消息内容
*/
private void sendWeChatMessagesBatch(List<String> studentNos, String content) {
// 企业微信批量发送限制每次最多发送1000个用户
int batchSize = 1000;
for (int i = 0; i < studentNos.size(); i += batchSize) {
List<String> batch = studentNos.subList(i, Math.min(i + batchSize, studentNos.size()));
// 拼接成"2023001|2023002|2023003"格式
String toUser = String.join("|", batch);
// 调用企业微信发送消息方法
weChatUtil.sendTextMessage(toUser, content);
}
}
/**
* 根据年级获取学生学号列表
*
* @param gradeIds 年级ID列表
* @return 学生学号列表
*/
@Override
public List<String> getStudentNosByGrades(List<String> gradeIds) {
return notificationManagementMapper.selectStudentNosByGrades(gradeIds);
}
}

View File

@@ -137,4 +137,19 @@ public class RtStuIdReissueServiceImpl extends ServiceImpl<RtStuIdReissueMapper,
return null;
}
}
/**
* 完成制作
*
* @param id 学生证补办主键
* @return 结果
*/
@Override
public int completedRtStuIdReissue(Long id) {
RtStuIdReissue rtStuIdReissue = new RtStuIdReissue();
rtStuIdReissue.setId(id);
rtStuIdReissue.setInspectionProgress(3L); // 设置完成制作状态
rtStuIdReissue.setUpdateTime(DateUtils.getNowDate());
return rtStuIdReissueMapper.updateRtStuIdReissue(rtStuIdReissue);
}
}

View File

@@ -1,7 +1,7 @@
package com.srs.routine.service.impl;
import java.util.List;
import com.srs.common.utils.WeChatUtil;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -98,4 +98,29 @@ public class RtStuMultiLevelReviewServiceImpl extends ServiceImpl<RtStuMultiLeve
public int deleteRtStuMultiLevelReviewById(Long id) {
return rtStuMultiLevelReviewMapper.deleteRtStuMultiLevelReviewById(id);
}
/**
* 更新审核信息并同时更新学生证补办状态
*
* @param rtStuMultiLevelReview 审核信息
* @return 结果
*/
@Override
public int updateRtStuMultiLevelReviewWithStuIdReissue(RtStuMultiLevelReview rtStuMultiLevelReview) {
rtStuMultiLevelReview.setReviewTime(DateUtils.getNowDate());
rtStuMultiLevelReview.setReviewer(SecurityUtils.getLoginUser().getUser().getNickName());
rtStuMultiLevelReview.setReviewerId(SecurityUtils.getUserId());
int result = rtStuMultiLevelReviewMapper.updateRtStuMultiLevelReviewWithStuIdReissue(rtStuMultiLevelReview);
if (result > 0) {
String messageContent = rtStuMultiLevelReview.getNotes();
if (messageContent == null || messageContent.trim().isEmpty()) {
messageContent = "你申请办理的学生证制作完成长堽校区前往xxx领取里建校区前往xxx领取";
}
WeChatUtil weChatUtil = new WeChatUtil();
weChatUtil.sendTextMessage(rtStuMultiLevelReview.getStuNo(), messageContent);
}
return result;
}
}