4670101279
2 years ago
5 changed files with 263 additions and 263 deletions
@ -1,60 +1,60 @@
@@ -1,60 +1,60 @@
|
||||
package com.ruoyi.code.camera.scheduled; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.ruoyi.code.camera.domain.Camera; |
||||
import com.ruoyi.code.camera.service.ICameraService; |
||||
import com.ruoyi.common.core.page.R; |
||||
import com.ruoyi.common.utils.IPUtils; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.core.env.Environment; |
||||
import org.springframework.scheduling.annotation.EnableScheduling; |
||||
import org.springframework.scheduling.annotation.Scheduled; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.PostConstruct; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/*@Author: tongw |
||||
*@CreateDate: 2020/8/11 8:58 |
||||
*@Description: |
||||
**/ |
||||
|
||||
@Component |
||||
@Configuration |
||||
@EnableScheduling |
||||
public class RegisterServer { |
||||
private static String sercer_ip = ""; |
||||
|
||||
@Autowired |
||||
private Environment env; |
||||
|
||||
@PostConstruct |
||||
public void config() { |
||||
sercer_ip = env.getProperty("localip"); |
||||
} |
||||
@Autowired |
||||
private ICameraService cameraService; |
||||
|
||||
@Scheduled(initialDelay = 5000, fixedRate = Long.MAX_VALUE) |
||||
public void synStart(){ |
||||
start(); |
||||
} |
||||
|
||||
private void start(){ |
||||
String ip = IPUtils.getLocalIpAddress(); |
||||
if(sercer_ip.equals(ip)){ |
||||
R result = cameraService.register(); |
||||
if("0".equals(result.get("code").toString())){ |
||||
System.out.println("主动注册服务已启动"); |
||||
}else{ |
||||
System.out.println("主动注册服务启动失败"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
//package com.ruoyi.code.camera.scheduled;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSON;
|
||||
//import com.alibaba.fastjson.JSONArray;
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.ruoyi.code.camera.domain.Camera;
|
||||
//import com.ruoyi.code.camera.service.ICameraService;
|
||||
//import com.ruoyi.common.core.page.R;
|
||||
//import com.ruoyi.common.utils.IPUtils;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.core.env.Environment;
|
||||
//import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
//import org.springframework.scheduling.annotation.Scheduled;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.PostConstruct;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
///*@Author: tongw
|
||||
// *@CreateDate: 2020/8/11 8:58
|
||||
// *@Description:
|
||||
// **/
|
||||
//
|
||||
//@Component
|
||||
//@Configuration
|
||||
//@EnableScheduling
|
||||
//public class RegisterServer {
|
||||
// private static String sercer_ip = "";
|
||||
//
|
||||
// @Autowired
|
||||
// private Environment env;
|
||||
//
|
||||
// @PostConstruct
|
||||
// public void config() {
|
||||
// sercer_ip = env.getProperty("localip");
|
||||
// }
|
||||
// @Autowired
|
||||
// private ICameraService cameraService;
|
||||
//
|
||||
// @Scheduled(initialDelay = 5000, fixedRate = Long.MAX_VALUE)
|
||||
// public void synStart(){
|
||||
// start();
|
||||
// }
|
||||
//
|
||||
// private void start(){
|
||||
// String ip = IPUtils.getLocalIpAddress();
|
||||
// if(sercer_ip.equals(ip)){
|
||||
// R result = cameraService.register();
|
||||
// if("0".equals(result.get("code").toString())){
|
||||
// System.out.println("主动注册服务已启动");
|
||||
// }else{
|
||||
// System.out.println("主动注册服务启动失败");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
Loading…
Reference in new issue