🔥 删除无效文件

This commit is contained in:
ronger 2020-11-20 18:32:41 +08:00
parent 7a39eb3293
commit ee3afcd7f8
6 changed files with 3 additions and 407 deletions

View File

@ -1,4 +1,4 @@
package com.rymcu.vertical.dto;
package com.rymcu.forest.dto;
import lombok.Data;

View File

@ -1,6 +1,6 @@
package com.rymcu.vertical.dto;
package com.rymcu.forest.dto;
import com.rymcu.vertical.entity.Notification;
import com.rymcu.forest.entity.Notification;
import lombok.Data;
import lombok.EqualsAndHashCode;

View File

@ -1,23 +0,0 @@
package com.rymcu.vertical.service;
import com.rymcu.vertical.core.service.Service;
import com.rymcu.vertical.entity.Permission;
import com.rymcu.vertical.entity.User;
import java.util.List;
/**
*
* @author CodeGenerator
* @date 2018/05/29
*/
public interface PermissionService extends Service<Permission> {
/**
* 获取用户权限
* @param sysUser
* @return
*/
List<Permission> selectPermissionByUser(User sysUser);
}

View File

@ -1,135 +0,0 @@
package com.rymcu.vertical.service.impl;
import com.rymcu.vertical.core.service.AbstractService;
import com.rymcu.vertical.dto.ArticleDTO;
import com.rymcu.vertical.dto.Author;
import com.rymcu.vertical.dto.NotificationDTO;
import com.rymcu.vertical.entity.Comment;
import com.rymcu.vertical.entity.Follow;
import com.rymcu.vertical.entity.Notification;
import com.rymcu.vertical.entity.User;
import com.rymcu.vertical.mapper.NotificationMapper;
import com.rymcu.vertical.service.*;
import com.rymcu.vertical.util.BeanCopierUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* @author ronger
*/
@Service
public class NotificationServiceImpl extends AbstractService<Notification> implements NotificationService {
@Resource
private NotificationMapper notificationMapper;
@Resource
private ArticleService articleService;
@Resource
private CommentService commentService;
@Resource
private UserService userService;
@Resource
private FollowService followService;
@Value("${resource.domain}")
private String domain;
@Override
public List<Notification> findUnreadNotifications(Integer idUser) {
List<Notification> list = notificationMapper.selectUnreadNotifications(idUser);
return list;
}
@Override
public List<NotificationDTO> findNotifications(Integer idUser) {
List<Notification> list = notificationMapper.selectNotifications(idUser);
List<NotificationDTO> notifications = new ArrayList<>();
list.forEach(notification -> {
NotificationDTO notificationDTO = genNotification(notification);
notifications.add(notificationDTO);
});
return notifications;
}
private NotificationDTO genNotification(Notification notification) {
NotificationDTO notificationDTO = new NotificationDTO();
BeanCopierUtil.copy(notification, notificationDTO);
ArticleDTO article;
Comment comment;
User user;
Follow follow;
switch (notification.getDataType()) {
case "0":
// 系统公告/帖子
article = articleService.findArticleDTOById(notification.getDataId(), 0);
notificationDTO.setDataTitle("系统公告");
notificationDTO.setDataUrl(article.getArticlePermalink());
user = userService.findById(article.getArticleAuthorId().toString());
notificationDTO.setAuthor(genAuthor(user));
break;
case "1":
// 关注
follow = followService.findById(notification.getDataId().toString());
notificationDTO.setDataTitle("关注提醒");
user = userService.findById(follow.getFollowerId().toString());
notificationDTO.setDataUrl(getFollowLink(follow.getFollowingType(), user.getNickname()));
notificationDTO.setAuthor(genAuthor(user));
break;
case "2":
// 回帖
comment = commentService.findById(notification.getDataId().toString());
article = articleService.findArticleDTOById(comment.getCommentArticleId(), 0);
notificationDTO.setDataTitle(article.getArticleTitle());
notificationDTO.setDataUrl(comment.getCommentSharpUrl());
user = userService.findById(comment.getCommentAuthorId().toString());
notificationDTO.setAuthor(genAuthor(user));
break;
default:
break;
}
return notificationDTO;
}
private String getFollowLink(String followingType, String id) {
StringBuilder url = new StringBuilder();
url.append(domain);
switch (followingType) {
case "0":
url = url.append("/user/").append(id);
break;
default:
url.append("/notification");
}
return url.toString();
}
private Author genAuthor(User user) {
Author author = new Author();
author.setUserNickname(user.getNickname());
author.setUserAvatarURL(user.getAvatarUrl());
author.setIdUser(user.getIdUser());
return author;
}
@Override
public Notification findNotification(Integer idUser, Integer dataId, String dataType) {
return notificationMapper.selectNotification(idUser, dataId, dataType);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Integer save(Integer idUser, Integer dataId, String dataType, String dataSummary) {
return notificationMapper.insertNotification(idUser, dataId, dataType, dataSummary);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Integer readNotification(Integer id) {
return notificationMapper.readNotification(id);
}
}

View File

@ -1,174 +0,0 @@
package com.rymcu.vertical.web.api.common;
import com.rymcu.vertical.core.result.GlobalResult;
import com.rymcu.vertical.core.result.GlobalResultGenerator;
import com.rymcu.vertical.dto.TokenUser;
import com.rymcu.vertical.jwt.def.JwtConstants;
import com.rymcu.vertical.util.FileUtils;
import com.rymcu.vertical.util.UserUtils;
import com.rymcu.vertical.util.Utils;
import com.rymcu.vertical.web.api.exception.ErrorCode;
import com.rymcu.vertical.web.api.exception.BaseApiException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* 文件上传控制器
*
* @author ronger
*/
@RestController
@RequestMapping("/api/v1/upload")
public class UploadController {
private final static String UPLOAD_SIMPLE_URL = "/api/upload/file";
private final static String UPLOAD_URL = "/api/upload/file/batch";
public static final String ctxHeadPicPath = "/usr/local/src/nebula/static";
@PostMapping("/file")
public GlobalResult uploadPicture(@RequestParam(value = "file", required = false) MultipartFile multipartFile, @RequestParam(defaultValue = "1") Integer type, HttpServletRequest request) {
if (multipartFile == null) {
return GlobalResultGenerator.genErrorResult("请选择要上传的文件");
}
String typePath = getTypePath(type);
//图片存储路径
String dir = ctxHeadPicPath + "/" + typePath;
File file = new File(dir);
if (!file.exists()) {
file.mkdirs();// 创建文件根目录
}
String localPath = Utils.getProperty("resource.file-path") + "/" + typePath + "/";
String orgName = multipartFile.getOriginalFilename();
String fileName = System.currentTimeMillis() + "." + FileUtils.getExtend(orgName).toLowerCase();
String savePath = file.getPath() + File.separator + fileName;
Map data = new HashMap(2);
File saveFile = new File(savePath);
try {
FileCopyUtils.copy(multipartFile.getBytes(), saveFile);
data.put("url", localPath + fileName);
} catch (IOException e) {
data.put("message", "上传失败!");
}
return GlobalResultGenerator.genSuccessResult(data);
}
@PostMapping("/file/batch")
public GlobalResult batchFileUpload(@RequestParam(value = "file[]", required = false) MultipartFile[] multipartFiles, @RequestParam(defaultValue = "1") Integer type, HttpServletRequest request) {
String typePath = getTypePath(type);
//图片存储路径
String dir = ctxHeadPicPath + "/" + typePath;
File file = new File(dir);
if (!file.exists()) {
file.mkdirs();// 创建文件根目录
}
String localPath = Utils.getProperty("resource.file-path") + "/" + typePath + "/";
Map succMap = new HashMap(10);
Set errFiles = new HashSet();
for (int i = 0, len = multipartFiles.length; i < len; i++) {
MultipartFile multipartFile = multipartFiles[i];
String orgName = multipartFile.getOriginalFilename();
String fileName = System.currentTimeMillis() + "." + FileUtils.getExtend(orgName).toLowerCase();
String savePath = file.getPath() + File.separator + fileName;
File saveFile = new File(savePath);
try {
FileCopyUtils.copy(multipartFile.getBytes(), saveFile);
succMap.put(orgName, localPath + fileName);
} catch (IOException e) {
errFiles.add(orgName);
}
}
Map data = new HashMap(2);
data.put("errFiles", errFiles);
data.put("succMap", succMap);
return GlobalResultGenerator.genSuccessResult(data);
}
private static String getTypePath(Integer type) {
String typePath;
switch (type) {
case 0:
typePath = "avatar";
break;
case 1:
typePath = "article";
break;
case 2:
typePath = "tags";
break;
default:
typePath = "images";
}
return typePath;
}
@GetMapping("/simple/token")
public GlobalResult uploadSimpleToken(HttpServletRequest request) throws BaseApiException {
String authHeader = request.getHeader(JwtConstants.AUTHORIZATION);
if (StringUtils.isBlank(authHeader)) {
throw new BaseApiException(ErrorCode.UNAUTHORIZED);
}
TokenUser tokenUser = UserUtils.getTokenUser(authHeader);
Map map = new HashMap(2);
map.put("uploadToken", tokenUser.getToken());
map.put("uploadURL", UPLOAD_SIMPLE_URL);
return GlobalResultGenerator.genSuccessResult(map);
}
@GetMapping("/token")
public GlobalResult uploadToken(HttpServletRequest request) throws BaseApiException {
String authHeader = request.getHeader(JwtConstants.AUTHORIZATION);
if (StringUtils.isBlank(authHeader)) {
throw new BaseApiException(ErrorCode.UNAUTHORIZED);
}
TokenUser tokenUser = UserUtils.getTokenUser(authHeader);
Map map = new HashMap(2);
map.put("uploadToken", tokenUser.getToken());
map.put("uploadURL", UPLOAD_URL);
return GlobalResultGenerator.genSuccessResult(map);
}
public static String uploadBase64File(String fileStr, Integer type) {
if (StringUtils.isBlank(fileStr)) {
return "";
}
String typePath = getTypePath(type);
//图片存储路径
String dir = ctxHeadPicPath + "/" + typePath;
File file = new File(dir);
if (!file.exists()) {
file.mkdirs();// 创建文件根目录
}
String localPath = Utils.getProperty("resource.file-path") + "/" + typePath + "/";
String fileName = System.currentTimeMillis() + ".png";
String savePath = file.getPath() + File.separator + fileName;
File saveFile = new File(savePath);
try {
FileCopyUtils.copy(Base64.decodeBase64(fileStr.substring(fileStr.indexOf(",") + 1)), saveFile);
fileStr = localPath + fileName;
} catch (IOException e) {
fileStr = "上传失败!";
}
return fileStr;
}
}

View File

@ -1,72 +0,0 @@
package com.rymcu.vertical.web.api.user;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rymcu.vertical.core.result.GlobalResult;
import com.rymcu.vertical.core.result.GlobalResultGenerator;
import com.rymcu.vertical.core.service.log.annotation.VisitLogger;
import com.rymcu.vertical.dto.ArticleDTO;
import com.rymcu.vertical.dto.PortfolioDTO;
import com.rymcu.vertical.dto.UserDTO;
import com.rymcu.vertical.service.ArticleService;
import com.rymcu.vertical.service.PortfolioService;
import com.rymcu.vertical.service.UserService;
import com.rymcu.vertical.util.Utils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author ronger
*/
@RestController
@RequestMapping("/api/v1/user")
public class UserController {
@Resource
private UserService userService;
@Resource
private ArticleService articleService;
@Resource
private PortfolioService portfolioService;
@GetMapping("/{nickname}")
@VisitLogger
public GlobalResult detail(@PathVariable String nickname){
UserDTO userDTO = userService.findUserDTOByNickname(nickname);
return GlobalResultGenerator.genSuccessResult(userDTO);
}
@GetMapping("/{nickname}/articles")
public GlobalResult userArticles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){
UserDTO userDTO = userService.findUserDTOByNickname(nickname);
if (userDTO == null){
return GlobalResultGenerator.genErrorResult("用户不存在!");
}
PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findUserArticlesByIdUser(userDTO.getIdUser());
PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
}
@GetMapping("/{nickname}/portfolios")
public GlobalResult userPortfolios(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){
UserDTO userDTO = userService.findUserDTOByNickname(nickname);
if (userDTO == null){
return GlobalResultGenerator.genErrorResult("用户不存在!");
}
PageHelper.startPage(page, rows);
List<PortfolioDTO> list = portfolioService.findUserPortfoliosByUser(userDTO);
PageInfo<PortfolioDTO> pageInfo = new PageInfo(list);
Map map = new HashMap(2);
map.put("portfolios", list);
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
}
}