|
@@ -37,8 +37,12 @@ import java.util.UUID;
|
|
|
@Service
|
|
|
@Transactional(readOnly = true)
|
|
|
public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
|
- @Value("${photo.relativePath}")
|
|
|
- private String relativePath;
|
|
|
+ @Value("${photo.uploadPath}")
|
|
|
+ private String uploadPath;
|
|
|
+ @Value("${photo.accessPath}")
|
|
|
+ private String accessPath;
|
|
|
+ @Value("${photo.accessResource}")
|
|
|
+ private String accessResource;
|
|
|
|
|
|
@Resource
|
|
|
PhotoMapper photoMapper;
|
|
@@ -48,7 +52,7 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
|
public String upload(MultipartFile photo) {
|
|
|
String fileName = UUID.randomUUID().toString().replace("-","") + "-" +
|
|
|
photo.getOriginalFilename();
|
|
|
- String filePath = relativePath + File.separator + fileName;
|
|
|
+ String filePath = uploadPath + File.separator + fileName;
|
|
|
try {
|
|
|
UploadUtil.upload(photo, filePath);
|
|
|
} catch (IOException ioe) {
|
|
@@ -60,14 +64,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(filePath);
|
|
|
+ photoPo.setUrl(File.separator + fileName);
|
|
|
photoMapper.insert(photoPo);
|
|
|
} catch (Exception e) {
|
|
|
log.error("图片上传-新增图片失败, 图片地址:{}", filePath);
|
|
|
log.error("图片上传-新增图片失败,失败原因:{}", e.getMessage());
|
|
|
throw new ServiceException("图片上传-新增图片失败");
|
|
|
}
|
|
|
- return filePath;
|
|
|
+ return accessPath + accessResource + fileName;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -88,7 +92,7 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
|
validate(photoDto);
|
|
|
String fileName = UUID.randomUUID().toString().replace("-","") + "-" +
|
|
|
photoDto.getPhoto().getOriginalFilename();
|
|
|
- String filePath = relativePath + File.separator + fileName;
|
|
|
+ String filePath = uploadPath + File.separator + fileName;
|
|
|
|
|
|
try {
|
|
|
UploadUtil.upload(photoDto.getPhoto(), filePath);
|
|
@@ -97,7 +101,7 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
|
throw new ServiceException("图片上传失败");
|
|
|
}
|
|
|
|
|
|
- photoDto.setUrl(filePath);
|
|
|
+ photoDto.setUrl(File.separator + fileName);
|
|
|
PhotoPo photoPo = new PhotoPo();
|
|
|
BeanUtil.copyProperties(photoPo, photoDto);
|
|
|
photoPo.setCreateTime(new Date());
|
|
@@ -149,7 +153,7 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
|
PhotoPo photoPo = photoMapper.selectById(id);
|
|
|
AssertUtils.assertNotNull(photoPo, CommonConstant.PHOTO_NOT_EXIST);
|
|
|
|
|
|
- String url = photoPo.getUrl();
|
|
|
+ String url = uploadPath + photoPo.getUrl();
|
|
|
File file = new File(url);
|
|
|
|
|
|
boolean deleteResult = false;
|