update:
fix upload
This commit is contained in:
@@ -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")
|
||||
@@ -22,7 +24,7 @@ public class UploadController {
|
||||
* 上传文件
|
||||
*
|
||||
* @param code code
|
||||
* @param file file
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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,8 +95,13 @@ public class KioskServiceImpl implements IKioskApiService {
|
||||
|
||||
User user = userService.userByAccount(tenantId, machine);
|
||||
|
||||
BladeFile bladeFile = ossTemplate.putFile(fileName, stream);
|
||||
|
||||
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());
|
||||
@@ -103,8 +111,9 @@ public class KioskServiceImpl implements IKioskApiService {
|
||||
photoAttachmentEntity.setCreateUser(user.getId());
|
||||
photoAttachmentEntity.setCreateDept(Long.valueOf(user.getDeptId()));
|
||||
photoAttachmentEntity.setCreateTime(DateUtil.now());
|
||||
|
||||
return photoAttachmentService.save(photoAttachmentEntity);
|
||||
photoAttachmentService.save(photoAttachmentEntity);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user