自动模式,设备日志
parent
7498db935f
commit
3de90ccc70
|
|
@ -9,6 +9,7 @@ import com.agri.framework.manager.MqttAutoOffManager;
|
||||||
import com.agri.system.domain.SysAgriInfo;
|
import com.agri.system.domain.SysAgriInfo;
|
||||||
import com.agri.system.domain.SysAgriLimit;
|
import com.agri.system.domain.SysAgriLimit;
|
||||||
import com.agri.system.domain.SysDevOperLog;
|
import com.agri.system.domain.SysDevOperLog;
|
||||||
|
import com.agri.system.domain.SysImeiAutoLog;
|
||||||
import com.agri.system.domain.vo.RollerTermVO;
|
import com.agri.system.domain.vo.RollerTermVO;
|
||||||
import com.agri.system.service.*;
|
import com.agri.system.service.*;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
|
@ -23,6 +24,7 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -79,7 +81,10 @@ public class RollerAutoTask {
|
||||||
@Value("${spring.mqtt.dtu-ctl-lock-ttl}")
|
@Value("${spring.mqtt.dtu-ctl-lock-ttl}")
|
||||||
private int dtuCtlLockTTL;
|
private int dtuCtlLockTTL;
|
||||||
|
|
||||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
|
@Autowired
|
||||||
|
private ISysImeiAutoLogService imeiAutoLogService;
|
||||||
|
|
||||||
|
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("HH:mm");
|
||||||
|
|
||||||
|
|
||||||
private static final Map<String, Function<SysAgriLimit, Integer>> LIMIT_MAP = new HashMap<>();
|
private static final Map<String, Function<SysAgriLimit, Integer>> LIMIT_MAP = new HashMap<>();
|
||||||
|
|
@ -143,6 +148,7 @@ public class RollerAutoTask {
|
||||||
|
|
||||||
// 查询每个IMEI今天的第一条日志
|
// 查询每个IMEI今天的第一条日志
|
||||||
Map<String, Map<String, Integer>> todayLogCountByImeiMap = devOperLogService.getTodayLogCountByImeiMap(imeiList);
|
Map<String, Map<String, Integer>> todayLogCountByImeiMap = devOperLogService.getTodayLogCountByImeiMap(imeiList);
|
||||||
|
ArrayList<SysImeiAutoLog> logArrayList = new ArrayList<SysImeiAutoLog>();
|
||||||
// 循环所有开启自动化的大棚
|
// 循环所有开启自动化的大棚
|
||||||
for (SysAgriInfo agriInfo : agriInfos) {
|
for (SysAgriInfo agriInfo : agriInfos) {
|
||||||
String imei = agriInfo.getImei();
|
String imei = agriInfo.getImei();
|
||||||
|
|
@ -223,12 +229,22 @@ public class RollerAutoTask {
|
||||||
// 在范围内
|
// 在范围内
|
||||||
//判断温度是否在适宜温度内
|
//判断温度是否在适宜温度内
|
||||||
TempCommandStatus tempCommandStatus = TempJudgeUtil.judgeTempCommand(currentTemp, term.getTemp());
|
TempCommandStatus tempCommandStatus = TempJudgeUtil.judgeTempCommand(currentTemp, term.getTemp());
|
||||||
|
SysImeiAutoLog imeiAutoLog = new SysImeiAutoLog();
|
||||||
|
imeiAutoLog.setImei(imei);
|
||||||
|
imeiAutoLog.setMonitorPeriod(term.getStartTime().format(FORMATTER)+"~"+term.getEndTime().format(FORMATTER));
|
||||||
|
imeiAutoLog.setCurrentTemp(currentTemp);
|
||||||
|
imeiAutoLog.setRefTemp(term.getTemp());
|
||||||
|
imeiAutoLog.setSuitableTemp(refTempCode);
|
||||||
|
imeiAutoLog.setFanStatus(term.getVent());
|
||||||
|
imeiAutoLog.setIsLast(isCancelOff?1:0);
|
||||||
// todo 开关指令需要通知用户 推送主题 && 更新数据 前端重新请求消息表
|
// todo 开关指令需要通知用户 推送主题 && 更新数据 前端重新请求消息表
|
||||||
if (tempCommandStatus == TempCommandStatus.OPEN) {
|
if (tempCommandStatus == TempCommandStatus.OPEN) {
|
||||||
log.info("【定时任务-卷膜自动化控制】大棚『{}』-卷膜『{}』当前温湿度:『{}℃』,适宜温度为:「{}℃」,触发自动化条件,即将执行『开』指令!",
|
log.info("【定时任务-卷膜自动化控制】大棚『{}』-卷膜『{}』当前温湿度:『{}℃』,适宜温度为:「{}℃」,触发自动化条件,即将执行『开』指令!",
|
||||||
imei, roller, currentTemp, term.getTemp());
|
imei, roller, currentTemp, term.getTemp());
|
||||||
// 判断是否首次开
|
// 判断是否首次开
|
||||||
Integer openLen = todayLogByRoller.getOrDefault(roller + "k1", 0);
|
Integer openLen = todayLogByRoller.getOrDefault(roller + "k1", 0);
|
||||||
|
imeiAutoLog.setRollFilm(roller + "k1");
|
||||||
|
imeiAutoLog.setExecCmd("开");
|
||||||
// 开指令
|
// 开指令
|
||||||
sendOpenCommand(imei, agriName, roller, openLen == 0, term.getVent(), reservedLen);
|
sendOpenCommand(imei, agriName, roller, openLen == 0, term.getVent(), reservedLen);
|
||||||
// 每次后,数量累计+1 不需要因为只循环到一次
|
// 每次后,数量累计+1 不需要因为只循环到一次
|
||||||
|
|
@ -237,6 +253,8 @@ public class RollerAutoTask {
|
||||||
imei, roller, currentTemp, term.getTemp());
|
imei, roller, currentTemp, term.getTemp());
|
||||||
// 判断是否首次开
|
// 判断是否首次开
|
||||||
Integer closeLen = todayLogByRoller.getOrDefault(roller + "g1", 0);
|
Integer closeLen = todayLogByRoller.getOrDefault(roller + "g1", 0);
|
||||||
|
imeiAutoLog.setRollFilm(roller + "g1");
|
||||||
|
imeiAutoLog.setExecCmd("关");
|
||||||
// 关指令
|
// 关指令
|
||||||
sendCloseCommand(imei, agriName, roller, closeLen == 0, term.getVent(), isCancelOff);
|
sendCloseCommand(imei, agriName, roller, closeLen == 0, term.getVent(), isCancelOff);
|
||||||
// 每次后,数量累计+1
|
// 每次后,数量累计+1
|
||||||
|
|
@ -244,10 +262,11 @@ public class RollerAutoTask {
|
||||||
log.info("【定时任务-卷膜自动化控制】大棚『{}』-卷膜『{}』当前温湿度:『{}℃』,适宜温度为:「{}℃」,温度适宜,无需操作!",
|
log.info("【定时任务-卷膜自动化控制】大棚『{}』-卷膜『{}』当前温湿度:『{}℃』,适宜温度为:「{}℃」,温度适宜,无需操作!",
|
||||||
imei, roller, currentTemp, term.getTemp());
|
imei, roller, currentTemp, term.getTemp());
|
||||||
}
|
}
|
||||||
|
logArrayList.add(imeiAutoLog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
imeiAutoLogService.saveBatch(logArrayList);
|
||||||
log.info("=============【定时任务】大棚自动模式监测执行完毕,时间:{}=============", LocalDateTime.now());
|
log.info("=============【定时任务】大棚自动模式监测执行完毕,时间:{}=============", LocalDateTime.now());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
WxUtil.pushText("【定时任务】大棚自动模式监测执行终端, \n发生错误.错误原因:"+e+",\n时间:"+LocalDateTime.now());
|
WxUtil.pushText("【定时任务】大棚自动模式监测执行终端, \n发生错误.错误原因:"+e+",\n时间:"+LocalDateTime.now());
|
||||||
|
|
@ -440,6 +459,7 @@ public class RollerAutoTask {
|
||||||
// 可选:增加异常捕获,避免日志保存失败影响指令执行
|
// 可选:增加异常捕获,避免日志保存失败影响指令执行
|
||||||
try {
|
try {
|
||||||
devOperLogService.save(logDto);
|
devOperLogService.save(logDto);
|
||||||
|
log.info("【日志保存】设备{}功能{}日志保存成功,日志id:{}", imei, funcCode,logDto.getId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("【日志保存失败】设备{}功能{}日志保存失败", imei, funcCode, e);
|
log.error("【日志保存失败】设备{}功能{}日志保存失败", imei, funcCode, e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
package com.agri.system.domain;
|
package com.agri.system.domain;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.agri.common.annotation.Excel;
|
import com.agri.common.annotation.Excel;
|
||||||
import com.agri.common.core.domain.BaseEntity;
|
import com.agri.common.core.domain.BaseEntity;
|
||||||
|
|
@ -22,6 +24,8 @@ public class SysImeiAutoLog extends BaseEntity
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/** 主键 */
|
/** 主键 */
|
||||||
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/** 设备IMEI */
|
/** 设备IMEI */
|
||||||
|
|
@ -50,11 +54,11 @@ public class SysImeiAutoLog extends BaseEntity
|
||||||
|
|
||||||
/** 运行风口 */
|
/** 运行风口 */
|
||||||
@Excel(name = "运行风口")
|
@Excel(name = "运行风口")
|
||||||
private String fanStatus;
|
private BigDecimal fanStatus;
|
||||||
|
|
||||||
/** 是否最后一条 0否1是 */
|
/** 是否最后一条 0否1是 */
|
||||||
@Excel(name = "是否最后一条 0否1是")
|
@Excel(name = "是否最后一条 0否1是")
|
||||||
private Long isLast;
|
private int isLast;
|
||||||
|
|
||||||
/** 执行指令 */
|
/** 执行指令 */
|
||||||
@Excel(name = "执行指令")
|
@Excel(name = "执行指令")
|
||||||
|
|
@ -134,27 +138,24 @@ public class SysImeiAutoLog extends BaseEntity
|
||||||
return suitableTemp;
|
return suitableTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFanStatus(String fanStatus)
|
public BigDecimal getFanStatus() {
|
||||||
{
|
|
||||||
this.fanStatus = fanStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFanStatus()
|
|
||||||
{
|
|
||||||
return fanStatus;
|
return fanStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsLast(Long isLast)
|
public void setFanStatus(BigDecimal fanStatus) {
|
||||||
{
|
this.fanStatus = fanStatus;
|
||||||
this.isLast = isLast;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getIsLast()
|
|
||||||
{
|
public int getIsLast() {
|
||||||
return isLast;
|
return isLast;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExecCmd(String execCmd)
|
public void setIsLast(int isLast) {
|
||||||
|
this.isLast = isLast;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExecCmd(String execCmd)
|
||||||
{
|
{
|
||||||
this.execCmd = execCmd;
|
this.execCmd = execCmd;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue