From db0aaa2033a43c016ca165513faaee993117ecf8 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期五, 22 八月 2025 12:14:14 +0800 Subject: [PATCH] 修改bug --- user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/DriverServiceImpl.java | 47 +++++++++++++++++++---------------------------- 1 files changed, 19 insertions(+), 28 deletions(-) diff --git a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/DriverServiceImpl.java b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/DriverServiceImpl.java index f3f2706..90d3568 100644 --- a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/DriverServiceImpl.java +++ b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/DriverServiceImpl.java @@ -1,9 +1,12 @@ package com.supersavedriving.user.modular.system.service.impl; +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.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; -import com.heredata.hos.model.bucket.Bucket; import com.supersavedriving.user.core.util.ToolUtil; import com.supersavedriving.user.modular.system.dao.DriverMapper; import com.supersavedriving.user.modular.system.model.*; @@ -12,14 +15,13 @@ import com.supersavedriving.user.modular.system.util.RedisUtil; import com.supersavedriving.user.modular.system.util.ResultUtil; import com.supersavedriving.user.modular.system.util.UUIDUtil; -import com.supersavedriving.user.modular.system.util.huawei.OBSUtil; import com.supersavedriving.user.modular.system.util.mongodb.model.Location; -import com.supersavedriving.user.modular.system.util.qianyuntong.NCOSSUtil; import com.supersavedriving.user.modular.system.util.qianyuntong.QianYunTongConfig; import com.supersavedriving.user.modular.system.util.weChat.WeChatUtil; import com.supersavedriving.user.modular.system.warpper.DriverRegisterWarpper; import com.supersavedriving.user.modular.system.warpper.NearbyDriverWarpper; 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; @@ -30,6 +32,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.io.File; import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.*; @@ -70,8 +73,11 @@ @Autowired private ITBranchOfficeAreaService branchOfficeAreaService; - @Resource - private QianYunTongConfig qianYunTongConfig; + @Value("${qyt.admin_url}") + private String adminUrl; + + @Value("${filePath}") + private String filePath; @@ -255,29 +261,14 @@ 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"); + HttpRequest form = post.form("file", file); + HttpResponse execute = form.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(); } } -- Gitblit v1.7.1