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/api/AppUserController.java | 74 +++++++++++++++++++------------------ 1 files changed, 38 insertions(+), 36 deletions(-) diff --git a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/AppUserController.java b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/AppUserController.java index fbc077c..1d57649 100644 --- a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/AppUserController.java +++ b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/AppUserController.java @@ -1,16 +1,18 @@ package com.supersavedriving.user.modular.api; +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.heredata.hos.model.bucket.Bucket; import com.supersavedriving.user.core.util.ToolUtil; import com.supersavedriving.user.modular.system.model.*; import com.supersavedriving.user.modular.system.service.*; import com.supersavedriving.user.modular.system.util.*; import com.supersavedriving.user.modular.system.util.GaoDe.MapUtil; import com.supersavedriving.user.modular.system.util.GaoDe.model.District; -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.qianyuntong.SMSUtil; import com.supersavedriving.user.modular.system.util.qianyuntong.model.SendSmsRequest; @@ -21,10 +23,12 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.io.File; import java.io.InputStream; import java.util.Date; import java.util.HashMap; @@ -70,9 +74,12 @@ private TCheckCarActivityService checkCarActivityService; @Autowired private ITBranchOfficeAreaService branchOfficeAreaService; - - @Resource - private QianYunTongConfig qianYunTongConfig; + + @Value("${qyt.admin_url}") + private String adminUrl; + + @Value("${filePath}") + private String filePath; @@ -243,21 +250,30 @@ BeanUtils.copyProperties(appUser, userInfoWarpper); District geocode = MapUtil.geocode(lon, lat); - TBranchOfficeArea branchOfficeArea = branchOfficeAreaService.selectOne(new EntityWrapper<TBranchOfficeArea>().eq("areaCode", geocode.getDistrictCode()) - .last("LIMIT 1")); - if(null == branchOfficeArea){ + if(null != geocode){ + TBranchOfficeArea branchOfficeArea = branchOfficeAreaService.selectOne(new EntityWrapper<TBranchOfficeArea>().eq("areaCode", geocode.getDistrictCode()) + .last("LIMIT 1")); + if(null == branchOfficeArea){ + SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 7)); + if(null != systemConfig){ + JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); + userInfoWarpper.setServiceCell(jsonObject.getString("num1")); + } + }else{ + SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8).eq("companyId", branchOfficeArea.getBranchOfficeId())); + if(null != systemConfig){ + JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); + userInfoWarpper.setServiceCell(jsonObject.getString("num2")); + } + } + }else{ SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 7)); if(null != systemConfig){ JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); userInfoWarpper.setServiceCell(jsonObject.getString("num1")); } - }else{ - SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8).eq("companyId", branchOfficeArea.getBranchOfficeId())); - if(null != systemConfig){ - JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); - userInfoWarpper.setServiceCell(jsonObject.getString("num2")); - } } + return ResponseWarpper.success(userInfoWarpper); }catch (Exception e){ e.printStackTrace(); @@ -278,29 +294,15 @@ InputStream inputStream = file.getInputStream(); String name = file.getOriginalFilename(); name = UUIDUtil.getRandomCode() + name.substring(name.lastIndexOf(".")); - 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 file1 = FileUtil.writeFromStream(inputStream, new File(filePath + name)); + HttpRequest post = HttpUtil.createPost(adminUrl + "/upload/image"); + HttpRequest form = post.form("file", file1); + HttpResponse execute = form.execute(); + int status = execute.getStatus(); + if(200 != status){ + throw new RuntimeException("上传图片异常"); } - //上传对象 - String key = "imgs/daijia/user/" + name; - String object = NCOSSUtil.putObject(bucketName, key, inputStream); - if (null == object) { - throw new RuntimeException("上传图片失败"); - } - return ResponseWarpper.success("https://traffic.qytzt.cn/v1/AUTH_" + qianYunTongConfig1.getAccount() + "/" + bucketName + "/" + key); + return ResponseWarpper.success(execute.body()); }catch (Exception e){ e.printStackTrace(); return new ResponseWarpper(500, e.getMessage()); -- Gitblit v1.7.1