Merge remote-tracking branch 'origin/main'

This commit is contained in:
2025-08-04 15:23:27 +08:00
7 changed files with 756 additions and 0 deletions

View File

@@ -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<NotificationManagement> 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<NotificationManagement> list = notificationManagementService.selectNotificationManagementList(notificationManagement);
ExcelUtil<NotificationManagement> util = new ExcelUtil<NotificationManagement>(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<SrsGrade> 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<NotificationManagement> list = notificationManagementService.selectNotificationManagementListBySender(notificationManagement);
return getDataTable(list);
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.srs.routine.mapper.NotificationManagementMapper">
<resultMap type="NotificationManagement" id="NotificationManagementResult">
<result property="id" column="id" />
<result property="sender" column="sender" />
<result property="receiver" column="receiver" />
<result property="content" column="content" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<resultMap type="SrsGrade" id="GradeResult">
<result property="gradeId" column="grade_id" />
<result property="gradeName" column="grade_name" />
<result property="gradeCode" column="grade_code" />
<result property="status" column="status" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectNotificationManagementVo">
select id, sender, receiver, content, create_by, create_time, update_by, update_time from cph_msg
</sql>
<sql id="selectGradeVo">
select grade_id, grade_name, grade_code, status, create_by, create_time, update_by, update_time from srs_grade
</sql>
<select id="selectNotificationManagementList" parameterType="NotificationManagement" resultMap="NotificationManagementResult">
<include refid="selectNotificationManagementVo"/>
<where>
<if test="sender != null "> and sender = #{sender}</if>
<if test="receiver != null "> and receiver = #{receiver}</if>
<if test="content != null and content != ''"> and content = #{content}</if>
</where>
</select>
<!-- 查询当前用户发送的通知列表 -->
<select id="selectNotificationManagementListBySender" resultMap="NotificationManagementResult">
<include refid="selectNotificationManagementVo"/>
<where>
sender = #{senderId}
<if test="notification.receiver != null "> and receiver = #{notification.receiver}</if>
<if test="notification.content != null and notification.content != ''"> and content = #{notification.content}</if>
</where>
order by create_time desc
</select>
<select id="selectNotificationManagementById" parameterType="Long" resultMap="NotificationManagementResult">
<include refid="selectNotificationManagementVo"/>
where id = #{id}
</select>
<insert id="insertNotificationManagement" parameterType="NotificationManagement" useGeneratedKeys="true" keyProperty="id">
insert into cph_msg
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="sender != null">sender,</if>
<if test="receiver != null">receiver,</if>
<if test="content != null">content,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="sender != null">#{sender},</if>
<if test="receiver != null">#{receiver},</if>
<if test="content != null">#{content},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateNotificationManagement" parameterType="NotificationManagement">
update cph_msg
<trim prefix="SET" suffixOverrides=",">
<if test="sender != null">sender = #{sender},</if>
<if test="receiver != null">receiver = #{receiver},</if>
<if test="content != null">content = #{content},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteNotificationManagementById" parameterType="Long">
delete from cph_msg where id = #{id}
</delete>
<delete id="deleteNotificationManagementByIds" parameterType="String">
delete from cph_msg where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<!-- 查询年级列表 -->
<select id="selectGradeList" resultMap="GradeResult">
<include refid="selectGradeVo"/>
where status = '0'
order by grade_code desc
</select>
<!-- 根据年级ID列表查询学生用户ID -->
<select id="selectStudentIdsByGrades" resultType="Long">
SELECT DISTINCT u.user_id
FROM srs_student ss
left JOIN srs_class sc ON ss.class_id = sc.class_id
left JOIN sys_user u ON ss.stu_no = u.user_name
WHERE u.user_id IS NOT NULL
AND sc.grade_id IN
<foreach item="gradeId" collection="gradeIds" open="(" separator="," close=")">
#{gradeId}
</foreach>
</select>
<!-- 批量插入通知记录 -->
<insert id="batchInsertNotification" parameterType="java.util.List">
insert into cph_msg (sender, receiver, content, create_time)
values
<foreach collection="list" item="item" separator=",">
(#{item.sender}, #{item.receiver}, #{item.content}, #{item.createTime})
</foreach>
</insert>
</mapper>