|
@@ -3,12 +3,12 @@ package com.fdkankan.scene.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.constant.UploadFilePath;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.user.SSOLoginHelper;
|
|
|
import com.fdkankan.common.user.SSOUser;
|
|
|
import com.fdkankan.common.util.BASE64DecodedMultipartFile;
|
|
|
import com.fdkankan.common.util.FileUtil;
|
|
|
-import com.fdkankan.fyun.oss.UploadFilePath;
|
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
import com.fdkankan.scene.entity.SceneUpload;
|
|
|
import com.fdkankan.scene.mapper.ISceneUploadMapper;
|
|
@@ -55,7 +55,7 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
|
|
|
private SSOLoginHelper ssoLoginHelper;
|
|
|
|
|
|
@Override
|
|
|
- public String uploads(String imgData,String fileName,MultipartFile[] files,String sceneCode,Integer type,String token) throws Exception{
|
|
|
+ public String uploads(String imgData,String fileName,String blzType,MultipartFile[] files,String sceneCode,Integer type,String token) throws Exception{
|
|
|
SSOUser ssoUser = ssoLoginHelper.loginCheck(token);
|
|
|
// if(ssoUser == null ){
|
|
|
// throw new BusinessException(ErrorCode.USER_NOT_LOGIN);
|
|
@@ -70,30 +70,21 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
|
|
|
if(files !=null && files.length >0){
|
|
|
multipartFiles.addAll(Arrays.asList(files));
|
|
|
}
|
|
|
- return this.uploadFiles(fileName,multipartFiles,sceneCode,type,userId);
|
|
|
+ return this.uploadFiles(fileName,blzType,multipartFiles,sceneCode,type,userId);
|
|
|
}
|
|
|
|
|
|
- public String uploadFiles(String sendFileName,List<MultipartFile> files, String sceneCode, Integer type,Long userId) throws Exception{
|
|
|
- if (StringUtils.isEmpty(sceneCode) || files == null || files.size() <= 0) {
|
|
|
+ public String uploadFiles(String sendFileName,String blzType,List<MultipartFile> files, String sceneCode, Integer type,Long userId) throws Exception{
|
|
|
+ if (StringUtils.isEmpty(sceneCode) || files == null || files.size() <= 0 || StringUtils.isEmpty(blzType)) {
|
|
|
throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
}
|
|
|
List<String> urlList = new ArrayList<>();
|
|
|
- String prefix ="";
|
|
|
- for (MultipartFile file : files) {
|
|
|
- String fileName = file.getOriginalFilename();
|
|
|
- if(StringUtils.isNotBlank(prefix) && !prefix.equals(fileName.substring(fileName.lastIndexOf(".")))){
|
|
|
- throw new BusinessException(-1,"文件类型不一致");
|
|
|
- }
|
|
|
- // 获取文件后缀
|
|
|
- prefix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
- }
|
|
|
if(type != null && 1 == type){
|
|
|
- this.updateFileByPreFix(sceneCode,prefix);
|
|
|
+ this.updateFileByPreFix(sceneCode,blzType);
|
|
|
}
|
|
|
for (MultipartFile file : files) {
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
// 获取文件后缀
|
|
|
- prefix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
+ String prefix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
File newFile = File.createTempFile(UUID.randomUUID().toString() ,prefix);
|
|
|
file.transferTo(newFile);
|
|
|
String realFileName = fileName;
|
|
@@ -112,7 +103,7 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
|
|
|
|
|
|
FileUtil.delFile(newFile.getPath());
|
|
|
//添加记录
|
|
|
- this.saveData(sceneCode,ossPath,prefix,userId);
|
|
|
+ this.saveData(sceneCode,ossPath,blzType,userId);
|
|
|
}
|
|
|
StringBuilder returnString = new StringBuilder();
|
|
|
for (String res : urlList) {
|
|
@@ -124,20 +115,20 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
|
|
|
return returnString.toString();
|
|
|
}
|
|
|
|
|
|
- private void updateFileByPreFix(String sceneCode, String prefix) {
|
|
|
+ private void updateFileByPreFix(String sceneCode, String blzType) {
|
|
|
LambdaQueryWrapper<SceneUpload> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(SceneUpload::getNum,sceneCode)
|
|
|
- .eq(SceneUpload::getFilePrefix,prefix)
|
|
|
+ .eq(SceneUpload::getBlzType,blzType)
|
|
|
.eq(SceneUpload::getTbStatus,0);
|
|
|
List<SceneUpload> list = this.list(queryWrapper);
|
|
|
|
|
|
if(list != null && list.size() >0){
|
|
|
for (SceneUpload sceneUpload : list) {
|
|
|
try {
|
|
|
- uploadToOssUtil.delete(sceneUpload.getFileName());
|
|
|
+ uploadToOssUtil.delete(sceneUpload.getFilePath());
|
|
|
this.removeEntity(sceneUpload);
|
|
|
}catch (Exception e){
|
|
|
- log.error(sceneUpload.getFileName()+"删除oss文件失败",e);
|
|
|
+ log.error(sceneUpload.getFilePath()+"删除oss文件失败",e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -151,8 +142,8 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
|
|
|
private void saveData(String sceneCode, String ossPath, String prefix,Long userId) {
|
|
|
SceneUpload sceneUpload = new SceneUpload();
|
|
|
sceneUpload.setNum(sceneCode);
|
|
|
- sceneUpload.setFileName(ossPath);
|
|
|
- sceneUpload.setFilePrefix(prefix);
|
|
|
+ sceneUpload.setFilePath(ossPath);
|
|
|
+ sceneUpload.setBlzType(prefix);
|
|
|
sceneUpload.setUploadUser(userId);
|
|
|
this.save(sceneUpload);
|
|
|
}
|