From 504fdd09f7ae6278308156ad416a35fc02ecb8b8 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期四, 16 二月 2023 19:08:10 +0800
Subject: [PATCH] 新增加代客下单接口

---
 driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java |  147 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 142 insertions(+), 5 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 3bebf26..6cd2522 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,7 @@
 package com.supersavedriving.driver.modular.system.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 import com.supersavedriving.driver.core.common.constant.JwtConstants;
@@ -10,11 +12,16 @@
 import com.supersavedriving.driver.modular.system.dao.DriverMapper;
 import com.supersavedriving.driver.modular.system.model.BranchOffice;
 import com.supersavedriving.driver.modular.system.model.Driver;
+import com.supersavedriving.driver.modular.system.model.DriverWork;
 import com.supersavedriving.driver.modular.system.service.IBranchOfficeService;
 import com.supersavedriving.driver.modular.system.service.IDriverService;
+import com.supersavedriving.driver.modular.system.service.IDriverWorkService;
+import com.supersavedriving.driver.modular.system.service.IOrderPositionService;
 import com.supersavedriving.driver.modular.system.util.RedisUtil;
 import com.supersavedriving.driver.modular.system.util.ResultUtil;
 import com.supersavedriving.driver.modular.system.util.UUIDUtil;
+import com.supersavedriving.driver.modular.system.util.mongodb.model.Location;
+import com.supersavedriving.driver.modular.system.warpper.DriverPositionWarpper;
 import com.supersavedriving.driver.modular.system.warpper.DriverRegisterWarpper;
 import com.supersavedriving.driver.modular.system.warpper.TokenWarpper;
 import org.apache.shiro.authc.SimpleAuthenticationInfo;
@@ -23,10 +30,25 @@
 import org.apache.shiro.crypto.hash.Md5Hash;
 import org.apache.shiro.util.ByteSource;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.geo.Circle;
+import org.springframework.data.geo.Distance;
+import org.springframework.data.geo.Metrics;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.data.mongodb.core.query.Update;
 import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
+import java.util.Objects;
 
 import static org.bouncycastle.asn1.x500.style.RFC4519Style.c;
 
@@ -45,6 +67,18 @@
 
     @Autowired
     private RedisUtil redisUtil;
+
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
+    @Autowired
+    private IOrderPositionService orderPositionService;
+
+    @Autowired
+    private IDriverWorkService driverWorkService;
+
+    @Value("${filePath}")
+    private String filePath;
 
 
     /**
@@ -141,10 +175,6 @@
         if(!value.equals(code)){
             return ResultUtil.error("短信验证码无效");
         }
-        String token = getToken(phone, code);
-        if(ToolUtil.isEmpty(token)){
-            return ResultUtil.error("登录异常,请联系管理员。");
-        }
         Driver driver = this.selectOne(new EntityWrapper<Driver>().eq("phone", phone).ne("status", 3));
         if(null == driver){
             return ResultUtil.error("请先进行注册");
@@ -158,7 +188,10 @@
         if(driver.getApprovalStatus() == 3){
             return ResultUtil.error("账号审核不通过,请重新申请。");
         }
-
+        String token = getToken(phone, code);
+        if(ToolUtil.isEmpty(token)){
+            return ResultUtil.error("登录异常,请联系管理员。");
+        }
         TokenWarpper tokenWarpper = new TokenWarpper();
         tokenWarpper.setToken(token);
         tokenWarpper.setValidTime(7200L);
@@ -166,6 +199,43 @@
         return ResultUtil.success(tokenWarpper);
     }
 
+
+    /**
+     * 司机密码登录
+     * @param receiver  国家代码+86
+     * @param phone     手机号
+     * @param password  密码
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public ResultUtil<TokenWarpper> driverPassLogin(String receiver, String phone, String password) throws Exception {
+        Driver driver = this.selectOne(new EntityWrapper<Driver>().eq("phone", phone).ne("status", 3));
+        if(null == driver){
+            return ResultUtil.error("请先进行注册");
+        }
+        if(driver.getStatus() == 2){
+            return ResultUtil.error("账号已被冻结,请联系管理员。");
+        }
+        if(driver.getApprovalStatus() == 1){
+            return ResultUtil.error("账号正在审核中。");
+        }
+        if(driver.getApprovalStatus() == 3){
+            return ResultUtil.error("账号审核不通过,请重新申请。");
+        }
+        if(!driver.getPassword().equals(ShiroKit.md5(password, salt))){
+            return ResultUtil.error("账号密码错误。");
+        }
+        String token = getToken(phone, password);
+        if(ToolUtil.isEmpty(token)){
+            return ResultUtil.error("登录异常,请联系管理员。");
+        }
+        TokenWarpper tokenWarpper = new TokenWarpper();
+        tokenWarpper.setToken(token);
+        tokenWarpper.setValidTime(7200L);
+        tokenWarpper.setIsSetPassword(ToolUtil.isEmpty(driver.getPassword()) ? 0 : 1);
+        return ResultUtil.success(tokenWarpper);
+    }
 
     /**
      * 获取身份凭证
@@ -263,4 +333,71 @@
         driver.setPassword(ShiroKit.md5(password, salt));
         this.updateById(driver);
     }
+
+
+    @Override
+    public ResultUtil<List<String>> queryDriverPosition(Integer uid) throws Exception {
+        DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", uid).eq("status", 1));
+        if(null == driverWork){
+            return ResultUtil.error("请先上班");
+        }
+        String value = redisUtil.getValue("DRIVER" + uid);
+        List<String> list = new ArrayList<>();
+        if(ToolUtil.isNotEmpty(value)){
+            String[] split = value.split(",");
+            String lon = split[0];
+            String lat = split[1];
+            //找到中心点
+            GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(lon), Double.valueOf(lat));
+            //构造半径
+            Distance distanceR = new Distance(5D, 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);
+            locations.forEach(s -> {
+                list.add(s.getLocation().getX() + "," + s.getLocation().getY());
+            });
+        }
+        return ResultUtil.success(list);
+    }
+
+
+
+    @Override
+    public void addDriverPosition(DriverPositionWarpper driverPositionWarpper) throws Exception {
+        //实时位置存入redis中
+        Double lon = driverPositionWarpper.getLon();
+        Double lat = driverPositionWarpper.getLat();
+        Integer driverId = driverPositionWarpper.getDriverId();
+        Integer orderId = driverPositionWarpper.getOrderId();
+        redisUtil.setStrValue("DRIVER" + driverId, lon + "," + lat, 30);
+        Query query = Query.query(Criteria.where("driverId").is(driverId));
+        Location old = this.mongoTemplate.findOne(query, Location.class);
+        if (Objects.isNull(old)) {
+            old = new Location();
+            old.setDriverId(driverId);
+            old.setLocation(new GeoJsonPoint(lon, lat));
+            old.setUpdated(System.currentTimeMillis());
+            old.setLastUpdated(System.currentTimeMillis());
+            this.mongoTemplate.save(old);
+        } else {
+            //更新
+            Update update = Update
+                    .update("location", new GeoJsonPoint(lon, lat))
+                    .set("updated", System.currentTimeMillis())
+                    .set("lastUpdated", System.currentTimeMillis());
+            this.mongoTemplate.updateFirst(query, update, Location.class);
+        }
+
+        //存储订单轨迹
+        if(null != orderId){
+            orderPositionService.saveOrderPosition(driverPositionWarpper);
+        }
+
+    }
+
+
+
 }

--
Gitblit v1.7.1