|
@@ -0,0 +1,83 @@
|
|
|
|
+package com.bosshand.virgo.api.job;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.bosshand.virgo.api.operate.dao.OperateDeviceDao;
|
|
|
|
+import com.bosshand.virgo.api.operate.model.OperateDevice;
|
|
|
|
+import com.bosshand.virgo.api.service.ReminderService;
|
|
|
|
+import com.bosshand.virgo.core.utils.StringUtil;
|
|
|
|
+import org.quartz.JobDataMap;
|
|
|
|
+import org.quartz.JobExecutionContext;
|
|
|
|
+import org.quartz.JobExecutionException;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.scheduling.quartz.QuartzJobBean;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+public class JobRemoteReminderQuartz extends QuartzJobBean {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ ReminderService reminderService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ OperateDeviceDao operateDeviceDao;
|
|
|
|
+
|
|
|
|
+ static Logger log = LoggerFactory.getLogger(JobRemoteReminderQuartz.class);
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
|
|
+ log.info("=====================发送远程提醒====================");
|
|
|
|
+ JobDataMap mergedJobDataMap = jobExecutionContext.getMergedJobDataMap();
|
|
|
|
+ String data = mergedJobDataMap.getString("data");
|
|
|
|
+ JSONObject json = JSONObject.parseObject(data);
|
|
|
|
+
|
|
|
|
+ int type = json.getIntValue("type");
|
|
|
|
+ String deviceIds = json.getString("deviceIds");
|
|
|
|
+ if (StringUtil.notBlank(deviceIds)) {
|
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
|
+ String[] split = deviceIds.split(",");
|
|
|
|
+ for (String s : split) {
|
|
|
|
+ ids.add(Long.parseLong(s));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<JSONObject> openList = new ArrayList<>();
|
|
|
|
+ List<OperateDevice> deviceList = operateDeviceDao.getIds(ids);
|
|
|
|
+
|
|
|
|
+ for (OperateDevice od : deviceList) {
|
|
|
|
+ if (od.getState() == 1) {
|
|
|
|
+ JSONObject js = new JSONObject();
|
|
|
|
+ js.put("deviceId", od.getId());
|
|
|
|
+ js.put("deviceName", od.getName());
|
|
|
|
+ js.put("deviceState", od.getState());
|
|
|
|
+ openList.add(js);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (openList.size() > 0) {
|
|
|
|
+ String jsonString = JSON.toJSONString(openList);
|
|
|
|
+ List<String> userIds = new ArrayList<>();
|
|
|
|
+ String userList = json.getString("userList");
|
|
|
|
+ if (StringUtil.notBlank(userList)) {
|
|
|
|
+ JSONArray jsonArray = JSONObject.parseArray(userList);
|
|
|
|
+ if (jsonArray.size() > 0) {
|
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
+ long uid = jsonArray.getJSONObject(i).getLongValue("id");
|
|
|
|
+ userIds.add(String.valueOf(uid));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String token = reminderService.getToken();
|
|
|
|
+ for (String d : userIds) {
|
|
|
|
+ reminderService.send(token, d, jsonString, String.valueOf(type));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|