|
|
|
@ -15,14 +15,17 @@ import org.apache.shiro.SecurityUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
/** |
|
|
|
* @description: 处理文件上传接口实现 |
|
|
|
@ -43,57 +46,61 @@ public class SysFileServiceImpl implements SysFileService { |
|
|
|
private String filePath; |
|
|
|
|
|
|
|
@Override |
|
|
|
public SysOssEntity upload(MultipartFile file, GetParamInData inData) { |
|
|
|
if (file.isEmpty()) { |
|
|
|
@Transactional |
|
|
|
public List<SysOssEntity> upload(MultipartFile[] list, GetParamInData inData) { |
|
|
|
if (Objects.isNull(list) || list.length == 0) { |
|
|
|
throw new XJException("上传文件不能为空"); |
|
|
|
} |
|
|
|
R r = new R(); |
|
|
|
//保存文件信息 |
|
|
|
SysOssEntity ossEntity = new SysOssEntity(); |
|
|
|
SysUserEntity user = getUser(); |
|
|
|
//处理文件后缀 |
|
|
|
int chartIndex = file.getOriginalFilename().lastIndexOf("."); |
|
|
|
String suffix = ""; |
|
|
|
String fileName = ""; |
|
|
|
//判断是否存在 |
|
|
|
if(chartIndex > 0){ |
|
|
|
suffix = file.getOriginalFilename().substring(chartIndex); |
|
|
|
fileName = file.getOriginalFilename().substring(0, chartIndex); |
|
|
|
} |
|
|
|
String newFileName = RandomUtil.getOrderNoByAtomic1("file") + suffix; |
|
|
|
String basePath = filePath; |
|
|
|
String baseDatePath = DateUtils.format(new Date()); |
|
|
|
File baseFilePath = new File(basePath + "\\" + baseDatePath + "\\" + inData.getFolder()); |
|
|
|
if (!baseFilePath.exists()) { |
|
|
|
baseFilePath.mkdirs(); |
|
|
|
} |
|
|
|
// 最终的目录 |
|
|
|
String finalFileName = baseFilePath.getPath()+"\\" + newFileName; |
|
|
|
try { |
|
|
|
baseFilePath = multipartFileToFile(file, finalFileName); |
|
|
|
}catch (Exception e){ |
|
|
|
throw new XJException(e.getMessage()); |
|
|
|
} |
|
|
|
ossEntity.setUrl(baseFilePath.getPath()); |
|
|
|
ossEntity.setCreatedBy(user.getUsername()); |
|
|
|
ossEntity.setFileType(suffix.substring(1)); |
|
|
|
ossEntity.setFileName(fileName+suffix); |
|
|
|
ossEntity.setNewFileName(newFileName); |
|
|
|
ossEntity.setCreateDate(new Date()); |
|
|
|
ossEntity.setOrderRef1(inData.getSite()); |
|
|
|
ossEntity.setOrderRef2(inData.getObjectID()); |
|
|
|
if ("reportFault".equals(inData.getFolder()) || "reportSparPart".equals(inData.getFolder())) { |
|
|
|
ossEntity.setOrderRef3(inData.getFolder()); |
|
|
|
} else if ("DJItemImageFile".equals(inData.getFolder()) || "WBItemImageFile".equals(inData.getFolder()) || "IQCItemImageFile".equals(inData.getFolder()) || "IPQCItemImageFile".equals(inData.getFolder()) || "FAIItemImageFile".equals(inData.getFolder()) || "FQCItemImageFile".equals(inData.getFolder())) { // 点检和维保的项目图片上传 |
|
|
|
ossEntity.setOrderRef3(inData.getOrderRef1()); |
|
|
|
} else if ("eamObject".equals(inData.getFolder())) { |
|
|
|
ossEntity.setOrderRef3(inData.getOrderRef3()); |
|
|
|
} else { |
|
|
|
ossEntity.setOrderRef3(inData.getRemark()); |
|
|
|
List<SysOssEntity> ossEntityList = new ArrayList<>(); |
|
|
|
for (MultipartFile file : list) { |
|
|
|
//保存文件信息 |
|
|
|
SysOssEntity ossEntity = new SysOssEntity(); |
|
|
|
SysUserEntity user = getUser(); |
|
|
|
//处理文件后缀 |
|
|
|
int chartIndex = file.getOriginalFilename().lastIndexOf("."); |
|
|
|
String suffix = ""; |
|
|
|
String fileName = ""; |
|
|
|
//判断是否存在 |
|
|
|
if(chartIndex > 0){ |
|
|
|
suffix = file.getOriginalFilename().substring(chartIndex); |
|
|
|
fileName = file.getOriginalFilename().substring(0, chartIndex); |
|
|
|
} |
|
|
|
String newFileName = RandomUtil.getOrderNoByAtomic1("file") + suffix; |
|
|
|
String basePath = filePath; |
|
|
|
String baseDatePath = DateUtils.format(new Date()); |
|
|
|
File baseFilePath = new File(basePath + "\\" + baseDatePath + "\\" + inData.getFolder()); |
|
|
|
if (!baseFilePath.exists()) { |
|
|
|
baseFilePath.mkdirs(); |
|
|
|
} |
|
|
|
// 最终的目录 |
|
|
|
String finalFileName = baseFilePath.getPath()+"\\" + newFileName; |
|
|
|
try { |
|
|
|
baseFilePath = multipartFileToFile(file, finalFileName); |
|
|
|
}catch (Exception e){ |
|
|
|
throw new XJException(e.getMessage()); |
|
|
|
} |
|
|
|
ossEntity.setUrl(baseFilePath.getPath()); |
|
|
|
ossEntity.setCreatedBy(user.getUsername()); |
|
|
|
ossEntity.setFileType(suffix.substring(1)); |
|
|
|
ossEntity.setFileName(fileName+suffix); |
|
|
|
ossEntity.setNewFileName(newFileName); |
|
|
|
ossEntity.setCreateDate(new Date()); |
|
|
|
ossEntity.setOrderRef1(inData.getSite()); |
|
|
|
ossEntity.setOrderRef2(inData.getObjectID()); |
|
|
|
if ("reportFault".equals(inData.getFolder()) || "reportSparPart".equals(inData.getFolder())) { |
|
|
|
ossEntity.setOrderRef3(inData.getFolder()); |
|
|
|
} else if ("DJItemImageFile".equals(inData.getFolder()) || "WBItemImageFile".equals(inData.getFolder()) || "IQCItemImageFile".equals(inData.getFolder()) || "IPQCItemImageFile".equals(inData.getFolder()) || "FAIItemImageFile".equals(inData.getFolder()) || "FQCItemImageFile".equals(inData.getFolder())) { // 点检和维保的项目图片上传 |
|
|
|
ossEntity.setOrderRef3(inData.getOrderRef1()); |
|
|
|
} else if ("eamObject".equals(inData.getFolder())) { |
|
|
|
ossEntity.setOrderRef3(inData.getOrderRef3()); |
|
|
|
} else { |
|
|
|
ossEntity.setOrderRef3(inData.getRemark()); |
|
|
|
} |
|
|
|
ossEntity.setOrderRef4(inData.getOrderRef4()); |
|
|
|
sysOssService.save(ossEntity); |
|
|
|
ossEntityList.add(ossEntity); |
|
|
|
} |
|
|
|
ossEntity.setOrderRef4(inData.getOrderRef4()); |
|
|
|
sysOssService.save(ossEntity); |
|
|
|
return ossEntity; |
|
|
|
return ossEntityList; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|