fix upload
This commit is contained in:
2025-10-24 18:31:29 +08:00
parent 10783b28cb
commit 29da330eb2
3 changed files with 31 additions and 19 deletions

View File

@@ -9,6 +9,8 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@RestController
@AllArgsConstructor
@RequestMapping("kiosk-upload")
@@ -21,8 +23,8 @@ public class UploadController {
/**
* 上传文件
*
* @param code code
* @param file file
* @param code code
* @param files files
* @return Boolean
*/
@SneakyThrows
@@ -30,8 +32,8 @@ public class UploadController {
public R<Boolean> upload(@RequestParam @NotBlank(message = "Invalid code") String code,
@RequestParam @NotBlank(message = "Invalid machine") String machine,
@RequestParam @NotBlank(message = "Invalid store") String store,
@RequestParam MultipartFile file) {
Boolean result = kioskApiService.uploadByCode(code, machine, store, file.getOriginalFilename(), file.getInputStream());
@RequestParam List<MultipartFile> files) {
Boolean result = kioskApiService.uploadByCode(code, machine, store, files);
return R.data(result);
}

View File

@@ -2,6 +2,7 @@ package org.springblade.modules.kiosk.service;
import org.springblade.modules.kiosk.pojo.dto.OrderApiRequest;
import org.springblade.modules.kiosk.pojo.vo.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.List;
@@ -11,7 +12,7 @@ public interface IKioskApiService {
List<CategoryApiVO> categoryList();
Boolean uploadByCode(String code, String machine, String store,String fileName, InputStream stream);
Boolean uploadByCode(String code, String machine, String store, List<MultipartFile> files);
String generateUploadUrl();

View File

@@ -19,10 +19,13 @@ import org.springblade.modules.system.service.IDictBizService;
import org.springblade.modules.system.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -73,7 +76,7 @@ public class KioskServiceImpl implements IKioskApiService {
}
@Override
public Boolean uploadByCode(String code, String machine, String store, String fileName, InputStream stream) {
public Boolean uploadByCode(String code, String machine, String store, List<MultipartFile> files) {
String tenantId = WebUtil.getHeader("Tenant-Id");
if (StringUtil.isBlank(tenantId)) {
@@ -92,19 +95,25 @@ public class KioskServiceImpl implements IKioskApiService {
User user = userService.userByAccount(tenantId, machine);
BladeFile bladeFile = ossTemplate.putFile(fileName, stream);
PhotoAttachmentEntity photoAttachmentEntity = new PhotoAttachmentEntity();
photoAttachmentEntity.setTenantId(tenantId);
photoAttachmentEntity.setLink(bladeFile.getLink());
photoAttachmentEntity.setDomainUrl(bladeFile.getDomain());
photoAttachmentEntity.setName(bladeFile.getName());
photoAttachmentEntity.setOriginalName(bladeFile.getOriginalName());
photoAttachmentEntity.setCreateUser(user.getId());
photoAttachmentEntity.setCreateDept(Long.valueOf(user.getDeptId()));
photoAttachmentEntity.setCreateTime(DateUtil.now());
return photoAttachmentService.save(photoAttachmentEntity);
files.forEach(file -> {
BladeFile bladeFile;
try {
bladeFile = ossTemplate.putFile(file.getOriginalFilename(), file.getInputStream());
} catch (IOException e) {
throw new RuntimeException(e);
}
PhotoAttachmentEntity photoAttachmentEntity = new PhotoAttachmentEntity();
photoAttachmentEntity.setTenantId(tenantId);
photoAttachmentEntity.setLink(bladeFile.getLink());
photoAttachmentEntity.setDomainUrl(bladeFile.getDomain());
photoAttachmentEntity.setName(bladeFile.getName());
photoAttachmentEntity.setOriginalName(bladeFile.getOriginalName());
photoAttachmentEntity.setCreateUser(user.getId());
photoAttachmentEntity.setCreateDept(Long.valueOf(user.getDeptId()));
photoAttachmentEntity.setCreateTime(DateUtil.now());
photoAttachmentService.save(photoAttachmentEntity);
});
return true;
}
@Override