Commit 58eda78b authored by 赵啸非's avatar 赵啸非

添加首页统计模块

parent f954d7dc
package com.mortals.xhx.base.login.web; package com.mortals.xhx.base.login.web;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.ap.CookieService; import com.mortals.framework.ap.CookieService;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.IAuthTokenService; import com.mortals.framework.service.IAuthTokenService;
import com.mortals.framework.service.ICacheService; import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IUser; import com.mortals.framework.service.IUser;
...@@ -18,11 +22,26 @@ import com.mortals.xhx.base.system.valid.service.ValidCodeService; ...@@ -18,11 +22,26 @@ import com.mortals.xhx.base.system.valid.service.ValidCodeService;
import com.mortals.xhx.common.key.RedisKey; import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.pdu.user.UserPdu; import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.common.utils.MenuEncodeUtil; import com.mortals.xhx.common.utils.MenuEncodeUtil;
import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.feign.user.IUserFeign; import com.mortals.xhx.feign.user.IUserFeign;
import com.mortals.xhx.module.access.model.AccessEntity;
import com.mortals.xhx.module.access.model.AccessQuery;
import com.mortals.xhx.module.access.service.AccessService;
import com.mortals.xhx.module.ph.model.PhQueueStatEntity;
import com.mortals.xhx.module.ph.model.PhQueueStatQuery;
import com.mortals.xhx.module.ph.service.PhQueueStatService;
import com.mortals.xhx.module.pj.model.PjEvaluateEntity;
import com.mortals.xhx.module.pj.model.PjEvaluateStatEntity;
import com.mortals.xhx.module.pj.model.PjEvaluateStatQuery;
import com.mortals.xhx.module.pj.service.PjEvaluateStatService;
import com.mortals.xhx.module.stat.model.StatEntity;
import com.mortals.xhx.module.stat.model.StatQuery;
import com.mortals.xhx.module.stat.service.StatService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -30,8 +49,8 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -30,8 +49,8 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.lang.foreign.StructLayout;
import java.util.Set; import java.util.*;
import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED; import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED;
import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED_CONTENT; import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED_CONTENT;
...@@ -51,6 +70,20 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -51,6 +70,20 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
private IAuthTokenService authTokenService; private IAuthTokenService authTokenService;
@Autowired @Autowired
private IUserFeign userFeign; private IUserFeign userFeign;
@Autowired
private StatService statService;
@Autowired
private PhQueueStatService phQueueStatService;
@Autowired
private PjEvaluateStatService pjEvaluateStatService;
@Autowired
private ISiteFeign siteFeign;
@Autowired
private AccessService accessService;
@RequestMapping("login") @RequestMapping("login")
public String login(@RequestBody LoginForm loginForm) throws Exception { public String login(@RequestBody LoginForm loginForm) throws Exception {
...@@ -79,7 +112,7 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -79,7 +112,7 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
return JSONObject.toJSONString(Rest.fail(ERROR_TOKEN_EXPIRED, ERROR_TOKEN_EXPIRED_CONTENT)); return JSONObject.toJSONString(Rest.fail(ERROR_TOKEN_EXPIRED, ERROR_TOKEN_EXPIRED_CONTENT));
} }
Set<String> urls = resourceService.findUrlSetByUserId(user.getId()); Set<String> urls = resourceService.findUrlSetByUserId(user.getId());
log.info("userId:{},urls:{}", user.getId(),JSON.toJSONString(urls)); log.info("userId:{},urls:{}", user.getId(), JSON.toJSONString(urls));
List<MenuEntity> outlookBarList = menuService.findTreeMenu(user, urls); List<MenuEntity> outlookBarList = menuService.findTreeMenu(user, urls);
String currUserName = user.getRealName(); String currUserName = user.getRealName();
if (currUserName == null || currUserName.trim().length() == 0) { if (currUserName == null || currUserName.trim().length() == 0) {
...@@ -99,11 +132,108 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -99,11 +132,108 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS); ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "用户登录系统成功!"); ret.put(KEY_RESULT_MSG, "用户登录系统成功!");
ret.put("resources", urls); ret.put("resources", urls);
//todo 首页统计报表
int totalAccessSite = 0;
List<AccessEntity> accessEntities = new ArrayList<>();
RedisTemplate<String, String> baseRedisTemplate = cacheService.selectDbRedisTemplate(1);
//com:mortals:xhx:module:site:model:SiteEntity redis调用
String siteTreeStr = (String) baseRedisTemplate.opsForHash().get("user:site:tree", String.valueOf(user.getId()));
if (!ObjectUtils.isEmpty(siteTreeStr)) {
log.info("siteTreeStr:{}", siteTreeStr);
//获取当前用户所拥有的站点列表
accessEntities = accessService.find(new AccessQuery());
totalAccessSite = accessEntities.size();
if (!ObjectUtils.isEmpty(accessEntities)) {
//当前用户存在的区域或者站点列表
//遍历 如果不存在 正则
Iterator<AccessEntity> iterator = accessEntities.iterator();
while (iterator.hasNext()) {
AccessEntity next = iterator.next();
String type = next.getType();
if ("area".equals(type)) {
boolean contains = StrUtil.contains(siteTreeStr, next.getAreaCode());
if (!contains) {
iterator.remove();
}
} else if ("site".equals(type)) {
boolean contains = StrUtil.contains(siteTreeStr, next.getSiteCode());
if (!contains) {
iterator.remove();
}
} else {
log.info("未知类型节点,不做过滤!");
}
}
}
}
data.put("accessList", accessEntities);
data.put("totalAccessSite", totalAccessSite);
int totalCount = 0;
StatQuery statQuery = new StatQuery();
statQuery.setGroupList(Arrays.asList("year"));
PageInfo pageInfo = new PageInfo();
pageInfo.setPrePageResult(-1);
List<StatEntity> list = statService.find(statQuery, pageInfo, getContext()).getList();
if (!ObjectUtils.isEmpty(list)) {
totalCount = list.stream().mapToInt(i -> i.getCount()).sum();
}
data.put("totalCount", totalCount);
//近三十天数据总量趋势
getThirtyStats(data);
getThirtyPhStats(data);
getThirtyPjStats(data);
return ret.toJSONString(); return ret.toJSONString();
} }
private void getThirtyStats(JSONObject data) {
PageInfo pageInfo = new PageInfo();
pageInfo.setPrePageResult(-1);
StatQuery statThirtyQuery = new StatQuery();
statThirtyQuery.setTimeStart(DateUtil.offsetDay(new Date(), 30).toDateStr());
statThirtyQuery.setTimeEnd(DateUtil.today());
statThirtyQuery.setGroupList(Arrays.asList("year", "month", "day"));
List<StatEntity> thirtyStatList = statService.find(statThirtyQuery, pageInfo, getContext()).getList();
if (!ObjectUtils.isEmpty(thirtyStatList)) {
//todo 日期排序趋势降序图
data.put("thirtyStatList", thirtyStatList);
}
}
private void getThirtyPhStats(JSONObject data) {
PageInfo pageInfo = new PageInfo();
pageInfo.setPrePageResult(-1);
PhQueueStatQuery statThirtyQuery = new PhQueueStatQuery();
statThirtyQuery.setTimeStart(DateUtil.offsetDay(new Date(), 30).toDateStr());
statThirtyQuery.setTimeEnd(DateUtil.today());
statThirtyQuery.setGroupList(Arrays.asList("year", "month", "day"));
List<PhQueueStatEntity> thirtyStatList = phQueueStatService.find(statThirtyQuery, pageInfo, getContext()).getList();
if (!ObjectUtils.isEmpty(thirtyStatList)) {
//todo 日期排序趋势降序图
data.put("thirtyPhStatList", thirtyStatList);
}
}
private void getThirtyPjStats(JSONObject data) {
PageInfo pageInfo = new PageInfo();
pageInfo.setPrePageResult(-1);
PjEvaluateStatQuery statThirtyQuery = new PjEvaluateStatQuery();
statThirtyQuery.setTimeStart(DateUtil.offsetDay(new Date(), 30).toDateStr());
statThirtyQuery.setTimeEnd(DateUtil.today());
statThirtyQuery.setGroupList(Arrays.asList("year", "month", "day"));
List<PjEvaluateStatEntity> thirtyStatList = pjEvaluateStatService.find(statThirtyQuery, pageInfo, getContext()).getList();
if (!ObjectUtils.isEmpty(thirtyStatList)) {
//todo 日期排序趋势降序图
data.put("thirtyPjStatList", thirtyStatList);
}
}
@Override @Override
......
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