From 76e9e8e05cbe7dafeba51a235386f20ebf986e25 Mon Sep 17 00:00:00 2001
From: wang-hao-jie <1550036656@qq.com>
Date: 星期一, 27 十二月 2021 11:54:35 +0800
Subject: [PATCH] 违章记录

---
 xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/schedulings/StatisticScheduleImpl.java |   61 ++++++++++++++++++++++++------
 1 files changed, 48 insertions(+), 13 deletions(-)

diff --git a/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/schedulings/StatisticScheduleImpl.java b/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/schedulings/StatisticScheduleImpl.java
index bc93fad..2fae93d 100644
--- a/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/schedulings/StatisticScheduleImpl.java
+++ b/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/schedulings/StatisticScheduleImpl.java
@@ -11,7 +11,7 @@
 
 import java.io.IOException;
 import java.util.List;
-
+//瀹㈡埛绔椤垫暟鎹粺璁�
 @Component
 public class StatisticScheduleImpl {
 
@@ -33,8 +33,11 @@
     @Autowired
     private ICustomerService iCustomerService;
 
-    @Scheduled(cron="0 0 * * * ?")//姣忔櫄鍑屾櫒1鐐规墽琛�
-    public void execute() throws IOException {
+    @Autowired
+    private IAlarmService iAlarmService;
+
+    @Scheduled(cron="0 0 1 * * ?")//姣忔櫄鍑屾櫒1鐐规墽琛�
+    public void execute(){
         List<User> all = userService.findAll();
         for(User user:all){
             Integer type2 = user.getType2();
@@ -44,40 +47,72 @@
                 UserStatistic one = iUserStatisticService.getOne(wrapper);
                 if(one==null){
                     one = new UserStatistic();
+                    one.setUserId(user.getId());
                 }
                 //鍙告満
                 if(type2==0){
                     Integer max = iDrivingRecordService.maxByUserId(user.getId());
                     Integer min = iDrivingRecordService.minByUserId(user.getId());
-                    one.setSafeDriving(max-min);
-                    one.setDriving(max-min);
+                    if(max==null||min==null){
+                        one.setSafeDriving(0);//瀹夊叏椹鹃┒閲岀▼
+                        one.setDriving(0);//椹鹃┒閲岀▼
+                    }else{
+                        one.setSafeDriving(max-min);//瀹夊叏椹鹃┒閲岀▼
+                        one.setDriving(max-min);//椹鹃┒閲岀▼
+                    }
 
                     QueryWrapper<DrivingRecord> wrapper2 = new QueryWrapper<>();
                     wrapper2.eq("user_id",user.getId());
                     int count = iDrivingRecordService.count(wrapper2);
-                    one.setOutCar(count);
+                    one.setOutCar(count);//鍑鸿溅娆℃暟
 
+                    one.setLikes(iDrivingRecordService.sumLikeByUserId(user.getId()));//鐐硅禐鏁�
+
+                    QueryWrapper<Alarm> wrapper3 = new QueryWrapper<>();
+                    wrapper3.eq("car_user_id",user.getId());
+                    wrapper3.eq("type",1);
+                    one.setFatigueDriving(iAlarmService.count(wrapper3));//鐤插姵椹鹃┒
+                    wrapper3.eq("type",3);
+                    one.setNoBelt(iAlarmService.count(wrapper3));//涓嶇郴瀹夊叏甯�
+                    wrapper3.eq("type",4);
+                    one.setSmoking(iAlarmService.count(wrapper3));//鎶界儫
+                    wrapper3.eq("type",2);
+                    one.setPhone(iAlarmService.count(wrapper3));//鎺ユ墦鐢佃瘽
                 }
                 //閰嶉�佸憳
                 if(type2==1){
                     QueryWrapper<OrderTask> wrapper2 = new QueryWrapper<>();
                     wrapper2.eq("user_id",user.getId());
                     int count = iOrderTaskService.count(wrapper2);
+                    one.setSends(count);//閰嶉�佹鏁�
+
                     wrapper2.ne("status",0);
                     int count2 = iOrderTaskService.count(wrapper2);
-
-                    one.setSends(count);
-                    one.setSends2(count2);
+                    one.setSends2(count2);//閫佽揪娆℃暟
 
                     QueryWrapper<Area> wrapper3 = new QueryWrapper<>();
                     wrapper3.eq("user_id",user.getId());
                     Area area = iAreaService.getOne(wrapper3);
+                    if(area!=null){
+                        QueryWrapper<Customer> wrapper4 = new QueryWrapper<>();
+                        wrapper4.eq("area_id",area.getId());
+                        int count3 = iCustomerService.count(wrapper4);
+                        one.setService(count3);//鏈嶅姟鍟嗘埛鏁�
+                    }
 
-                    QueryWrapper<Customer> wrapper4 = new QueryWrapper<>();
-                    wrapper4.eq("area_id",area.getId());
-                    int count3 = iCustomerService.count(wrapper4);
+                    int i = iOrderTaskService.countLike();
+                    one.setLikes(i);//鐐硅禐娆℃暟
+                    int likeCount = iOrderTaskService.count();
+                    if(likeCount==0){
+                        one.setLikesRate(0);//鐐硅禐鐜�
+                    }else{
+                        one.setLikesRate((i*100)/likeCount);//鐐硅禐鐜�
+                    }
 
-                    one.setService(count3);
+                    QueryWrapper<Alarm> wrapper4 = new QueryWrapper<>();
+                    wrapper4.eq("follow_user_id",user.getId());
+                    wrapper4.eq("type",5);
+                    one.setAbnormalOpen(iAlarmService.count(wrapper4));//寮傚父寮�鍚�
                 }
 
                 iUserStatisticService.saveOrUpdate(one);

--
Gitblit v1.9.1