From 03552ae04973a224b5ccfce34e64999ea6a13d44 Mon Sep 17 00:00:00 2001
From: liujie <liujie>
Date: 星期四, 10 八月 2023 09:31:53 +0800
Subject: [PATCH] 超省2.0

---
 driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java |   97 +++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 87 insertions(+), 10 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 04833ee..957c73a 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
@@ -98,6 +98,9 @@
     @Autowired
     private RongYunUtil rongYunUtil;
 
+    @Autowired
+    private PushUtil pushUtil;
+
 
 
     /**
@@ -162,7 +165,10 @@
         String code = driverRegisterWarpper.getCode();
         BranchOffice branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("districtCode", code).eq("status", 1));
         if(null == branchOffice){
-            throw new Exception("该区域无服务商");
+            branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("cityCode", code).eq("status", 1));
+            if(null == branchOffice){
+                throw new Exception("该区域无服务商");
+            }
         }
         driver.setBranchOfficeId(branchOffice.getId());
         driver.setAgentId(branchOffice.getAgentId());
@@ -180,6 +186,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;
     }
 
@@ -313,13 +322,21 @@
                 usernamePasswordToken, simpleAuthenticationInfo);
 
         if (passwordTrueFlag) {
-            String token = JwtTokenUtil.generateToken(phone);
+            String token = JwtTokenUtil.generateToken(phone + System.currentTimeMillis());
             String key = token;
             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天
+
+            //下线
+            for (int i = 0; i < 5; i++) {
+                Integer code = pushUtil.pushOffline(driver.getId(), 2);
+                if(200 == code){
+                    break;
+                }
+            }
             return token;
         }
         return "";
@@ -388,7 +405,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("请先上班");
@@ -409,13 +427,36 @@
             Query query = Query.query(Criteria.where("location").withinSphere(circle));
             List<Location> locations = mongoTemplate.find(query, Location.class);
             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;
+                    }
+                }
                 String value1 = redisUtil.getValue("DRIVER" + s.getDriverId());
                 if(s.getDriverId().compareTo(uid) != 0 && ToolUtil.isNotEmpty(value1)){
-                    list.add(s.getLocation().getX() + "," + s.getLocation().getY());
+                    list.add(s.getLocation().getX() + "," + s.getLocation().getY()+","+i);
                 }
             });
         }
-        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);
+        List<Order> ordersOne = orderService.selectList(new EntityWrapper<Order>().eq("state",301));
+
+        ArrayList<String> red = new ArrayList<>();
+        ordersOne.forEach(e-> red.add(e.getStartLng()+","+e.getStartLat()));
+
+        map.put("cancelOrder",red);
+        return ResultUtil.success(map);
     }
 
 
@@ -545,8 +586,8 @@
         Driver driver = this.selectById(uid);
         DriverInfoWarpper driverInfo = new DriverInfoWarpper();
         BeanUtils.copyProperties(driver, driverInfo);
-        driverInfo.setBalance(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
         driverInfo.setWithdrawBalance(driver.getBalance());
+        driverInfo.setBalance(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
         YouTuiDriver youTuiDriver = youTuiDriverService.selectOne(new EntityWrapper<YouTuiDriver>().eq("driverId", uid)
                 .eq("state", 2).last(" and failureTime > now() order by failureTime limit 0, 1"));
         if(null != youTuiDriver){
@@ -707,9 +748,9 @@
                                 accountChangeDetail.setType(1);
                                 accountChangeDetail.setCreateTime(new Date());
                                 accountChangeDetail.setExplain("余额充值");
-                                accountChangeDetail.setOldData(driver1.getBalance());
+                                accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
                                 driver1.setBalance(driver1.getBalance() + amount);
-                                accountChangeDetail.setNewData(driver1.getBalance());
+                                accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
                                 DriverServiceImpl.this.updateById(driver1);
                                 accountChangeDetailService.saveData(accountChangeDetail);
 
@@ -760,9 +801,9 @@
         accountChangeDetail.setType(1);
         accountChangeDetail.setCreateTime(new Date());
         accountChangeDetail.setExplain("余额充值");
-        accountChangeDetail.setOldData(driver1.getBalance());
+        accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
         driver1.setBalance(driver1.getBalance() + rechargeRecord1.getAmount());
-        accountChangeDetail.setNewData(driver1.getBalance());
+        accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
         this.updateById(driver1);
         accountChangeDetailService.saveData(accountChangeDetail);
 
@@ -887,4 +928,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);
+        // 有效时长
+        int okTime =  this.baseMapper.getTime(sTime,eTime,uid);
+        map.put("okTime",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