|
@@ -13,6 +13,7 @@ import com.jkcredit.sysnews.spi.lang.constant.CommonConstant;
|
|
import com.jkcredit.sysnews.spi.lang.exception.ServiceException;
|
|
import com.jkcredit.sysnews.spi.lang.exception.ServiceException;
|
|
import com.jkcredit.sysnews.util.AssertUtils;
|
|
import com.jkcredit.sysnews.util.AssertUtils;
|
|
import com.jkcredit.sysnews.util.BeanUtil;
|
|
import com.jkcredit.sysnews.util.BeanUtil;
|
|
|
|
+import com.jkcredit.sysnews.util.CommonUtil;
|
|
import com.jkcredit.sysnews.util.UploadUtil;
|
|
import com.jkcredit.sysnews.util.UploadUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -39,10 +40,6 @@ import java.util.*;
|
|
public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
@Value("${photo.uploadPath}")
|
|
@Value("${photo.uploadPath}")
|
|
private String uploadPath;
|
|
private String uploadPath;
|
|
- @Value("${photo.accessPath}")
|
|
|
|
- private String accessPath;
|
|
|
|
- @Value("${photo.accessResource}")
|
|
|
|
- private String accessResource;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
PhotoMapper photoMapper;
|
|
PhotoMapper photoMapper;
|
|
@@ -56,7 +53,8 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
int month = cal.get(Calendar.MONTH) + 1;
|
|
int month = cal.get(Calendar.MONTH) + 1;
|
|
int year = cal.get(Calendar.YEAR);
|
|
int year = cal.get(Calendar.YEAR);
|
|
String directoryName = year+"-"+month;
|
|
String directoryName = year+"-"+month;
|
|
- String filePath = uploadPath + File.separator + directoryName + File.separator + fileName;
|
|
|
|
|
|
+ String relativePath = File.separator + directoryName + File.separator + fileName;
|
|
|
|
+ String filePath = uploadPath + relativePath;
|
|
try {
|
|
try {
|
|
UploadUtil.upload(photo, filePath);
|
|
UploadUtil.upload(photo, filePath);
|
|
} catch (IOException ioe) {
|
|
} catch (IOException ioe) {
|
|
@@ -68,14 +66,14 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
PhotoPo photoPo = new PhotoPo();
|
|
PhotoPo photoPo = new PhotoPo();
|
|
photoPo.setCreateTime(new Date());
|
|
photoPo.setCreateTime(new Date());
|
|
photoPo.setStatus(PhotoStatusEnum.UPLOAD_SUCCESS_NOT_USE.getValue());
|
|
photoPo.setStatus(PhotoStatusEnum.UPLOAD_SUCCESS_NOT_USE.getValue());
|
|
- photoPo.setUrl(File.separator+ directoryName + File.separator + fileName);
|
|
|
|
|
|
+ photoPo.setUrl(relativePath);
|
|
photoMapper.insert(photoPo);
|
|
photoMapper.insert(photoPo);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("图片上传-新增图片失败, 图片地址:{}", filePath);
|
|
log.error("图片上传-新增图片失败, 图片地址:{}", filePath);
|
|
log.error("图片上传-新增图片失败,失败原因:{}", e.getMessage());
|
|
log.error("图片上传-新增图片失败,失败原因:{}", e.getMessage());
|
|
throw new ServiceException("图片上传-新增图片失败");
|
|
throw new ServiceException("图片上传-新增图片失败");
|
|
}
|
|
}
|
|
- return accessPath + accessResource + File.separator + directoryName + File.separator + fileName;
|
|
|
|
|
|
+ return CommonUtil.getDummyPath(relativePath);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -195,9 +193,7 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
PhotoVo photoVo = new PhotoVo();
|
|
PhotoVo photoVo = new PhotoVo();
|
|
BeanUtil.copyProperties(photoVo, photoPo);
|
|
BeanUtil.copyProperties(photoVo, photoPo);
|
|
if (photoPo.getUrl() != null) {
|
|
if (photoPo.getUrl() != null) {
|
|
- String[] photoUrlArgs = photoPo.getUrl().split("/");
|
|
|
|
- String url = accessPath + accessResource + photoUrlArgs[1] + File.separator + photoUrlArgs[2];
|
|
|
|
- photoVo.setUrl(url);
|
|
|
|
|
|
+ photoVo.setUrl(CommonUtil.getDummyPath(photoPo.getUrl()));
|
|
}
|
|
}
|
|
return photoVo;
|
|
return photoVo;
|
|
}
|
|
}
|
|
@@ -215,8 +211,7 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
if (middlePhoto != null) {
|
|
if (middlePhoto != null) {
|
|
BeanUtil.copyProperties(middlePhotoVo, middlePhoto);
|
|
BeanUtil.copyProperties(middlePhotoVo, middlePhoto);
|
|
if (middlePhoto.getUrl() != null) {
|
|
if (middlePhoto.getUrl() != null) {
|
|
- String url = accessPath + accessResource + middlePhoto.getUrl().replace("/","");
|
|
|
|
- middlePhotoVo.setUrl(url);
|
|
|
|
|
|
+ middlePhotoVo.setUrl(CommonUtil.getDummyPath(middlePhoto.getUrl()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -226,8 +221,7 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
|
|
PhotoVo vo = new PhotoVo();
|
|
PhotoVo vo = new PhotoVo();
|
|
BeanUtil.copyProperties(vo, po);
|
|
BeanUtil.copyProperties(vo, po);
|
|
if (po.getUrl() != null) {
|
|
if (po.getUrl() != null) {
|
|
- String url = accessPath + accessResource + po.getUrl().replace("/","");
|
|
|
|
- vo.setUrl(url);
|
|
|
|
|
|
+ vo.setUrl(CommonUtil.getDummyPath(po.getUrl()));
|
|
}
|
|
}
|
|
mainPhotos.add(vo);
|
|
mainPhotos.add(vo);
|
|
}
|
|
}
|