|
@@ -25,10 +25,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.UUID;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @description:
|
|
@@ -55,7 +52,11 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
|
public String upload(MultipartFile photo) {
|
|
|
String fileName = UUID.randomUUID().toString().replace("-","") + "-" +
|
|
|
photo.getOriginalFilename();
|
|
|
- String filePath = uploadPath + File.separator + fileName;
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ int month = cal.get(Calendar.MONTH) + 1;
|
|
|
+ int year = cal.get(Calendar.YEAR);
|
|
|
+ String directoryName = year+"-"+month;
|
|
|
+ String filePath = uploadPath + directoryName + File.separator + fileName;
|
|
|
try {
|
|
|
UploadUtil.upload(photo, filePath);
|
|
|
} catch (IOException ioe) {
|
|
@@ -67,14 +68,14 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
|
PhotoPo photoPo = new PhotoPo();
|
|
|
photoPo.setCreateTime(new Date());
|
|
|
photoPo.setStatus(PhotoStatusEnum.UPLOAD_SUCCESS_NOT_USE.getValue());
|
|
|
- photoPo.setUrl(File.separator + fileName);
|
|
|
+ photoPo.setUrl(File.separator+ directoryName + File.separator + fileName);
|
|
|
photoMapper.insert(photoPo);
|
|
|
} catch (Exception e) {
|
|
|
log.error("图片上传-新增图片失败, 图片地址:{}", filePath);
|
|
|
log.error("图片上传-新增图片失败,失败原因:{}", e.getMessage());
|
|
|
throw new ServiceException("图片上传-新增图片失败");
|
|
|
}
|
|
|
- return accessPath + accessResource + fileName;
|
|
|
+ return accessPath + accessResource + File.separator + directoryName + File.separator + fileName;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -95,7 +96,11 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
|
validate(photoDto);
|
|
|
String fileName = UUID.randomUUID().toString().replace("-","") + "-" +
|
|
|
photoDto.getPhoto().getOriginalFilename();
|
|
|
- String filePath = uploadPath + File.separator + fileName;
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ int month = cal.get(Calendar.MONTH) + 1;
|
|
|
+ int year = cal.get(Calendar.YEAR);
|
|
|
+ String directoryName = year+"-"+month;
|
|
|
+ String filePath = uploadPath +directoryName + File.separator + fileName;
|
|
|
|
|
|
try {
|
|
|
UploadUtil.upload(photoDto.getPhoto(), filePath);
|
|
@@ -110,7 +115,7 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
|
throw new ServiceException("图片上传失败");
|
|
|
}
|
|
|
|
|
|
- photoDto.setUrl(File.separator + fileName);
|
|
|
+ photoDto.setUrl(File.separator+ directoryName + File.separator + fileName);
|
|
|
PhotoPo photoPo = new PhotoPo();
|
|
|
BeanUtil.copyProperties(photoPo, photoDto);
|
|
|
photoPo.setCreateTime(new Date());
|