Browse Source

学生请假未归通知

dzx 4 months ago
parent
commit
335cbd16b8

+ 120 - 0
src/main/java/com/xjrsoft/module/job/StudentLeaveNoticeTask.java

@@ -0,0 +1,120 @@
+package com.xjrsoft.module.job;
+
+import cn.hutool.core.util.IdUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.xjrsoft.common.enums.DeleteMark;
+import com.xjrsoft.common.enums.OutInStatusEnum;
+import com.xjrsoft.common.utils.VoToColumnUtil;
+import com.xjrsoft.module.base.entity.BaseUserStudent;
+import com.xjrsoft.module.organization.dto.WeChatSendMessageDto;
+import com.xjrsoft.module.organization.entity.User;
+import com.xjrsoft.module.organization.service.IUserService;
+import com.xjrsoft.module.organization.service.IWeChatService;
+import com.xjrsoft.module.outint.entity.StudentOutInRecord;
+import com.xjrsoft.module.outint.service.IStudentOutInRecordService;
+import com.xjrsoft.module.student.service.IStudentLeaveService;
+import com.xjrsoft.module.student.vo.NoBackStudentInfoVo;
+import lombok.extern.slf4j.Slf4j;
+import me.zhyd.oauth.log.Log;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author dzx
+ * @date 2024/9/2
+ */
+@Component
+@Slf4j
+public class StudentLeaveNoticeTask {
+
+    @Autowired
+    private IStudentLeaveService studentLeaveService;
+
+    @Autowired
+    private IUserService userService;
+
+    @Autowired
+    private IStudentOutInRecordService recordService;
+
+    @Autowired
+    private IWeChatService weChatService;
+
+    private final static String wechatTemplate = "KsSLrcCaFC5LUNo3Y68AnrFBBu4xg9-Ab8QiFW82rDw";
+
+    @Scheduled(cron = "0 */15 * * * ?")
+    public void execute() {
+        doExecute();
+    }
+
+    public void doExecute(){
+        List<NoBackStudentInfoVo> noBackList = studentLeaveService.getNoBackStudentInfo();
+
+        List<Long> updateList = new ArrayList<>();
+        for (NoBackStudentInfoVo studentLeave : noBackList) {
+            //1、查询这些学生是否有进入记录
+            List<StudentOutInRecord> recordList = recordService.list(
+                    new QueryWrapper<StudentOutInRecord>().lambda()
+                            .eq(StudentOutInRecord::getStatus, OutInStatusEnum.goOut.getCode())
+                            .eq(StudentOutInRecord::getUserId, studentLeave.getStudentUserId())
+                            .between(StudentOutInRecord::getRecordTime, studentLeave.getStartDate(), studentLeave.getEndDate())
+                            .eq(StudentOutInRecord::getDeleteMark, DeleteMark.NODELETE.getCode())
+            );
+            if(!recordList.isEmpty()){
+                continue;
+            }
+            try {
+                WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
+                weChatSendMessageDto.setTemplateId(wechatTemplate);
+                weChatSendMessageDto.setMsgId(IdUtil.getSnowflakeNextId() + "");
+                JSONObject paramJson = new JSONObject();
+
+                JSONObject thing1 = new JSONObject();
+                thing1.put("value", studentLeave.getClassName());
+                paramJson.put("thing1", thing1);
+
+                JSONObject thing2 = new JSONObject();
+                thing2.put("value", studentLeave.getName());
+                paramJson.put("thing2", thing2);
+
+                JSONObject time3 = new JSONObject();
+                time3.put("value", studentLeave.getEndDateStr());
+                paramJson.put("time3", time3);
+
+                weChatSendMessageDto.setContent(paramJson);
+                if(studentLeave.getOpenId() != null){
+                    weChatSendMessageDto.setUserId(studentLeave.getOpenId());
+                    weChatService.sendTemplateMessage(weChatSendMessageDto);
+                }
+
+                //查询家长
+                List<User> parentList = userService.list(
+                        new MPJLambdaWrapper<User>()
+                                .select(User::getId)
+                                .select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
+                                .innerJoin(BaseUserStudent.class, BaseUserStudent::getUserId, User::getId)
+                                .eq(BaseUserStudent::getStudentId, studentLeave.getStudentUserId())
+                                .isNotNull(User::getOpenId)
+                );
+                for (User user : parentList) {
+                    weChatSendMessageDto.setUserId(user.getOpenId());
+                    weChatService.sendTemplateMessage(weChatSendMessageDto);
+                }
+                updateList.add(studentLeave.getId());
+            }catch (Exception e){
+                Log.error(e.getMessage(), e);
+            }
+        }
+
+        if(!updateList.isEmpty()){
+            studentLeaveService.updateIsNotice(updateList);
+        }
+    }
+
+}
+

+ 6 - 2
src/main/java/com/xjrsoft/module/student/entity/StudentLeave.java

@@ -11,6 +11,7 @@ import lombok.Data;
 
 import java.io.Serializable;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.Date;
 
 
@@ -78,10 +79,10 @@ public class StudentLeave implements Serializable {
     private Long classId;
 
     @ApiModelProperty("开始时间")
-    private LocalDate startDate;
+    private LocalDateTime startDate;
 
     @ApiModelProperty("开始时间")
-    private LocalDate endDate;
+    private LocalDateTime endDate;
 
     @ApiModelProperty("请假原因")
     private String reason;
@@ -106,4 +107,7 @@ public class StudentLeave implements Serializable {
 
     @ApiModelProperty("海康接口返回信息")
     private String hikvisionResult;
+
+    @ApiModelProperty("是否已通知班主任和家长(0:否 1:是)")
+    private Integer isNotice;
 }

+ 5 - 0
src/main/java/com/xjrsoft/module/student/mapper/StudentLeaveMapper.java

@@ -6,6 +6,7 @@ import com.xjrsoft.module.attendance.dto.AttendanceStatisticDto;
 import com.xjrsoft.module.outint.vo.IdCountVo;
 import com.xjrsoft.module.student.dto.StudentLeavePageDto;
 import com.xjrsoft.module.student.entity.StudentLeave;
+import com.xjrsoft.module.student.vo.NoBackStudentInfoVo;
 import com.xjrsoft.module.student.vo.StudentLeavePageVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -30,4 +31,8 @@ public interface StudentLeaveMapper extends MPJBaseMapper<StudentLeave> {
     List<StudentLeave> getLeaveList(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
 
     Page<StudentLeavePageVo> getLeavePage(Page<StudentLeavePageVo> page, StudentLeavePageDto dto);
+
+    List<NoBackStudentInfoVo> getNoBackStudentInfo();
+
+    void updateIsNotice(@Param("ids") List<Long> ids);
 }

+ 6 - 0
src/main/java/com/xjrsoft/module/student/service/IStudentLeaveService.java

@@ -5,10 +5,12 @@ import com.github.yulichang.base.MPJBaseService;
 import com.xjrsoft.module.attendance.dto.AttendanceStatisticDto;
 import com.xjrsoft.module.student.dto.StudentLeavePageDto;
 import com.xjrsoft.module.student.entity.StudentLeave;
+import com.xjrsoft.module.student.vo.NoBackStudentInfoVo;
 import com.xjrsoft.module.student.vo.StudentLeavePageVo;
 import org.apache.ibatis.annotations.Param;
 
 import java.time.LocalDateTime;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -32,4 +34,8 @@ public interface IStudentLeaveService extends MPJBaseService<StudentLeave> {
     Page<StudentLeavePageVo> getLeavePage(Page<StudentLeavePageVo> page, StudentLeavePageDto dto);
 
     Boolean noticeParents(Long id);
+
+    List<NoBackStudentInfoVo> getNoBackStudentInfo();
+
+    void updateIsNotice(List<Long> ids);
 }

+ 12 - 2
src/main/java/com/xjrsoft/module/student/service/impl/StudentLeaveServiceImpl.java

@@ -26,6 +26,7 @@ import com.xjrsoft.module.student.entity.StudentLeave;
 import com.xjrsoft.module.student.mapper.StudentLeaveMapper;
 import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
 import com.xjrsoft.module.student.service.IStudentLeaveService;
+import com.xjrsoft.module.student.vo.NoBackStudentInfoVo;
 import com.xjrsoft.module.student.vo.StudentLeavePageVo;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
@@ -69,8 +70,8 @@ public class StudentLeaveServiceImpl extends MPJBaseServiceImpl<StudentLeaveMapp
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern(outputFormat);
         JsonObject paramJson = new JsonObject();
 
-        paramJson.addProperty("startTime", studentLeave.getStartDate().atStartOfDay().format(formatter));
-        paramJson.addProperty("endTime", studentLeave.getEndDate().atTime(23,59,59).format(formatter));
+        paramJson.addProperty("startTime", studentLeave.getStartDate().toLocalDate().atStartOfDay().format(formatter));
+        paramJson.addProperty("endTime", studentLeave.getEndDate().toLocalDate().atTime(23,59,59).format(formatter));
 
         //组装人员数据
         JsonArray personDatas = new JsonArray();
@@ -212,4 +213,13 @@ public class StudentLeaveServiceImpl extends MPJBaseServiceImpl<StudentLeaveMapp
 
         return resourceInfos;
     }
+
+    public List<NoBackStudentInfoVo> getNoBackStudentInfo(){
+        return this.baseMapper.getNoBackStudentInfo();
+    }
+
+
+    public void updateIsNotice(List<Long> ids) {
+        baseMapper.updateIsNotice(ids);
+    }
 }

+ 45 - 0
src/main/java/com/xjrsoft/module/student/vo/NoBackStudentInfoVo.java

@@ -0,0 +1,45 @@
+package com.xjrsoft.module.student.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+* @title: 学生请假未归通知
+* @Author dzx
+* @Date: 2024年11月1日
+* @Version 1.0
+*/
+@Data
+public class NoBackStudentInfoVo {
+
+    @ApiModelProperty("主键编号")
+    private Long id;
+
+    @ApiModelProperty("学生id")
+    private Long studentUserId;
+
+    @ApiModelProperty("学生姓名")
+    private String name;
+
+    @ApiModelProperty("请假开始时间")
+    private LocalDateTime startDate;
+
+    @ApiModelProperty("请假结束时间")
+    private LocalDateTime endDate;
+
+    @ApiModelProperty("班级名称")
+    private String className;
+
+    @ApiModelProperty("班主任名称")
+    private String teacherName;
+
+    @ApiModelProperty("班主任openId")
+    private String openId;
+
+    @ApiModelProperty("请假到期时间")
+    private String endDateStr;
+
+
+}

+ 19 - 0
src/main/resources/mapper/student/StudentLeaveMapper.xml

@@ -59,4 +59,23 @@
             )
         </if>
     </select>
+
+    <select id="getNoBackStudentInfo" resultType="com.xjrsoft.module.student.vo.NoBackStudentInfoVo">
+        SELECT t1.id,t1.student_user_id,t2.name,t1.start_date,t1.end_date,t5.name AS class_name,
+        t6.name AS teacher_name,t6.open_id,DATE_FORMAT(t1.end_date, '%Y年%m月%d日 %H:%i') AS end_date_str FROM student_leave t1
+        INNER JOIN xjr_user t2 ON t1.student_user_id = t2.id
+        INNER JOIN xjr_workflow_form_relation t3 ON t3.form_key_value = t1.id
+        LEFT JOIN base_student_school_roll t4 ON t1.student_user_id = t4.user_id
+        LEFT JOIN base_class t5 ON t4.class_id = t5.id
+        LEFT JOIN xjr_user t6 ON t6.id = t5.teacher_id
+        WHERE t1.delete_mark = 0 AND t1.enabled_mark = 1
+        AND t3.current_state = 'COMPLETED' AND t1.is_notice = 0
+        AND NOW() > t1.end_date
+    </select>
+    <update id="updateIsNotice" parameterType="java.lang.Long">
+        update student_leave set is_notice = 1 where id in
+        <foreach item="id" index="index" collection="ids" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
+    </update>
 </mapper>