Commit ffe4ea54 authored by wangsong's avatar wangsong

update evn api

parent b0f09124
......@@ -110,66 +110,51 @@ public class StatisticsController {
@ResponseBody
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,Object> param = new HashMap<>();
param.put("loginSuccessFlag", true);
Map<String,Object> commonParam = new HashMap<>();
commonParam.put("loginSuccessFlag", true);
if (clientId != null){
param.put("clientId",clientId);
commonParam.put("clientId",clientId);
}
Date startDate = getStartDay(latestDays);
long all_auth = authLogService.count(param, startDate);
List<StatItem> browserResult = new ArrayList<>();
List<String> browserList = authLogService.distinct("browser", param, startDate);
long unknownBrowser = all_auth;
if (CollectionUtils.isNotEmpty(browserList)){
for (String item : browserList) {
param.put("browser",item);
long count = authLogService.count(param, startDate);
StatItem statItem = new StatItem();
statItem.setName(item);
statItem.setCount(count);
unknownBrowser = unknownBrowser - count;
browserResult.add(statItem);
}
List<String> browserList = authLogService.distinct("browser", commonParam, startDate);
List<String> osList = authLogService.distinct("os", commonParam, startDate);
Map<String, List<Long>> browserOsListMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(browserList) && CollectionUtils.isNotEmpty(osList)){
for (String browser : browserList) {
Map<String, Object> param = new HashMap<>();
param.putAll(commonParam);
param.put("browser",browser);
long otherCount = authLogService.count(param, startDate);
List<Long> osDataList = new ArrayList<>();
for(String os : osList){
param.put("os", os);
long osCount = authLogService.count(param, startDate);
osDataList.add(osCount);
otherCount = otherCount - osCount;
}
if (unknownBrowser > 0){
StatItem statItem = new StatItem();
statItem.setName("unknown");
statItem.setCount(unknownBrowser);
browserResult.add(statItem);
osDataList.add(otherCount);
browserOsListMap.put(browser, osDataList);
}
result.put("browser", browserResult);
List<StatItem> osResult = new ArrayList<>();
param.remove("browser");
List<String> osList = authLogService.distinct("os", param, startDate);
long unknownOs = all_auth;
if (CollectionUtils.isNotEmpty(osList)){
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;
Map<String, Object> unknownParam = new HashMap<>();
unknownParam.putAll(commonParam);
long unknownOtherCount = authLogService.count(unknownParam, browserList, startDate);
List<Long> unknownDataList = new ArrayList<>();
for(String os : osList){
unknownParam.put("os", os);
long osCount = authLogService.count(unknownParam, browserList, startDate);
unknownDataList.add(osCount);
unknownOtherCount = unknownOtherCount - osCount;
}
unknownDataList.add(unknownOtherCount);
browserOsListMap.put("unknown", unknownDataList);
}
if (unknownOs > 0){
StatItem statItem = new StatItem();
statItem.setName("unknown");
statItem.setCount(unknownOs);
osResult.add(statItem);
}
result.put("os", osResult);
return MapMessage.successMessage().add("data", result);
browserList.add("unknown");
osList.add("unknown");
return MapMessage.successMessage().add("browserList", browserList).add("osList", osList).add("dataMap", browserOsListMap);
}
......@@ -305,4 +290,5 @@ public class StatisticsController {
return MapMessage.successMessage().add("data", data);
}
}
......@@ -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.Pageable;
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.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
......@@ -103,6 +104,24 @@ public class AuthLogDao extends StaticCacheDimensionDocumentMongoDao<AuthLog, St
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) {
Criteria criteria = new Criteria();
if (null != prams && prams.size() > 0){
......
......@@ -23,6 +23,8 @@ public interface AuthLogService {
long count(Map<String,Object> prams);
long count(Map<String,Object> prams, Date beginTime);
long count(Map<String, Object> params, List<String> notInBrowserList, Date beginTime);
void replace(AuthLog authLog);
public List<AuthLog> listLogWithPage(int pageNo, int pageSize,Map<String, Object> prams);
......
......@@ -82,6 +82,11 @@ public class AuthLogServiceImpl implements AuthLogService {
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
public void replace(AuthLog 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