实现用户访问量/功能访问量的统计信息的查询-接上篇过滤器 拦截器

前言

上一篇链接:SpringBoot拦截器与过滤器 实现用户访问量/功能访问量的统计

真正在公司中的实践:NoSQL + RDBMS 一起使用才是最强的

技术没有高低之分,就看你如何去使用!(提升内功,思维的提高!多思考!)

云计算的长征之路:阿里云的这群疯子,阿里巴巴的架构演进!

1、情景分析与介绍

经过上篇过滤器 拦截器实现了,用户访问量/功能访问量在redis的统计,并将统计信息定时持久化到数据库后
现在:
我们要让后台人员直观的看到
    1.访客数的波动情况
    2.各主要功能用户点击量的波动情况
然后我们对这些数据进行分析
    1.访客数变少
        我们就要分析原因,加大宣传,
    2.某功能热门
        我们就不断推出新功能,持续吸流,提高并发能力
    等等…

最终实现的功能接口
在这里插入图片描述

1.1 数据库表

1.1.1 设计表

在这里插入图片描述

1.1.2 visit_records_number用户访问数 数据展示

在这里插入图片描述

1.1.3 visit_records_function各功能的用户点击量 数据展示

在这里插入图片描述

2、SpringBoot各业务逻辑层

2.1 VisitHandle Control层 控制业务逻辑

package com.hut.weekcp.server.handle;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.hut.weekcp.server.entity.ResultVO;
import com.hut.weekcp.server.iservice.ITalkService;
import com.hut.weekcp.server.iservice.IVisitService;

import java.text.SimpleDateFormat;
import java.util.Calendar;

@RequestMapping("/api/visit")
@Api(tags = "后台管理:用户访问量/功能访问量")
@RestController

public class VisitHandle {
    
    
    @Autowired
    IVisitService visitService;

    @Autowired
    ITalkService talkService;

    @GetMapping("/visitor/today")
    @ApiOperation(value = "  今天的用户访问数")
    public ResultVO doGet(@RequestParam("token") String token,
                          @RequestParam(value = "date", required = false, defaultValue = "") String date) {
    
    
        Calendar cal = Calendar.getInstance();
        String day = cal.get(Calendar.DATE) + "";
        String month = (cal.get(Calendar.MONTH) + 1) + "";
        String year = cal.get(Calendar.YEAR) + "";
        return new ResultVO(200, visitService.getDateVisit(year, month, day));
    }

    @GetMapping("/visitor/recentWeek")
    @ApiOperation(value = "  获取近7天的用户访问数(天)")
    public ResultVO doWeekGet(@RequestParam("token") String token,
                              @RequestParam(value = "date", required = false, defaultValue = "") String date) {
    
    
        return new ResultVO(200, visitService.getWeekVisit());
    }

    @GetMapping("/function/recentWeek")
    @ApiOperation(value = "  获取近7天各功能的用户点击量(天)")
    public ResultVO dofunctionWeekGet(@RequestParam("token") String token,
                              @RequestParam(value = "date", required = false, defaultValue = "") String date) {
    
    
        return new ResultVO(200, visitService.dofunctionWeekGet());
    }


    @GetMapping("/visitor/recentMonth")
    @ApiOperation(value = "  获取近30天的用户访问数(天)")
    public ResultVO doDayGet(@RequestParam("token") String token,
                             @RequestParam(value = "date", required = false, defaultValue = "") String date) {
    
    
        return new ResultVO(200, visitService.getMonthVisit());
    }

    @GetMapping("/function/recentMonth")
    @ApiOperation(value = "  获取近30天各功能的用户点击量(天)")
    public ResultVO dofunctionDayGet(@RequestParam("token") String token,
                             @RequestParam(value = "date", required = false, defaultValue = "") String date) {
    
    
        return new ResultVO(200, visitService.getfunctionMonthVisit());
    }

    @GetMapping("/function/recentYear")
    @ApiOperation(value = "  获取近一年各月各功能的用户点击量(月)")
    public ResultVO dofunctionYearGet(@RequestParam("token") String token,
                                     @RequestParam(value = "date", required = false, defaultValue = "") String date) {
    
    
        return new ResultVO(200, visitService.dofunctionYearGet());
    }

    @GetMapping("/visitor/byMonth")
    @ApiOperation(value = "  获取某年某月各天用户访问数(天)")
    public ResultVO getVisitByMonth(@RequestParam("token") String token,
                                    @RequestParam("month") String month,
                                    @RequestParam("year") String year,
                                    @RequestParam(value = "date", required = false, defaultValue = "") String date) {
    
    
        return new ResultVO(200, visitService.getVisitByMonth(month, year));
    }

    @GetMapping("/visitor/byYear")
    @ApiOperation(value = "  获取某年各月的用户访问数(月)")
    public ResultVO byYear(@RequestParam("token") String token,
                               @RequestParam("year") String year,
                               @RequestParam(value = "date", required = false, defaultValue = "") String date) {
    
    
        return new ResultVO(200, visitService.byYear(year));
    }

    @GetMapping("/visitor/recentYear")
    @ApiOperation(value = "  获取近一年各月的用户访问数(月)")
    public ResultVO visitorRecentYear(@RequestParam("token") String token,
                               @RequestParam(value = "date", required = false, defaultValue = "") String date) {
    
    
        return new ResultVO(200, visitService.visitorRecentYear());
    }

    @GetMapping("/function/getFunctionVisitorNumber")
    @ApiOperation(value = "  今天各功能的用户点击量")
    public ResultVO recentYear(@RequestParam("token") String token,
                               @RequestParam(value = "date", required = false, defaultValue = "") String date) {
    
    
        return new ResultVO(200, visitService.getFunctionVisitorNumber());
    }
}

2.2 IVisitService Service层 控制业务

2.2.1 接口 IVisitService

package com.hut.weekcp.server.iservice;

import com.hut.weekcp.server.entity.*;
import com.hut.weekcp.server.entity.talk.TalkDO;
import com.hut.weekcp.server.entity.user.UserDO;
import org.apache.ibatis.annotations.Insert;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public interface IVisitService {
    
    
    /**
     * 获取今天的用户访问数
     * @return
     */
    Integer getDateVisit(String year, String month, String day);

    /**
     * 获取近30天的用户访问数
     * @return
     */
    List<VisitDO> getMonthVisit();

    /**
     * 获取某年某月各天用户访问数(天)
     * @return
     */
    List<VisitDO> getVisitByMonth(String month, String year);

    /**
     * 获取某年各月的用户访问数(月)
     * @return
     */
    List<Map> byYear(String year);

    /**
     * 获取近一年各月的用户访问数(月)
     * @return
     */
    List<Map> visitorRecentYear();

    /**
     * 今天各功能的用户点击量
     * @return
     */
    List<VisitRrecordsFunction> getFunctionVisitorNumber();

    /**
     * 获取近7天的用户访问数
     * @return
     */
    List<VisitDO> getWeekVisit();

    /**
     * 获取近7天各功能的用户点击量(天)
     * @return
     */
    Map<String,List<SimpleVisitRrecordsFunction>> dofunctionWeekGet();

    /**
     * 获取近30天各功能的用户点击量(天)
     * @return
     */
    Map<String,List<SimpleVisitRrecordsFunction>> getfunctionMonthVisit();

    /**
     *  获取近一年各月各功能的用户点击量(月)
     * @return
     */
    Map<String,List<SimpleVisitRrecordsFunction>> dofunctionYearGet();

    /**
     * 根据Url映射UrlModule信息
     * @return
     */
    UrlModuleDO getUrlModule(String Url);

    /**
     * 根据token查询userId
     * @return
     */
    Integer getUserId(String token);


}

2.2.1 实现类 VisitServiceImpl

package com.hut.weekcp.server.serviceImpl;

import com.hut.weekcp.server.entity.SimpleVisitRrecordsFunction;
import com.hut.weekcp.server.entity.UrlModuleDO;
import com.hut.weekcp.server.entity.VisitRrecordsFunction;
import com.hut.weekcp.server.entity.talk.SimpleCommentDTO;
import com.hut.weekcp.server.exception.NotSuchUserIdException;
import com.hut.weekcp.server.utils.ConstantUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.hut.weekcp.server.entity.VisitDO;
import com.hut.weekcp.server.iservice.IVisitService;
import com.hut.weekcp.server.mapper.VisitMapper;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Service
public class VisitServiceImpl implements IVisitService {
    
    
    @Autowired
    VisitMapper mapper;

    @Autowired
    //@Qualifier:表明我们自定义的RedisTemplate才是我们所需要的
    @Qualifier(value = "redisTemplates")
    private RedisTemplate redisTemplates;

    /**
     * 获取今天的用户访问数
     *
     * @return
     */
    @Override
    public Integer getDateVisit(String year, String month, String day) {
    
    
        //直接从redis统计最新的 用户数量
        return getNewestVisitorsData();
    }

    /**
     * 获取近7天各功能的用户点击量(天)
     *
     * @return
     */
    public Map<String, List<SimpleVisitRrecordsFunction>> dofunctionWeekGet() {
    
    
        Map<String, List<SimpleVisitRrecordsFunction>> map = new LinkedHashMap<>();
        //今天最新的用户点击量(天)
        List<SimpleVisitRrecordsFunction> listToday = new ArrayList<SimpleVisitRrecordsFunction>();
        listToday = getNewDataSimple();
        String[] TadayYearMonthDay = getYearMonthDayByNumber(0);
        map.put(TadayYearMonthDay[0] + "年" + TadayYearMonthDay[1] + "月" + TadayYearMonthDay[2] + "日", listToday);

        //前6天的用户点击量(天)
        for (int i = -1; i >= -6; i--) {
    
    
            String[] YearMonthDay = getYearMonthDayByNumber(i);
            int year = Integer.parseInt(YearMonthDay[0]);
            int month = Integer.parseInt(YearMonthDay[1]);
            int day = Integer.parseInt(YearMonthDay[2]);
            List<SimpleVisitRrecordsFunction> list = mapper.dofunctionWeekGet(Integer.parseInt((YearMonthDay[0])) + "", Integer.parseInt(YearMonthDay[1]) + "", Integer.parseInt(YearMonthDay[2]) + "");
            map.put(YearMonthDay[0] + "年" + YearMonthDay[1] + "月" + YearMonthDay[2] + "日", list);
        }
        return map;
    }

    /**
     * 获取近30天各功能的用户点击量(天)
     *
     * @return
     */
    public Map<String, List<SimpleVisitRrecordsFunction>> getfunctionMonthVisit() {
    
    
        Map<String, List<SimpleVisitRrecordsFunction>> map = new LinkedHashMap<>();
        //今天最新的用户点击量(天)
        List<SimpleVisitRrecordsFunction> listToday = new ArrayList<SimpleVisitRrecordsFunction>();
        listToday = getNewDataSimple();
        String[] TadayYearMonthDay = getYearMonthDayByNumber(0);
        map.put(TadayYearMonthDay[0] + "年" + TadayYearMonthDay[1] + "月" + TadayYearMonthDay[2] + "日", listToday);

        //前6天的用户点击量(天)
        for (int i = -1; i >= -29; i--) {
    
    
            String[] YearMonthDay = getYearMonthDayByNumber(i);
            int year = Integer.parseInt(YearMonthDay[0]);
            int month = Integer.parseInt(YearMonthDay[1]);
            int day = Integer.parseInt(YearMonthDay[2]);
            List<SimpleVisitRrecordsFunction> list = mapper.dofunctionWeekGet(Integer.parseInt((YearMonthDay[0])) + "", Integer.parseInt(YearMonthDay[1]) + "", Integer.parseInt(YearMonthDay[2]) + "");
            map.put(YearMonthDay[0] + "年" + YearMonthDay[1] + "月" + YearMonthDay[2] + "日", list);
        }
        return map;
    }
    /**
     *  获取近一年各月各功能的用户点击量(月)
     * @return
     */
    public Map<String,List<SimpleVisitRrecordsFunction>> dofunctionYearGet(){
    
    
        Map<String, List<SimpleVisitRrecordsFunction>> map = new LinkedHashMap<>();
        Calendar cal = Calendar.getInstance();
        String todayYear = cal.get(Calendar.YEAR) + "";

        //12个月的用户点击量
        for (int i = 1; i <= 12; i++) {
    
    
            List<SimpleVisitRrecordsFunction> list = mapper.byFunctionYear(todayYear,i+"");
            map.put(todayYear+"年" + i+ "月", list);
        }
        return map;
    }


    /**
     * 获取近7天的用户访问数
     *
     * @return
     */
    public List<VisitDO> getWeekVisit() throws NotSuchUserIdException {
    
    

        List<VisitDO> list = mapper.getWeekVisit();

        //list可能不包含今天的用户访问数
        Calendar cal = Calendar.getInstance();
        String day = cal.get(Calendar.DATE) + "";
        boolean YesNo = false;
        for (VisitDO visitDO : list) {
    
    
            if (visitDO.getDay().equals(day)) {
    
    
                YesNo = true;
            }
        }
        Integer NumberOfVisitors = 0;
        if (!YesNo) {
    
    //取出今天最新的用户访问数
            String month = (cal.get(Calendar.MONTH) + 1) + "";
            String year = cal.get(Calendar.YEAR) + "";
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            NumberOfVisitors = getNewestVisitorsData();
            VisitDO visitDO = new VisitDO();
            visitDO.setYear(year);
            visitDO.setMonth(month);
            visitDO.setDay(day);
            visitDO.setCreatTime(format.format(cal.getTime()));
            visitDO.setVisitors(NumberOfVisitors);
            list.add(visitDO);
        }
        return list;
    }

    /**
     * 获取近30天的用户访问数
     *
     * @return
     */
    @Override
    public List<VisitDO> getMonthVisit() {
    
    
        List<VisitDO> list = mapper.getMonthVisit();

        //list可能不包含今天的用户访问数
        Calendar cal = Calendar.getInstance();
        String day = cal.get(Calendar.DATE) + "";
        boolean YesNo = false;
        for (VisitDO visitDO : list) {
    
    
            if (visitDO.getDay().equals(day)) {
    
    
                YesNo = true;
            }
        }
        Integer NumberOfVisitors = 0;
        if (!YesNo) {
    
    //取出今天最新的用户访问数
            String month = (cal.get(Calendar.MONTH) + 1) + "";
            String year = cal.get(Calendar.YEAR) + "";
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            NumberOfVisitors = getNewestVisitorsData();
            VisitDO visitDO = new VisitDO();
            visitDO.setYear(year);
            visitDO.setMonth(month);
            visitDO.setDay(day);
            visitDO.setCreatTime(format.format(cal.getTime()));
            visitDO.setVisitors(NumberOfVisitors);
            list.add(visitDO);
        }
        return list;
    }

    /**
     * 获取某年某月各天用户访问数(天)
     *
     * @return
     */
    public List<VisitDO> getVisitByMonth(String month, String year) {
    
    
        Calendar cal = Calendar.getInstance();
        String todayMonth = (cal.get(Calendar.MONTH) + 1) + "";
        String todayYear = cal.get(Calendar.YEAR) + "";
        String day = cal.get(Calendar.DATE) + "";
        List<VisitDO> list = mapper.getVisitByMonth(month, year);

        //如果查的是本月 ,list可能不包含今天的用户访问数
        if (todayYear.equals(year) && todayMonth.equals(month)) {
    
    
            boolean YesNo = false;
            for (VisitDO visitDO : list) {
    
    
                if (visitDO.getDay().equals(day)) {
    
    
                    YesNo = true;
                }
            }
            Integer NumberOfVisitors = 0;
            if (!YesNo) {
    
    //取出今天最新的用户访问数
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                NumberOfVisitors = getNewestVisitorsData();
                VisitDO visitDO = new VisitDO();
                visitDO.setYear(todayMonth);
                visitDO.setMonth(todayYear);
                visitDO.setDay(day);
                visitDO.setCreatTime(format.format(cal.getTime()));
                visitDO.setVisitors(NumberOfVisitors);
                list.add(visitDO);
            }
        }
        return list;
    }

    /**
     * 获取某年各月的用户访问数(月)
     *
     * @return
     */
    public List<Map> byYear(String year) {
    
    
        List<Map> list = mapper.byYear(year);
        if (list.size() == 0) {
    
    
            return null;
        }
        return list;
    }

    /**
     * 获取近一年各月的用户访问数(月)
     * @return
     */
    public List<Map> visitorRecentYear(){
    
    
        Calendar cal = Calendar.getInstance();
        String todayYear = cal.get(Calendar.YEAR) + "";
        List<Map> list = mapper.byYear(todayYear);
        if (list.size() == 0) {
    
    
            return null;
        }
        return list;
    }

    /**
     * 今天各功能的用户点击量
     *
     * @return
     */
    public List<VisitRrecordsFunction> getFunctionVisitorNumber() {
    
    
        List<VisitRrecordsFunction> list = new ArrayList<VisitRrecordsFunction>();
        list = getNewData();
        return list;
    }

    //直接从redis统计最新的 用户数量
    private Integer getNewestVisitorsData() {
    
    
        Integer NumberOfVisitors = 0;
        Object object = redisTemplates.opsForHash().size(ConstantUtil.Redis.HASH_VISITOR_TNTERCEPTOR);
        if (object != null) {
    
    
            Long a = (long) object;
            NumberOfVisitors = a.intValue();
        }
        return NumberOfVisitors;
    }

    //得到前 i 天的Year Month Day
    private String[] getYearMonthDayByNumber(int i) {
    
    
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());

        c.add(Calendar.DATE, i);
        Date start = c.getTime();
        String qyt = format.format(start);//前一天的字符串
        String[] arr1 = qyt.split("-");//分割为Year Month Day
        return arr1;
    }

    //redis取最新的各功能的用户点击量(Simple)
    private List<SimpleVisitRrecordsFunction> getNewDataSimple() {
    
    
        List<SimpleVisitRrecordsFunction> list = new ArrayList<SimpleVisitRrecordsFunction>();
        //从redis取最新的数据
        //记录用户功能访问信息
        List<String> Functions = mapper.getAllFunction();
        //利用redis hash 来统计各功能访问人数 key为功能 value是访问次数
        for (
                String function : Functions) {
    
    
            if (!function.equals("")) {
    
    //                            Funtion                                    Funtion:
                redisTemplates.opsForHash().put(ConstantUtil.Redis.HASH_Funtion, ConstantUtil.Redis.HASH_Funtion_PREX + function, 0);
            }
        }

        //遍历统计,所有用户访问过的功能
        List<Object> hValuesList = redisTemplates.opsForHash().values("VisitorInterceptor");
        if (hValuesList.size() > 0) {
    
    
            for (Object functionObject : hValuesList) {
    
    
                List<String> functionList = (List<String>) functionObject;
                for (String function : functionList) {
    
    
                    redisTemplates.opsForHash().increment(ConstantUtil.Redis.HASH_Funtion, ConstantUtil.Redis.HASH_Funtion_PREX + function, 1);
                }
            }
        }

        Object objectKeyList = redisTemplates.opsForHash().keys(ConstantUtil.Redis.HASH_Funtion);
        if (objectKeyList != null) {
    
    
            Set<String> functionSet = (Set<String>) objectKeyList;
            //根据 key(功能)获得value(访问次数)
            for (String function : functionSet) {
    
    
                Object object = (redisTemplates.opsForHash().get(ConstantUtil.Redis.HASH_Funtion, function));//key:"Funtion", value:"Funtion:cim匿名聊天有关"
                if (object != null) {
    
    
                    Integer number = (int) object;
                    SimpleVisitRrecordsFunction simpleVisitRrecordsFunction = new SimpleVisitRrecordsFunction();
                    simpleVisitRrecordsFunction.setFunction(function);
                    simpleVisitRrecordsFunction.setNumber(number);
                    list.add(simpleVisitRrecordsFunction);
                }
            }
        }
        //删除 统计各功能访问人数的redis hash
        redisTemplates.delete(ConstantUtil.Redis.HASH_Funtion);
        return list;
    }

    //redis取最新的各功能的用户点击量
    private List<VisitRrecordsFunction> getNewData() {
    
    
        List<VisitRrecordsFunction> list = new ArrayList<VisitRrecordsFunction>();

        Calendar cal = Calendar.getInstance();
        String day = cal.get(Calendar.DATE) + "";
        String month = (cal.get(Calendar.MONTH) + 1) + "";
        String year = cal.get(Calendar.YEAR) + "";
        String hour = cal.get(Calendar.HOUR_OF_DAY) + "";
        //从redis取最新的数据
        //记录用户功能访问信息
        List<String> Functions = mapper.getAllFunction();
        //利用redis hash 来统计各功能访问人数 key为功能 value是访问次数
        for (
                String function : Functions) {
    
    
            if (!function.equals("")) {
    
    //                            Funtion                                    Funtion:
                redisTemplates.opsForHash().put(ConstantUtil.Redis.HASH_Funtion, ConstantUtil.Redis.HASH_Funtion_PREX + function, 0);
            }
        }

        //遍历统计,所有用户访问过的功能
        List<Object> hValuesList = redisTemplates.opsForHash().values("VisitorInterceptor");
        if (hValuesList.size() > 0) {
    
    
            for (Object functionObject : hValuesList) {
    
    
                List<String> functionList = (List<String>) functionObject;
                for (String function : functionList) {
    
    
                    redisTemplates.opsForHash().increment(ConstantUtil.Redis.HASH_Funtion, ConstantUtil.Redis.HASH_Funtion_PREX + function, 1);
                }
            }
        }

        Object objectKeyList = redisTemplates.opsForHash().keys(ConstantUtil.Redis.HASH_Funtion);
        if (objectKeyList != null) {
    
    
            Set<String> functionSet = (Set<String>) objectKeyList;
            //根据 key(功能)获得value(访问次数)
            for (String function : functionSet) {
    
    
                Object object = (redisTemplates.opsForHash().get(ConstantUtil.Redis.HASH_Funtion, function));//key:"Funtion", value:"Funtion:cim匿名聊天有关"
                if (object != null) {
    
    
                    Integer number = (int) object;
                    VisitRrecordsFunction visitRrecordsFunction = new VisitRrecordsFunction();
                    visitRrecordsFunction.setYear(year);
                    visitRrecordsFunction.setMonth(month);
                    visitRrecordsFunction.setDay(day);
                    visitRrecordsFunction.setHour(hour);
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                    visitRrecordsFunction.setCreatTime(format.format(cal.getTime()));
                    visitRrecordsFunction.setFunction(function);
                    visitRrecordsFunction.setNumber(number);
                    list.add(visitRrecordsFunction);
                }
            }
        }
        //删除 统计各功能访问人数的redis hash
        redisTemplates.delete(ConstantUtil.Redis.HASH_Funtion);
        return list;
    }


    /**
     * 根据Url映射UrlModule信息
     *
     * @return
     */
    public UrlModuleDO getUrlModule(String Url) {
    
    
        return mapper.getUrlModule(Url);
    }

    /**
     * 根据token查询userId
     *
     * @return
     */
    public Integer getUserId(String token) {
    
    
        return mapper.getUserId(token);
    }

}

3、VisitMapper Dao层 与数据库进行交互,持久化

package com.hut.weekcp.server.mapper;

import com.hut.weekcp.server.entity.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface VisitMapper {
    
    

    @Insert("INSERT INTO visit(dayTime, hourTime, visitors) values (#{dayTime}, #{hourTime}, #{visitors})")
    void addVisitor(VisitDO visit);

    /**
     *记录访问人数
     * @return
     */
    @Insert("INSERT INTO visit_records_number(year, month, day,hour,visitors,creatTime) values (#{year}, #{month}, #{day},#{hour}, #{visitors}, #{creatTime})")
    void addVisitRecordsNumber(VisitDO visit);

    /**
     *记录用户功能访问信息
     * @return
     */
    @Insert("INSERT INTO visit_records_function(function,number,year, month, day,hour,creatTime) values (#{function}, #{number},#{year}, #{month}, #{day},#{hour},#{creatTime})")
    void addVisitRecordsFunction( VisitRrecordsFunction visitRrecordsFunction);

    /**
     *查询用户访问人数
     * @return
     */
    @Select("SELECT visitors FROM visit_records_number  WHERE year = #{year} and month = #{month} and day = #{day} and is_delete=0")
    Integer queryVisitor(String year,String month,String day);

    /**
     * 获取近7天的用户访问数
     * @return
     */
    @Select("SELECT year,month,day,creatTime,visitors FROM visit_records_number where `hour`=23 and is_delete=0 and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(creatTime) order by creatTime asc")
    List<VisitDO> getWeekVisit();

    /**
     * 获取近1天各功能的用户点击量(天)
     * @return
     */
    @Select("SELECT function,number FROM visit_records_function where year = #{year} and  month=#{month}  and day=#{day} and  `hour`=23 and is_delete=0")
    List<SimpleVisitRrecordsFunction> dofunctionWeekGet(String year,String month,String day);

    /**
     * 获取近30天的用户访问数
     * @return
     */
    @Select("SELECT year,month,day,creatTime,visitors FROM visit_records_number where `hour`=23 and is_delete=0 and DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(creatTime) order by creatTime asc")
    List<VisitDO> getMonthVisit();


    /**
     * 获取某年某月各天用户访问数(天)
     * @return
     */
    @Select("SELECT year,month,day,creatTime,visitors FROM visit_records_number where `hour`=23 and month=#{month} and year = #{year} and is_delete=0 order by creatTime asc")
    List<VisitDO> getVisitByMonth(String month,String year);

    /**
     * 获取某年各月的用户访问数(月)
     * @return
     */
    @Select("select month as month,sum(visitors) as visitors from visit_records_number where year = #{year} and `hour`=23 and is_delete=0 group by month")
    List<Map> byYear(String year);


    /**
     * 获取近一年各月各功能的用户点击量(月)
     * @return
     */
    @Select("select function as function,sum(number) as number from visit_records_function where year=#{year} and month=#{month} group by function")
    List<SimpleVisitRrecordsFunction> byFunctionYear(String year ,String month);

    /**
     * 今天各功能分别多少用户使用
     * @return
     */
    @Select("select * from visit_records_function where year = #{year} and month = #{month} and day = #{day} and hour =0 and is_delete=0")
    List<VisitRrecordsFunction> getFunctionVisitorNumber(String year,String month,String day,String hour);

    /**
     * 根据Url映射UrlModule信息
     * @return
     */
    @Select("SELECT * FROM url_action_module  WHERE url = #{Url} and is_delete = 0")
    UrlModuleDO getUrlModule(String Url);

    /**
     * 查询所有映射功能
     */
    @Select("select `function` from url_action_module WHERE is_delete = 0 group by `function`")
    List<String>  getAllFunction();

    /**
     * 根据token查询userId
     * @return
     */
    @Select("SELECT user_id FROM qz_token  WHERE token = #{token} and is_delete = 0")
    Integer getUserId(String token);


    @Insert("INSERT into visitorinterceptor(userId, moduleId,function,url,year,month,day,hour) values (#{userId},#{moduleId},#{function},#{url},#{year},#{month},#{day},#{hour})")
    void setVisitorsModule(VisitorsModule visitorsModule);
}

猜你喜欢

转载自blog.csdn.net/ws13575291650/article/details/113187031