1
13693261870
2024-11-27 63f04d92a2376a6272d0ad61358475d527f26a2d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.se.system.controller;
 
import com.se.common.core.utils.ip.IpUtils;
import com.se.common.core.web.controller.BaseController;
import com.se.common.core.web.domain.AjaxResult;
import com.se.common.core.web.page.TableDataInfo;
import com.se.common.log.annotation.Log;
import com.se.common.log.enums.BusinessType;
import com.se.common.security.utils.SecurityUtils;
import com.se.system.api.domain.SysLogininfor;
import com.se.system.api.domain.SysOperLog;
import com.se.system.api.model.LoginUser;
import com.se.system.service.IndexService;
import com.se.system.service.inte.ISysLogininforService;
import com.se.system.service.inte.ISysOperLogService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@RestController
@RequestMapping("/index")
@SuppressWarnings("ALL")
public class IndexController extends BaseController {
    @Resource
    IndexService indexService;
 
    @Resource
    ISysOperLogService operLogService;
 
    @Resource
    ISysLogininforService logininforService;
 
    // ①PV统计:PV(Page View):页面浏览量或点击量,即网站所有页面被访问的总次数。
    // 每打开或刷新一个页面,PV就会增加一次,多次打开或刷新同一页面则浏览量累计。
    // PV反映了网站用户访问的网页数量,是衡量网站流量的重要指标之一
    @Log(title = "PV统计", businessType = BusinessType.OTHER)
    @GetMapping("/pvCount")
    public Map<String, Object> pvCount() {
        Map<String, Object> map = new HashMap<>();
 
        return map;
    }
 
    // ②访问数量:UV(Unique Visitor):独立访客数,指访问网站的独立用户数。一天内同一访客多次访问只计算一次。
    // 可以理解成访问某网站的电脑的数量。网站判断来访电脑的身份是通过来访电脑的cookies实现的。
    // 如果更换了IP后但不清除cookies,再访问相同网站,该网站的统计中UV数是不变的。
    @Log(title = "UV统计", businessType = BusinessType.OTHER)
    @GetMapping("/uvCount")
    public Map<String, Object> uvCount() {
        Map<String, Object> map = new HashMap<>();
 
        return map;
    }
 
    // ③新增用户统计:一段时间内新注册的用户数量。目前定为一周内的新增用户数量。
    @Log(title = "新增用户统计", businessType = BusinessType.OTHER)
    @GetMapping("/newUserCount")
    public Map<String, Object> newUserCount(Integer day) {
        if (null == day || day < 1) day = 15;
        if (day > 365) day = 365;
 
        Map<String, Object> map = new HashMap<>();
        map.put("newUserCount", indexService.newUserCount(day));
 
        return map;
    }
 
    // ④用户登录信息:以一定形式展示新登录或退出登录的用户账户及时间。
    @Log(title = "用户登录信息", businessType = BusinessType.OTHER)
    @GetMapping("/lastLogin")
    public TableDataInfo lastLogin(SysLogininfor logininfor) {
        startPage();
        List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
 
        return getDataTable(list);
    }
 
    // ⑤用户统计排行(活跃用户):以一定时间段内的登录时间或登录次数排名,展示前五名的用户信息
    @Log(title = "用户统计排行", businessType = BusinessType.OTHER)
    @GetMapping("/userCountList")
    public List<Map<String, Object>> userCountList(Integer day, Integer amount) {
        if (null == day || day < 1) day = 15;
        if (day > 365) day = 365;
        if (null == amount) amount = 5;
        if (amount > 100) amount = 100;
 
        return indexService.userCountList(day, amount);
    }
 
    // ⑥常用系统展示/各系统访问信息:基于用户访问次数排名,展示前五个系统的排名
    // 并展示各个系统一天内、三天内、一周内的访问次数。【可考虑按其他指标进行排名展示】
    @Log(title = "用户统计排行", businessType = BusinessType.OTHER)
    @GetMapping("/sysVisitList")
    public Map<String, Object> sysVisitList() {
        Map<String, Object> map = new HashMap<>();
 
        return map;
    }
 
    @Log(title = "运维监控", businessType = BusinessType.OTHER)
    @GetMapping("/monitor")
    public Map<String, Object> monitor() {
        Map<String, Object> map = new HashMap<>();
        map.put("cpu", "50%");
        map.put("mem", "65%");
        map.put("ratio", "40%");
 
        return map;
    }
 
    @GetMapping("/addAccessLog")
    public AjaxResult addAccessLog(String title, int status) {
        long start = System.currentTimeMillis();
 
        SysOperLog log = new SysOperLog();
        log.setTitle(title);
        // 0=其它,1=新增,2=修改,3=删除,4=授权,5=导出,6=导入,7=强退,8=生成代码,9=清空数据
        log.setBusinessType(0);
        // ServletUtils.getRequest().getMethod()
        log.setMethod("com.se.system.controller.IndexController.addAccessLog()");
        log.setRequestMethod("GET");
        log.setOperatorType(1);
 
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (null != loginUser) {
            log.setOperName(loginUser.getUsername());
            log.setDeptName(loginUser.getSysUser().getDept().getDeptName());
        }
        // StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255)
        log.setOperUrl("/index/addAccessLog");
        log.setOperIp(IpUtils.getIpAddr());
        log.setOperParam("{\"title\":\"" + title + "\"}");
 
        log.setJsonResult(String.format("{\"msg\":\"%s\",\"code\":%d}", 0 == status ? "成功" : "失败", 0 == status ? 200 : 400));
        log.setStatus(status);
        log.setOperTime(new Date());
        log.setCostTime(System.currentTimeMillis() - start + 10);
 
        int rows = operLogService.insertOperlog(log);
 
        return toAjax(rows);
    }
}