fs-danaus
2021-09-29 03b162821b77a3d9686b0bc2104388f10a31cf66
提交 | 用户 | age
413001 1 package com.yc.open.init.shcedule;
F 2
3 import cn.jiguang.common.resp.APIConnectionException;
4 import cn.jiguang.common.resp.APIRequestException;
5 import com.yc.api.bean.attendance.T180252;
6 import com.yc.api.service.AttendanceServiceIfc;
7 import com.yc.api.utils.PushMessageType;
8 import com.yc.entity.DataSourceEntity;
9 import com.yc.factory.FactoryBean;
10 import com.yc.jpush.JpushAction;
11 import com.yc.multiData.SpObserver;
12
f0db04 13 import java.util.ArrayList;
F 14 import java.util.HashMap;
15 import java.util.List;
16 import java.util.Map;
413001 17
F 18 /**
19  * 打卡提醒
20  */
21 public class AttendanceReMindSchedule extends BaseSchedule implements Runnable {
03b162 22 private String dateTime;//执行时间点
F 23     private  int perMinute;
24     public AttendanceReMindSchedule(DataSourceEntity dataSourceEntity,String dateTime,int perMinute) {
413001 25         super(dataSourceEntity);
03b162 26         this.dateTime=dateTime;
F 27         this.perMinute=perMinute;
413001 28     }
F 29
30     @Override
31     public void run() {
f0db04 32         try {
F 33             if (Thread.interrupted())  // Clears interrupted status!
34                 throw new InterruptedException();
35             String dbid = dataSourceEntity.getDbId() + "";
03b162 36             log.info(dataSourceEntity.getSystemDescribe() + "开始执行打卡提醒推送V2:"+dbid);
f0db04 37             SpObserver.setDBtoInstance("_" + dbid);
F 38             AttendanceServiceIfc attendanceServiceIfc = (AttendanceServiceIfc) FactoryBean.getBean("attendanceService");
03b162 39             final List<T180252> list = attendanceServiceIfc.getT180252List(dateTime,perMinute);
F 40             log.info(dataSourceEntity.getSystemDescribe() + "准备推送数量V2:" + (list != null ? list.size() : 0));
f0db04 41             JpushAction jpushAction = JpushAction.getInstance();
F 42             //保存需要更新的sql,批量提交
43             List<String> seqList = new ArrayList<>();
44             if (list != null && list.size() > 0) {
45                 for (T180252 t180252 : list) {
46                     String usercode = t180252.getUserCode();
47                     Map<String, String> extras = new HashMap<>();
48                     extras.put("actionType", PushMessageType.ATTENDANCE);
49                     extras.put("msg", t180252.getDescription() + "");
50                     extras.put("msgCount", "1");
51                     extras.put("title", "打卡提醒");
52                     List<String> alais = new ArrayList<String>();
53                     alais.add(dataSourceEntity.getDbId() + "_" + usercode);
54                     try {
55                         boolean flag = jpushAction.sendPush(
56                                 JpushAction.buildPushObject_with_extra(
57                                         alais, t180252.getTitle(), extras));
58                         if (flag) {
59                             //推送成功
60                             seqList.add(String.valueOf(t180252.getSeq()));
413001 61
F 62                         }
f0db04 63                     } catch (APIConnectionException e) {
F 64                         // Connection error, should retry later
65                         log.error(usercode + " Connection error, should retry later" + e.getMessage());
66                     } catch (APIRequestException e) {
67                         // Should review the error, and fix the request
68                         log.error("dbid: " + dataSourceEntity.getDbId() + ">" + usercode);
69                         log.error("HTTP Status: " + e.getStatus());
70                         log.error("Error Code: " + e.getErrorCode());
71                         log.error("Error Message: " + e.getErrorMessage());
72
73                     } catch (Exception e) {
74                         log.error(dataSourceEntity.getSystemDescribe() + ":" + usercode + ">推送出错:" + e.getMessage());
75                         e.printStackTrace();
413001 76                     }
F 77                 }
78             }
f0db04 79             if (seqList.size() > 0) {
F 80                 //更新可发送次数
81                 attendanceServiceIfc.updateT180252(seqList);
82             }
83         } catch (InterruptedException inter) {
84             log.info(dataSourceEntity.getSystemID() + "考勤定时任务已被终止");
85         } catch (RuntimeException r) {
86             throw r;
87         } catch (Exception ex) {
88             ex.printStackTrace();
89             log.info(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage());
90         } finally {
91             SpObserver.setDBtoInstance();
92         }
93         log.info("定时打卡提醒推送V2完成.....");
413001 94     }
F 95
96 }