125 lines
5.8 KiB
Java
125 lines
5.8 KiB
Java
|
|
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package com.ifish.socket.config;
|
|
|
|
import com.ifish.bean.Tbl_Device;
|
|
import com.ifish.bean.Tbl_Device_Statistics;
|
|
import com.ifish.bean.Tbl_Device_User;
|
|
import com.ifish.bean.Tbl_Push_List;
|
|
import com.ifish.bean.Tbl_User;
|
|
import com.ifish.enums.PushTypeEnum;
|
|
import com.ifish.helper.DeviceHelperI;
|
|
import com.ifish.helper.JpushHelperI;
|
|
import com.ifish.helper.UserHelperI;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.mina.core.session.IoSession;
|
|
import org.quartz.Job;
|
|
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;
|
|
|
|
/**
|
|
*
|
|
* @author Administrator
|
|
*/
|
|
public class ExecuteJob implements Job {
|
|
|
|
private static Logger log = LoggerFactory.getLogger(ExecuteJob.class);
|
|
//@Autowired
|
|
//private NeteaseIM neteaseIM;
|
|
@Autowired
|
|
private UserHelperI userHelperI;
|
|
@Autowired
|
|
private DeviceHelperI deviceHelperI;
|
|
@Autowired
|
|
private JpushHelperI jpushHelperI;
|
|
|
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
|
//任务传递的参数
|
|
JobDataMap dataMap = context.getJobDetail().getJobDataMap();
|
|
String macAddress = dataMap.getString("macAddress");
|
|
String timestamp = dataMap.getString("timestamp");
|
|
try {
|
|
//移除为null的连接
|
|
IoSession session_cz = SomeServer.sessions_cz.get(macAddress);
|
|
if (session_cz == null || session_cz.getRemoteAddress() == null) {
|
|
SomeServer.sessions_cz.remove(macAddress);
|
|
}
|
|
//设备是否存在
|
|
Tbl_Device device = deviceHelperI.getDeviceByMacAddress(macAddress);
|
|
Tbl_Device_Statistics device_Statistics = null;
|
|
if (device != null) {
|
|
//记录次数
|
|
Integer number1 = device_Statistics.getMcuCount();
|
|
Integer number2 = device_Statistics.getModuleCount();
|
|
Integer number3 = device_Statistics.getRouterCount();
|
|
Integer number4 = device_Statistics.getServerCount();
|
|
Integer number5 = device_Statistics.getServerTryCount();
|
|
List<Tbl_Device_User> list = deviceHelperI.getTbl_Device_UsersListByDeviceId(device.getDeviceId());
|
|
//是否被绑定
|
|
if (list != null) {
|
|
for (Tbl_Device_User deviceUser : list) {
|
|
Integer userId = deviceUser.getUserId();
|
|
String showName = deviceUser.getShowName();
|
|
String title = PushTypeEnum.offline_push.getValue();
|
|
String msg = "【" + title + "】你的水族箱“" + showName + "”于" + timestamp + "离线,请及时查看!";
|
|
Tbl_User user = userHelperI.findById(userId);
|
|
//推送记录
|
|
Tbl_Push_List pushList = new Tbl_Push_List();
|
|
Integer deviceId = deviceUser.getDeviceId();
|
|
if (user != null) {
|
|
String loginType = user.getLoginType();
|
|
if (StringUtils.isNotBlank(loginType) && userId != null) {
|
|
Map<String, String> map = new HashMap<String, String>();
|
|
map.put("device_id", deviceId.toString());
|
|
map.put("device_name", showName);
|
|
map.put("timestamp", timestamp);
|
|
map.put("msg_type", PushTypeEnum.offline_push.getKey());
|
|
//极光推送
|
|
boolean result = false;
|
|
if (loginType.equals("android")) {
|
|
result = jpushHelperI.pushMessageByAndroid(title, msg, userId.toString(), map);
|
|
} else if (loginType.equals("ios")) {
|
|
result = jpushHelperI.pushMessageByIOS(title, msg, userId.toString(), map);
|
|
}
|
|
if (result) {
|
|
//推送记录
|
|
pushList.setUserId(userId);
|
|
pushList.setDeviceId(deviceId);
|
|
pushList.setPhoneType(loginType.toLowerCase());
|
|
pushList.setShowName(showName);
|
|
pushList.setPushType(PushTypeEnum.offline_push.getKey());
|
|
pushList.setJpushStatus(result ? "1" : "0");
|
|
pushList.setPushTitle(title);
|
|
pushList.setPushContext(msg);
|
|
pushList.setCreateTime(new Date());
|
|
pushList.setMcuCount(number1);
|
|
pushList.setModularCount(number2);
|
|
pushList.setRouterCount(number3);
|
|
pushList.setServerCount(number4);
|
|
pushList.setServerTryCount(number5);
|
|
userHelperI.save(pushList);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
log.error("error msg:{}", e.toString());
|
|
}
|
|
}
|
|
}
|