From f71719bf3e2b433b790cfaa83265611faf1f1a1c Mon Sep 17 00:00:00 2001
From: tj <1378534974@qq.com>
Date: 星期五, 11 四月 2025 17:38:06 +0800
Subject: [PATCH] 1.账户注销等
---
src/main/java/com/mzl/flower/web/supplier/SupplierController.java | 48 ++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/mzl/flower/web/supplier/SupplierController.java b/src/main/java/com/mzl/flower/web/supplier/SupplierController.java
index 59aa78c..a0fdd16 100644
--- a/src/main/java/com/mzl/flower/web/supplier/SupplierController.java
+++ b/src/main/java/com/mzl/flower/web/supplier/SupplierController.java
@@ -9,11 +9,15 @@
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.request.supplier.*;
import com.mzl.flower.dto.response.supplier.SupplierDTO;
+import com.mzl.flower.entity.customer.Customer;
+import com.mzl.flower.service.TosService;
+import com.mzl.flower.service.customer.CustomerService;
import com.mzl.flower.service.supplier.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -35,6 +39,12 @@
// private static final R ALLOWED_CONTENT_TYPES = R.valueOf("jpg");
private final SupplierService supplierService;
+
+ @Autowired
+ private CustomerService customerService;
+
+ @Autowired
+ private TosService tosService;
public SupplierController(SupplierService supplierService) {
this.supplierService = supplierService;
@@ -79,15 +89,24 @@
// }
// 3. 生成文件名
- String fileName = "avatar/" + UUID.randomUUID().toString() +
- getFileExtension(avatar.getOriginalFilename());
+ String originalFilename = avatar.getOriginalFilename(); // 原始文件名可能没有后缀
+ String contentType = avatar.getContentType(); // 例如 image/jpeg
+ String extension = getExtensionFromContentType(contentType); // 我们下面实现这个方法
+
+ String newFileName = originalFilename + (extension != null ? extension : "");
// 4. 上传到 OSS
- //avatarUrl = ossService.uploadFile(fileName, avatar.getInputStream());
+ avatarUrl = tosService.uploadFile( avatar.getInputStream(),newFileName);
}
// 5. 更新用户信息
- //supplierService.operationUpdate(nickname, avatarUrl);
+// supplierService.operationUpdate(nickname, avatarUrl);
+ String userId = SecurityUtils.getUserId();
+ Customer customer=new Customer();
+ customer.setUserId(userId);
+ customer.setCover(avatarUrl);
+ customer.setName(nickname);
+ customerService.updateMemberInfoByUserId(customer);
return returnData(R.SUCCESS.getCode(),null);
} catch (Exception e) {
@@ -96,6 +115,27 @@
}
}
+
+ private String getExtensionFromContentType(String contentType) {
+ if (contentType == null) return null;
+
+ switch (contentType) {
+ case "image/jpeg":
+ return ".jpg";
+ case "image/png":
+ return ".png";
+ case "image/gif":
+ return ".gif";
+ case "image/webp":
+ return ".webp";
+ case "image/bmp":
+ return ".bmp";
+ default:
+ return ".png";
+ }
+ }
+
+
@GetMapping("/page")
@ApiOperation(value = "运营端-供应商分页查询", notes = "运营端-供应商分页查询")
public ResponseEntity<ReturnDataDTO<Page<SupplierDTO>>> querySupplier(QuerySupplierDTO dto, Page page) {
--
Gitblit v1.9.3