限制了给辅导员发送心理预警的次数
This commit is contained in:
@@ -18,6 +18,7 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* Dify心理问题发送企业微信 知无涯
|
||||
@@ -51,18 +52,32 @@ public class WeChatMentalAlertController extends BaseController {
|
||||
return AjaxResult.error("Token无效或已过期");
|
||||
}
|
||||
|
||||
String studentId = request.getUserId();
|
||||
|
||||
// 查询辅导员信息
|
||||
SysUser teacher = sysUserMapper.selectTeacherByStuNo(request.getUserId());
|
||||
if (teacher == null || !StringUtils.hasText(teacher.getUserName())) {
|
||||
log.error("辅导员信息不完整,学号: {}", request.getUserId());
|
||||
return AjaxResult.error("未分配辅导员或信息不完整");
|
||||
}
|
||||
|
||||
// 获取今天日期
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
// 查询该学生今天已触发的心理预警次数
|
||||
int todayCount = studentMentalRatingMapper.countTodayByStudentId(studentId, today);
|
||||
|
||||
/* 保存学生心理问题评级 */
|
||||
StudentMentalRating record = new StudentMentalRating();
|
||||
record.setStudentId(request.getUserId());
|
||||
record.setRating(request.getRating());
|
||||
studentMentalRatingMapper.insert(record);
|
||||
|
||||
// === 判断是否超过当日发送上限(3次)=== 陈冠元
|
||||
if (todayCount > 3) {
|
||||
return AjaxResult.success("预警已记录,因当日已达上限未发送通知");
|
||||
}
|
||||
|
||||
// 构建并发送消息
|
||||
try {
|
||||
String content = buildContent(request, teacher);
|
||||
|
@@ -3,6 +3,7 @@ package com.srs.system.mapper;
|
||||
import com.srs.system.domain.StudentMentalRating;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
public interface StudentMentalRatingMapper {
|
||||
@@ -28,5 +29,13 @@ public interface StudentMentalRatingMapper {
|
||||
/** 单学号全部记录 */
|
||||
List<StudentMentalRating> selectByStuNo(@Param("stuNo") String stuNo);
|
||||
|
||||
/**
|
||||
* 查询今天的心理评级记录 陈冠元
|
||||
* @param studentId 学生ID
|
||||
* @param today 今天的日期
|
||||
* @return 记录数
|
||||
*/
|
||||
int countTodayByStudentId(@Param("studentId") String studentId, @Param("today") LocalDate today);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -43,4 +43,12 @@
|
||||
WHERE student_id = #{stuNo}
|
||||
ORDER BY created_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 查询今天该学生是否已经填写过心理评测 陈冠元 -->
|
||||
<select id="countTodayByStudentId" resultType="int">
|
||||
SELECT COUNT(*)
|
||||
FROM student_mental_rating
|
||||
WHERE student_id = #{studentId}
|
||||
AND DATE(created_time) = #{today}
|
||||
</select>
|
||||
</mapper>
|
Reference in New Issue
Block a user