Commit ffe4ea54 authored by wangsong's avatar wangsong

update evn api

parent b0f09124
...@@ -110,66 +110,51 @@ public class StatisticsController { ...@@ -110,66 +110,51 @@ public class StatisticsController {
@ResponseBody @ResponseBody
public MapMessage environments(@RequestParam(value = "clientId", required = false) String clientId, @RequestParam(value = "latestDays", defaultValue = "7") Integer latestDays) { public MapMessage environments(@RequestParam(value = "clientId", required = false) String clientId, @RequestParam(value = "latestDays", defaultValue = "7") Integer latestDays) {
Map<String, List<StatItem>> result = new HashMap<>(); Map<String, List<StatItem>> result = new HashMap<>();
Map<String,Object> param = new HashMap<>(); Map<String,Object> commonParam = new HashMap<>();
param.put("loginSuccessFlag", true); commonParam.put("loginSuccessFlag", true);
if (clientId != null){ if (clientId != null){
param.put("clientId",clientId); commonParam.put("clientId",clientId);
} }
Date startDate = getStartDay(latestDays); Date startDate = getStartDay(latestDays);
long all_auth = authLogService.count(param, startDate); List<String> browserList = authLogService.distinct("browser", commonParam, startDate);
List<StatItem> browserResult = new ArrayList<>(); List<String> osList = authLogService.distinct("os", commonParam, startDate);
List<String> browserList = authLogService.distinct("browser", param, startDate);
long unknownBrowser = all_auth; Map<String, List<Long>> browserOsListMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(browserList)){ if (CollectionUtils.isNotEmpty(browserList) && CollectionUtils.isNotEmpty(osList)){
for (String item : browserList) { for (String browser : browserList) {
param.put("browser",item); Map<String, Object> param = new HashMap<>();
long count = authLogService.count(param, startDate); param.putAll(commonParam);
StatItem statItem = new StatItem(); param.put("browser",browser);
statItem.setName(item); long otherCount = authLogService.count(param, startDate);
statItem.setCount(count); List<Long> osDataList = new ArrayList<>();
unknownBrowser = unknownBrowser - count; for(String os : osList){
browserResult.add(statItem); param.put("os", os);
long osCount = authLogService.count(param, startDate);
osDataList.add(osCount);
otherCount = otherCount - osCount;
}
osDataList.add(otherCount);
browserOsListMap.put(browser, osDataList);
} }
}
if (unknownBrowser > 0){
StatItem statItem = new StatItem();
statItem.setName("unknown");
statItem.setCount(unknownBrowser);
browserResult.add(statItem);
}
result.put("browser", browserResult);
Map<String, Object> unknownParam = new HashMap<>();
unknownParam.putAll(commonParam);
List<StatItem> osResult = new ArrayList<>(); long unknownOtherCount = authLogService.count(unknownParam, browserList, startDate);
List<Long> unknownDataList = new ArrayList<>();
param.remove("browser"); for(String os : osList){
List<String> osList = authLogService.distinct("os", param, startDate); unknownParam.put("os", os);
long osCount = authLogService.count(unknownParam, browserList, startDate);
long unknownOs = all_auth; unknownDataList.add(osCount);
if (CollectionUtils.isNotEmpty(osList)){ unknownOtherCount = unknownOtherCount - osCount;
for (String item : osList) {
param.put("os",item);
long count = authLogService.count(param, startDate);
StatItem statItem = new StatItem();
statItem.setName(item);
statItem.setCount(count);
osResult.add(statItem);
unknownOs = unknownOs - count;
} }
unknownDataList.add(unknownOtherCount);
browserOsListMap.put("unknown", unknownDataList);
} }
if (unknownOs > 0){ browserList.add("unknown");
StatItem statItem = new StatItem(); osList.add("unknown");
statItem.setName("unknown"); return MapMessage.successMessage().add("browserList", browserList).add("osList", osList).add("dataMap", browserOsListMap);
statItem.setCount(unknownOs);
osResult.add(statItem);
}
result.put("os", osResult);
return MapMessage.successMessage().add("data", result);
} }
...@@ -305,4 +290,5 @@ public class StatisticsController { ...@@ -305,4 +290,5 @@ public class StatisticsController {
return MapMessage.successMessage().add("data", data); return MapMessage.successMessage().add("data", data);
} }
} }
...@@ -3,6 +3,7 @@ package com.chineseall.eden.authcenter.log.dao; ...@@ -3,6 +3,7 @@ package com.chineseall.eden.authcenter.log.dao;
import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.PageRequest; import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.PageRequest;
import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Pageable; import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Pageable;
import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Sort; import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Sort;
import cn.sh.chineseall.framework.core.util.CollectionUtils;
import cn.sh.chineseall.framework.core.util.StringUtils; import cn.sh.chineseall.framework.core.util.StringUtils;
import cn.sh.chineseall.framework.dao.core.hql.Criteria; import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query; import cn.sh.chineseall.framework.dao.core.hql.Query;
...@@ -103,6 +104,24 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St ...@@ -103,6 +104,24 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
return count(query); return count(query);
} }
public long count(Map<String, Object> params, List<String> notInBrowserList, Date beginTime){
Criteria criteria = new Criteria();
if (null != params && params.size() > 0){
params.forEach((k,v)->{
criteria.and(k).is(v);
});
}
if(CollectionUtils.isNotEmpty(notInBrowserList)){
criteria.and("browser").nin(notInBrowserList);
}
if(beginTime!=null){
criteria.and("createTime").gte(beginTime);
}
Query query = Query.query(criteria);
return count(query);
}
public List<AuthLog> listLogWithPage(int pageNo, int pageSize,Map<String, Object> prams) { public List<AuthLog> listLogWithPage(int pageNo, int pageSize,Map<String, Object> prams) {
Criteria criteria = new Criteria(); Criteria criteria = new Criteria();
if (null != prams && prams.size() > 0){ if (null != prams && prams.size() > 0){
......
...@@ -23,6 +23,8 @@ public interface AuthLogService { ...@@ -23,6 +23,8 @@ public interface AuthLogService {
long count(Map<String,Object> prams); long count(Map<String,Object> prams);
long count(Map<String,Object> prams, Date beginTime); long count(Map<String,Object> prams, Date beginTime);
long count(Map<String, Object> params, List<String> notInBrowserList, Date beginTime);
void replace(AuthLog authLog); void replace(AuthLog authLog);
public List<AuthLog> listLogWithPage(int pageNo, int pageSize,Map<String, Object> prams); public List<AuthLog> listLogWithPage(int pageNo, int pageSize,Map<String, Object> prams);
......
...@@ -82,6 +82,11 @@ public class AuthLogServiceImpl implements AuthLogService { ...@@ -82,6 +82,11 @@ public class AuthLogServiceImpl implements AuthLogService {
return authLogDao.count(prams, beginTime); return authLogDao.count(prams, beginTime);
} }
@Override
public long count(Map<String, Object> params, List<String> notInBrowserList, Date beginTime) {
return authLogDao.count(params, notInBrowserList, beginTime);
}
@Override @Override
public void replace(AuthLog authLog) { public void replace(AuthLog authLog) {
authLogDao.replace(authLog); authLogDao.replace(authLog);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment