Commit b604d645 authored by 王夏晖's avatar 王夏晖

1.定时任务:保证网关数据链路活跃状态

2.个推改为群推
parent 6cc1b012
...@@ -15,7 +15,7 @@ import org.springframework.context.annotation.Bean; ...@@ -15,7 +15,7 @@ import org.springframework.context.annotation.Bean;
import com.codahale.metrics.CsvReporter; import com.codahale.metrics.CsvReporter;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
@MapperScan("com.adc.da.**.dao") @MapperScan("com.adc.da.**.dao")
@ComponentScan("com.adc") @ComponentScan("com.adc")
...@@ -23,6 +23,7 @@ import org.springframework.context.annotation.ComponentScan; ...@@ -23,6 +23,7 @@ import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication(exclude = { @SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class DataSourceAutoConfiguration.class
}) })
@EnableScheduling
public class AdcDaApplication { public class AdcDaApplication {
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -23,7 +23,7 @@ public class AppPushUtils { ...@@ -23,7 +23,7 @@ public class AppPushUtils {
private static String appKey = "XRxH4VbaVZAkl7uK44pd97"; private static String appKey = "XRxH4VbaVZAkl7uK44pd97";
private static String masterSecret = "xhUi7HRWsv8uj28GJdjhR2"; private static String masterSecret = "xhUi7HRWsv8uj28GJdjhR2";
private static String url = "http://sdk.open.api.igexin.com/apiex.htm"; private static String url = "http://sdk.open.api.igexin.com/apiex.htm";
public static void push(String title, String msg, String clientId) throws IOException { public static void push(String title, String msg, String[] clientId) throws IOException {
// 配置返回每个用户返回用户状态,可选 // 配置返回每个用户返回用户状态,可选
System.setProperty("gexin_pushList_needDetails", "true"); System.setProperty("gexin_pushList_needDetails", "true");
...@@ -40,10 +40,12 @@ public class AppPushUtils { ...@@ -40,10 +40,12 @@ public class AppPushUtils {
message.setOfflineExpireTime(24 * 1000 * 3600); message.setOfflineExpireTime(24 * 1000 * 3600);
// 配置推送目标 // 配置推送目标
List<Target> targets = new ArrayList<>(1); List<Target> targets = new ArrayList<>(1);
for(String client : clientId){
Target target1 = new Target(); Target target1 = new Target();
target1.setAppId(appId); target1.setAppId(appId);
target1.setClientId(clientId); target1.setClientId(client);
targets.add(target1); targets.add(target1);
}
// taskId用于在推送时去查找对应的message // taskId用于在推送时去查找对应的message
String taskId = push.getContentId(message); String taskId = push.getContentId(message);
IPushResult ret = push.pushMessageToList(taskId, targets); IPushResult ret = push.pushMessageToList(taskId, targets);
...@@ -76,7 +78,7 @@ public class AppPushUtils { ...@@ -76,7 +78,7 @@ public class AppPushUtils {
return template; return template;
} }
public static void pushTc(String title, String msg, String clientId) throws IOException { public static void pushTc(String title, String msg, String[] clientId) throws IOException {
// 配置返回每个用户返回用户状态,可选 // 配置返回每个用户返回用户状态,可选
System.setProperty("gexin_pushList_needDetails", "true"); System.setProperty("gexin_pushList_needDetails", "true");
...@@ -93,10 +95,12 @@ public class AppPushUtils { ...@@ -93,10 +95,12 @@ public class AppPushUtils {
message.setOfflineExpireTime(24 * 1000 * 3600); message.setOfflineExpireTime(24 * 1000 * 3600);
// 配置推送目标 // 配置推送目标
List<Target> targets = new ArrayList<>(1); List<Target> targets = new ArrayList<>(1);
for(String client : clientId){
Target target1 = new Target(); Target target1 = new Target();
target1.setAppId(appId); target1.setAppId(appId);
target1.setClientId(clientId); target1.setClientId(client);
targets.add(target1); targets.add(target1);
}
// taskId用于在推送时去查找对应的message // taskId用于在推送时去查找对应的message
String taskId = push.getContentId(message); String taskId = push.getContentId(message);
IPushResult ret = push.pushMessageToList(taskId, targets); IPushResult ret = push.pushMessageToList(taskId, targets);
...@@ -115,11 +119,11 @@ public class AppPushUtils { ...@@ -115,11 +119,11 @@ public class AppPushUtils {
} }
public static void main(String[] args) { public static void main(String[] args) {
try { /*try {
push("提示", "测试推送", "c3d2cb373109db849b7ecfb22a4fd93d"); // push("提示", "测试推送", "c3d2cb373109db849b7ecfb22a4fd93d");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }*/
} }
} }
package com.adc.da.znks.util.netty;
import com.adc.da.znks.util.SystemValue;
import io.netty.channel.Channel;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @ClassName ActiveGateWay
* @Descroption TODO
* @Author 王夏晖
* @Date 2018/9/17 0017 19:50
**/
@Component
public class ActiveGateWay {
@Scheduled(cron = "0 0/1 * * * ?")
public void timerToNow(){
Map<String,Object> channelMap = SystemValue.channelMap;
for (Map.Entry<String,Object> entry : channelMap.entrySet()) {
byte[] request = new byte[23];
request[0] = 0x4d;
request[1] = 0x41;
request[2] = 0x43;
request[3] = 0x5F;
request[4] = 0x52;
request[5] = 0x45;
request[6] = 0x51;
request[7] = 0x55;
request[8] = 0x45;
request[9] = 0x53;
request[10] = 0x54;
Channel channel = (Channel)entry.getValue();
channel.writeAndFlush(request);
}
}
}
...@@ -108,28 +108,20 @@ public class ServerHandler extends ChannelInboundHandlerAdapter { ...@@ -108,28 +108,20 @@ public class ServerHandler extends ChannelInboundHandlerAdapter {
System.out.println(lockType); System.out.println(lockType);
serverHandler.lockRecordService.insertLockRecord(lockRecord); serverHandler.lockRecordService.insertLockRecord(lockRecord);
if(list != null){ if(list != null){
if("80".equals(instruct)){ // 远程开锁触发请求,发送透传 String[] client = new String[list.size()];
for(int i=0;i<list.size();i++){ for(int i=0;i<list.size();i++){
clientId = list.get(i).get("client_id")!=null?list.get(i).get("client_id").toString():""; clientId = list.get(i).get("client_id")!=null?list.get(i).get("client_id").toString():"";
if(!"".equals(clientId)){ if(!"".equals(clientId)){
AppPushUtils.pushTc(title,message,clientId); client[i] = clientId;
AppPushUtils.push(title,message,clientId);
}else{ }else{
logger.info("clientId为空"); logger.info("clientId为空");
} }
} }
if("80".equals(instruct)){ // 远程开锁触发请求,发送透传
}else{ AppPushUtils.pushTc(title,message,client);
for(int i=0;i<list.size();i++){ AppPushUtils.push(title,message,client);
clientId = list.get(i).get("client_id")!=null?list.get(i).get("client_id").toString():"";
if(!"".equals(clientId)){
AppPushUtils.push(title,message,clientId);
}else{ }else{
logger.info("clientId为空"); AppPushUtils.push(title,message,client);
}
}
} }
}else{ }else{
logger.info("clientId未获取,消息发送失败"); logger.info("clientId未获取,消息发送失败");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment