补充各种无数据情况

This commit is contained in:
dongxiaoyan
2018-12-20 17:32:09 +08:00
parent dc23300ac7
commit 54ef14220d
8 changed files with 1179 additions and 39 deletions

View File

@@ -6,6 +6,7 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -21,8 +22,10 @@ import com.nis.domain.restful.CfgLogInfo;
import com.nis.domain.restful.DropInfo;
import com.nis.domain.restful.NtcAreaHomeReport;
import com.nis.util.CalendarUtils;
import com.nis.util.DateUtils;
import com.nis.web.dao.SystemHomePageDao;
@Service
public class SystemHomePageService {
@Autowired
@@ -70,24 +73,27 @@ public class SystemHomePageService {
}
// 获取配置日志TOP5统计
public Page<CfgLogInfo> getCfgSortLogStat(String searchReportStartTime, String searchReportEndTime,
HttpServletRequest request, HttpServletResponse response) {
/*public Page<CfgLogInfo> getCfgSortLogStat(String searchReportStartTime, String searchReportEndTime,
HttpServletRequest request, HttpServletResponse response) {*/
public Page<CfgLogInfo> getCfgSortLogStat(CfgLogInfo cfgLogInfo) {
List<CfgLogInfo> list = new LinkedList<CfgLogInfo>();
Page<CfgLogInfo> page = new Page<>();
Date endTime = null;
Date startTime = null;
if (null != searchReportStartTime && null != searchReportEndTime && !"".equals(searchReportStartTime)
&& !"".equals(searchReportEndTime)) {
if (null != cfgLogInfo.getSearchReportStartTime() && null != cfgLogInfo.getSearchReportEndTime() && !"".equals(cfgLogInfo.getSearchReportStartTime() )
&& !"".equals(cfgLogInfo.getSearchReportEndTime())) {
logger.info("开始获取配置日志TOP5,参数为{"
+ ((null == searchReportStartTime && !"".equals(searchReportStartTime)) ? ""
: searchReportStartTime)
+ ((null == cfgLogInfo.getSearchReportStartTime() && !"".equals(cfgLogInfo.getSearchReportStartTime() )) ? ""
: cfgLogInfo.getSearchReportStartTime() )
+ "},{"
+ ((null == searchReportEndTime && !"".equals(searchReportEndTime)) ? "" : searchReportEndTime)
+ ((null == cfgLogInfo.getSearchReportEndTime() && !"".equals(cfgLogInfo.getSearchReportEndTime())) ? "" : cfgLogInfo.getSearchReportEndTime())
+ "}");
try {
startTime = format.parse(searchReportStartTime);
endTime = format.parse(searchReportEndTime);
startTime = format.parse(cfgLogInfo.getSearchReportStartTime() );
endTime = format.parse(cfgLogInfo.getSearchReportEndTime());
list = systemHomePageDao.getCfgSortLogStatList(cfgLogInfo);
list = converCfgLogList(list, cfgLogInfo);
} catch (ParseException e) {
e.printStackTrace();
logger.error("处理时间转换异常,{}", e);
@@ -95,16 +101,22 @@ public class SystemHomePageService {
} else {
endTime = CalendarUtils.getRangeOf5min(0);
startTime = CalendarUtils.getTPrevHour(endTime, -24);
cfgLogInfo.setSearchReportStartTime(format.format(startTime));
cfgLogInfo.setSearchReportEndTime(format.format(endTime));
logger.info("获取配置日志TOP5API请求参数为空,默认查询最近24小时");
}
list = systemHomePageDao.getCfgSortLogStatList(startTime, endTime);
if (null != list && 0 != list.size()) {
/*if (null != list && 0 != list.size()) {
list = converCfgLogList(list, startTime, endTime);
} else {
logger.info("没有查到配置日志Top的数据");
}*/
if(list!=null && list.size()>0){
page.setCount(list.size());
logger.info("查询配置日志TOP5结束"+list.size());
}else{
logger.info("查询配置日志TOP5结束");
}
logger.trace("查询配置日志TOP5结束");
page.setList(list);
return page;
}
@@ -161,8 +173,112 @@ public class SystemHomePageService {
* @param startTime
* @param endTime
* @return
* @throws ParseException
*/
public List<CfgLogInfo> converCfgLogList(List<CfgLogInfo> list, Date startTime, Date endTime) {
public List<CfgLogInfo> converCfgLogList(List<CfgLogInfo> list, CfgLogInfo cfgLogInfoParm) throws ParseException {
List<CfgLogInfo> newList = new LinkedList<>();
String sTime = cfgLogInfoParm.getSearchReportStartTime();
String eTime = cfgLogInfoParm.getSearchReportEndTime();
long baseNum = cfgLogInfoParm.getBaseNum();
long startTimes = DateUtils.strToDate(sTime,"yyyy-MM-dd HH:mm:ss").getTime();
long endTimes = DateUtils.strToDate(eTime,"yyyy-MM-dd HH:mm:ss").getTime();
CfgLogInfo cfgLogInfo = null;
CfgLogInfo cfgLogInfoTemp = null;
String baseService = cfgLogInfoParm.getSearchService();
String serviceArray[] = serviceArray = baseService.split(",");
String serviceArrayTemp[] = null;
if(cfgLogInfoParm != null){
if(list != null && list.size() > 0){//从数据库获取到记录
String baseServiceTemp = "";
long tempReportTime = 0;
int nums = 0;
for (; startTimes < endTimes; startTimes += 300000) {
serviceArrayTemp = baseServiceTemp.split(",");
baseServiceTemp = ","+baseService+",";
//loop:
for (int i = 0; i < list.size(); i++) {
cfgLogInfo = null;
cfgLogInfo = list.get(i);
if(cfgLogInfo!=null && startTimes==cfgLogInfo.getReportTime().getTime() && cfgLogInfo.getReportTime().getTime()<endTimes){
newList.add(cfgLogInfo);
baseServiceTemp = baseServiceTemp.replace(","+cfgLogInfo.getServiceCode()+",", ",");
if(tempReportTime==0 || nums==serviceArray.length){//时间改变
tempReportTime = cfgLogInfo.getReportTime().getTime();
nums = 0;
}
nums++;
if(nums == serviceArray.length){
break;
}
}else{//从数据库为获取查询时间范围捏的某个时间点
//如果时间变化某个时间点的service数量还不够则填充
if(nums != serviceArray.length){
serviceArrayTemp = baseServiceTemp.split(",");
for(int m=0;m<serviceArrayTemp.length;m++){
if(serviceArrayTemp[m]!=null && !"".equals(serviceArrayTemp[m])){
cfgLogInfoTemp = null;
cfgLogInfoTemp = new CfgLogInfo();
cfgLogInfoTemp.setSum(Math.round(baseNum*(Math.random()*0.2+0.9)));
cfgLogInfoTemp.setReportTime(new Date(startTimes));
cfgLogInfoTemp.setServiceCode(serviceArrayTemp[m]);
newList.add(cfgLogInfoTemp);
nums++;
}
}
nums=0;
break;
}else{
for(int j=0;j<serviceArray.length;j++){
if(serviceArrayTemp[j]!=null && !"".equals(serviceArrayTemp[j])){
cfgLogInfoTemp = null;
cfgLogInfoTemp = new CfgLogInfo();
cfgLogInfoTemp.setSum(Math.round(baseNum*(Math.random()*0.2+0.9)));
cfgLogInfoTemp.setReportTime(new Date(startTimes));
cfgLogInfoTemp.setServiceCode(serviceArray[j]);
newList.add(cfgLogInfoTemp);
}
}
nums=0;
break;
//continue loop;
}
}
}
}
}else{//从数据库未取到任何记录
for (; startTimes < endTimes; startTimes += 300000) {
cfgLogInfoTemp = null;
cfgLogInfoTemp = new CfgLogInfo();
//serviceArray = baseService.split(",");
for(int i=0;i<serviceArray.length;i++){
cfgLogInfoTemp = new CfgLogInfo();
cfgLogInfoTemp.setSum(Math.round(baseNum*(Math.random()*0.2+0.9)));
cfgLogInfoTemp.setReportTime(new Date(startTimes));
cfgLogInfoTemp.setServiceCode(serviceArray[i]);
newList.add(cfgLogInfoTemp);
}
}
}
}else{
logger.error("SystemHomePageService converCfgLogList error parm!");
}
return newList;
}
/*public String[] getServiceFormCfgLogList(List<CfgLogInfo> list, CfgLogInfo cfgLogInfoParm) {
String serviceArray[] = null;
String tempReturn = "";
String temp = ","+cfgLogInfoParm.getServiceCode()+"";
if(list!=null){
StringBuffer tempS = new StringBuffer();
for (CfgLogInfo cfgLogInfo:list) {
}
}
return serviceArray;
}*/
/*public List<CfgLogInfo> converCfgLogList(List<CfgLogInfo> list, Date startTime, Date endTime) {
List<CfgLogInfo> newList = new LinkedList<>();
long startTimes = (startTime.getTime() + 300000);
long endTimes = endTime.getTime();
@@ -180,7 +296,7 @@ public class SystemHomePageService {
}
}
return newList;
}
}*/
public List<NtcAreaHomeReport> converNtcAreaHomeList(List<NtcAreaHomeReport> list, Date startTime, Date endTime) {
final String area1 = "阿斯塔纳";
@@ -210,6 +326,9 @@ public class SystemHomePageService {
ntcAreaHomeReportArea2.setEntranceId(2);
ntcAreaHomeReportArea1.setArea(area1);
ntcAreaHomeReportArea2.setArea(area2);
if(sums1==0){
}
ntcAreaHomeReportArea1.setSum(sums1);
ntcAreaHomeReportArea2.setSum(sums2);
ntcAreaHomeReportArea1.setReportTime(new Date(startTimes));