|
@@ -53,58 +53,62 @@ public class FeedTimer {
|
|
|
private FeedingDataMapper dataMapper;
|
|
|
|
|
|
|
|
|
-// @Scheduled(cron = "0 0 */1 * * ? ")
|
|
|
+ // @Scheduled(cron = "0 0 */1 * * ? ")
|
|
|
@Scheduled(cron = "0 0/59 * * * ? ")
|
|
|
@Transactional
|
|
|
public void getFeed() throws Exception {
|
|
|
QueryWrapper<FeedArea> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("farm_id", 26);
|
|
|
List<FeedArea> feedAreas = feedAreaMapper.selectList(queryWrapper);
|
|
|
- Date now = new Date(); // 获取当前时间
|
|
|
- long oneHour = 1 * 60 * 60 * 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()));
|
|
|
- System.out.println("这个是传入的时间数组:" + time);
|
|
|
+// Date now = new Date(); // 获取当前时间
|
|
|
+// long oneHour = 1 * 60 * 60 * 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()));
|
|
|
+// System.out.println("这个是传入的时间数组:" + time);
|
|
|
for (FeedArea feedArea : feedAreas) {
|
|
|
HashMap<String, String> paramMap = new HashMap<>();
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("pageNum", "1");
|
|
|
- jsonObject.put("pageSize", "20");
|
|
|
- jsonObject.put("createTime", time);
|
|
|
+// jsonObject.put("pageNum", "1");
|
|
|
+// jsonObject.put("pageSize", "50");
|
|
|
+// jsonObject.put("createTime", time);
|
|
|
jsonObject.put("fdQrcode", "");
|
|
|
jsonObject.put("fenceNum", "");
|
|
|
- jsonObject.put("gatewayNo", "");
|
|
|
+ jsonObject.put("gatewayNo", feedArea.getGatewayNo());
|
|
|
jsonObject.put("areaId", feedArea.getAreaId());
|
|
|
paramMap.put("Content-Type", "application/json;charset=utf-8");
|
|
|
paramMap.put("AuthorizationF", getToken());
|
|
|
- String post = HttpRequest.post("http://znsw.zxkj2006.com/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?pageNum=1&pageSize=50").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, Object>> list = (List) map.get("records");
|
|
|
- for (Map<String, Object> stringMap : list) {
|
|
|
- FeedingData data = new FeedingData();
|
|
|
- data.setFarmId(26);
|
|
|
- data.setUnitName(feedArea.getUnitName());
|
|
|
- data.setDeviceCode(stringMap.get("fdQrcode").toString());
|
|
|
- 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").toString()));
|
|
|
- data.setBlanking(stringMap.get("zkAlram").toString());
|
|
|
- FeedingEnv env = envMapper.selectOne(queryWrapper1);
|
|
|
- if (ObjectUtil.isNotEmpty(env)) {
|
|
|
- data.setEartag(env.getEartag());
|
|
|
- env.setUnitName(feedArea.getUnitName());
|
|
|
- env.setBlanking(stringMap.get("zkAlram").toString());
|
|
|
- envMapper.updateById(env);
|
|
|
+ System.out.println("取到了记录:"+list);
|
|
|
+ if (null !=list) {
|
|
|
+ for (Map<String, Object> stringMap : list) {
|
|
|
+ FeedingData data = new FeedingData();
|
|
|
+ data.setFarmId(26);
|
|
|
+ data.setUnitName(feedArea.getName());
|
|
|
+ data.setDeviceCode(stringMap.get("fdQrcode").toString());
|
|
|
+// 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").toString()));
|
|
|
+ data.setBlanking(stringMap.get("zkAlram").toString());
|
|
|
+// FeedingEnv env = envMapper.selectOne(queryWrapper1);
|
|
|
+// if (ObjectUtil.isNotEmpty(env)) {
|
|
|
+//// data.setEartag(env.getEartag());
|
|
|
+// env.setUnitName(feedArea.getName());
|
|
|
+// env.setBlanking(stringMap.get("zkAlram").toString());
|
|
|
+// envMapper.updateById(env);
|
|
|
+// }
|
|
|
+ data.setMeals(Integer.parseInt(stringMap.get("dayDeliver").toString()));
|
|
|
+ data.setFoodIntake(stringMap.get("intFdWeight").toString());
|
|
|
+ dataMapper.insert(data);
|
|
|
}
|
|
|
- data.setMeals(Integer.parseInt(stringMap.get("dayDeliver").toString()));
|
|
|
- data.setFoodIntake(stringMap.get("intFdWeight").toString());
|
|
|
- dataMapper.insert(data);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -149,7 +153,7 @@ public class FeedTimer {
|
|
|
|
|
|
|
|
|
//饲养器添加
|
|
|
- @Scheduled(cron = "0 0/30 * * * ? ")
|
|
|
+ @Scheduled(cron = "0 0/59 * * * ? ")
|
|
|
@Transactional
|
|
|
public void getFeedEnv() throws Exception {
|
|
|
QueryWrapper<FeedArea> queryWrapper = new QueryWrapper<>();
|
|
@@ -159,29 +163,30 @@ public class FeedTimer {
|
|
|
HashMap<String, String> paramMap = new HashMap<>();
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("pageNum", "1");
|
|
|
- jsonObject.put("pageSize", "20");
|
|
|
+ jsonObject.put("pageSize", "200");
|
|
|
jsonObject.put("areaId", feedArea.getAreaId());
|
|
|
paramMap.put("Content-Type", "application/json;charset=utf-8");
|
|
|
paramMap.put("AuthorizationF", getToken());
|
|
|
- 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();
|
|
|
+ String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/api/v1/feeder/pageQry?pageNum=1&pageSize=50").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, Object>> list = (List) map.get("records");
|
|
|
for (Map<String, Object> stringMap : list) {
|
|
|
QueryWrapper<FeedingEnv> queryWrapper1 = new QueryWrapper<>();
|
|
|
- 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);
|
|
|
- }
|
|
|
+ queryWrapper1.eq("farm_id", 26).eq("device_code", stringMap.get("qrcode"));
|
|
|
+ if (ObjectUtil.isEmpty(envMapper.selectOne(queryWrapper1))) {
|
|
|
+ FeedingEnv feedingEnv = new FeedingEnv();
|
|
|
+ feedingEnv.setFarmId(26);
|
|
|
+ feedingEnv.setUnitName(feedArea.getName());
|
|
|
+ feedingEnv.setUnitId(Integer.parseInt(feedArea.getUnitId()));
|
|
|
+ feedingEnv.setDeviceType(feedArea.getType());
|
|
|
+ feedingEnv.setDeviceCode(stringMap.get("qrcode").toString());
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
+ feedingEnv.setLastTime(dateFormat.parse((String) stringMap.get("createTime")));
|
|
|
+ feedingEnv.setOnlineStatus((Integer) stringMap.get("feedStatus"));
|
|
|
+ envMapper.insert(feedingEnv);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|