🎨 代码优化

This commit is contained in:
ronger 2022-08-17 09:46:19 +08:00
parent d31822133c
commit 42eaab1a87
17 changed files with 199 additions and 129 deletions

View File

@ -1,7 +1,7 @@
package com.rymcu.forest.config;
import com.alibaba.fastjson.support.spring.FastJsonJsonView;
import com.rymcu.forest.core.exception.DataDuplicationException;
import com.rymcu.forest.core.exception.BusinessException;
import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.core.exception.TransactionException;
import com.rymcu.forest.core.result.GlobalResult;
@ -63,7 +63,7 @@ public class BaseExceptionHandler {
} else if (ex instanceof ServletException) {
result.setCode(ResultCode.FAIL.getCode());
result.setMessage(ex.getMessage());
} else if (ex instanceof DataDuplicationException) {
} else if (ex instanceof BusinessException) {
result.setCode(ResultCode.FAIL.getCode());
result.setMessage(ex.getMessage());
} else if (ex instanceof TransactionException) {
@ -112,7 +112,7 @@ public class BaseExceptionHandler {
} else if (ex instanceof ServletException) {
attributes.put("code", ResultCode.FAIL.getCode());
attributes.put("message", ex.getMessage());
} else if (ex instanceof DataDuplicationException) {
} else if (ex instanceof BusinessException) {
attributes.put("code", ResultCode.FAIL.getCode());
attributes.put("message", ex.getMessage());
} else if (ex instanceof TransactionException) {

View File

@ -0,0 +1,28 @@
package com.rymcu.forest.core.exception;
/**
* @author KKould
*/
public class BusinessException extends RuntimeException {
private static final long serialVersionUID = 3206744387536223284L;
public BusinessException() {
}
public BusinessException(String message) {
super(message);
}
public BusinessException(String message, Throwable cause) {
super(message, cause);
}
public BusinessException(Throwable cause) {
super(cause);
}
public BusinessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -1,6 +1,9 @@
package com.rymcu.forest.core.exception;
public class ContentNotExistException extends RuntimeException{
/**
* @author KKould
*/
public class ContentNotExistException extends BusinessException {
private static final long serialVersionUID = 3206734387536223284L;
public ContentNotExistException() {

View File

@ -1,28 +0,0 @@
package com.rymcu.forest.core.exception;
/**
* @author KKould
*/
public class DataDuplicationException extends RuntimeException {
private static final long serialVersionUID = 3206744387536223284L;
public DataDuplicationException() {
}
public DataDuplicationException(String message) {
super(message);
}
public DataDuplicationException(String message, Throwable cause) {
super(message, cause);
}
public DataDuplicationException(Throwable cause) {
super(cause);
}
public DataDuplicationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -1,6 +1,9 @@
package com.rymcu.forest.core.exception;
public class UltraViresException extends RuntimeException {
/**
* @author KKould
*/
public class UltraViresException extends BusinessException {
private static final long serialVersionUID = 3206744387536228284L;

View File

@ -0,0 +1,57 @@
package com.rymcu.forest.handler;
import com.rymcu.forest.core.constant.NotificationConstant;
import com.rymcu.forest.entity.Comment;
import com.rymcu.forest.handler.event.CommentEvent;
import com.rymcu.forest.mapper.CommentMapper;
import com.rymcu.forest.util.Html2TextUtil;
import com.rymcu.forest.util.NotificationUtils;
import com.rymcu.forest.wx.mp.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* Created on 2022/8/17 7:38.
*
* @author ronger
* @email ronger-x@outlook.com
* @packageName com.rymcu.forest.handler
*/
@Slf4j
@Component
public class CommentHandler {
private static final int MAX_PREVIEW = 200;
@Resource
private CommentMapper commentMapper;
@Async
@EventListener
public void processCommentCreatedEvent(CommentEvent commentEvent) throws InterruptedException {
log.info(String.format("开始执行评论发布事件:[%s]", JsonUtils.toJson(commentEvent)));
String commentContent = commentEvent.getContent();
Integer length = commentContent.length();
if (length > MAX_PREVIEW) {
length = 200;
}
String commentPreviewContent = commentContent.substring(0, length);
commentContent = Html2TextUtil.getContent(commentPreviewContent);
// 判断是否是回复消息
if (commentEvent.getCommentOriginalCommentId() != null && commentEvent.getCommentOriginalCommentId() != 0) {
Comment originalComment = commentMapper.selectByPrimaryKey(commentEvent.getCommentOriginalCommentId());
// 回复消息时,评论者不是上级评论作者则进行消息通知
if (!commentEvent.getCommentAuthorId().equals(originalComment.getCommentAuthorId())) {
NotificationUtils.saveNotification(originalComment.getCommentAuthorId(), commentEvent.getIdComment(), NotificationConstant.Comment, commentContent);
}
} else {
// 评论者不是作者本人则进行消息通知
if (!commentEvent.getCommentAuthorId().equals(commentEvent.getArticleAuthorId())) {
NotificationUtils.saveNotification(commentEvent.getArticleAuthorId(), commentEvent.getIdComment(), NotificationConstant.Comment, commentContent);
}
}
}
}

View File

@ -0,0 +1,26 @@
package com.rymcu.forest.handler.event;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* Created on 2022/8/17 7:43.
*
* @author ronger
* @email ronger-x@outlook.com
* @packageName com.rymcu.forest.handler.event
*/
@Data
@AllArgsConstructor
public class CommentEvent {
private Long idComment;
private Long articleAuthorId;
private Long commentAuthorId;
private String content;
private Long commentOriginalCommentId;
}

View File

@ -3,11 +3,9 @@ package com.rymcu.forest.service;
import com.rymcu.forest.core.service.Service;
import com.rymcu.forest.dto.CommentDTO;
import com.rymcu.forest.entity.Comment;
import com.rymcu.forest.web.api.exception.BaseApiException;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* @author ronger
@ -27,7 +25,7 @@ public interface CommentService extends Service<Comment> {
* @param request
* @return
*/
Map postComment(Comment comment, HttpServletRequest request) throws BaseApiException;
Comment postComment(Comment comment, HttpServletRequest request);
/**
* 获取评论列表数据

View File

@ -71,12 +71,18 @@ public interface PortfolioService extends Service<Portfolio> {
*/
Map unbindArticle(Long idPortfolio, Long idArticle);
/**
* 删除作品集
*
* @param idPortfolio
* @param idUser
* @param roleWeights
* @return
* @throws BaseApiException
* @throws IllegalAccessException
*/
Map deletePortfolio(Long idPortfolio) throws BaseApiException;
boolean deletePortfolio(Long idPortfolio, Long idUser, Integer roleWeights) throws BaseApiException, IllegalAccessException;
/**
* 获取作品集列表数据

View File

@ -40,7 +40,7 @@ public interface UserService extends Service<User> {
* @param password 密码
* @return Map
* */
Map login(String account, String password);
TokenUser login(String account, String password);
/**
* 通过 account 获取用户信息接口

View File

@ -2,7 +2,7 @@ package com.rymcu.forest.service.impl;
import com.rymcu.forest.core.constant.NotificationConstant;
import com.rymcu.forest.core.exception.ContentNotExistException;
import com.rymcu.forest.core.exception.DataDuplicationException;
import com.rymcu.forest.core.exception.BusinessException;
import com.rymcu.forest.core.exception.UltraViresException;
import com.rymcu.forest.core.service.AbstractService;
import com.rymcu.forest.dto.*;
@ -28,7 +28,6 @@ import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Condition;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.*;
@ -199,7 +198,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
luceneService.deleteArticle(id);
return result;
} else {
throw new DataDuplicationException("已有评论的文章不允许删除!");
throw new BusinessException("已有评论的文章不允许删除!");
}
}

View File

@ -1,23 +1,26 @@
package com.rymcu.forest.service.impl;
import com.rymcu.forest.core.constant.NotificationConstant;
import com.rymcu.forest.core.exception.ContentNotExistException;
import com.rymcu.forest.core.service.AbstractService;
import com.rymcu.forest.dto.Author;
import com.rymcu.forest.dto.CommentDTO;
import com.rymcu.forest.entity.Article;
import com.rymcu.forest.entity.Comment;
import com.rymcu.forest.handler.event.CommentEvent;
import com.rymcu.forest.mapper.CommentMapper;
import com.rymcu.forest.service.ArticleService;
import com.rymcu.forest.service.CommentService;
import com.rymcu.forest.util.*;
import com.rymcu.forest.web.api.exception.BaseApiException;
import com.rymcu.forest.util.Utils;
import com.rymcu.forest.util.XssUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.Date;
import java.util.List;
/**
* @author ronger
@ -29,8 +32,8 @@ public class CommentServiceImpl extends AbstractService<Comment> implements Comm
private CommentMapper commentMapper;
@Resource
private ArticleService articleService;
private static final int MAX_PREVIEW = 200;
@Resource
private ApplicationEventPublisher applicationEventPublisher;
@Override
public List<CommentDTO> getArticleComments(Integer idArticle) {
@ -63,25 +66,19 @@ public class CommentServiceImpl extends AbstractService<Comment> implements Comm
@Override
@Transactional(rollbackFor = Exception.class)
public Map postComment(Comment comment, HttpServletRequest request) throws BaseApiException {
comment.setCommentAuthorId(Objects.requireNonNull(UserUtils.getCurrentUserByToken()).getIdUser());
Map map = new HashMap(1);
public Comment postComment(Comment comment, HttpServletRequest request) {
if (comment.getCommentArticleId() == null) {
map.put("message", "非法访问,文章主键异常!");
return map;
throw new IllegalArgumentException("非法访问,文章主键异常!");
}
if (comment.getCommentAuthorId() == null) {
map.put("message", "非法访问,用户未登录!");
return map;
throw new IllegalArgumentException("非法访问,用户未登录!");
}
if (StringUtils.isBlank(comment.getCommentContent())) {
map.put("message", "回帖内容不能为空!");
return map;
throw new IllegalArgumentException("回帖内容不能为空!");
}
Article article = articleService.findById(comment.getCommentArticleId().toString());
if (article == null) {
map.put("message", "文章不存在!");
return map;
throw new ContentNotExistException("文章不存在!");
}
String ip = Utils.getIpAddress(request);
String ua = request.getHeader("user-agent");
@ -95,28 +92,9 @@ public class CommentServiceImpl extends AbstractService<Comment> implements Comm
String commentContent = comment.getCommentContent();
if (StringUtils.isNotBlank(commentContent)) {
Integer length = commentContent.length();
if (length > MAX_PREVIEW) {
length = 200;
}
String commentPreviewContent = commentContent.substring(0, length);
commentContent = Html2TextUtil.getContent(commentPreviewContent);
// 评论者不是作者本人则进行消息通知
if (!article.getArticleAuthorId().equals(comment.getCommentAuthorId())) {
NotificationUtils.saveNotification(article.getArticleAuthorId(), comment.getIdComment(), NotificationConstant.Comment, commentContent);
}
// 判断是否是回复消息
if (comment.getCommentOriginalCommentId() != null && comment.getCommentOriginalCommentId() != 0) {
Comment originalComment = commentMapper.selectByPrimaryKey(comment.getCommentOriginalCommentId());
// 回复消息时,评论者不是上级评论作者则进行消息通知
if (!comment.getCommentAuthorId().equals(originalComment.getCommentAuthorId())) {
NotificationUtils.saveNotification(originalComment.getCommentAuthorId(), comment.getIdComment(), NotificationConstant.Comment, commentContent);
}
}
applicationEventPublisher.publishEvent(new CommentEvent(comment.getIdComment(), article.getArticleAuthorId(), comment.getCommentAuthorId(), commentContent, comment.getCommentOriginalCommentId()));
}
return map;
return comment;
}
@Override

View File

@ -2,6 +2,7 @@ package com.rymcu.forest.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rymcu.forest.core.exception.BusinessException;
import com.rymcu.forest.core.service.AbstractService;
import com.rymcu.forest.dto.*;
import com.rymcu.forest.entity.Portfolio;
@ -44,7 +45,7 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
List<PortfolioDTO> list = portfolioMapper.selectUserPortfoliosByIdUser(userDTO.getIdUser());
Author author = userService.selectAuthor(userDTO.getIdUser());
list.forEach(portfolioDTO -> {
genPortfolioAuthor(portfolioDTO,author);
genPortfolioAuthor(portfolioDTO, author);
Integer articleNumber = portfolioMapper.selectCountArticleNumber(portfolioDTO.getIdPortfolio());
portfolioDTO.setArticleNumber(articleNumber);
});
@ -53,12 +54,12 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
@Override
public PortfolioDTO findPortfolioDTOById(Long idPortfolio, Integer type) {
PortfolioDTO portfolio = portfolioMapper.selectPortfolioDTOById(idPortfolio,type);
PortfolioDTO portfolio = portfolioMapper.selectPortfolioDTOById(idPortfolio, type);
if (portfolio == null) {
return new PortfolioDTO();
}
Author author = userService.selectAuthor(portfolio.getPortfolioAuthorId());
genPortfolioAuthor(portfolio,author);
genPortfolioAuthor(portfolio, author);
Integer articleNumber = portfolioMapper.selectCountArticleNumber(portfolio.getIdPortfolio());
portfolio.setArticleNumber(articleNumber);
return portfolio;
@ -109,7 +110,7 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
map.put("message", "非法操作!");
} else {
PageHelper.startPage(page, rows);
List<ArticleDTO> articles = articleService.selectUnbindArticles(idPortfolio,searchText,user.getIdUser());
List<ArticleDTO> articles = articleService.selectUnbindArticles(idPortfolio, searchText, user.getIdUser());
PageInfo<ArticleDTO> pageInfo = new PageInfo(articles);
map = Utils.getArticlesGlobalResult(pageInfo);
}
@ -123,7 +124,7 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
Integer count = portfolioMapper.selectCountPortfolioArticle(portfolioArticle.getIdArticle(), portfolioArticle.getIdPortfolio());
if (count.equals(0)) {
Integer maxSortNo = portfolioMapper.selectMaxSortNo(portfolioArticle.getIdPortfolio());
portfolioMapper.insertPortfolioArticle(portfolioArticle.getIdArticle(),portfolioArticle.getIdPortfolio(),maxSortNo);
portfolioMapper.insertPortfolioArticle(portfolioArticle.getIdArticle(), portfolioArticle.getIdPortfolio(), maxSortNo);
map.put("message", "绑定成功!");
} else {
map.put("message", "该文章已经在作品集下!!");
@ -143,7 +144,7 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
if (portfolioArticle.getSortNo() == null) {
map.put("message", "排序号不能为空!");
}
Integer result = portfolioMapper.updateArticleSortNo(portfolioArticle.getIdPortfolio(),portfolioArticle.getIdArticle(),portfolioArticle.getSortNo());
Integer result = portfolioMapper.updateArticleSortNo(portfolioArticle.getIdPortfolio(), portfolioArticle.getIdArticle(), portfolioArticle.getSortNo());
if (result > 0) {
map.put("message", "更新成功!");
} else {
@ -161,7 +162,7 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
if (idArticle == null || idArticle.equals(0)) {
map.put("message", "文章数据异常");
}
Integer result = portfolioMapper.unbindArticle(idPortfolio,idArticle);
Integer result = portfolioMapper.unbindArticle(idPortfolio, idArticle);
if (result > 0) {
map.put("message", "操作成功!");
} else {
@ -171,35 +172,29 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
}
@Override
public Map deletePortfolio(Long idPortfolio) throws BaseApiException {
Map map = new HashMap(1);
if (idPortfolio == null || idPortfolio.equals(0)) {
map.put("message", "作品集数据异常");
public boolean deletePortfolio(Long idPortfolio, Long idUser, Integer roleWeights) throws BaseApiException, IllegalAccessException {
if (idPortfolio == null || idPortfolio == 0) {
throw new IllegalArgumentException("作品集数据异常!");
}
// 鉴权
User user = UserUtils.getCurrentUserByToken();
Integer roleWeights = userService.findRoleWeightsByUser(user.getIdUser());
if (roleWeights > 2) {
Portfolio portfolio = portfolioMapper.selectByPrimaryKey(idPortfolio);
if (!user.getIdUser().equals(portfolio.getPortfolioAuthorId())) {
map.put("message", "非法访问!");
return map;
if (!idUser.equals(portfolio.getPortfolioAuthorId())) {
throw new IllegalAccessException("非法访问!");
}
}
Integer articleNumber = portfolioMapper.selectCountArticleNumber(idPortfolio);
if (articleNumber > 0) {
map.put("message", "该作品集已绑定文章不允许删除!");
throw new BusinessException("该作品集已绑定文章不允许删除!");
} else {
Integer result = portfolioMapper.deleteByPrimaryKey(idPortfolio);
if (result.equals(0)) {
map.put("message", "操作失败!");
}else {
PortfolioIndexUtil.deleteIndex(idPortfolio);
throw new BusinessException("操作失败!");
}
PortfolioIndexUtil.deleteIndex(idPortfolio);
return true;
}
return map;
}
@Override

View File

@ -1,5 +1,7 @@
package com.rymcu.forest.service.impl;
import com.rymcu.forest.core.exception.CaptchaException;
import com.rymcu.forest.core.exception.ContentNotExistException;
import com.rymcu.forest.core.service.AbstractService;
import com.rymcu.forest.core.service.redis.RedisService;
import com.rymcu.forest.dto.*;
@ -20,6 +22,8 @@ import com.rymcu.forest.util.Utils;
import com.rymcu.forest.web.api.common.UploadController;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.exceptions.TooManyResultsException;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -114,8 +118,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
}
@Override
public Map login(String account, String password) {
Map map = new HashMap(2);
public TokenUser login(String account, String password) {
User user = userMapper.findByAccount(account);
if (user != null) {
if (Utils.comparePwd(password, user.getPassword())) {
@ -125,16 +128,15 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
BeanCopierUtil.copy(user, tokenUser);
tokenUser.setToken(tokenManager.createToken(account));
tokenUser.setWeights(userMapper.selectRoleWeightsByUser(user.getIdUser()));
map.put("user", tokenUser);
// 保存登录日志
loginRecordService.saveLoginRecord(tokenUser.getIdUser());
return tokenUser;
} else {
map.put("message", "密码错误!");
throw new AuthenticationException("密码错误");
}
} else {
map.put("message", "该账号不存在!");
throw new UnknownAccountException("账号不存在");
}
return map;
}
@Override
@ -183,7 +185,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
Map map = new HashMap(2);
UserInfoDTO user = userMapper.selectUserInfo(idUser);
if (user == null) {
map.put("message", "用户不存在!");
throw new ContentNotExistException("用户不存在!");
} else {
UserExtend userExtend = userExtendMapper.selectByPrimaryKey(user.getIdUser());
if (Objects.isNull(userExtend)) {
@ -270,7 +272,6 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
@Override
public Map updateEmail(ChangeEmailDTO changeEmailDTO) {
Map map = new HashMap(2);
map.put("message", "验证码无效!");
Long idUser = changeEmailDTO.getIdUser();
String email = changeEmailDTO.getEmail();
String code = changeEmailDTO.getCode();
@ -282,7 +283,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
map.put("email", email);
}
}
return map;
throw new CaptchaException();
}
@Override

View File

@ -4,6 +4,7 @@ import com.rymcu.forest.core.result.GlobalResult;
import com.rymcu.forest.core.result.GlobalResultGenerator;
import com.rymcu.forest.entity.Comment;
import com.rymcu.forest.service.CommentService;
import com.rymcu.forest.util.UserUtils;
import com.rymcu.forest.web.api.exception.BaseApiException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -12,8 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.Objects;
/**
* @author ronger
@ -26,8 +26,9 @@ public class CommentController {
private CommentService commentService;
@PostMapping("/post")
public GlobalResult postComment(@RequestBody Comment comment, HttpServletRequest request) throws BaseApiException {
Map map = commentService.postComment(comment,request);
return GlobalResultGenerator.genSuccessResult(map);
public GlobalResult<Comment> postComment(@RequestBody Comment comment, HttpServletRequest request) throws BaseApiException {
comment.setCommentAuthorId(Objects.requireNonNull(UserUtils.getCurrentUserByToken()).getIdUser());
comment = commentService.postComment(comment,request);
return GlobalResultGenerator.genSuccessResult(comment);
}
}

View File

@ -9,7 +9,6 @@ import com.rymcu.forest.core.service.log.annotation.VisitLogger;
import com.rymcu.forest.dto.*;
import com.rymcu.forest.entity.User;
import com.rymcu.forest.service.*;
import com.rymcu.forest.util.Utils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -75,9 +74,9 @@ public class CommonApiController {
}
@PostMapping("/login")
public GlobalResult<Map> login(@RequestBody User user) {
Map map = userService.login(user.getAccount(), user.getPassword());
return GlobalResultGenerator.genSuccessResult(map);
public GlobalResult<TokenUser> login(@RequestBody User user) {
TokenUser tokenUser = userService.login(user.getAccount(), user.getPassword());
return GlobalResultGenerator.genSuccessResult(tokenUser);
}
@GetMapping("/heartbeat")
@ -117,11 +116,9 @@ public class CommonApiController {
@GetMapping("/portfolio/{id}")
@VisitLogger
public GlobalResult<Map<String, Object>> portfolio(@PathVariable Long id) {
public GlobalResult<PortfolioDTO> portfolio(@PathVariable Long id) {
PortfolioDTO portfolioDTO = portfolioService.findPortfolioDTOById(id, 1);
Map<String, Object> map = new HashMap<>(1);
map.put("portfolio", portfolioDTO);
return GlobalResultGenerator.genSuccessResult(map);
return GlobalResultGenerator.genSuccessResult(portfolioDTO);
}
@GetMapping("/portfolio/{id}/articles")
@ -150,10 +147,8 @@ public class CommonApiController {
@GetMapping("/product/{id}")
@VisitLogger
public GlobalResult<Map<String, Object>> product(@PathVariable Integer id) {
public GlobalResult<ProductDTO> product(@PathVariable Integer id) {
ProductDTO productDTO = productService.findProductDTOById(id, 1);
Map<String, Object> map = new HashMap<>(1);
map.put("product", productDTO);
return GlobalResultGenerator.genSuccessResult(map);
return GlobalResultGenerator.genSuccessResult(productDTO);
}
}

View File

@ -6,8 +6,11 @@ import com.rymcu.forest.core.service.security.annotation.AuthorshipInterceptor;
import com.rymcu.forest.dto.PortfolioArticleDTO;
import com.rymcu.forest.dto.PortfolioDTO;
import com.rymcu.forest.entity.Portfolio;
import com.rymcu.forest.entity.User;
import com.rymcu.forest.enumerate.Module;
import com.rymcu.forest.service.PortfolioService;
import com.rymcu.forest.service.UserService;
import com.rymcu.forest.util.UserUtils;
import com.rymcu.forest.web.api.exception.BaseApiException;
import org.springframework.web.bind.annotation.*;
@ -24,6 +27,8 @@ public class PortfolioController {
@Resource
private PortfolioService portfolioService;
@Resource
private UserService userService;
@GetMapping("/detail/{idPortfolio}")
public GlobalResult detail(@PathVariable Long idPortfolio,@RequestParam(defaultValue = "0") Integer type) {
@ -76,8 +81,11 @@ public class PortfolioController {
@DeleteMapping("/delete")
@AuthorshipInterceptor(moduleName = Module.PORTFOLIO)
public GlobalResult delete(Long idPortfolio) throws BaseApiException {
Map map = portfolioService.deletePortfolio(idPortfolio);
public GlobalResult delete(Long idPortfolio) throws BaseApiException, IllegalAccessException {
User user = UserUtils.getCurrentUserByToken();
Long idUser = user.getIdUser();
Integer roleWeights = userService.findRoleWeightsByUser(idUser);
boolean map = portfolioService.deletePortfolio(idPortfolio, idUser, roleWeights);
return GlobalResultGenerator.genSuccessResult(map);
}