增加客户照片上传功能

This commit is contained in:
2026-05-02 18:34:28 +08:00
parent 1799735b21
commit b2547dce1e

View File

@@ -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<Map<String, Object>> uploadCustomerPhoto(
@Parameter(description = "客户ID", required = true)
@RequestParam String id,
@Parameter(description = "照片文件", required = true)
@RequestParam("file") MultipartFile file) {
Map<String, Object> 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("客户照片已上传 MinIOcustomerId={}, 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());