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.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@RequestMapping("kiosk-upload")
|
@RequestMapping("kiosk-upload")
|
||||||
@@ -21,8 +23,8 @@ public class UploadController {
|
|||||||
/**
|
/**
|
||||||
* 上传文件
|
* 上传文件
|
||||||
*
|
*
|
||||||
* @param code code
|
* @param code code
|
||||||
* @param file file
|
* @param files files
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@@ -30,8 +32,8 @@ public class UploadController {
|
|||||||
public R<Boolean> upload(@RequestParam @NotBlank(message = "Invalid code") String code,
|
public R<Boolean> upload(@RequestParam @NotBlank(message = "Invalid code") String code,
|
||||||
@RequestParam @NotBlank(message = "Invalid machine") String machine,
|
@RequestParam @NotBlank(message = "Invalid machine") String machine,
|
||||||
@RequestParam @NotBlank(message = "Invalid store") String store,
|
@RequestParam @NotBlank(message = "Invalid store") String store,
|
||||||
@RequestParam MultipartFile file) {
|
@RequestParam List<MultipartFile> files) {
|
||||||
Boolean result = kioskApiService.uploadByCode(code, machine, store, file.getOriginalFilename(), file.getInputStream());
|
Boolean result = kioskApiService.uploadByCode(code, machine, store, files);
|
||||||
return R.data(result);
|
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.dto.OrderApiRequest;
|
||||||
import org.springblade.modules.kiosk.pojo.vo.*;
|
import org.springblade.modules.kiosk.pojo.vo.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -11,7 +12,7 @@ public interface IKioskApiService {
|
|||||||
|
|
||||||
List<CategoryApiVO> categoryList();
|
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();
|
String generateUploadUrl();
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,13 @@ import org.springblade.modules.system.service.IDictBizService;
|
|||||||
import org.springblade.modules.system.service.IUserService;
|
import org.springblade.modules.system.service.IUserService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -73,7 +76,7 @@ public class KioskServiceImpl implements IKioskApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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");
|
String tenantId = WebUtil.getHeader("Tenant-Id");
|
||||||
if (StringUtil.isBlank(tenantId)) {
|
if (StringUtil.isBlank(tenantId)) {
|
||||||
@@ -92,19 +95,25 @@ public class KioskServiceImpl implements IKioskApiService {
|
|||||||
|
|
||||||
User user = userService.userByAccount(tenantId, machine);
|
User user = userService.userByAccount(tenantId, machine);
|
||||||
|
|
||||||
BladeFile bladeFile = ossTemplate.putFile(fileName, stream);
|
files.forEach(file -> {
|
||||||
|
BladeFile bladeFile;
|
||||||
PhotoAttachmentEntity photoAttachmentEntity = new PhotoAttachmentEntity();
|
try {
|
||||||
photoAttachmentEntity.setTenantId(tenantId);
|
bladeFile = ossTemplate.putFile(file.getOriginalFilename(), file.getInputStream());
|
||||||
photoAttachmentEntity.setLink(bladeFile.getLink());
|
} catch (IOException e) {
|
||||||
photoAttachmentEntity.setDomainUrl(bladeFile.getDomain());
|
throw new RuntimeException(e);
|
||||||
photoAttachmentEntity.setName(bladeFile.getName());
|
}
|
||||||
photoAttachmentEntity.setOriginalName(bladeFile.getOriginalName());
|
PhotoAttachmentEntity photoAttachmentEntity = new PhotoAttachmentEntity();
|
||||||
photoAttachmentEntity.setCreateUser(user.getId());
|
photoAttachmentEntity.setTenantId(tenantId);
|
||||||
photoAttachmentEntity.setCreateDept(Long.valueOf(user.getDeptId()));
|
photoAttachmentEntity.setLink(bladeFile.getLink());
|
||||||
photoAttachmentEntity.setCreateTime(DateUtil.now());
|
photoAttachmentEntity.setDomainUrl(bladeFile.getDomain());
|
||||||
|
photoAttachmentEntity.setName(bladeFile.getName());
|
||||||
return photoAttachmentService.save(photoAttachmentEntity);
|
photoAttachmentEntity.setOriginalName(bladeFile.getOriginalName());
|
||||||
|
photoAttachmentEntity.setCreateUser(user.getId());
|
||||||
|
photoAttachmentEntity.setCreateDept(Long.valueOf(user.getDeptId()));
|
||||||
|
photoAttachmentEntity.setCreateTime(DateUtil.now());
|
||||||
|
photoAttachmentService.save(photoAttachmentEntity);
|
||||||
|
});
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user