From db7fa6a91b9534ac90e219b6f554c54c43c83a5a Mon Sep 17 00:00:00 2001
From: liujie <liujie>
Date: 星期三, 16 八月 2023 09:28:15 +0800
Subject: [PATCH] update

---
 driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java |  199 ++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 163 insertions(+), 36 deletions(-)

diff --git a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java
index cabe128..7190d0f 100644
--- a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java
+++ b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java
@@ -1,5 +1,6 @@
 package com.supersavedriving.driver.modular.system.service.impl;
 
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
@@ -9,12 +10,13 @@
 import com.supersavedriving.driver.core.shiro.ShiroUser;
 import com.supersavedriving.driver.core.util.JwtTokenUtil;
 import com.supersavedriving.driver.core.util.ToolUtil;
+import com.supersavedriving.driver.modular.system.dao.DriverMapper;
 import com.supersavedriving.driver.modular.system.model.*;
 import com.supersavedriving.driver.modular.system.service.*;
-import com.supersavedriving.driver.modular.system.dao.DriverMapper;
-import com.supersavedriving.driver.modular.system.util.*;
 import com.supersavedriving.driver.modular.system.util.MallBook.model.*;
 import com.supersavedriving.driver.modular.system.util.MallBook.util.TrhRequest;
+import com.supersavedriving.driver.modular.system.util.*;
+import com.supersavedriving.driver.modular.system.util.huawei.OBSUtil;
 import com.supersavedriving.driver.modular.system.util.mongodb.model.Location;
 import com.supersavedriving.driver.modular.system.util.rongyun.RongYunUtil;
 import com.supersavedriving.driver.modular.system.util.weChat.WeChatUtil;
@@ -41,12 +43,16 @@
 import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.InputStream;
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.math.RoundingMode;
 import java.net.InetAddress;
 import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.util.*;
-import java.util.stream.Collectors;
 
 /**
 * 司机
@@ -109,6 +115,9 @@
     @Autowired
     private WeChatUtil weChatUtil;
 
+    @Autowired
+    private IDriverOnlineTimeService driverOnlineTimeService;
+
     @Value("${callbackPath}")
     private String callbackPath;
 
@@ -159,6 +168,10 @@
             }
             driver.setCreateTime(new Date());
             this.insert(driver);
+            String s = wechatMiniProgramORCode(driver.getId());
+            driver.setReferralCode(s);
+            this.updateById(driver);
+
 
             //司机邀请注册奖励
             if(null != driver.getInviterId()){
@@ -187,6 +200,16 @@
     }
 
 
+
+    //生成小程序二维码
+    public String wechatMiniProgramORCode(Integer driverId) throws Exception{
+        InputStream release = weChatUtil.getwxacodeunlimit("pages/index/index", "driverId=" + driverId, "release");
+        String s = OBSUtil.putObjectToBucket(release, "driver_" + driverId + "_" + UUIDUtil.getNumberRandom(5) + ".jpg");
+        return s;
+    }
+
+
+
     /**
      * 组装个人信息
      * @param driver
@@ -195,6 +218,7 @@
      */
     public Driver setDriverParamete(Driver driver, DriverRegisterWarpper driverRegisterWarpper) throws Exception{
         driver.setAvatar(driverRegisterWarpper.getAvatar());
+        driver.setName(driverRegisterWarpper.getName());
         driver.setPhone(driverRegisterWarpper.getPhone());
         driver.setEmergencyContact(driverRegisterWarpper.getEmergencyContact());
         driver.setEmergencyPhone(driverRegisterWarpper.getEmergencyPhone());
@@ -232,6 +256,9 @@
         driver.setApprovalUserId(null);
         driver.setStatus(1);
         driver.setSource(driverRegisterWarpper.getSource());
+        driver.setName(driverRegisterWarpper.getName());
+        driver.setIdcard(driverRegisterWarpper.getIdcard());
+        driver.setCarAge(driverRegisterWarpper.getCarAge());
         return driver;
     }
 
@@ -287,6 +314,11 @@
             }
         }
 
+        if(ToolUtil.isEmpty(driver.getReferralCode())){
+            String s = wechatMiniProgramORCode(driver.getId());
+            driver.setReferralCode(s);
+            this.updateById(driver);
+        }
         return ResultUtil.success(tokenWarpper);
     }
 
@@ -373,8 +405,8 @@
             if(token.length() > 16){
                 key = token.substring(token.length() - 16);
             }
-            redisUtil.setStrValue(key, driver.getId().toString(), 7 * 24 * 60 * 60);//7天
-            redisUtil.setStrValue("DRIVER_" + phone, key, 7 * 24 * 60 * 60);//7天
+            redisUtil.setStrValue(key, driver.getId().toString(), 94608000);//7天
+            redisUtil.setStrValue("DRIVER_" + phone, key, 94608000);//7天
 
             //下线
             for (int i = 0; i < 5; i++) {
@@ -451,7 +483,8 @@
 
 
     @Override
-    public ResultUtil<List<String>> queryDriverPosition(Integer uid) throws Exception {
+    public ResultUtil< HashMap<String, Object> > queryDriverPosition(Integer uid) throws Exception {
+        HashMap<String, Object> map = new HashMap<>();
         DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", uid).eq("status", 1));
         if(null == driverWork){
             return ResultUtil.error("请先上班");
@@ -465,27 +498,50 @@
             //找到中心点
             GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(lon), Double.valueOf(lat));
             //构造半径
-            Distance distanceR = new Distance(5D, Metrics.KILOMETERS);
+            Distance distanceR = new Distance(10D, Metrics.KILOMETERS);
             //画圆
             Circle circle = new Circle(geoJsonPoint, distanceR);
             // 构造query对象
             Query query = Query.query(Criteria.where("location").withinSphere(circle));
             List<Location> locations = mongoTemplate.find(query, Location.class);
-            List<Integer> collect = locations.stream().map(Location::getDriverId).collect(Collectors.toList());
-            List<Driver> drivers = this.selectBatchIds(collect);
-            for (Driver driver : drivers) {
-                String value1 = redisUtil.getValue("DRIVER" + driver.getId());
-                if(ToolUtil.isEmpty(value1)){
-                    continue;
+            locations.forEach(s -> {
+                int i=0;
+                Driver driver = this.baseMapper.selectById(s.getDriverId());
+                i = driver.getServerStatus();
+                if(driver.getServerStatus()==2){
+                    List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("driverId", s.getDriverId()).eq("state", 102));
+                    if(orders.size()>0){
+                        i = 3;
+                    }
                 }
-                if(driver.getId().compareTo(uid) == 0){
-                    continue;
+                String value1 = redisUtil.getValue("DRIVER" + s.getDriverId());
+                if(s.getDriverId().compareTo(uid) != 0 && ToolUtil.isNotEmpty(value1)){
+                    list.add(s.getLocation().getX() + "," + s.getLocation().getY()+","+i+","+driver.getName());
                 }
-                list.add(value1 + "," + driver.getServerStatus());
-            }
+            });
         }
-        return ResultUtil.success(list);
+
+        List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("hallOrder",1).eq("state",101));
+
+        map.put("driver",list);
+        ArrayList<String> blue = new ArrayList<>();
+        orders.forEach(e-> blue.add(e.getStartLng()+","+e.getStartLat()));
+
+        map.put("orderList",blue);
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTimeInMillis(System.currentTimeMillis());
+        calendar.add(Calendar.HOUR_OF_DAY, -2);
+        Date time = calendar.getTime();
+        List<Order> ordersOne = orderService.selectList(new EntityWrapper<Order>().eq("state",301).between("createTime",time,new Date()));
+
+        ArrayList<String> red = new ArrayList<>();
+        ordersOne.forEach(e-> red.add(e.getStartLng()+","+e.getStartLat()));
+
+        map.put("cancelOrder",red);
+        return ResultUtil.success(map);
     }
+
 
 
     /**
@@ -537,13 +593,19 @@
     @Override
     public PromotionWarpper queryPromotionQRCode(Integer uid) throws Exception {
         PromotionWarpper promotionWarpper = new PromotionWarpper();
-        promotionWarpper.setUrl("https://chaoshengdaijia.com/share/driverShare/index.html?inviterId=" + uid);
+        Driver driver1 = this.selectById(uid);
+        if(ToolUtil.isEmpty(driver1.getReferralCode())){
+            String s = wechatMiniProgramORCode(driver1.getId());
+            driver1.setReferralCode(s);
+            this.updateById(driver1);
+        }
+//        promotionWarpper.setUrl("https://chaoshengdaijia.com/share/driverShare/index.html?inviterId=" + uid);
+        promotionWarpper.setUrl(driver1.getReferralCode());
         int user = appUserService.selectCount(new EntityWrapper<AppUser>().eq("inviterType", 2).eq("inviterId", uid).eq("status", 1));
         int driver = this.selectCount(new EntityWrapper<Driver>().eq("inviterType", 2).eq("inviterId", uid).eq("approvalStatus", 2).eq("status", 1));
         promotionWarpper.setTotal(user + driver);
         promotionWarpper.setUser(user);
         promotionWarpper.setDriver(driver);
-        Driver driver1 = this.selectById(uid);
         promotionWarpper.setAvatar(driver1.getAvatar());
         promotionWarpper.setName(driver1.getName());
         return promotionWarpper;
@@ -555,20 +617,6 @@
      */
     public void addDurationCredits(Integer driverId) throws Exception {
         SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
-        String value = redisUtil.getValue("ONLINE" + driverId);
-        if(ToolUtil.isEmpty(value)){
-            redisUtil.setStrValue("ONLINE" + driverId, "0_" + sdf1.format(new Date()) + "_0", 25 * 60 * 60);
-            return;
-        }
-        String today = sdf1.format(new Date());
-        String[] s = value.split("_");
-        if(!today.equals(s[1])){
-            redisUtil.setStrValue("ONLINE" + driverId, "0_" + sdf1.format(new Date()) + "_0", 25 * 60 * 60);
-            return;
-        }
-        Integer second = Integer.valueOf(s[0]) + 5;
-        Integer time = Integer.valueOf(s[2]);
-
         SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4));
         if(null == systemConfig){
             return;
@@ -582,9 +630,37 @@
         long end = sdf.parse(sdf1.format(new Date()) + " " + num2 + ":00").getTime();
         long l = System.currentTimeMillis();
         if(start <= l && end > l){
+            Driver driver = this.selectById(driverId);
+            String value = redisUtil.getValue("ONLINE" + driverId);
+            if(ToolUtil.isEmpty(value)){
+                redisUtil.setStrValue("ONLINE" + driverId, "0_" + sdf1.format(new Date()) + "_0", 25 * 60 * 60);
+                return;
+            }
+            String today = sdf1.format(new Date());
+            String[] s = value.split("_");
+            if(!today.equals(s[1])){
+                //修改在线时长记录
+                DriverOnlineTime driverOnlineTime = driverOnlineTimeService.selectOne(new EntityWrapper<DriverOnlineTime>().eq("driverId", driverId).eq("DATE_FORMAT(`day`, '%Y-%m-%d')", s[1]));
+                if(null != driverOnlineTime){
+                    driverOnlineTime.setOnlineTime(new BigInteger(s[0]));
+                    driverOnlineTimeService.updateById(driverOnlineTime);
+                }else{
+                    driverOnlineTime = new DriverOnlineTime();
+                    driverOnlineTime.setDriverId(driverId);
+                    driverOnlineTime.setDay(sdf1.parse(s[1]));
+                    driverOnlineTime.setOnlineTime(new BigInteger(s[0]));
+                    driverOnlineTimeService.insert(driverOnlineTime);
+                }
+                driver.setOnlineTime(new BigInteger(s[0]));
+                this.updateById(driver);
+                redisUtil.setStrValue("ONLINE" + driverId, "0_" + sdf1.format(new Date()) + "_0", 25 * 60 * 60);
+                return;
+            }
+            Integer second = Integer.valueOf(s[0]) + 5;
+            Integer time = Integer.valueOf(s[2]);
+
             int h = Double.valueOf(second / 3600).intValue();
             if(h > 0 && h > time){
-                Driver driver = this.selectById(driverId);
                 AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
                 accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5));
                 accountChangeDetail.setUserType(2);
@@ -595,11 +671,26 @@
                 accountChangeDetail.setNewData(driver.getIntegral().doubleValue());
                 accountChangeDetail.setExplain("在线时长奖励");
                 accountChangeDetailService.saveData(accountChangeDetail);
+                driver.setOnlineTime(new BigInteger(s[0]));
                 this.updateById(driver);
                 time++;
+
+                //修改在线时长记录
+                DriverOnlineTime driverOnlineTime = driverOnlineTimeService.selectOne(new EntityWrapper<DriverOnlineTime>().eq("driverId", driverId).eq("DATE_FORMAT(`day`, '%Y-%m-%d')", s[1]));
+                if(null != driverOnlineTime){
+                    driverOnlineTime.setOnlineTime(new BigInteger(s[0]));
+                    driverOnlineTimeService.updateById(driverOnlineTime);
+                }else{
+                    driverOnlineTime = new DriverOnlineTime();
+                    driverOnlineTime.setDriverId(driverId);
+                    driverOnlineTime.setDay(sdf1.parse(s[1]));
+                    driverOnlineTime.setOnlineTime(new BigInteger(s[0]));
+                    driverOnlineTimeService.insert(driverOnlineTime);
+                }
             }
+            redisUtil.setStrValue("ONLINE" + driverId, second + "_" + s[1] + "_" + time);
         }
-        redisUtil.setStrValue("ONLINE" + driverId, second + "_" + s[1] + "_" + time);
+
     }
 
 
@@ -1005,4 +1096,40 @@
         this.updateById(driver);
         return ResultUtil.success();
     }
+
+    @Override
+    public ResultUtil<HashMap<String, Object>> queryDriverOrderNum(String time,Integer uid) {
+        String sTime = null;
+        String eTime =null;
+        EntityWrapper<Order> wrapper = new EntityWrapper<>();
+        EntityWrapper<AppUser> wrapperOne = new EntityWrapper<>();
+        if(ToolUtil.isNotEmpty(time)){
+            sTime = time.split(" - ")[0]+" 00:00:00";
+            eTime = time.split(" - ")[1]+" 23:59:59";
+            wrapper.between("orderTakingTime",sTime,eTime);
+            wrapperOne.between("createTime",sTime,eTime);
+        }
+        ArrayList<Integer> objects = new ArrayList<>();
+        objects.add(101);
+        objects.add(201);
+        objects.add(301);
+        objects.add(401);
+        wrapper.eq("driverId",uid);
+        wrapper.notIn("state",objects);
+        HashMap<String, Object> map = new HashMap<>();
+        int orderNum = orderService.selectCount(wrapper);
+        map.put("orderNum",orderNum);
+        // 有效时长
+        Integer okTime =  this.baseMapper.getTime(sTime,eTime,uid);
+        map.put("okTime",okTime==null?0:okTime);
+        wrapperOne.eq("inviterType",2);
+        wrapperOne.eq("inviterId",uid);
+        int userNum = appUserService.selectCount(wrapperOne);
+
+
+        map.put("userNum",userNum);
+
+
+        return ResultUtil.success(map);
+    }
 }

--
Gitblit v1.7.1