|
|
@ -14,11 +14,16 @@ import com.epmet.cloud.AbstractCloudStorageService; |
|
|
|
import com.epmet.cloud.OssFactory; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.Constant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
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; |
|
|
|
import com.epmet.dto.form.RemoveFileFormDTO; |
|
|
|
import com.epmet.dto.result.UploadImgResultDTO; |
|
|
|
import com.epmet.entity.OssEntity; |
|
|
|
import com.epmet.exception.ModuleErrorCode; |
|
|
@ -26,15 +31,22 @@ import com.epmet.service.OssService; |
|
|
|
import org.apache.commons.io.FilenameUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
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 { |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(OssServiceImpl.class); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<OssEntity> page(Map<String, Object> params) { |
|
|
|
IPage<OssEntity> page = baseDao.selectPage( |
|
|
@ -161,6 +173,7 @@ public class OssServiceImpl extends BaseServiceImpl<OssDao, OssEntity> implement |
|
|
|
} |
|
|
|
//保存文件信息
|
|
|
|
OssEntity ossEntity = new OssEntity(); |
|
|
|
|
|
|
|
ossEntity.setUrl(url); |
|
|
|
baseDao.insert(ossEntity); |
|
|
|
//文件信息
|
|
|
@ -169,4 +182,32 @@ public class OssServiceImpl extends BaseServiceImpl<OssDao, OssEntity> implement |
|
|
|
return new Result<UploadImgResultDTO>().ok(dto); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 删除附件 |
|
|
|
* |
|
|
|
* @return boolean |
|
|
|
* @author zhaoqifeng |
|
|
|
* @date 2021/3/30 9:55 |
|
|
|
* @param formDTO |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public boolean articleRemoveFile(RemoveFileFormDTO formDTO) { |
|
|
|
String[] strings = formDTO.getUrl().split(StrConstant.SEPARATOR); |
|
|
|
String fileName = strings[strings.length - 1]; |
|
|
|
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; |
|
|
|
} |
|
|
|
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); |
|
|
|
return Objects.requireNonNull(OssFactory.build()).delete(fileName); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|