feat(打印):打印标签模板上传方式修改
This commit is contained in:
parent
dd5db68502
commit
8d7ec91a25
@ -26,3 +26,11 @@ spring:
|
||||
|
||||
seata:
|
||||
data-source-proxy-mode: XA
|
||||
|
||||
file:
|
||||
bucketName: template
|
||||
oss:
|
||||
enable: true
|
||||
endpoint: http://192.168.100.7:9000
|
||||
accessKey: minioadmin
|
||||
secretKey: minioadmin
|
||||
|
||||
@ -141,5 +141,10 @@
|
||||
<artifactId>json-path</artifactId>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.foreverwin</groupId>
|
||||
<artifactId>mom-common-oss</artifactId>
|
||||
<version>4.5.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@ -135,10 +135,9 @@ public class PrintLabelTemplateController {
|
||||
*/
|
||||
@ResponseBody
|
||||
@PostMapping("/upload")
|
||||
public R doUpload(@RequestParam("file") MultipartFile file) throws Exception{
|
||||
String templateCode = file.getOriginalFilename();
|
||||
String site = TenantContextHolder.getTenantStrId();
|
||||
printLabelTemplateService.doUpload(site, templateCode, file);
|
||||
public R doUpload(@RequestParam("file") MultipartFile file, @RequestParam("templateCode") String templateCode) throws Exception{
|
||||
// String templateCode = file.getOriginalFilename();
|
||||
printLabelTemplateService.uploadTemplate(templateCode, file);
|
||||
return R.ok("");
|
||||
}
|
||||
|
||||
|
||||
@ -19,8 +19,10 @@ public interface PrintLabelTemplateService extends IService<PrintLabelTemplate>
|
||||
boolean validateAndSave(String site, String user, PrintLabelTemplate printLabelTemplate);
|
||||
|
||||
boolean validateAndUpdate(String site, String user, PrintLabelTemplate printLabelTemplate);
|
||||
|
||||
void doUpload(String site, String templateCode, MultipartFile multipartFile) throws Exception;
|
||||
|
||||
boolean uploadTemplate(String templateCode, MultipartFile uploadFile);
|
||||
|
||||
void doUpload(String site, String templateCode, MultipartFile multipartFile) throws Exception;
|
||||
|
||||
List<PrintLabelTemplate> selectList(PrintLabelTemplate printLabelTemplate);
|
||||
}
|
||||
|
||||
@ -4,8 +4,11 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.foreverwin.mom.common.core.exception.BaseException;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import com.foreverwin.mom.common.data.tenant.TenantContextHolder;
|
||||
import com.foreverwin.mom.common.file.core.FileProperties;
|
||||
import com.foreverwin.mom.common.file.core.FileTemplate;
|
||||
import com.foreverwin.nlv.print.entity.PrintLabelTemplate;
|
||||
import com.foreverwin.nlv.print.mapper.PrintLabelTemplateMapper;
|
||||
import com.foreverwin.nlv.print.service.PrintLabelTemplateService;
|
||||
@ -37,6 +40,10 @@ public class PrintLabelTemplateServiceImpl extends ServiceImpl<PrintLabelTemplat
|
||||
private final static Logger logger = LoggerFactory.getLogger(PrintLabelTemplateServiceImpl.class);
|
||||
|
||||
private final PrintLabelTemplateMapper printLabelTemplateMapper;
|
||||
|
||||
private final FileTemplate fileTemplate;
|
||||
|
||||
private final FileProperties properties;
|
||||
|
||||
@Override
|
||||
public PrintLabelTemplate getFullById(String handle) {
|
||||
@ -84,6 +91,31 @@ public class PrintLabelTemplateServiceImpl extends ServiceImpl<PrintLabelTemplat
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean uploadTemplate(String templateCode, MultipartFile uploadFile) {
|
||||
// 如果文件为空,则返回null
|
||||
if (uploadFile == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 处理文件名的编码转换,确保兼容性
|
||||
// new String(Objects.requireNonNull(uploadFile.getOriginalFilename()).getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
|
||||
// 上传文件并获取返回的文件URL
|
||||
uploadFile(uploadFile, templateCode);
|
||||
return true;
|
||||
}
|
||||
|
||||
private String uploadFile(MultipartFile file, String templateCode) {
|
||||
String fileName = templateCode + ".lab";
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
fileTemplate.createBucket(properties.getBucketName());
|
||||
fileTemplate.putObject(properties.getBucketName(), fileName, inputStream, file.getContentType());
|
||||
} catch (Exception e) {
|
||||
throw new BaseException("上传失败:" + e);
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doUpload(String site, String templateCode, MultipartFile multipartFile) throws Exception {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user