提交 71dd59ee 编写于 作者: J jialinsun

refactor database alteration jsp

上级 21ea5bb0
package com.dianping.cat.report.page.storage;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
......@@ -77,8 +77,6 @@ public class Handler implements PageHandler<Context> {
@Inject
private AlterationDao m_alterationDao;
private SimpleDateFormat m_sdf = new SimpleDateFormat("HH:mm");
private Map<String, Map<String, List<String>>> buildAlertLinks(Map<String, StorageAlertInfo> alertInfos, String type) {
Map<String, Map<String, List<String>>> links = new LinkedHashMap<String, Map<String, List<String>>>();
String format = m_storageGroupConfigManager.queryLinkFormat(type);
......@@ -114,34 +112,25 @@ public class Handler implements PageHandler<Context> {
return links;
}
private Map<String, List<Alteration>> buildAlterations(Payload payload, Model model) {
private List<Alteration> buildAlterations(Payload payload, Model model) {
int minuteCounts = payload.getMinuteCounts();
int minute = model.getMinute();
long end = payload.getDate() + (minute + 1) * TimeHelper.ONE_MINUTE - TimeHelper.ONE_SECOND;
long start = payload.getDate() + (minute + 1 - minuteCounts) * TimeHelper.ONE_MINUTE;
Map<String, List<Alteration>> results = new LinkedHashMap<String, List<Alteration>>();
List<Alteration> results = new LinkedList<Alteration>();
try {
List<Alteration> alterations = m_alterationDao.findByTypeDruation(new Date(start), new Date(end),
payload.getType(), AlterationEntity.READSET_FULL);
for (Alteration alteration : alterations) {
String date = m_sdf.format(alteration.getDate());
List<Alteration> alts = results.get(date);
if (alts == null) {
alts = new ArrayList<Alteration>();
results.put(date, alts);
}
alts.add(alteration);
results.add(alteration);
}
} catch (DalNotFoundException e) {
// ignore it
} catch (Exception e) {
Cat.logError(e);
}
return results;
}
......
......@@ -54,7 +54,7 @@ public class Model extends AbstractReportModel<Action, ReportPage, Context> {
private Map<String, Map<String, List<String>>> m_links;
private Map<String, List<Alteration>> m_alterations;
private List<Alteration> m_alterations;
private String m_distributionChart;
......@@ -74,7 +74,7 @@ public class Model extends AbstractReportModel<Action, ReportPage, Context> {
return m_alertInfos;
}
public Map<String, List<Alteration>> getAlterations() {
public List<Alteration> getAlterations() {
return m_alterations;
}
......@@ -184,7 +184,7 @@ public class Model extends AbstractReportModel<Action, ReportPage, Context> {
m_alertInfos = alertInfos;
}
public void setAlterations(Map<String, List<Alteration>> alterations) {
public void setAlterations(List<Alteration> alterations) {
m_alterations = alterations;
}
......
......@@ -5,6 +5,7 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="res" uri="http://www.unidal.org/webres"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:useBean id="ctx" type="com.dianping.cat.report.page.storage.Context" scope="request" />
<jsp:useBean id="payload" type="com.dianping.cat.report.page.storage.Payload" scope="request" />
<jsp:useBean id="model" type="com.dianping.cat.report.page.storage.Model" scope="request" />
......@@ -134,36 +135,29 @@
<th class="center">主机名</th>
<th class="center">IP</th>
<th class="center">标题</th>
<th class="center">内容</th>
<th class="left">内容</th>
<th class="center">状态</th>
</tr>
<c:forEach var="entry" items="${model.alterations}">
<tr><td rowspan="${w:size(entry.value)}" class="text-danger center" style="vertical-align:middle;">${entry.key}</td>
<c:forEach var="alt" items="${entry.value}" varStatus="index">
<c:if test="${index.index != 0 }">
<tr>
</c:if>
<td>${alt.domain}</td>
<td>${alt.hostname}</td>
<td>${alt.ip}</td>
<td>${alt.title}</td>
<td>${alt.content}</td>
<td>
<c:if test="${alt.status == 0}" >
<button class="btn btn-xs btn-success">
<i class="ace-icon glyphicon glyphicon-ok bigger-120 btn-success"></i>
</button>
</c:if>
<c:if test="${alt.status != 0}" >
<button class="btn btn-xs btn-danger">
<i class="ace-icon glyphicon glyphicon-remove bigger-120 btn-danger"></i>
</button>
</c:if>
</td>
<c:if test="${index.index != 0 }">
</tr>
</c:if>
</c:forEach>
<c:forEach var="alt" items="${model.alterations}">
<tr>
<td><fmt:formatDate value="${alt.date}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
<td>${alt.domain}</td>
<td>${alt.hostname}</td>
<td>${alt.ip}</td>
<td>${alt.title}</td>
<td class="left">${alt.content}</td>
<td>
<c:if test="${alt.status == 0}" >
<button class="btn btn-xs btn-success">
<i class="ace-icon glyphicon glyphicon-ok bigger-120 btn-success"></i>
</button>
</c:if>
<c:if test="${alt.status != 0}" >
<button class="btn btn-xs btn-danger">
<i class="ace-icon glyphicon glyphicon-remove bigger-120 btn-danger"></i>
</button>
</c:if>
</td>
</tr>
</c:forEach>
</c:if>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册