dzx пре 1 година
родитељ
комит
0967406350
1 измењених фајлова са 31 додато и 26 уклоњено
  1. 31 26
      src/main/java/com/xjrsoft/module/job/AttendanceMessageTask.java

+ 31 - 26
src/main/java/com/xjrsoft/module/job/AttendanceMessageTask.java

@@ -27,8 +27,6 @@ import com.xjrsoft.module.outint.entity.TeacherOutInRecord;
 import com.xjrsoft.module.outint.service.IStudentOutInRecordService;
 import com.xjrsoft.module.outint.service.ITeacherOutInRecordService;
 import com.xjrsoft.module.student.entity.BaseStudent;
-import com.xjrsoft.module.system.entity.WechatMessageLog;
-import com.xjrsoft.module.system.service.IWechatMessageLogService;
 import com.xjrsoft.module.teacher.entity.BaseTeacher;
 import com.xjrsoft.module.teacher.entity.XjrUser;
 import lombok.extern.slf4j.Slf4j;
@@ -83,9 +81,6 @@ public class AttendanceMessageTask {
     @Autowired
     private WeChatUtil weChatUtil;
 
-    @Autowired
-    private IWechatMessageLogService wechatMessageLogService;
-
     @Scheduled(cron = "0 */1 * * * ?")
     public void RefreshConnectionPool() {
         String active = SpringUtil.getActiveProfile();
@@ -111,7 +106,7 @@ public class AttendanceMessageTask {
         String dayOfWeek = now.getDayOfWeek().name();
         if(holidayDate == null || "SUNDAY".equals(dayOfWeek) || "SATURDAY".equals(dayOfWeek)){
             log.info("非工作日,不需要提醒");
-            return;
+//            return;
         }
         //查询今天的考勤规则
         List<AttendanceRuleDetails> ruleDetails = ruleCategoryService.getTodayRules();
@@ -136,7 +131,8 @@ public class AttendanceMessageTask {
         Set<Integer> roleTypes = list.stream().map(AttendanceMessageSet::getRoleType).collect(Collectors.toSet());
 
         //查询需要通知的人
-
+        String table = "wechat_message_log";
+        boolean isInsert = true;
         for (AttendanceMessageSet messageSet : list) {
             LocalDateTime recentlyTime = null;
             String characterKey = "character_string18";
@@ -148,15 +144,18 @@ public class AttendanceMessageTask {
                 recentlyTime = getRecentlyTime(ruleDetails, now);
                 if(recentlyTime.getHour() != now.getHour() || (recentlyTime.getHour() == now.getHour() && recentlyTime.getMinute() != now.getMinute())){
                     log.info("未到时间,不进行推送");
+                    isInsert = false;
                     continue;
                 }
-                long count = wechatMessageLogService.count(
-                        new QueryWrapper<WechatMessageLog>().lambda()
-                                .eq(WechatMessageLog::getSendTime, recentlyTime)
-                                .eq(WechatMessageLog::getTemplateId, wechatTemplate)
-                );
+                Entity entity = Entity.create(table);
+                entity.set("send_time", recentlyTime);
+                entity.set("template_id", wechatTemplate);
+                String sql = "SELECT COUNT(*) FROM wechat_message_log WHERE delete_mark = 0 AND template_id = '" + wechatTemplate
+                        + "' AND send_time = '" + recentlyTime.format(formatter) + "'";
+                long count = SqlRunnerAdapter.db().selectCount(sql);
                 if(count > 0){//已经推送过,不再进行推送
                     log.info("已推送过,不进行推送");
+                    isInsert = false;
                     continue;
                 }
             }else if(messageSet.getMessageCategory() != null && messageSet.getMessageCategory() == 3){
@@ -165,20 +164,21 @@ public class AttendanceMessageTask {
                 characterKey = "character_string36";
                 if(recentlyTime.getHour() != now.getHour() || (recentlyTime.getHour() == now.getHour() && recentlyTime.getMinute() != now.getMinute())){
                     log.info("未到时间,不进行推送");
+                    isInsert = false;
                     continue;
                 }
-                long count = wechatMessageLogService.count(
-                        new QueryWrapper<WechatMessageLog>().lambda()
-                                .eq(WechatMessageLog::getSendTime, recentlyTime)
-                                .eq(WechatMessageLog::getTemplateId, wechatTemplate)
-                );
+                String sql = "SELECT COUNT(*) FROM wechat_message_log WHERE delete_mark = 0 AND template_id = '" + wechatTemplate
+                        + "' AND send_time = '" + recentlyTime.format(formatter) + "'";
+                long count = SqlRunnerAdapter.db().selectCount(sql);
                 if(count > 0){//已经推送过,不再进行推送
                     log.info("已推送过,不进行推送");
+                    isInsert = false;
                     continue;
                 }
             }
 
             if(!messageSet.getTimePeriod().contains(timePeriod + "")){
+                isInsert = false;
                 continue;
             }
 
@@ -194,9 +194,11 @@ public class AttendanceMessageTask {
 
             //没有需要通知的,直接跳过
             if(userList.isEmpty()){
+                isInsert = false;
                 continue;
             }
             if(recentlyTime == null){
+                isInsert = false;
                 continue;
             }
 
@@ -249,7 +251,7 @@ public class AttendanceMessageTask {
                 for (XjrUser xjrUser : userList) {
                     weChatSendMessageDto.setMsgId(IdUtil.getSnowflakeNextId() + "");
                     weChatSendMessageDto.setUserId(xjrUser.getOpenId());
-                    weChatService.sendTemplateMessage(weChatSendMessageDto);
+                    //weChatService.sendTemplateMessage(weChatSendMessageDto);
                 }
             }else if(messageSet.getRoleType() != null && messageSet.getRoleType() == 2){
                 //教师总人数
@@ -294,17 +296,20 @@ public class AttendanceMessageTask {
                 for (XjrUser xjrUser : userList) {
                     weChatSendMessageDto.setMsgId(IdUtil.getSnowflakeNextId() + "");
                     weChatSendMessageDto.setUserId(xjrUser.getOpenId());
-                    weChatService.sendTemplateMessage(weChatSendMessageDto);
+                    //weChatService.sendTemplateMessage(weChatSendMessageDto);
                 }
+                isInsert = true;
+            }
+
+            if(isInsert){
+                Entity entity = Entity.create(table);
+                entity.set("content", "消息推送人数:" + userCount);
+                entity.set("create_date", LocalDateTime.now());
+                entity.set("template_id", wechatTemplate);
+                entity.set("send_time", recentlyTime);
+                SqlRunnerAdapter.db().dynamicInsert(table, entity);
             }
 
-            String table = "wechat_message_log";
-            Entity entity = Entity.create(table);
-            entity.set("content", "消息推送人数:" + userCount);
-            entity.set("create_date", new Date());
-            entity.set("template_id", wechatTemplate);
-            entity.set("send_time", recentlyTime);
-            SqlRunnerAdapter.db().dynamicInsert(table, entity);
         }
     }