|
@@ -3,6 +3,7 @@ package com.huimv.eartag2.manage2.schedule;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
@@ -61,6 +62,11 @@ public class EartagTask {
|
|
@Autowired
|
|
@Autowired
|
|
private EartagData2Mapper eartagData2Mapper;
|
|
private EartagData2Mapper eartagData2Mapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private EartagAbnormalAlarmMapper eartagAbnormalAlarmMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private BasePigpenMapper pigpenMapper;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Method : countEartagOnlineTimes
|
|
* @Method : countEartagOnlineTimes
|
|
@@ -73,7 +79,8 @@ public class EartagTask {
|
|
*/
|
|
*/
|
|
|
|
|
|
// 10分钟
|
|
// 10分钟
|
|
- @Scheduled(cron = "0 0/1 * * * ? ")
|
|
|
|
|
|
+ @Scheduled(cron = "0 0/10 * * * ? ")
|
|
|
|
+// @Scheduled(cron = "0 * * * * ? ")
|
|
private void countEartagOnlineTimes() throws IOException, ParseException {
|
|
private void countEartagOnlineTimes() throws IOException, ParseException {
|
|
Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
|
|
Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
|
|
// System.out.println("时间戳="+nowTimestamp);
|
|
// System.out.println("时间戳="+nowTimestamp);
|
|
@@ -99,37 +106,68 @@ public class EartagTask {
|
|
|
|
|
|
// 5分钟
|
|
// 5分钟
|
|
// @Scheduled(cron = "0 * * * * ? ")
|
|
// @Scheduled(cron = "0 * * * * ? ")
|
|
- @Scheduled(cron = "0 0 * * * ? ")
|
|
|
|
|
|
+ @Scheduled(cron = "0 5 * * * ? ")
|
|
private void updateDevice() {
|
|
private void updateDevice() {
|
|
- List<SysBaseConfig> baseConfig = baseConfigService.list(new QueryWrapper<SysBaseConfig>().groupBy("row_id"));
|
|
|
|
-
|
|
|
|
- for (SysBaseConfig sysBaseConfig : baseConfig) {
|
|
|
|
- String rowId = sysBaseConfig.getRowId();
|
|
|
|
-// SysBaseConfig one = baseConfigService.getOne(new QueryWrapper<SysBaseConfig>().eq("row_id", rowId).eq("config_key", "eartagOfflineTime"));
|
|
|
|
- SysBaseConfig one = baseConfigService.getOne(new QueryWrapper<SysBaseConfig>().eq("row_id", rowId).eq("config_key", "deviceOfflineTime"));
|
|
|
|
-
|
|
|
|
- String configValueStr = one.getConfigValue();
|
|
|
|
- if (StringUtils.isBlank(configValueStr)) {
|
|
|
|
- configValueStr ="1440";
|
|
|
|
|
|
+ List<EartagDeviceRegister> list = deviceRegisterService.list();
|
|
|
|
+ for (EartagDeviceRegister eartagDeviceRegister : list) {
|
|
|
|
+ Integer farmerId = eartagDeviceRegister.getFarmerId();
|
|
|
|
+ SysBaseConfig config_value = baseConfigService.getOne(new QueryWrapper<SysBaseConfig>().eq("config_value", farmerId));
|
|
|
|
+ String configValueStr ="60";
|
|
|
|
+ if(ObjectUtil.isNotEmpty(config_value) ){
|
|
|
|
+ SysBaseConfig one = baseConfigService.getOne(new QueryWrapper<SysBaseConfig>().eq("row_id", config_value.getRowId()).eq("config_key", "deviceOfflineTime"));
|
|
|
|
+ configValueStr = one.getConfigValue();
|
|
}
|
|
}
|
|
|
|
|
|
int configValueInt = Integer.parseInt(configValueStr);
|
|
int configValueInt = Integer.parseInt(configValueStr);
|
|
- DateTime dateTime = DateUtil.offsetMinute(new Date(), -configValueInt);
|
|
|
|
-
|
|
|
|
- UpdateWrapper<EartagDeviceRegister> wrapper = new UpdateWrapper<>();
|
|
|
|
- wrapper.ge("last_time", dateTime);
|
|
|
|
- EartagDeviceRegister deviceRegister = new EartagDeviceRegister();
|
|
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ DateTime dateTime = DateUtil.offsetMinute(date, -configValueInt);
|
|
//未离线
|
|
//未离线
|
|
- deviceRegister.setActiveStatus(1);
|
|
|
|
- deviceRegister.setDeviceStatus(1);
|
|
|
|
- deviceRegisterService.update(deviceRegister, wrapper);
|
|
|
|
|
|
+ if (eartagDeviceRegister.getLastTime() !=null && dateTime.before(eartagDeviceRegister.getLastTime())){
|
|
|
|
+ if (eartagDeviceRegister.getActiveStatus() != 1){
|
|
|
|
+ eartagDeviceRegister.setActiveStatus(1);
|
|
|
|
+ eartagDeviceRegister.setDeviceStatus(1);
|
|
|
|
+ deviceRegisterService.updateById(eartagDeviceRegister);
|
|
|
|
+ }
|
|
|
|
+ }else { //离线
|
|
|
|
+ if ( eartagDeviceRegister.getActiveStatus() != 2){
|
|
|
|
+ eartagDeviceRegister.setActiveStatus(2);
|
|
|
|
+ eartagDeviceRegister.setDeviceStatus(0);
|
|
|
|
+ deviceRegisterService.updateById(eartagDeviceRegister);
|
|
|
|
+
|
|
|
|
+ String deviceCode = eartagDeviceRegister.getDeviceCode();
|
|
|
|
+ String farmId = eartagDeviceRegister.getFarmId();
|
|
|
|
+ Integer unitId = eartagDeviceRegister.getUnitId();
|
|
|
|
+ Integer pigpenId = eartagDeviceRegister.getPigpenId();
|
|
|
|
+ BasePigpen basePigpen = pigpenMapper.selectById(unitId);
|
|
|
|
+ BasePigpen basePigpen1 = pigpenMapper.selectById(pigpenId);
|
|
|
|
+ String pigpen = "";
|
|
|
|
+ if (ObjectUtil.isNotEmpty(basePigpen)){
|
|
|
|
+ pigpen += basePigpen.getPigpenName();
|
|
|
|
+ }
|
|
|
|
+ if (ObjectUtil.isNotEmpty(basePigpen1)){
|
|
|
|
+ pigpen += basePigpen1.getPigpenName();
|
|
|
|
+ }
|
|
|
|
+ //耳标离线:6
|
|
|
|
+ int alarmSort = 2;
|
|
|
|
+ //耳标:2
|
|
|
|
+ int alarmFrom = 1;
|
|
|
|
+ //状态:1
|
|
|
|
+ int alarmType = 1;
|
|
|
|
|
|
- //离线
|
|
|
|
- deviceRegister.setActiveStatus(2);
|
|
|
|
- deviceRegister.setDeviceStatus(0);
|
|
|
|
- wrapper.clear();
|
|
|
|
- wrapper.le("last_time", dateTime).or().isNull("last_time");
|
|
|
|
- deviceRegisterService.update(deviceRegister, wrapper);
|
|
|
|
|
|
+ //报警
|
|
|
|
+ String alarmContent = "离线警报:"+pigpen+"设备号["+deviceCode+"]已离线";
|
|
|
|
+ EartagAbnormalAlarm newEartagAbnormalAlarmEntity = new EartagAbnormalAlarm();
|
|
|
|
+ newEartagAbnormalAlarmEntity.setFarmCode(farmId);
|
|
|
|
+ newEartagAbnormalAlarmEntity.setAddTime(date);
|
|
|
|
+ newEartagAbnormalAlarmEntity.setAddDate(date);
|
|
|
|
+ newEartagAbnormalAlarmEntity.setAlarmSort(alarmSort);
|
|
|
|
+ newEartagAbnormalAlarmEntity.setAlarmType(alarmType);
|
|
|
|
+ newEartagAbnormalAlarmEntity.setAlarmFrom(alarmFrom);
|
|
|
|
+ newEartagAbnormalAlarmEntity.setContent(alarmContent);
|
|
|
|
+ eartagAbnormalAlarmMapper.insert(newEartagAbnormalAlarmEntity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|