package com.zhazhapan.efo.service.impl;
import com.zhazhapan.efo.EfoApplication;
import com.zhazhapan.efo.config.SettingConfig;
import com.zhazhapan.efo.dao.DownloadedDAO;
import com.zhazhapan.efo.dao.FileDAO;
import com.zhazhapan.efo.entity.Category;
import com.zhazhapan.efo.entity.File;
import com.zhazhapan.efo.entity.User;
import com.zhazhapan.efo.model.AuthRecord;
import com.zhazhapan.efo.model.BaseAuthRecord;
import com.zhazhapan.efo.model.FileBasicRecord;
import com.zhazhapan.efo.model.FileRecord;
import com.zhazhapan.efo.modules.constant.ConfigConsts;
import com.zhazhapan.efo.modules.constant.DefaultValues;
import com.zhazhapan.efo.service.IAuthService;
import com.zhazhapan.efo.service.ICategoryService;
import com.zhazhapan.efo.service.IFileService;
import com.zhazhapan.efo.util.BeanUtils;
import com.zhazhapan.efo.util.ServiceUtils;
import com.zhazhapan.modules.constant.ValueConsts;
import com.zhazhapan.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;
/**
* @author pantao
* @since 2018/1/29
*/
@Service
public class FileServiceImpl implements IFileService {
private final static Logger logger = LoggerFactory.getLogger(FileServiceImpl.class);
private static final String FILE_SUFFIX = "{fileSuffix}";
private static final String RANDOM_ID = "{randomId}";
private static final String YEAR = "{year}";
private static final String MONTH = "{month}";
private static final String DAY = "{day}";
private static final String AUTHOR = "{author}";
private static final String FILE_NAME = "{fileName}";
private static final String CATEGORY_NAME = "{categoryName}";
private final FileDAO fileDAO;
private final ICategoryService categoryService;
private final IAuthService authService;
private final DownloadedDAO downloadDAO;
@Autowired
public FileServiceImpl(FileDAO fileDAO, ICategoryService categoryService, IAuthService authService,
DownloadedDAO downloadDAO) {
this.fileDAO = fileDAO;
this.categoryService = categoryService;
this.authService = authService;
this.downloadDAO = downloadDAO;
}
@Override
public boolean updateAuth(long id, String auth) {
int[] au = BeanUtils.getAuth(auth);
return fileDAO.updateAuthById(id, au[0], au[1], au[2], au[3], au[4]);
}
@Override
public BaseAuthRecord getAuth(long id) {
return fileDAO.getAuth(id);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor =
Exception.class)
public boolean deleteFiles(String ids) {
if (Checker.isNotEmpty(ids)) {
String[] id = ids.split(ValueConsts.COMMA_SIGN);
for (String s : id) {
long fileId = Formatter.stringToLong(s);
String localUrl = fileDAO.getLocalUrlById(fileId);
FileExecutor.deleteFile(localUrl);
removeById(fileId);
}
return true;
}
return false;
}
@Override
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor =
Exception.class)
public boolean[] updateUrl(int id, String oldLocalUrl, String localUrl, String visitUrl) {
boolean[] b = new boolean[]{false, false};
boolean canUpdateLocalUrl = Checker.isExists(oldLocalUrl) && Checker.isNotEmpty(localUrl) && Checker
.isNotExists(localUrl) && !localUrlExists(localUrl);
if (canUpdateLocalUrl) {
FileExecutor.renameTo(oldLocalUrl, localUrl);
fileDAO.updateLocalUrlById(id, localUrl);
b[0] = true;
}
if (Checker.isNotEmpty(visitUrl) && !visitUrlExists(visitUrl)) {
fileDAO.updateVisitUrlById(id, visitUrl);
b[1] = true;
}
return b;
}
@Override
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor =
Exception.class)
public boolean updateFileInfo(long id, User user, String name, String category, String tag, String description) {
File file = fileDAO.getById(id);
if (Checker.isNotNull(file) && file.getIsUpdatable() == 1) {
AuthRecord authRecord = authService.getByFileIdAndUserId(id, user.getId());
String suffix = FileExecutor.getFileSuffix(name);
boolean canUpdate = (Checker.isNull(authRecord) ? user.getIsUpdatable() == 1 :
authRecord.getIsUpdatable() == 1) && Checker.isNotEmpty(name) && Pattern.compile(EfoApplication.settings.getStringUseEval(ConfigConsts.FILE_SUFFIX_MATCH_OF_SETTING)).matcher(suffix).matches();
if (canUpdate) {
String localUrl = file.getLocalUrl();
java.io.File newFile = new java.io.File(localUrl);
String visitUrl = file.getVisitUrl();
String newLocalUrl = localUrl.substring(0, localUrl.lastIndexOf(ValueConsts.SEPARATOR) + 1) + name;
String newVisitUrl = visitUrl.substring(0, visitUrl.lastIndexOf(ValueConsts.SPLASH_STRING) + 1) + name;
file.setName(name);
file.setSuffix(suffix);
file.setLocalUrl(newLocalUrl);
file.setVisitUrl(newVisitUrl);
file.setCategoryId(categoryService.getIdByName(category));
file.setTag(tag);
file.setDescription(description);
boolean isValid = (localUrl.endsWith(ValueConsts.SEPARATOR + name) || (!Checker.isExists(newLocalUrl)
&& !localUrlExists(newLocalUrl) && !visitUrlExists(newVisitUrl)));
if (isValid && fileDAO.updateFileInfo(file)) {
return newFile.renameTo(new java.io.File(newLocalUrl));
}
}
}
return false;
}
@Override
public boolean removeFile(User user, long fileId) {
File file = fileDAO.getById(fileId);
boolean isDeleted = false;
if (Checker.isNotNull(file) && file.getIsDeletable() == 1) {
AuthRecord authRecord = authService.getByFileIdAndUserId(fileId, user.getId());
String localUrl = fileDAO.getLocalUrlById(fileId);
isDeleted = (Checker.isNull(authRecord) ? user.getIsDeletable() == 1 : authRecord.getIsDeletable() == 1)
&& removeById(fileId);
if (isDeleted) {
FileExecutor.deleteFile(localUrl);
}
}
return isDeleted;
}
@Override
public List<FileRecord> listUserDownloaded(int userId, int offset, String search) {
return fileDAO.listUserDownloaded(userId, offset, search);
}
@Override
public List<FileRecord> listUserUploaded(int userId, int offset, String search) {
return fileDAO.listUserUploaded(userId, offset, search);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor =
Exception.class)
public boolean removeById(long id) {
downloadDAO.removeByFileId(id);
authService.removeByFileId(id);
return fileDAO.removeById(id);
}
@Override
public boolean removeByVisitUrl(String visitUrl) {
long fileId = fileDAO.getIdByVisitUrl(visitUrl);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
efo-master.zip (178个子文件)
efo.mwb.bak 17KB
mvnw.cmd 5KB
bootstrap.min.css 171KB
bootstrap.min.css 139KB
fontawesome-all.css 44KB
pretty-checkbox.min.css 23KB
glyphicons.css 15KB
layer.css 14KB
iconfont.css 14KB
fileinput.min.css 11KB
angular-filemanager.min.css 8KB
layer.css 5KB
nav.css 3KB
style.css 1KB
glyphicons-regular.eot 143KB
fa-solid-900.eot 100KB
fa-brands-400.eot 96KB
fa-regular-400.eot 30KB
glyphicons-halflings-regular.eot 20KB
iconfont.eot 0B
loading-sm.gif 1.48MB
loading.gif 1.48MB
loading-0.gif 6KB
loading-2.gif 2KB
loading-1.gif 701B
.gitignore 850B
404.html 44KB
admin.html 42KB
index.html 15KB
signin.html 7KB
upload.html 3KB
filemanager.html 2KB
error.html 301B
efo.iml 16KB
maven-wrapper.jar 46KB
FileServiceImpl.java 17KB
UserController.java 12KB
FileController.java 11KB
FileDAO.java 10KB
FileManagerServiceImpl.java 9KB
UserServiceImpl.java 6KB
FileMangerController.java 6KB
FileRecord.java 6KB
File.java 6KB
ConfigConsts.java 5KB
IFileService.java 5KB
UserDAO.java 5KB
FileSqlProvider.java 5KB
User.java 4KB
CommonController.java 4KB
ConfigController.java 4KB
AuthServiceImpl.java 3KB
IUserService.java 3KB
WebInterceptor.java 3KB
AuthDAO.java 3KB
AuthController.java 3KB
AuthRecord.java 3KB
Auth.java 3KB
CategoryController.java 3KB
SettingConfig.java 3KB
IFileManagerService.java 3KB
TokenConfig.java 3KB
ControllerUtils.java 2KB
DownloadRecord.java 2KB
CategoryDAO.java 2KB
CommonServiceImpl.java 2KB
UploadedRecord.java 2KB
ServiceUtils.java 2KB
BeanUtils.java 2KB
ViewController.java 2KB
WebMvcConfig.java 2KB
FileBasicRecord.java 2KB
IAuthService.java 2KB
AuthSqlProvider.java 2KB
DownloadedDAO.java 2KB
DownloadedSqlProvider.java 2KB
DownloadedController.java 2KB
UploadedSqlProvider.java 2KB
UploadedController.java 2KB
UserDAOTest.java 2KB
DefaultValues.java 2KB
CategoryServiceImpl.java 2KB
EfoApplication.java 2KB
UserSqlProvider.java 1KB
BaseAuthRecord.java 1KB
CommonTest.java 1KB
GlobalExceptionHandler.java 1KB
Download.java 1KB
CustomErrorController.java 1KB
UploadedDAO.java 1KB
DownloadedServiceImpl.java 1KB
CategoryDAOTest.java 1KB
ConfigServiceImpl.java 1KB
ICategoryService.java 1KB
Category.java 1KB
FileSqlProviderTest.java 1023B
UploadedServiceImpl.java 926B
IDownloadedService.java 819B
FileDAOTest.java 791B
DownloadedDAOTest.java 753B
共 178 条
- 1
- 2
资源评论
m0_72731342
- 粉丝: 2
- 资源: 1832
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功