|
|
@ -20,7 +20,6 @@ import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.redis.RedisKeys; |
|
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constants.PrivacyType; |
|
|
|
import com.epmet.dao.OssDao; |
|
|
@ -37,9 +36,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class OssServiceImpl extends BaseServiceImpl<OssDao, OssEntity> implements OssService { |
|
|
@ -194,22 +191,24 @@ public class OssServiceImpl extends BaseServiceImpl<OssDao, OssEntity> implement |
|
|
|
@Override |
|
|
|
public boolean articleRemoveFile(RemoveFileFormDTO formDTO) { |
|
|
|
logger.info("articleRemoveFile param:{}", JSON.toJSONString(formDTO)); |
|
|
|
String[] strings = formDTO.getUrl().split(StrConstant.SEPARATOR); |
|
|
|
String fileName = strings[strings.length - 1]; |
|
|
|
AbstractCloudStorageService build = OssFactory.build(); |
|
|
|
String ossDomain = build.getOssDomain(null); |
|
|
|
String fileName = formDTO.getUrl().replace(ossDomain, StrConstant.EPMETY_STR); |
|
|
|
if (fileName.startsWith(StrConstant.SEPARATOR)){ |
|
|
|
fileName = fileName.replaceFirst(StrConstant.SEPARATOR,StrConstant.EPMETY_STR); |
|
|
|
} |
|
|
|
String key = RedisKeys.getOssFileKey(fileName); |
|
|
|
Object o = redisUtils.get(key); |
|
|
|
if (o == null){ |
|
|
|
//return false;
|
|
|
|
} |
|
|
|
logger.info("articleRemoveFile oss delete fileName:{}", fileName); |
|
|
|
OssFactory.build().delete(fileName,null); |
|
|
|
OssEntity entity = baseDao.selectByUrl(formDTO.getUrl()); |
|
|
|
long thirty = 30*60*1000; |
|
|
|
Date now = new Date(); |
|
|
|
long time = now.getTime() - entity.getCreatedTime().getTime(); |
|
|
|
if (time > thirty) { |
|
|
|
return false; |
|
|
|
if (entity != null){ |
|
|
|
baseDao.deleteDataById(entity.getId()); |
|
|
|
} |
|
|
|
baseDao.deleteDataById(entity.getId()); |
|
|
|
String dateStr = DateUtils.format(entity.getCreatedTime(), DateUtils.DATE_PATTERN_YYYYMMDD); |
|
|
|
fileName = StrConstant.SEPARATOR + dateStr + StrConstant.SEPARATOR + fileName; |
|
|
|
String key = RedisKeys.getOssFileKey(formDTO.getUrl()); |
|
|
|
redisUtils.delete(key); |
|
|
|
logger.info("articleRemoveFile oss delete fileName:{}", JSON.toJSONString(fileName)); |
|
|
|
return Objects.requireNonNull(OssFactory.build()).delete(fileName,null); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|