|  |  |  | 
|---|
|  |  |  | package com.supersavedriving.driver.modular.system.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cn.hutool.core.date.DateUtil; | 
|---|
|  |  |  | import cn.hutool.core.io.FileUtil; | 
|---|
|  |  |  | import cn.hutool.http.HttpRequest; | 
|---|
|  |  |  | import cn.hutool.http.HttpResponse; | 
|---|
|  |  |  | import cn.hutool.http.HttpUtil; | 
|---|
|  |  |  | 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.heredata.hos.model.bucket.Bucket; | 
|---|
|  |  |  | import com.supersavedriving.driver.core.common.constant.JwtConstants; | 
|---|
|  |  |  | import com.supersavedriving.driver.core.shiro.ShiroKit; | 
|---|
|  |  |  | import com.supersavedriving.driver.core.shiro.ShiroUser; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.supersavedriving.driver.modular.system.util.MallBook.util.TrhRequest; | 
|---|
|  |  |  | import com.supersavedriving.driver.modular.system.util.*; | 
|---|
|  |  |  | import com.supersavedriving.driver.modular.system.util.MiniPay.MiniAppPay; | 
|---|
|  |  |  | 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.qianyuntong.NCOSSUtil; | 
|---|
|  |  |  | import com.supersavedriving.driver.modular.system.util.qianyuntong.QianYunTongConfig; | 
|---|
|  |  |  | import com.supersavedriving.driver.modular.system.util.rongyun.RongYunUtil; | 
|---|
|  |  |  | import com.supersavedriving.driver.modular.system.util.weChat.WeChatUtil; | 
|---|
|  |  |  | import com.supersavedriving.driver.modular.system.util.weChat.model.Code2Session; | 
|---|
|  |  |  | import com.supersavedriving.driver.modular.system.warpper.*; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.lang.StringUtils; | 
|---|
|  |  |  | import org.apache.shiro.authc.SimpleAuthenticationInfo; | 
|---|
|  |  |  | import org.apache.shiro.authc.UsernamePasswordToken; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.io.File; | 
|---|
|  |  |  | import java.io.InputStream; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.math.BigInteger; | 
|---|
|  |  |  | 
|---|
|  |  |  | * @author pzb | 
|---|
|  |  |  | * @Date 2023/2/8 18:52 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class DriverServiceImpl extends ServiceImpl<DriverMapper, Driver> implements IDriverService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${filePath}") | 
|---|
|  |  |  | private String filePath; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${qyt.admin_url}") | 
|---|
|  |  |  | private String adminUrl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IAppUserService appUserService; | 
|---|
|  |  |  | 
|---|
|  |  |  | public String wechatMiniProgramORCode(Integer driverId) throws Exception{ | 
|---|
|  |  |  | InputStream release = weChatUtil.getwxacodeunlimit("pages/index/index", "driverId=" + driverId, "release"); | 
|---|
|  |  |  | String pictureName = "driver_" + driverId + ".png"; | 
|---|
|  |  |  | QianYunTongConfig qianYunTongConfig1 = qianYunTongConfig.getQianYunTongConfig(); | 
|---|
|  |  |  | String bucketName = qianYunTongConfig1.getBucketName(); | 
|---|
|  |  |  | Bucket grjyTest = NCOSSUtil.getBucketInfo(bucketName); | 
|---|
|  |  |  | if (null == grjyTest) { | 
|---|
|  |  |  | //创建桶 | 
|---|
|  |  |  | Boolean bucket = NCOSSUtil.createBucket(bucketName); | 
|---|
|  |  |  | if (!bucket) { | 
|---|
|  |  |  | throw new RuntimeException("创建存储桶失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //设置桶策略 | 
|---|
|  |  |  | String policyText = "{\"Version\":\"2025-06-23\",\"Statement\":[{\"Sid\":\"Stmt20250623\",\"Action\":[\"GetObject\"],\"Effect\":\"Allow\",\"Resource\":\"" + bucketName + "/*\",\"Principal\":\"*\"}]}"; | 
|---|
|  |  |  | Boolean bucketPolicy = NCOSSUtil.setBucketPolicy(bucketName, policyText); | 
|---|
|  |  |  | if (!bucketPolicy) { | 
|---|
|  |  |  | throw new RuntimeException("设置桶策略失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | File file = FileUtil.writeFromStream(release, new File(filePath + pictureName)); | 
|---|
|  |  |  | HttpRequest post = HttpUtil.createPost(adminUrl + "/upload/image"); | 
|---|
|  |  |  | post.form("file", file); | 
|---|
|  |  |  | HttpResponse execute = post.execute(); | 
|---|
|  |  |  | int status = execute.getStatus(); | 
|---|
|  |  |  | if(200 != status){ | 
|---|
|  |  |  | throw new RuntimeException("上传图片异常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //上传对象 | 
|---|
|  |  |  | String key = "imgs/daijia/driver/" + pictureName; | 
|---|
|  |  |  | String object = NCOSSUtil.putObject(bucketName, key, release); | 
|---|
|  |  |  | if (null == object) { | 
|---|
|  |  |  | throw new RuntimeException("上传图片失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return "https://traffic.qytzt.cn/v1/AUTH_" + qianYunTongConfig1.getAccount() + "/" + bucketName + "/" + key; | 
|---|
|  |  |  | return execute.body(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //司机下单二维码 | 
|---|
|  |  |  | public String wechatMiniOrderQRCode(Integer driverId) throws Exception{ | 
|---|
|  |  |  | InputStream release = weChatUtil.getwxacodeunlimitOrder("pages/index/index", "driverIds=" + driverId, "release"); | 
|---|
|  |  |  | String pictureName = "driver_" + driverId + ".png"; | 
|---|
|  |  |  | QianYunTongConfig qianYunTongConfig1 = qianYunTongConfig.getQianYunTongConfig(); | 
|---|
|  |  |  | String bucketName = qianYunTongConfig1.getBucketName(); | 
|---|
|  |  |  | Bucket grjyTest = NCOSSUtil.getBucketInfo(bucketName); | 
|---|
|  |  |  | if (null == grjyTest) { | 
|---|
|  |  |  | //创建桶 | 
|---|
|  |  |  | Boolean bucket = NCOSSUtil.createBucket(bucketName); | 
|---|
|  |  |  | if (!bucket) { | 
|---|
|  |  |  | throw new RuntimeException("创建存储桶失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //设置桶策略 | 
|---|
|  |  |  | String policyText = "{\"Version\":\"2025-06-23\",\"Statement\":[{\"Sid\":\"Stmt20250623\",\"Action\":[\"GetObject\"],\"Effect\":\"Allow\",\"Resource\":\"" + bucketName + "/*\",\"Principal\":\"*\"}]}"; | 
|---|
|  |  |  | Boolean bucketPolicy = NCOSSUtil.setBucketPolicy(bucketName, policyText); | 
|---|
|  |  |  | if (!bucketPolicy) { | 
|---|
|  |  |  | throw new RuntimeException("设置桶策略失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | File file = FileUtil.writeFromStream(release, new File(filePath + pictureName)); | 
|---|
|  |  |  | HttpRequest post = HttpUtil.createPost(adminUrl + "/upload/image"); | 
|---|
|  |  |  | post.form("file", file); | 
|---|
|  |  |  | HttpResponse execute = post.execute(); | 
|---|
|  |  |  | int status = execute.getStatus(); | 
|---|
|  |  |  | if(200 != status){ | 
|---|
|  |  |  | throw new RuntimeException("上传图片异常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //上传对象 | 
|---|
|  |  |  | String key = "imgs/daijia/driver/" + pictureName; | 
|---|
|  |  |  | String object = NCOSSUtil.putObject(bucketName, key, release); | 
|---|
|  |  |  | if (null == object) { | 
|---|
|  |  |  | throw new RuntimeException("上传图片失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return "https://traffic.qytzt.cn/v1/AUTH_" + qianYunTongConfig1.getAccount() + "/" + bucketName + "/" + key; | 
|---|
|  |  |  | return execute.body(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | tokenWarpper.setValidTime(7200L); | 
|---|
|  |  |  | tokenWarpper.setIsSetPassword(ToolUtil.isEmpty(driver.getPassword()) ? 0 : 1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String RYToken = rongYunUtil.getToken(driver.getId().toString(), driver.getName(), driver.getAvatar()); | 
|---|
|  |  |  | if(ToolUtil.isNotEmpty(RYToken)){ | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(RYToken); | 
|---|
|  |  |  | Integer code1 = jsonObject.getInteger("code"); | 
|---|
|  |  |  | if(200 == code1){ | 
|---|
|  |  |  | tokenWarpper.setRytoken(jsonObject.getString("token")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        String RYToken = rongYunUtil.getToken(driver.getId().toString(), driver.getName(), driver.getAvatar()); | 
|---|
|  |  |  | //        if(ToolUtil.isNotEmpty(RYToken)){ | 
|---|
|  |  |  | //            JSONObject jsonObject = JSON.parseObject(RYToken); | 
|---|
|  |  |  | //            Integer code1 = jsonObject.getInteger("code"); | 
|---|
|  |  |  | //            if(200 == code1){ | 
|---|
|  |  |  | //                tokenWarpper.setRytoken(jsonObject.getString("token")); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | // todo 正式放开 | 
|---|
|  |  |  | if(ToolUtil.isEmpty(driver.getReferralCode())){ | 
|---|
|  |  |  | String s = wechatMiniProgramORCode(driver.getId()); | 
|---|
|  |  |  | driver.setReferralCode(s); | 
|---|
|  |  |  | 
|---|
|  |  |  | return ResultUtil.success(tokenWarpper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) { | 
|---|
|  |  |  | String s = ShiroKit.md5(MD5AndKL.MD5("123456"), "i#sm4"); | 
|---|
|  |  |  | System.out.println(s); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 司机密码登录 | 
|---|
|  |  |  | 
|---|
|  |  |  | redisUtil.setStrValue(key, driver.getId().toString(), 94608000);//7天 | 
|---|
|  |  |  | redisUtil.setStrValue("DRIVER_" + phone, key, 94608000);//7天 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // todo 正式放开 | 
|---|
|  |  |  | //下线 | 
|---|
|  |  |  | for (int i = 0; i < 5; i++) { | 
|---|
|  |  |  | Integer code = pushUtil.pushOffline(driver.getId(), 2); | 
|---|
|  |  |  | 
|---|
|  |  |  | if(null == driverWork){ | 
|---|
|  |  |  | return ResultUtil.error("请先上班"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String value = redisUtil.getValue("DRIVER" + uid); | 
|---|
|  |  |  | String value = redisUtil.getValue("daijia:DRIVER" + uid); | 
|---|
|  |  |  | List<String> list = new ArrayList<>(); | 
|---|
|  |  |  | if(ToolUtil.isNotEmpty(value)){ | 
|---|
|  |  |  | String[] split = value.split(","); | 
|---|
|  |  |  | 
|---|
|  |  |  | i = 3; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String value1 = redisUtil.getValue("DRIVER" + s.getDriverId()); | 
|---|
|  |  |  | String value1 = redisUtil.getValue("daijia:DRIVER" + s.getDriverId()); | 
|---|
|  |  |  | if(s.getDriverId().compareTo(uid) != 0 && ToolUtil.isNotEmpty(value1)){ | 
|---|
|  |  |  | list.add(s.getLocation().getX() + "," + s.getLocation().getY()+","+i+","+driver.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | Double lat = driverPositionWarpper.getLat(); | 
|---|
|  |  |  | Integer driverId = driverPositionWarpper.getDriverId(); | 
|---|
|  |  |  | Integer orderId = driverPositionWarpper.getOrderId(); | 
|---|
|  |  |  | redisUtil.setStrValue("daijia_DRIVER" + driverId, lon + "," + lat, 30); | 
|---|
|  |  |  | log.info("存储地理空间:{}", driverPositionWarpper); | 
|---|
|  |  |  | redisUtil.setStrValue("daijia: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)) { | 
|---|
|  |  |  | 
|---|
|  |  |  | .eq("state", 2).last(" and failureTime > now() order by failureTime limit 0, 1")); | 
|---|
|  |  |  | if(null != youTuiDriver){ | 
|---|
|  |  |  | driverInfo.setYouTuiEnd(youTuiDriver.getType() == 1 ? youTuiDriver.getFailureTime().getTime() : youTuiDriver.getEndTime().getTime()); | 
|---|
|  |  |  | driverInfo.setType(youTuiDriver.getType()); | 
|---|
|  |  |  | driverInfo.setSurplusQuantity(youTuiDriver.getSurplusQuantity()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Integer> state = Arrays.asList(107, 108, 109); | 
|---|
|  |  |  | int count = orderService.selectCount(new EntityWrapper<Order>().eq("driverId", uid).eq("status", 1).in("state", state).last(" and DATE_FORMAT(createTime, '%Y-%m-%d') = DATE_FORMAT(now(), '%Y-%m-%d')")); | 
|---|