|
@@ -52,9 +52,59 @@ public class ScheduleTask {
|
|
@Value("${url.environ.device.service}")
|
|
@Value("${url.environ.device.service}")
|
|
private String URL_ENVIRON_DEVICE_SERVICE;
|
|
private String URL_ENVIRON_DEVICE_SERVICE;
|
|
// private static String URL = "http://www.0531yun.com/app/GetDeviceData";
|
|
// private static String URL = "http://www.0531yun.com/app/GetDeviceData";
|
|
|
|
+// @Value("${dry.deviceCode}")
|
|
|
|
+// private String dryDeviceCode;
|
|
|
|
|
|
@Scheduled(cron = "0 0/5 * * * ?") //每5分钟执行一次
|
|
@Scheduled(cron = "0 0/5 * * * ?") //每5分钟执行一次
|
|
// @Scheduled(cron = "*/5 * * * * ?") //每10秒钟执行一次
|
|
// @Scheduled(cron = "*/5 * * * * ?") //每10秒钟执行一次
|
|
|
|
+ public void autoRunDryList() throws ParseException {
|
|
|
|
+ DateUtil dateUtil = new DateUtil();
|
|
|
|
+ System.out.println("开始取数:" + dateUtil.fromLongToDate(new Date().getTime(), "yyyy-MM-dd HH:mm:ss.SSS"));
|
|
|
|
+ //查询所有设备
|
|
|
|
+// List<Map> ecoDeviceList = ecoDeviceService.getDeviceList2();
|
|
|
|
+ List<Map> ecoDeviceList = ecoDeviceService.getDryDeviceByDeviceType();
|
|
|
|
+ System.out.println("ecoDeviceList = " + ecoDeviceList);
|
|
|
|
+ System.out.println("ecoDeviceList.size=" + ecoDeviceList.size());
|
|
|
|
+ if (ecoDeviceList.size() == 0) {
|
|
|
|
+ System.out.println("设备记录为空.");
|
|
|
|
+ } else {
|
|
|
|
+ for (int a = 0; a < ecoDeviceList.size(); a++) {
|
|
|
|
+ System.out.println("a========================================================================================================" + a);
|
|
|
|
+ Map deviceMap = ecoDeviceList.get(a);
|
|
|
|
+ Integer farmId = Integer.parseInt(deviceMap.get("farm_id") + "");
|
|
|
|
+ String dryDeviceCode = deviceMap.get("device_code") + "";
|
|
|
|
+ System.out.println("dryDeviceCode=" + dryDeviceCode);
|
|
|
|
+ System.out.println("id=" + deviceMap.get("id"));
|
|
|
|
+ //读取高温阈值数据
|
|
|
|
+ JSONObject thresholdJo = getThresholdURL(farmId);
|
|
|
|
+// JSONObject thresholdJo = getThresholdURL2(farmId);
|
|
|
|
+ System.out.println("调取牧场[" + farmId + "]服务获取阈值接口:" + thresholdJo);
|
|
|
|
+ if (thresholdJo == null) {
|
|
|
|
+ log.error("thresholdJo======" + thresholdJo);
|
|
|
|
+ log.error("牧场[" + farmId + "]暂时没有洗消烘干温度设置.");
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ Date todayTime = dateUtil.getTodayDateTime();
|
|
|
|
+ //读取最新一条烘干记录
|
|
|
|
+ System.out.println("最近一条烘干记录 dryDeviceCode=" + dryDeviceCode);
|
|
|
|
+ System.out.println("最近一条烘干记录 todayTime=" + todayTime);
|
|
|
|
+ String datetime = dateUtil.formatDateTime(todayTime);
|
|
|
|
+ System.out.println("最近一条烘干记录 datetime=" + datetime);
|
|
|
|
+ EcoDeviceFlow ecoDeviceFlow = ecoDeviceFlowService.getLastDryDeviceFlow(dryDeviceCode, datetime);
|
|
|
|
+ //新建烘干记录
|
|
|
|
+ if (ecoDeviceFlow != null) {
|
|
|
|
+ String temp = ecoDeviceFlow.getId1Value();
|
|
|
|
+ System.out.println(" DD temp=" + temp);
|
|
|
|
+ ecoDryListService.saveDryList(deviceMap, temp, thresholdJo, todayTime);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println("完成取数:" + dateUtil.fromLongToDate(new Date().getTime(), "yyyy-MM-dd HH:mm:ss.SSS"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //以下是旧的代码
|
|
|
|
+// @Scheduled(cron = "0 0/5 * * * ?") //每5分钟执行一次
|
|
|
|
+// @Scheduled(cron = "*/5 * * * * ?") //每10秒钟执行一次
|
|
public void getDeviceFlow() throws ParseException {
|
|
public void getDeviceFlow() throws ParseException {
|
|
DateUtil dateUtil = new DateUtil();
|
|
DateUtil dateUtil = new DateUtil();
|
|
System.out.println("开始取数:" + dateUtil.fromLongToDate(new Date().getTime(), "yyyy-MM-dd HH:mm:ss.SSS"));
|
|
System.out.println("开始取数:" + dateUtil.fromLongToDate(new Date().getTime(), "yyyy-MM-dd HH:mm:ss.SSS"));
|
|
@@ -128,6 +178,36 @@ public class ScheduleTask {
|
|
return thresholdJo.getJSONObject("data");
|
|
return thresholdJo.getJSONObject("data");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @Method : getThresholdURL2
|
|
|
|
+ * @Description :
|
|
|
|
+ * @Params : [farmId]
|
|
|
|
+ * @Return : com.alibaba.fastjson.JSONObject
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2022/12/6
|
|
|
|
+ * @Time : 20:12
|
|
|
|
+ */
|
|
|
|
+ private JSONObject getThresholdURL2(Integer farmId) {
|
|
|
|
+ // 设置请求头,请求类型为json
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
+// 设置请求参数
|
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("farmId", farmId);
|
|
|
|
+ //用HttpEntity封装整个请求报文
|
|
|
|
+ HttpEntity<HashMap<String, Object>> request = new HttpEntity<>(map, headers);
|
|
|
|
+ //读取真实数据
|
|
|
|
+// String remoteUrl = "http://192.168.1.67:8010/produce/threshold/getThresholdByFarmId";
|
|
|
|
+ String url = "http://localhost:10052/threshold/getThresholdByFarmId";
|
|
|
|
+ System.out.println("url=" + url);
|
|
|
|
+ JSONObject resultJo = restTemplate.postForObject(url, request, JSONObject.class);
|
|
|
|
+ System.out.println("resultJo=" + resultJo);
|
|
|
|
+ if (resultJo.getInteger("code") != 10000) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ return resultJo.getJSONObject("data");
|
|
|
|
+ }
|
|
|
|
+
|
|
//获取远程数据
|
|
//获取远程数据
|
|
private String getDeviceFlowFromRemoteURL(String userId, String groupId) {
|
|
private String getDeviceFlowFromRemoteURL(String userId, String groupId) {
|
|
//请求头
|
|
//请求头
|