wang-hao-jie
2022-05-03 b8086d8c8bf084ed20488a005f957e29ee3cbc8e
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
package cn.exrick.xboot.your.schedulings;
import cn.exrick.xboot.core.common.redis.RedisTemplateHelper;
import cn.exrick.xboot.core.service.MessageService;
import cn.exrick.xboot.core.service.UserService;
import cn.exrick.xboot.your.entity.*;
import cn.exrick.xboot.your.service.*;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.Date;
//大屏首页统计
@Component
public class StatisticPcScheduleImpl {
 
    @Autowired
    private IUserStatisticService iUserStatisticService;
 
    @Autowired
    private UserService userService;
 
    @Autowired
    private IDrivingRecordService iDrivingRecordService;
 
    @Autowired
    private IOrderTaskService iOrderTaskService;
 
    @Autowired
    private IAreaService iAreaService;
 
    @Autowired
    private ICustomerService iCustomerService;
 
    @Autowired
    private RedisTemplateHelper redisTemplate;
 
    @Autowired
    private ICarService iCarService;
 
    @Autowired
    private MessageService messageService;
 
    @Autowired
    private IRemoteCallService iRemoteCallService;
 
    @Autowired
    private IEventLogService eventLogService;
 
    @Autowired
    private IOrderLogService iOrderLogService;
 
    public static final String HEAD = "statistic1::";
 
    @Scheduled(cron="0 15 * * * ?")//每小时15分钟时执行
    public void execute(){
        redisTemplate.set(HEAD+"car",iCarService.count()+"");//车辆
        redisTemplate.set(HEAD+"user",userService.countByType(0)+"");//司机
        redisTemplate.set(HEAD+"user2",userService.countByType(1)+"");//配送员
 
        redisTemplate.set(HEAD+"dept","3");//转运站数
        redisTemplate.set(HEAD+"area",iAreaService.count()+"");//片区数
        int customNum = iCustomerService.count();
        redisTemplate.set(HEAD+"customer",customNum+"");//商户数
 
        redisTemplate.set(HEAD+"out",iDrivingRecordService.count()+"");//出车次数
        redisTemplate.set(HEAD+"driving",iUserStatisticService.sumDriving()+"");//行驶里程
        redisTemplate.set(HEAD+"num",iOrderLogService.sumNum()+"");//送货包数
        redisTemplate.set(HEAD+"status",getNum(2)+"");//电子签收次数
 
        redisTemplate.set(HEAD+"notice",messageService.getTotalCount()+"");//通知公告条数
        redisTemplate.set(HEAD+"video","0");//视频监控次数
        redisTemplate.set(HEAD+"call",iRemoteCallService.count()+"");//远程呼叫次数
        redisTemplate.set(HEAD+"paiCha",iDrivingRecordService.count2()+"");//事故隐患排查
 
        redisTemplate.set(HEAD+"wx",iCustomerService.sumLogin()+"");//小程序登陆次数
        redisTemplate.set(HEAD+"wxRate",iCustomerService.countOpenId()+"");//小程序使用率
 
        int i = getNum(1);
        redisTemplate.set(HEAD+"like",i+"");//互动次数
        int count = iOrderLogService.sumNum();
        if(count==0){
            redisTemplate.set(HEAD+"likeRate","0");//互动率
        }else{
            redisTemplate.set(HEAD+"likeRate",(((i*100)/customNum)+1)+"");//互动率
        }
 
        String format = DateUtil.format(new Date(), "yyyy-MM-dd");
 
        QueryWrapper<DrivingRecord> wp = new QueryWrapper<>();
        wp.between("create_time",format+" 00:00:00",format+" 23:59:59");
        redisTemplate.set(HEAD+"outCar",iDrivingRecordService.count(wp)+"");//出发车辆
 
        QueryWrapper<EventLog> wrapper2=new QueryWrapper<>();
        wrapper2.eq("type",5);
        redisTemplate.set(HEAD+"open",eventLogService.count(wrapper2)+"");//危险开启
 
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();
        wrapper.between("create_time",format+" 00:00:00",format+" 23:59:59");
        redisTemplate.set(HEAD+"addCustomer",iCustomerService.count(wrapper)+"");//今日新增商户
    }
 
    private int getNum(int type){
        QueryWrapper<OrderLog> wp = new QueryWrapper<>();
        wp.eq("type",type);
        OrderLog one = iOrderLogService.getOne(wp);
        if(one!=null){
            return one.getNum();
        }else{
            return 0;
        }
    }
}