From b2547dce1e862ab31605fe648654dc37712f6899 Mon Sep 17 00:00:00 2001 From: cst61 Date: Sat, 2 May 2026 18:34:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=A2=E6=88=B7=E7=85=A7?= =?UTF-8?q?=E7=89=87=E4=B8=8A=E4=BC=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomerManagementController.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/main/java/com/rj/controller/CustomerManagementController.java b/src/main/java/com/rj/controller/CustomerManagementController.java index 50d3746..52f050f 100644 --- a/src/main/java/com/rj/controller/CustomerManagementController.java +++ b/src/main/java/com/rj/controller/CustomerManagementController.java @@ -10,13 +10,16 @@ import com.rj.entity.SalesManagement; import com.rj.service.IAudioManagementService; import com.rj.service.ICustomerManagementService; import com.rj.service.ISalesManagementService; +import com.rj.service.MinIOService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.time.LocalDateTime; import java.util.HashMap; @@ -32,6 +35,7 @@ import java.util.UUID; * @author 李中华 ,spllzh * @since 2025-08-07 */ +@Slf4j @RestController @RequestMapping("/api/customerManagement") @Tag(name = "客户管理", description = "客户管理相关接口") @@ -46,6 +50,9 @@ public class CustomerManagementController { @Autowired private ISalesManagementService salesManagementService; + @Autowired + private MinIOService minIOService; + /** * 新增客户 */ @@ -382,6 +389,54 @@ public class CustomerManagementController { } } + /** + * 客户照片上传至 MinIO,返回可访问 URL + */ + @PostMapping("/uploadPhoto") + @Operation(summary = "上传客户照片", description = "根据客户ID上传照片到 MinIO,返回文件访问 URL") + public ResponseEntity> uploadCustomerPhoto( + @Parameter(description = "客户ID", required = true) + @RequestParam String id, + @Parameter(description = "照片文件", required = true) + @RequestParam("file") MultipartFile file) { + Map result = new HashMap<>(); + try { + if (id == null || id.trim().isEmpty()) { + result.put("success", false); + result.put("message", "客户ID不能为空"); + return ResponseEntity.badRequest().body(result); + } + if (file == null || file.isEmpty()) { + result.put("success", false); + result.put("message", "请选择要上传的文件"); + return ResponseEntity.badRequest().body(result); + } + CustomerManagement customer = customerManagementService.getById(id.trim()); + if (customer == null) { + result.put("success", false); + result.put("message", "客户不存在"); + return ResponseEntity.badRequest().body(result); + } + String original = file.getOriginalFilename(); + String ext = ""; + if (original != null && original.contains(".")) { + ext = original.substring(original.lastIndexOf(".")); + } + String objectName = "customer-management/photo/" + id.trim() + "/" + UUID.randomUUID().toString().replace("-", "") + ext; + String url = minIOService.uploadFileWithName(file, objectName); + log.info("客户照片已上传 MinIO,customerId={}, url={}", id, url); + result.put("success", true); + result.put("message", "上传成功"); + result.put("url", url); + return ResponseEntity.ok(result); + } catch (Exception e) { + log.error("客户照片上传失败: {}", e.getMessage(), e); + result.put("success", false); + result.put("message", "上传失败:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } + private AudioManagement buildAudioRecordFromCustomer(CustomerManagement customer, LocalDateTime now) { AudioManagement audio = new AudioManagement(); audio.setId(UUID.randomUUID().toString());