|
@@ -53,7 +53,7 @@ public class FeedTimer {
|
|
|
private FeedingDataMapper dataMapper;
|
|
|
|
|
|
|
|
|
- @Scheduled(cron = "0 0/11 * * * ? ")
|
|
|
+ @Scheduled(cron = "0 0 */1 * * ? ")
|
|
|
@Transactional
|
|
|
public void getFeed() throws Exception {
|
|
|
QueryWrapper<FeedArea> queryWrapper = new QueryWrapper<>();
|
|
@@ -78,22 +78,28 @@ public class FeedTimer {
|
|
|
jsonObject.put("areaId", feedArea.getAreaId());
|
|
|
paramMap.put("Content-Type", "application/json;charset=utf-8");
|
|
|
paramMap.put("AuthorizationF", getToken());
|
|
|
- String post = HttpRequest.post("http://xxxxxxxx:xx /feed/api/mqtt/pageQryRealtime").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
|
|
|
+ String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/mqtt/pageQryRealtime").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
|
|
|
JSONObject jsonObject1 = JSONObject.parseObject(post);
|
|
|
Map map = (Map) jsonObject1.get("data");
|
|
|
- List<Map<String, String>> list = (List) map.get("records");
|
|
|
- for (Map<String, String> stringMap : list) {
|
|
|
+ List<Map<String, Object>> list = (List) map.get("records");
|
|
|
+ for (Map<String, Object> stringMap : list) {
|
|
|
FeedingData data = new FeedingData();
|
|
|
data.setFarmId(26);
|
|
|
data.setUnitName(feedArea.getUnitName());
|
|
|
QueryWrapper<FeedingEnv> queryWrapper1 = new QueryWrapper<>();
|
|
|
queryWrapper1.eq("device_code", stringMap.get("fdQrcode"));
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
- data.setUploadTime(dateFormat.parse(stringMap.get("createTime")));
|
|
|
- data.setBlanking(stringMap.get("zkAlram"));
|
|
|
- data.setFoodIntake(stringMap.get("intFdWeight"));
|
|
|
- data.setMeals(ThreadLocalRandom.current().nextInt());
|
|
|
+ data.setUploadTime(dateFormat.parse(stringMap.get("createTime").toString()));
|
|
|
+ data.setBlanking(stringMap.get("zkAlram").toString());
|
|
|
+ FeedingEnv env = envMapper.selectOne(queryWrapper1);
|
|
|
+ data.setEartag(env.getEartag());
|
|
|
+ env.setUnitName(feedArea.getUnitName());
|
|
|
+ env.setBlanking(stringMap.get("zkAlram").toString());
|
|
|
+ data.setFoodIntake(stringMap.get("intFdWeight").toString());
|
|
|
+// data.setMeals((int)Math.random() * 10 + 1);
|
|
|
+// env.setMeals((int)Math.random() * 10 + 1);
|
|
|
dataMapper.insert(data);
|
|
|
+ envMapper.updateById(env);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -115,34 +121,34 @@ public class FeedTimer {
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- Date now = new Date(); // 获取当前时间
|
|
|
- long oneHour = 1 * 30 * 1000; // 1小时的毫秒数
|
|
|
- Date oneHourAgo = new Date(now.getTime() - oneHour); // 获取1小时前的时间
|
|
|
- List<String> time = new ArrayList<>();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- time.add(sdf.format(oneHourAgo));
|
|
|
- time.add(sdf.format(new Date()));
|
|
|
- HashMap<String, String> paramMap = new HashMap<>();
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("pageNum", 1);
|
|
|
- jsonObject.put("pageSize", 20);
|
|
|
- jsonObject.put("createTime", time);
|
|
|
- jsonObject.put("areaId","1017517");
|
|
|
- paramMap.put("Content-Type", "application/json;charset=utf-8");
|
|
|
- paramMap.put("AuthorizationF","Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJoZW5sdSIsImNyZWF0ZWQiOjE2OTUzNjg1OTE4MjEsImV4cCI6MTY5NTQ1NDk5MX0.63A5FNJD714MVLp2cdH9HLyN25lYtAzsXHysXLEp1eR-FfkQZel6FnuoLfkIoFbgaht1OsEN-2ERabw0Lby7Pg");
|
|
|
- String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/mqtt/pageQryRealtime").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
|
|
|
- JSONObject jsonObject1 = JSONObject.parseObject(post);
|
|
|
- Map map = (Map) jsonObject1.get("data");
|
|
|
- System.out.println(map);
|
|
|
- List<Map<String, String>> list = (List) map.get("records");
|
|
|
- System.out.println(list);
|
|
|
+// Date now = new Date(); // 获取当前时间
|
|
|
+// long oneHour = 1 * 30 * 1000; // 1小时的毫秒数
|
|
|
+// Date oneHourAgo = new Date(now.getTime() - oneHour); // 获取1小时前的时间
|
|
|
+// List<String> time = new ArrayList<>();
|
|
|
+// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+// time.add(sdf.format(oneHourAgo));
|
|
|
+// time.add(sdf.format(new Date()));
|
|
|
+// HashMap<String, String> paramMap = new HashMap<>();
|
|
|
+// JSONObject jsonObject = new JSONObject();
|
|
|
+// jsonObject.put("pageNum", 1);
|
|
|
+// jsonObject.put("pageSize", 20);
|
|
|
+// jsonObject.put("createTime", time);
|
|
|
+// jsonObject.put("areaId","1017517");
|
|
|
+// paramMap.put("Content-Type", "application/json;charset=utf-8");
|
|
|
+// paramMap.put("AuthorizationF","Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJoZW5sdSIsImNyZWF0ZWQiOjE2OTUzNjg1OTE4MjEsImV4cCI6MTY5NTQ1NDk5MX0.63A5FNJD714MVLp2cdH9HLyN25lYtAzsXHysXLEp1eR-FfkQZel6FnuoLfkIoFbgaht1OsEN-2ERabw0Lby7Pg");
|
|
|
+// String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/mqtt/pageQryRealtime").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
|
|
|
+// JSONObject jsonObject1 = JSONObject.parseObject(post);
|
|
|
+// Map map = (Map) jsonObject1.get("data");
|
|
|
+// System.out.println(map);
|
|
|
+// List<Map<String, String>> list = (List) map.get("records");
|
|
|
+// System.out.println(list);
|
|
|
// List<String> jsonArray = (ArrayList) map.get("records");
|
|
|
// System.out.println(jsonArray);
|
|
|
}
|
|
|
|
|
|
|
|
|
//饲养器添加
|
|
|
- @Scheduled(cron = "0 0/1 * * * ? ")
|
|
|
+ @Scheduled(cron = "0 0 */1 * * ? ")
|
|
|
@Transactional
|
|
|
public void getFeedEnv() throws Exception {
|
|
|
QueryWrapper<FeedArea> queryWrapper = new QueryWrapper<>();
|
|
@@ -159,19 +165,21 @@ public class FeedTimer {
|
|
|
String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/api/v1/feeder/pageQry").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
|
|
|
JSONObject jsonObject1 = JSONObject.parseObject(post);
|
|
|
Map map = (Map) jsonObject1.get("data");
|
|
|
- List<Map<String, String>> list = (List) map.get("records");
|
|
|
- for (Map<String, String> stringMap : list) {
|
|
|
+ List<Map<String, Object>> list = (List) map.get("records");
|
|
|
+ for (Map<String, Object> stringMap : list) {
|
|
|
QueryWrapper<FeedingEnv> queryWrapper1 = new QueryWrapper<>();
|
|
|
- queryWrapper1.eq("farm_id", 26).eq("eartag", stringMap.get("earTag"));
|
|
|
- if (ObjectUtil.isEmpty(envMapper.selectOne(queryWrapper1))) {
|
|
|
- FeedingEnv feedingEnv = new FeedingEnv();
|
|
|
- feedingEnv.setFarmId(26);
|
|
|
- feedingEnv.setEartag(stringMap.get("earTag"));
|
|
|
- feedingEnv.setDeviceCode(stringMap.get("qrcode"));
|
|
|
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
- feedingEnv.setLastTime(dateFormat.parse(stringMap.get("createTime")));
|
|
|
- feedingEnv.setDeviceType(Integer.valueOf(stringMap.get("feedStatus")));
|
|
|
- envMapper.insert(feedingEnv);
|
|
|
+ if (ObjectUtil.isNotEmpty(stringMap.get("earTag"))) {
|
|
|
+ queryWrapper1.eq("farm_id", 26).eq("eartag", stringMap.get("earTag"));
|
|
|
+ if (ObjectUtil.isEmpty(envMapper.selectOne(queryWrapper1))) {
|
|
|
+ FeedingEnv feedingEnv = new FeedingEnv();
|
|
|
+ feedingEnv.setFarmId(26);
|
|
|
+ feedingEnv.setEartag(stringMap.get("earTag").toString());
|
|
|
+ feedingEnv.setDeviceCode(stringMap.get("qrcode").toString());
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
+ feedingEnv.setLastTime(dateFormat.parse((String) stringMap.get("createTime")));
|
|
|
+ feedingEnv.setDeviceType((Integer) stringMap.get("feedStatus"));
|
|
|
+ envMapper.insert(feedingEnv);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|