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