用户行为统计修改默认时间为当前一小时

This commit is contained in:
zhanghongqing
2018-12-15 18:44:16 +08:00
parent f8d1a49b9d
commit 2386f2ce92
2 changed files with 18 additions and 71 deletions

View File

@@ -1,7 +1,10 @@
package com.nis.web.controller.dashboard;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -15,6 +18,7 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -40,7 +44,7 @@ public class TrafficStatisticsReportController extends BaseController {
* @return
*/
@RequestMapping("userBehavior")
public String list(@ModelAttribute("log") NtcRadiusReport bean,Model model, HttpServletRequest request, HttpServletResponse response) {
public String list(@ModelAttribute("log") NtcRadiusReport bean,Model model, HttpServletRequest request, HttpServletResponse response,RedirectAttributes redirectAttributes) {
Map<String, Object> fromJsonList = new HashMap<String, Object>();
Map<String, Object> userJsonList = new HashMap<String, Object>();
Map<String, Object> ipJsonList = new HashMap<String, Object>();
@@ -64,8 +68,15 @@ public class TrafficStatisticsReportController extends BaseController {
List ipList = new ArrayList();
try {
if(StringUtil.isBlank(statTime)&&StringUtil.isBlank(endTime)) {
statTime=DateUtils.getDate()+" 00:00:00"; // 默认今天
endTime=DateUtils.getDateTime();
// 设置默认时间为1小时
// statTime=DateUtils.getDate()+" 00:00:00"; // 默认今天
// endTime=DateUtils.getDateTime();
Calendar cal = Calendar. getInstance ();
cal.setTime(new Date());
endTime = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format(cal.getTime());//获取到完整的时间
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
statTime = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format(cal.getTime());
bean.setSearchFoundStartTime(statTime);
bean.setSearchFoundEndTime(endTime);
statTime=URLEncoder.encode(statTime, "UTF-8");
@@ -82,6 +93,7 @@ public class TrafficStatisticsReportController extends BaseController {
userUrl=userUrl+paramUrl;
ipUrl=ipUrl+paramUrl;
}
model.addAttribute("nowTime", DateUtils.getDateTime());
// 用户及IP数据
String string = HttpClientUtil.get(destUrl);
Gson gson = new GsonBuilder().create();
@@ -142,28 +154,8 @@ public class TrafficStatisticsReportController extends BaseController {
}
} catch (Exception e) {
e.printStackTrace();
addMessage(redirectAttributes,"error","request_service_failed");
}
return "/dashboard/trafficUserBehavior";
}
/* public static void main(String[] args) {
Map<String, Object> fromJsonList = new HashMap<String, Object>();
HashMap<String, Object> m = new HashMap<String, Object>();
List list = new ArrayList();
String string;
try {
string = HttpClientUtil.get("http://localhost:8082/galaxy-service/service/log/v1/ntcRadiusReport?"
+ "searchBusinessType=1&searchReportStartTime=2018-06-01+15%3A41%3A21&searchReportEndTime=2018-10-30+15%3A46%3A21");
Gson gson = new GsonBuilder().create();
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
list = (ArrayList) fromJsonList.get("data");
Map map = (Map) list.get(0);
List nasIpList=(List) map.get("nasIpList");
List accountList=(List) map.get("accountList");
System.err.println(map.get("nasIpList"));
System.err.println(map.get("accountList"));
} catch (Exception e) {
e.printStackTrace();
}
}
*/
}