From 28383d3a94f43c5ef46438169a28d051b4c56433 Mon Sep 17 00:00:00 2001 From: MDSMO Date: Mon, 4 Aug 2025 15:10:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E5=B7=A5=E5=8F=91=E5=B8=83=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E5=8A=9F=E8=83=BD=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NotificationManagementController.java | 142 ++++++++++++++ .../domain/NotificationManagement.java | 59 ++++++ .../domain/dto/SendNotificationDto.java | 28 +++ .../mapper/NotificationManagementMapper.java | 102 ++++++++++ .../INotificationManagementService.java | 104 ++++++++++ .../NotificationManagementServiceImpl.java | 182 ++++++++++++++++++ .../routine/NotificationManagementMapper.xml | 139 +++++++++++++ 7 files changed, 756 insertions(+) create mode 100644 srs-admin/src/main/java/com/srs/web/controller/routine/NotificationManagementController.java create mode 100644 srs-routine/src/main/java/com/srs/routine/domain/NotificationManagement.java create mode 100644 srs-routine/src/main/java/com/srs/routine/domain/dto/SendNotificationDto.java create mode 100644 srs-routine/src/main/java/com/srs/routine/mapper/NotificationManagementMapper.java create mode 100644 srs-routine/src/main/java/com/srs/routine/service/INotificationManagementService.java create mode 100644 srs-routine/src/main/java/com/srs/routine/service/impl/NotificationManagementServiceImpl.java create mode 100644 srs-routine/src/main/resources/mapper/routine/NotificationManagementMapper.xml diff --git a/srs-admin/src/main/java/com/srs/web/controller/routine/NotificationManagementController.java b/srs-admin/src/main/java/com/srs/web/controller/routine/NotificationManagementController.java new file mode 100644 index 0000000..95e692f --- /dev/null +++ b/srs-admin/src/main/java/com/srs/web/controller/routine/NotificationManagementController.java @@ -0,0 +1,142 @@ +package com.srs.web.controller.routine; +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import com.srs.routine.domain.NotificationManagement; +import com.srs.routine.domain.dto.SendNotificationDto; +import com.srs.routine.service.INotificationManagementService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import org.springframework.security.access.prepost.PreAuthorize; +import com.srs.common.core.controller.BaseController; +import com.srs.common.core.domain.AjaxResult; +import com.srs.common.utils.poi.ExcelUtil; +import com.srs.common.enums.BusinessType; +import com.srs.common.annotation.Log; +import com.srs.common.core.page.TableDataInfo; +import com.srs.comprehensive.domain.SrsGrade; +/** + * 通知管理Controller + * + * @author srs + * @date 2025-07-30 + */ +@RestController +@RequestMapping("/routine/NotificationManagement") +@Api(value = "通知管理管理", tags = "通知管理管理") +public class NotificationManagementController extends BaseController { + @Autowired + private INotificationManagementService notificationManagementService; + + /** + * 查询通知管理列表 + */ +@PreAuthorize("@ss.hasPermi('routine:NotificationManagement:list')") +@GetMapping("/list") +@ApiOperation("查询通知管理列表") + public TableDataInfo list(NotificationManagement notificationManagement) + { + startPage(); + List list = notificationManagementService.selectNotificationManagementList(notificationManagement); + return getDataTable(list); + } + + /** + * 导出通知管理列表 + */ + @PreAuthorize("@ss.hasPermi('routine:NotificationManagement:export')") + @Log(title = "通知管理", businessType = BusinessType.EXPORT) + @PostMapping("/export") + @ApiOperation("导出通知管理列表") + public void export(HttpServletResponse response, NotificationManagement notificationManagement) + { + List list = notificationManagementService.selectNotificationManagementList(notificationManagement); + ExcelUtil util = new ExcelUtil(NotificationManagement.class); + util.exportExcel(response, list, "通知管理数据"); + } + + /** + * 获取通知管理详细信息 + */ + @PreAuthorize("@ss.hasPermi('routine:NotificationManagement:query')") + @GetMapping(value = "/{id}") + @ApiOperation("获取通知管理详细信息") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(notificationManagementService.selectNotificationManagementById(id)); + } + + /** + * 新增通知管理 + */ + @PreAuthorize("@ss.hasPermi('routine:NotificationManagement:add')") + @Log(title = "通知管理", businessType = BusinessType.INSERT) + @PostMapping("/add") + @ApiOperation("新增通知管理") + public AjaxResult add(@RequestBody NotificationManagement notificationManagement) + { + return toAjax(notificationManagementService.insertNotificationManagement(notificationManagement)); + } + + /** + * 修改通知管理 + */ + @PreAuthorize("@ss.hasPermi('routine:NotificationManagement:edit')") + @Log(title = "通知管理", businessType = BusinessType.UPDATE) + @PostMapping("/update") + @ApiOperation("修改通知管理") + public AjaxResult edit(@RequestBody NotificationManagement notificationManagement) + { + return toAjax(notificationManagementService.updateNotificationManagement(notificationManagement)); + } + + /** + * 删除通知管理 + */ + @PreAuthorize("@ss.hasPermi('routine:NotificationManagement:remove')") + @Log(title = "通知管理", businessType = BusinessType.DELETE) + @PostMapping("/{ids}") + @ApiOperation("删除通知管理") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(notificationManagementService.deleteNotificationManagementByIds(ids)); + } + + /** + * 获取年级列表 + */ + @PreAuthorize("@ss.hasPermi('routine:NotificationManagement:list')") + @GetMapping("/gradeList") + @ApiOperation("获取年级列表") + public AjaxResult getGradeList() + { + List gradeList = notificationManagementService.getGradeList(); + return success(gradeList); + } + + /** + * 按年级发送通知 + */ + @PreAuthorize("@ss.hasPermi('routine:NotificationManagement:add')") + @Log(title = "按年级发送通知", businessType = BusinessType.INSERT) + @PostMapping("/sendByGrades") + @ApiOperation("按年级发送通知") + public AjaxResult sendNotificationByGrades(@RequestBody SendNotificationDto sendNotificationDto) + { + int result = notificationManagementService.sendNotificationByGrades(sendNotificationDto); + return toAjax(result); + } + + /** + * 查询当前用户发送的通知列表 + */ + @PreAuthorize("@ss.hasPermi('routine:NotificationManagement:list')") + @GetMapping("/my-sent") + @ApiOperation("查询当前用户发送的通知列表") + public TableDataInfo mySentList(NotificationManagement notificationManagement) + { + startPage(); + List list = notificationManagementService.selectNotificationManagementListBySender(notificationManagement); + return getDataTable(list); + } +} diff --git a/srs-routine/src/main/java/com/srs/routine/domain/NotificationManagement.java b/srs-routine/src/main/java/com/srs/routine/domain/NotificationManagement.java new file mode 100644 index 0000000..5baed55 --- /dev/null +++ b/srs-routine/src/main/java/com/srs/routine/domain/NotificationManagement.java @@ -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; + + +} diff --git a/srs-routine/src/main/java/com/srs/routine/domain/dto/SendNotificationDto.java b/srs-routine/src/main/java/com/srs/routine/domain/dto/SendNotificationDto.java new file mode 100644 index 0000000..18d78dd --- /dev/null +++ b/srs-routine/src/main/java/com/srs/routine/domain/dto/SendNotificationDto.java @@ -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 selectedGrades; + + @ApiModelProperty("通知内容") + private String content; + +} \ No newline at end of file diff --git a/srs-routine/src/main/java/com/srs/routine/mapper/NotificationManagementMapper.java b/srs-routine/src/main/java/com/srs/routine/mapper/NotificationManagementMapper.java new file mode 100644 index 0000000..01107e1 --- /dev/null +++ b/srs-routine/src/main/java/com/srs/routine/mapper/NotificationManagementMapper.java @@ -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 { + /** + * 查询通知管理 + * + * @param id 通知管理主键 + * @return 通知管理 + */ + public NotificationManagement selectNotificationManagementById(Long id); + + /** + * 查询通知管理列表 + * + * @param notificationManagement 通知管理 + * @return 通知管理集合 + */ + List 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 selectGradeList(); + + /** + * 根据年级ID列表查询学生用户ID + * + * @param gradeIds 年级ID列表 + * @return 学生用户ID列表 + */ + List selectStudentIdsByGrades(@Param("gradeIds") List gradeIds); + + /** + * 根据学号查询用户ID + * + * @param stuNo 学号 + * @return 用户ID + */ + Long selectUserIdByStuNo(@Param("stuNo") String stuNo); + + /** + * 批量插入通知记录 + * + * @param notifications 通知记录列表 + * @return 结果 + */ + int batchInsertNotification(@Param("list") List notifications); + + /** + * 查询当前用户发送的通知列表 + * + * @param notificationManagement 通知管理 + * @param senderId 发送人ID + * @return 通知管理集合 + */ + List selectNotificationManagementListBySender(@Param("notification") NotificationManagement notificationManagement, @Param("senderId") Long senderId); +} diff --git a/srs-routine/src/main/java/com/srs/routine/service/INotificationManagementService.java b/srs-routine/src/main/java/com/srs/routine/service/INotificationManagementService.java new file mode 100644 index 0000000..21135bc --- /dev/null +++ b/srs-routine/src/main/java/com/srs/routine/service/INotificationManagementService.java @@ -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 { + /** + * 查询通知管理 + * + * @param id 通知管理主键 + * @return 通知管理 + */ + public NotificationManagement selectNotificationManagementById(Long id); + + /** + * 查询通知管理列表 + * + * @param notificationManagement 通知管理 + * @return 通知管理集合 + */ + List 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 getGradeList(); + + /** + * 按年级发送通知 + * + * @param sendNotificationDto 发送通知DTO + * @return 结果 + */ + int sendNotificationByGrades(SendNotificationDto sendNotificationDto); + + /** + * 根据年级获取学生用户ID列表 + * + * @param gradeIds 年级ID列表 + * @return 学生用户ID列表 + */ + List getStudentIdsByGrades(List gradeIds); + + /** + * 根据学号查询用户ID + * + * @param stuNo 学号 + * @return 用户ID + */ + Long getUserIdByStuNo(String stuNo); + + + /** + * 查询当前用户发送的通知列表 + * + * @param notificationManagement 通知管理 + * @return 通知管理集合 + */ + List selectNotificationManagementListBySender(NotificationManagement notificationManagement); + + +} diff --git a/srs-routine/src/main/java/com/srs/routine/service/impl/NotificationManagementServiceImpl.java b/srs-routine/src/main/java/com/srs/routine/service/impl/NotificationManagementServiceImpl.java new file mode 100644 index 0000000..d9e10e3 --- /dev/null +++ b/srs-routine/src/main/java/com/srs/routine/service/impl/NotificationManagementServiceImpl.java @@ -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 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 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 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 studentIds = getStudentIdsByGrades(sendNotificationDto.getSelectedGrades()); + + if (studentIds == null || studentIds.isEmpty()) { + return 0; + } + + // 批量构建通知记录 + final Long finalSenderId = senderId; + List 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 getStudentIdsByGrades(List 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 selectNotificationManagementListBySender(NotificationManagement notificationManagement) { + // 获取当前登录用户ID + Long senderId = SecurityUtils.getUserId(); + return notificationManagementMapper.selectNotificationManagementListBySender(notificationManagement, senderId); + } + + +} diff --git a/srs-routine/src/main/resources/mapper/routine/NotificationManagementMapper.xml b/srs-routine/src/main/resources/mapper/routine/NotificationManagementMapper.xml new file mode 100644 index 0000000..bbcd073 --- /dev/null +++ b/srs-routine/src/main/resources/mapper/routine/NotificationManagementMapper.xml @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + select id, sender, receiver, content, create_by, create_time, update_by, update_time from cph_msg + + + + select grade_id, grade_name, grade_code, status, create_by, create_time, update_by, update_time from srs_grade + + + + + + + + + + + insert into cph_msg + + sender, + receiver, + content, + create_by, + create_time, + update_by, + update_time, + + + #{sender}, + #{receiver}, + #{content}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + update cph_msg + + sender = #{sender}, + receiver = #{receiver}, + content = #{content}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where id = #{id} + + + + delete from cph_msg where id = #{id} + + + + delete from cph_msg where id in + + #{id} + + + + + + + + + + + + + insert into cph_msg (sender, receiver, content, create_time) + values + + (#{item.sender}, #{item.receiver}, #{item.content}, #{item.createTime}) + + + + \ No newline at end of file