fix: alertmessage属性endat赋值 utc时间+10min asset chart模板var type赋值

assetinfo不添加入template
This commit is contained in:
tanghao
2021-05-21 17:13:24 +08:00
parent a0a987d183
commit 00022eb894
3 changed files with 88 additions and 2 deletions

View File

@@ -12,12 +12,20 @@ import com.nis.service.AlertMessageActiveService;
import com.nis.service.AlertMessageHistoryService;
import com.nis.service.AlertMessageService;
import com.nis.service.AlertRuleService;
import com.nis.util.DateUtil;
import com.nis.util.ToolUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import javax.tools.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -72,6 +80,9 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
if(message.getState().equals(1)) {
AlertMessageActiveEntity activeMessage = new AlertMessageActiveEntity();
BeanUtil.copyProperties(message, activeMessage);
Date utcTime = DateUtil.getUTCTimeByConfigTimeZone();
DateTime date = DateUtil.offsetSecond(utcTime, 600);
activeMessage.setEndAt(date);
activeMessages.add(activeMessage);
}else {
AlertMessageHistoryEntity historyMessage = new AlertMessageHistoryEntity();
@@ -89,5 +100,5 @@ public class AlertMessageServiceImpl extends ServiceImpl<AlertMessageDao, AlertM
}
}
}

View File

@@ -96,7 +96,7 @@ public class ChartServiceImpl extends ServiceImpl<ChartDao, Chart> implements Ch
visualChart.setHeight(chart.getHeight());
visualChart.setPid(chart.getPid());
Panel panel = panelIdAndPanel.get(chart.getPanelId());
if(panel.getType().equals("model")) {
if(panel.getType().equals("model")&& !chart.getType().equals("assetInfo")) {
visualChart.setPanelId(0);
String string = modelIdAndChartIds.get(panel.getLink());
if(StrUtil.isBlank(string)) {
@@ -104,6 +104,7 @@ public class ChartServiceImpl extends ServiceImpl<ChartDao, Chart> implements Ch
}else {
string = string +","+chart.getId();
}
visualChart.setVarType(1);
modelIdAndChartIds.put(panel.getLink(), string);
}else {
visualChart.setPanelId(chart.getPanelId());

View File

@@ -0,0 +1,74 @@
package com.nis.util;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.log.Log;
public class DateUtil {
private static Log logger = Log.get();
public static Date getUTCTimeByConfigTimeZone() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(DateUtil.getConfigTimeZone(0));
String format = sdf.format(new Date());
Date parse = null;
try {
sdf.setTimeZone(TimeZone.getDefault());
parse = sdf.parse(format);
} catch (Exception e) {
logger.error(e);
}
return parse;
}
public static TimeZone getConfigTimeZone(int configTimeZone) {
int newTime = configTimeZone * 60 * 60 * 1000;
TimeZone timeZone;
String[] ids = TimeZone.getAvailableIDs(newTime);
if (ids.length == 0) {
timeZone = TimeZone.getDefault();
} else {
timeZone = new SimpleTimeZone(newTime, ids[0]);
}
return timeZone;
}
/**
* 偏移秒数
*
* @param date 日期
* @param offset 偏移秒数,正数向未来偏移,负数向历史偏移
* @return 偏移后的日期
*/
public static DateTime offsetSecond(Date date, int offset) {
return offset(date, DateField.SECOND, offset);
}
/**
* 获取指定日期偏移指定时间后的时间,生成的偏移日期不影响原日期
*
* @param date 基准日期
* @param dateField 偏移的粒度大小(小时、天、月等){@link DateField}
* @param offset 偏移量,正数为向后偏移,负数为向前偏移
* @return 偏移后的日期
*/
public static DateTime offset(Date date, DateField dateField, int offset) {
return dateNew(date).offset(dateField, offset);
}
/**
* 根据已有{@link Date} 产生新的{@link DateTime}对象
*
* @param date Date对象
* @return {@link DateTime}对象
* @since 4.3.1
*/
public static DateTime dateNew(Date date) {
return new DateTime(date);
}
}