🐛 map返回修正

This commit is contained in:
你一个人在这儿干嘛你是来拉屎的吧 2022-08-21 17:35:29 +08:00
parent a019078802
commit 4c17685ff0
20 changed files with 273 additions and 327 deletions

View File

@ -4,17 +4,16 @@ import com.rymcu.forest.core.service.Service;
import com.rymcu.forest.entity.ArticleThumbsUp; import com.rymcu.forest.entity.ArticleThumbsUp;
import com.rymcu.forest.web.api.exception.BaseApiException; import com.rymcu.forest.web.api.exception.BaseApiException;
import java.util.Map;
/** /**
* @author ronger * @author ronger
*/ */
public interface ArticleThumbsUpService extends Service<ArticleThumbsUp> { public interface ArticleThumbsUpService extends Service<ArticleThumbsUp> {
/** /**
* 点赞 * 点赞
*
* @param articleThumbsUp * @param articleThumbsUp
* @throws BaseApiException
* @return * @return
* @throws BaseApiException
*/ */
Map thumbsUp(ArticleThumbsUp articleThumbsUp) throws BaseApiException; String thumbsUp(ArticleThumbsUp articleThumbsUp) throws Exception;
} }

View File

@ -1,5 +1,6 @@
package com.rymcu.forest.service; package com.rymcu.forest.service;
import com.github.pagehelper.PageInfo;
import com.rymcu.forest.core.service.Service; import com.rymcu.forest.core.service.Service;
import com.rymcu.forest.dto.PortfolioArticleDTO; import com.rymcu.forest.dto.PortfolioArticleDTO;
import com.rymcu.forest.dto.PortfolioDTO; import com.rymcu.forest.dto.PortfolioDTO;
@ -8,7 +9,6 @@ import com.rymcu.forest.entity.Portfolio;
import com.rymcu.forest.web.api.exception.BaseApiException; import com.rymcu.forest.web.api.exception.BaseApiException;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author ronger * @author ronger
@ -44,32 +44,35 @@ public interface PortfolioService extends Service<Portfolio> {
* @param rows * @param rows
* @param searchText * @param searchText
* @param idPortfolio * @param idPortfolio
* @throws BaseApiException
* @return * @return
* @throws BaseApiException
*/ */
Map findUnbindArticles(Integer page, Integer rows, String searchText, Long idPortfolio) throws BaseApiException; PageInfo findUnbindArticles(Integer page, Integer rows, String searchText, Long idPortfolio) throws Exception;
/** /**
* 绑定文章 * 绑定文章
*
* @param portfolioArticle * @param portfolioArticle
* @return * @return
*/ */
Map bindArticle(PortfolioArticleDTO portfolioArticle); boolean bindArticle(PortfolioArticleDTO portfolioArticle) throws Exception;
/** /**
* 更新文章排序号 * 更新文章排序号
*
* @param portfolioArticle * @param portfolioArticle
* @return * @return
*/ */
Map updateArticleSortNo(PortfolioArticleDTO portfolioArticle); boolean updateArticleSortNo(PortfolioArticleDTO portfolioArticle) throws Exception;
/** /**
* 取消绑定文章 * 取消绑定文章
*
* @param idPortfolio * @param idPortfolio
* @param idArticle * @param idArticle
* @return * @return
*/ */
Map unbindArticle(Long idPortfolio, Long idArticle); boolean unbindArticle(Long idPortfolio, Long idArticle) throws Exception;
/** /**
@ -84,6 +87,7 @@ public interface PortfolioService extends Service<Portfolio> {
*/ */
boolean deletePortfolio(Long idPortfolio, Long idUser, Integer roleWeights) throws BaseApiException, IllegalAccessException; boolean deletePortfolio(Long idPortfolio, Long idUser, Integer roleWeights) throws BaseApiException, IllegalAccessException;
/** /**
* 获取作品集列表数据 * 获取作品集列表数据
* @return * @return

View File

@ -5,7 +5,6 @@ import com.rymcu.forest.entity.Role;
import com.rymcu.forest.entity.User; import com.rymcu.forest.entity.User;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
@ -31,16 +30,18 @@ public interface RoleService extends Service<Role> {
/** /**
* 更新用户状态 * 更新用户状态
*
* @param idRole * @param idRole
* @param status * @param status
* @return * @return
* */ */
Map updateStatus(Long idRole, String status); boolean updateStatus(Long idRole, String status) throws Exception;
/** /**
* 添加/更新角色 * 添加/更新角色
*
* @param role * @param role
* @return * @return
* */ */
Map saveRole(Role role); boolean saveRole(Role role) throws Exception;
} }

View File

@ -3,17 +3,16 @@ package com.rymcu.forest.service;
import com.rymcu.forest.core.service.Service; import com.rymcu.forest.core.service.Service;
import com.rymcu.forest.entity.Sponsor; import com.rymcu.forest.entity.Sponsor;
import java.util.Map;
/** /**
* @author ronger * @author ronger
*/ */
public interface SponsorService extends Service<Sponsor> { public interface SponsorService extends Service<Sponsor> {
/** /**
* 赞赏 * 赞赏
*
* @param sponsor * @param sponsor
* @return * @return
* @throws Exception * @throws Exception
*/ */
Map sponsorship(Sponsor sponsor) throws Exception; boolean sponsorship(Sponsor sponsor) throws Exception;
} }

View File

@ -8,7 +8,6 @@ import com.rymcu.forest.web.api.exception.BaseApiException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author ronger * @author ronger
@ -27,16 +26,18 @@ public interface TagService extends Service<Tag> {
/** /**
* 清除未使用标签 * 清除未使用标签
*
* @return * @return
* */ */
Map cleanUnusedTag(); boolean cleanUnusedTag();
/** /**
* 添加/更新标签 * 添加/更新标签
*
* @param tag * @param tag
* @return * @return
*/ */
Map saveTag(Tag tag); Tag saveTag(Tag tag) throws Exception;
/** /**
* 获取标签列表 * 获取标签列表

View File

@ -1,12 +1,12 @@
package com.rymcu.forest.service; package com.rymcu.forest.service;
import com.github.pagehelper.PageInfo;
import com.rymcu.forest.core.service.Service; import com.rymcu.forest.core.service.Service;
import com.rymcu.forest.dto.admin.TopicTagDTO; import com.rymcu.forest.dto.admin.TopicTagDTO;
import com.rymcu.forest.entity.Tag; import com.rymcu.forest.entity.Tag;
import com.rymcu.forest.entity.Topic; import com.rymcu.forest.entity.Topic;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author ronger * @author ronger
@ -28,10 +28,11 @@ public interface TopicService extends Service<Topic> {
/** /**
* 新增/更新主题信息 * 新增/更新主题信息
*
* @param topic 主题信息 * @param topic 主题信息
* @return * @return
* */ */
Map saveTopic(Topic topic); Topic saveTopic(Topic topic) throws Exception;
/** /**
* 查询未绑定标签 * 查询未绑定标签
@ -43,24 +44,27 @@ public interface TopicService extends Service<Topic> {
/** /**
* 绑定标签 * 绑定标签
*
* @param topicTag * @param topicTag
* @return * @return
*/ */
Map bindTopicTag(TopicTagDTO topicTag); TopicTagDTO bindTopicTag(TopicTagDTO topicTag) throws Exception;
/** /**
* 取消绑定标签 * 取消绑定标签
*
* @param topicTag * @param topicTag
* @return * @return
*/ */
Map unbindTopicTag(TopicTagDTO topicTag); TopicTagDTO unbindTopicTag(TopicTagDTO topicTag) throws Exception;
/** /**
* 获取主题下标签列表 * 获取主题下标签列表
*
* @param topicUri * @param topicUri
* @param page * @param page
* @param rows * @param rows
* @return * @return
*/ */
Map findTagsByTopicUri(String topicUri, Integer page, Integer rows); PageInfo findTagsByTopicUri(String topicUri, Integer page, Integer rows);
} }

View File

@ -1,5 +1,6 @@
package com.rymcu.forest.service; package com.rymcu.forest.service;
import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.core.service.Service; import com.rymcu.forest.core.service.Service;
import com.rymcu.forest.dto.*; import com.rymcu.forest.dto.*;
import com.rymcu.forest.entity.User; import com.rymcu.forest.entity.User;
@ -27,20 +28,22 @@ public interface UserService extends Service<User> {
/** /**
* 注册接口 * 注册接口
* @param email 邮箱 *
* @param password 密码 * @param email 邮箱
* @param code 验证码 * @param password 密码
* @param code 验证码
* @return Map * @return Map
* */ */
Map register(String email, String password, String code); void register(String email, String password, String code) throws ServiceException;
/** /**
* 登录接口 * 登录接口
* @param account 邮箱 *
* @param password 密码 * @param account 邮箱
* @param password 密码
* @return Map * @return Map
* */ */
TokenUser login(String account, String password); TokenUser login(String account, String password) throws ServiceException;
/** /**
* 通过 account 获取用户信息接口 * 通过 account 获取用户信息接口
@ -51,27 +54,30 @@ public interface UserService extends Service<User> {
/** /**
* 找回密码接口 * 找回密码接口
* @param code 验证码 *
* @param code 验证码
* @param password 密码 * @param password 密码
* @return Map * @return Map
* */ */
Map forgetPassword(String code, String password); String forgetPassword(String code, String password) throws ServiceException;
/** /**
* 更新用户角色接口 * 更新用户角色接口
*
* @param idUser 用户 id * @param idUser 用户 id
* @param idRole 角色 id * @param idRole 角色 id
* @return Map * @return Map
* */ */
Map updateUserRole(Long idUser, Long idRole); boolean updateUserRole(Long idUser, Long idRole) throws ServiceException;
/** /**
* 更新用户状态 * 更新用户状态
*
* @param idUser 用户 id * @param idUser 用户 id
* @param status 状态 * @param status 状态
* @return Map * @return Map
* */ */
Map updateStatus(Long idUser, String status); boolean updateStatus(Long idUser, String status) throws ServiceException;
/** /**
* 获取用户信息 * 获取用户信息
@ -82,18 +88,20 @@ public interface UserService extends Service<User> {
/** /**
* 更新用户信息 * 更新用户信息
*
* @param user * @param user
* @return * @return
*/ */
Map updateUserInfo(UserInfoDTO user); UserInfoDTO updateUserInfo(UserInfoDTO user) throws Exception;
/** /**
* 验证昵称是否重复 * 验证昵称是否重复
*
* @param idUser * @param idUser
* @param nickname * @param nickname
* @return * @return
*/ */
Map checkNickname(Long idUser, String nickname); boolean checkNickname(Long idUser, String nickname) throws ServiceException;
/** /**
* 获取用户权限 * 获取用户权限
@ -111,10 +119,11 @@ public interface UserService extends Service<User> {
/** /**
* 更新用户扩展信息 * 更新用户扩展信息
*
* @param userExtend * @param userExtend
* @return * @return
*/ */
Map updateUserExtend(UserExtend userExtend); UserExtend updateUserExtend(UserExtend userExtend) throws ServiceException;
/** /**
* 获取用户扩展信息 * 获取用户扩展信息
@ -125,17 +134,19 @@ public interface UserService extends Service<User> {
/** /**
* 更换邮箱 * 更换邮箱
*
* @param changeEmailDTO * @param changeEmailDTO
* @return * @return
*/ */
Map updateEmail(ChangeEmailDTO changeEmailDTO); String updateEmail(ChangeEmailDTO changeEmailDTO) throws ServiceException;
/** /**
* 更新密码 * 更新密码
*
* @param updatePasswordDTO * @param updatePasswordDTO
* @return * @return
*/ */
Map updatePassword(UpdatePasswordDTO updatePasswordDTO); boolean updatePassword(UpdatePasswordDTO updatePasswordDTO);
/** /**
* 查询用户列表 * 查询用户列表

View File

@ -1,5 +1,6 @@
package com.rymcu.forest.service.impl; package com.rymcu.forest.service.impl;
import com.rymcu.forest.core.exception.BusinessException;
import com.rymcu.forest.core.service.AbstractService; import com.rymcu.forest.core.service.AbstractService;
import com.rymcu.forest.entity.Article; import com.rymcu.forest.entity.Article;
import com.rymcu.forest.entity.ArticleThumbsUp; import com.rymcu.forest.entity.ArticleThumbsUp;
@ -8,14 +9,11 @@ import com.rymcu.forest.mapper.ArticleThumbsUpMapper;
import com.rymcu.forest.service.ArticleService; import com.rymcu.forest.service.ArticleService;
import com.rymcu.forest.service.ArticleThumbsUpService; import com.rymcu.forest.service.ArticleThumbsUpService;
import com.rymcu.forest.util.UserUtils; import com.rymcu.forest.util.UserUtils;
import com.rymcu.forest.web.api.exception.BaseApiException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
@ -31,17 +29,14 @@ public class ArticleThumbsUpServiceImpl extends AbstractService<ArticleThumbsUp>
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map thumbsUp(ArticleThumbsUp articleThumbsUp) throws BaseApiException { public String thumbsUp(ArticleThumbsUp articleThumbsUp) throws Exception {
Map map = new HashMap(3);
if (Objects.isNull(articleThumbsUp) || Objects.isNull(articleThumbsUp.getIdArticle())) { if (Objects.isNull(articleThumbsUp) || Objects.isNull(articleThumbsUp.getIdArticle())) {
map.put("message", "数据异常,文章不存在!"); throw new BusinessException("数据异常,文章不存在!");
map.put("success", false);
} else { } else {
Integer thumbsUpNumber = 1; Integer thumbsUpNumber = 1;
Article article = articleService.findById(String.valueOf(articleThumbsUp.getIdArticle())); Article article = articleService.findById(String.valueOf(articleThumbsUp.getIdArticle()));
if (Objects.isNull(article)) { if (Objects.isNull(article)) {
map.put("message", "数据异常,文章不存在!"); throw new BusinessException("数据异常,文章不存在!");
map.put("success", false);
} else { } else {
User user = UserUtils.getCurrentUserByToken(); User user = UserUtils.getCurrentUserByToken();
articleThumbsUp.setIdUser(user.getIdUser()); articleThumbsUp.setIdUser(user.getIdUser());
@ -56,15 +51,12 @@ public class ArticleThumbsUpServiceImpl extends AbstractService<ArticleThumbsUp>
thumbsUpNumber = -1; thumbsUpNumber = -1;
} }
articleThumbsUpMapper.updateArticleThumbsUpNumber(articleThumbsUp.getIdArticle(), thumbsUpNumber); articleThumbsUpMapper.updateArticleThumbsUpNumber(articleThumbsUp.getIdArticle(), thumbsUpNumber);
map.put("success", true);
map.put("thumbsUpNumber", thumbsUpNumber);
if (thumbsUpNumber > 0) { if (thumbsUpNumber > 0) {
map.put("message", "点赞成功"); return "点赞成功";
} else { } else {
map.put("message", "已取消点赞"); return "已取消点赞";
} }
} }
} }
return map;
} }
} }

View File

@ -13,7 +13,10 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @author ronger * @author ronger

View File

@ -3,6 +3,7 @@ package com.rymcu.forest.service.impl;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.rymcu.forest.core.exception.BusinessException; import com.rymcu.forest.core.exception.BusinessException;
import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.core.service.AbstractService; import com.rymcu.forest.core.service.AbstractService;
import com.rymcu.forest.dto.*; import com.rymcu.forest.dto.*;
import com.rymcu.forest.entity.Portfolio; import com.rymcu.forest.entity.Portfolio;
@ -14,7 +15,6 @@ import com.rymcu.forest.service.ArticleService;
import com.rymcu.forest.service.PortfolioService; import com.rymcu.forest.service.PortfolioService;
import com.rymcu.forest.service.UserService; import com.rymcu.forest.service.UserService;
import com.rymcu.forest.util.UserUtils; import com.rymcu.forest.util.UserUtils;
import com.rymcu.forest.util.Utils;
import com.rymcu.forest.util.XssUtils; import com.rymcu.forest.util.XssUtils;
import com.rymcu.forest.web.api.common.UploadController; import com.rymcu.forest.web.api.common.UploadController;
import com.rymcu.forest.web.api.exception.BaseApiException; import com.rymcu.forest.web.api.exception.BaseApiException;
@ -23,9 +23,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author ronger * @author ronger
@ -99,76 +97,66 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
} }
@Override @Override
public Map findUnbindArticles(Integer page, Integer rows, String searchText, Long idPortfolio) throws BaseApiException { public PageInfo findUnbindArticles(Integer page, Integer rows, String searchText, Long idPortfolio) throws Exception {
Map map = new HashMap(1);
User user = UserUtils.getCurrentUserByToken(); User user = UserUtils.getCurrentUserByToken();
Portfolio portfolio = portfolioMapper.selectByPrimaryKey(idPortfolio); Portfolio portfolio = portfolioMapper.selectByPrimaryKey(idPortfolio);
if (portfolio == null) { if (portfolio == null) {
map.put("message", "该作品集不存在或已被删除!"); throw new ServiceException("该作品集不存在或已被删除!");
} else { } else {
if (!user.getIdUser().equals(portfolio.getPortfolioAuthorId())) { if (!user.getIdUser().equals(portfolio.getPortfolioAuthorId())) {
map.put("message", "非法操作!"); throw new ServiceException("非法操作!");
} else { } else {
PageHelper.startPage(page, rows); 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); PageInfo<ArticleDTO> pageInfo = new PageInfo(articles);
map = Utils.getArticlesGlobalResult(pageInfo); return pageInfo;
} }
} }
return map;
} }
@Override @Override
public Map bindArticle(PortfolioArticleDTO portfolioArticle) { public boolean bindArticle(PortfolioArticleDTO portfolioArticle) throws Exception {
Map map = new HashMap(1);
Integer count = portfolioMapper.selectCountPortfolioArticle(portfolioArticle.getIdArticle(), portfolioArticle.getIdPortfolio()); Integer count = portfolioMapper.selectCountPortfolioArticle(portfolioArticle.getIdArticle(), portfolioArticle.getIdPortfolio());
if (count.equals(0)) { if (count.equals(0)) {
Integer maxSortNo = portfolioMapper.selectMaxSortNo(portfolioArticle.getIdPortfolio()); Integer maxSortNo = portfolioMapper.selectMaxSortNo(portfolioArticle.getIdPortfolio());
portfolioMapper.insertPortfolioArticle(portfolioArticle.getIdArticle(), portfolioArticle.getIdPortfolio(), maxSortNo); portfolioMapper.insertPortfolioArticle(portfolioArticle.getIdArticle(), portfolioArticle.getIdPortfolio(), maxSortNo);
map.put("message", "绑定成功!"); return true;
} else { } else {
map.put("message", "该文章已经在作品集下!!"); throw new ServiceException("该文章已经在作品集下!!");
} }
return map;
} }
@Override @Override
public Map updateArticleSortNo(PortfolioArticleDTO portfolioArticle) { public boolean updateArticleSortNo(PortfolioArticleDTO portfolioArticle) throws Exception {
Map map = new HashMap(1);
if (portfolioArticle.getIdPortfolio() == null || portfolioArticle.getIdPortfolio().equals(0)) { if (portfolioArticle.getIdPortfolio() == null || portfolioArticle.getIdPortfolio().equals(0)) {
map.put("message", "作品集数据异常!"); throw new ServiceException("作品集数据异常!");
} }
if (portfolioArticle.getIdArticle() == null || portfolioArticle.getIdArticle().equals(0)) { if (portfolioArticle.getIdArticle() == null || portfolioArticle.getIdArticle().equals(0)) {
map.put("message", "文章数据异常!"); throw new ServiceException("文章数据异常!");
} }
if (portfolioArticle.getSortNo() == null) { if (portfolioArticle.getSortNo() == null) {
map.put("message", "排序号不能为空!"); throw new ServiceException("排序号不能为空!");
} }
Integer result = portfolioMapper.updateArticleSortNo(portfolioArticle.getIdPortfolio(), portfolioArticle.getIdArticle(), portfolioArticle.getSortNo()); Integer result = portfolioMapper.updateArticleSortNo(portfolioArticle.getIdPortfolio(), portfolioArticle.getIdArticle(), portfolioArticle.getSortNo());
if (result > 0) { if (result > 0) {
map.put("message", "更新成功!"); throw new ServiceException("更新失败!");
} else {
map.put("message", "更新失败!");
} }
return map; return true;
} }
@Override @Override
public Map unbindArticle(Long idPortfolio, Long idArticle) { public boolean unbindArticle(Long idPortfolio, Long idArticle) throws Exception {
Map map = new HashMap(1);
if (idPortfolio == null || idPortfolio.equals(0)) { if (idPortfolio == null || idPortfolio.equals(0)) {
map.put("message", "作品集数据异常"); throw new ServiceException("作品集数据异常");
} }
if (idArticle == null || idArticle.equals(0)) { if (idArticle == null || idArticle.equals(0)) {
map.put("message", "文章数据异常"); throw new ServiceException("文章数据异常");
} }
Integer result = portfolioMapper.unbindArticle(idPortfolio, idArticle); Integer result = portfolioMapper.unbindArticle(idPortfolio, idArticle);
if (result > 0) { if (result == 0) {
map.put("message", "操作成功!"); throw new ServiceException("操作失败!");
} else {
map.put("message", "操作失败!");
} }
return map; return true;
} }
@Override @Override

View File

@ -1,5 +1,6 @@
package com.rymcu.forest.service.impl; package com.rymcu.forest.service.impl;
import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.core.service.AbstractService; import com.rymcu.forest.core.service.AbstractService;
import com.rymcu.forest.entity.Role; import com.rymcu.forest.entity.Role;
import com.rymcu.forest.entity.User; import com.rymcu.forest.entity.User;
@ -10,9 +11,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
@ -38,33 +37,29 @@ public class RoleServiceImpl extends AbstractService<Role> implements RoleServic
@Override @Override
@Transactional @Transactional
public Map updateStatus(Long idRole, String status) { public boolean updateStatus(Long idRole, String status) throws Exception {
Map map = new HashMap(1); Integer result = roleMapper.updateStatus(idRole, status);
Integer result = roleMapper.updateStatus(idRole,status); if (result == 0) {
if(result == 0) { throw new ServiceException("更新失败");
map.put("message","更新失败!");
} }
return map; return true;
} }
@Override @Override
public Map saveRole(Role role) { public boolean saveRole(Role role) throws Exception {
Integer result = 0; Integer result;
if (role.getIdRole() == null) { if (role.getIdRole() == null) {
role.setCreatedTime(new Date()); role.setCreatedTime(new Date());
role.setUpdatedTime(role.getCreatedTime()); role.setUpdatedTime(role.getCreatedTime());
result = roleMapper.insertSelective(role); result = roleMapper.insertSelective(role);
} else { } else {
role.setCreatedTime(new Date()); role.setCreatedTime(new Date());
result = roleMapper.update(role.getIdRole(),role.getName(),role.getInputCode(),role.getWeights()); result = roleMapper.update(role.getIdRole(), role.getName(), role.getInputCode(), role.getWeights());
} }
Map map = new HashMap(1);
if (result == 0) { if (result == 0) {
map.put("message","操作失败!"); throw new ServiceException("操作失败!");
} else {
map.put("role", role);
} }
return map; return true;
} }
} }

View File

@ -1,6 +1,7 @@
package com.rymcu.forest.service.impl; package com.rymcu.forest.service.impl;
import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.core.exception.TransactionException; import com.rymcu.forest.core.exception.TransactionException;
import com.rymcu.forest.core.service.AbstractService; import com.rymcu.forest.core.service.AbstractService;
import com.rymcu.forest.dto.ArticleDTO; import com.rymcu.forest.dto.ArticleDTO;
@ -19,7 +20,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.Date;
import java.util.Objects;
/** /**
* @author ronger * @author ronger
@ -36,11 +38,9 @@ public class SponsorServiceImpl extends AbstractService<Sponsor> implements Spon
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map sponsorship(Sponsor sponsor) throws Exception { public boolean sponsorship(Sponsor sponsor) throws Exception {
Map map = new HashMap(2);
if (Objects.isNull(sponsor) || Objects.isNull(sponsor.getDataId()) || Objects.isNull(sponsor.getDataType())) { if (Objects.isNull(sponsor) || Objects.isNull(sponsor.getDataId()) || Objects.isNull(sponsor.getDataType())) {
map.put("success", false); throw new ServiceException("数据异常");
map.put("message", "数据异常");
} else { } else {
TransactionEnum result = TransactionEnum.findTransactionEnum(sponsor.getDataType()); TransactionEnum result = TransactionEnum.findTransactionEnum(sponsor.getDataType());
BigDecimal money = BigDecimal.valueOf(result.getMoney()); BigDecimal money = BigDecimal.valueOf(result.getMoney());
@ -59,9 +59,7 @@ public class SponsorServiceImpl extends AbstractService<Sponsor> implements Spon
// 更新文章赞赏数 // 更新文章赞赏数
sponsorMapper.updateArticleSponsorCount(articleDTO.getIdArticle()); sponsorMapper.updateArticleSponsorCount(articleDTO.getIdArticle());
} }
map.put("success", true);
map.put("message", "赞赏成功");
} }
return map; return true;
} }
} }

View File

@ -1,18 +1,17 @@
package com.rymcu.forest.service.impl; package com.rymcu.forest.service.impl;
import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.core.service.AbstractService; import com.rymcu.forest.core.service.AbstractService;
import com.rymcu.forest.dto.ArticleTagDTO; import com.rymcu.forest.dto.ArticleTagDTO;
import com.rymcu.forest.dto.LabelModel; import com.rymcu.forest.dto.LabelModel;
import com.rymcu.forest.dto.baidu.TagNlpDTO; import com.rymcu.forest.dto.baidu.TagNlpDTO;
import com.rymcu.forest.entity.Article; import com.rymcu.forest.entity.Article;
import com.rymcu.forest.entity.Tag; import com.rymcu.forest.entity.Tag;
import com.rymcu.forest.entity.User;
import com.rymcu.forest.mapper.ArticleMapper; import com.rymcu.forest.mapper.ArticleMapper;
import com.rymcu.forest.mapper.TagMapper; import com.rymcu.forest.mapper.TagMapper;
import com.rymcu.forest.service.TagService; import com.rymcu.forest.service.TagService;
import com.rymcu.forest.util.BaiDuAipUtils; import com.rymcu.forest.util.BaiDuAipUtils;
import com.rymcu.forest.util.CacheUtils; import com.rymcu.forest.util.CacheUtils;
import com.rymcu.forest.util.UserUtils;
import com.rymcu.forest.util.XssUtils; import com.rymcu.forest.util.XssUtils;
import com.rymcu.forest.web.api.common.UploadController; import com.rymcu.forest.web.api.common.UploadController;
import com.rymcu.forest.web.api.exception.BaseApiException; import com.rymcu.forest.web.api.exception.BaseApiException;
@ -25,9 +24,7 @@ import javax.annotation.Resource;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author ronger * @author ronger
@ -115,47 +112,42 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map cleanUnusedTag() { public boolean cleanUnusedTag() {
Map map = new HashMap(1); return tagMapper.deleteUnusedTag() > 0;
tagMapper.deleteUnusedTag();
return map;
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map saveTag(Tag tag) { public Tag saveTag(Tag tag) throws Exception {
Integer result; Integer result;
Map map = new HashMap(1);
tag.setTagDescription(XssUtils.filterHtmlCode(tag.getTagDescription())); tag.setTagDescription(XssUtils.filterHtmlCode(tag.getTagDescription()));
if (tag.getIdTag() == null) { if (tag.getIdTag() == null) {
if (StringUtils.isBlank(tag.getTagTitle())) { if (StringUtils.isBlank(tag.getTagTitle())) {
map.put("message", "标签名不能为空!"); throw new ServiceException("标签名不能为空!");
return map;
} else { } else {
Condition tagCondition = new Condition(Tag.class); Condition tagCondition = new Condition(Tag.class);
tagCondition.createCriteria().andCondition("tag_title =", tag.getTagTitle()); tagCondition.createCriteria().andCondition("tag_title =", tag.getTagTitle());
List<Tag> tags = tagMapper.selectByCondition(tagCondition); List<Tag> tags = tagMapper.selectByCondition(tagCondition);
if (!tags.isEmpty()) { if (!tags.isEmpty()) {
map.put("message", "标签 '" + tag.getTagTitle() + "' 已存在!"); throw new ServiceException("标签 '" + tag.getTagTitle() + "' 已存在!");
return map;
} }
} }
Tag newTag = new Tag(); tag = new Tag();
newTag.setTagTitle(tag.getTagTitle()); tag.setTagTitle(tag.getTagTitle());
newTag.setTagUri(tag.getTagUri()); tag.setTagUri(tag.getTagUri());
if (StringUtils.isNotBlank(tag.getTagIconPath()) && tag.getTagIconPath().contains("base64")) { if (StringUtils.isNotBlank(tag.getTagIconPath()) && tag.getTagIconPath().contains("base64")) {
String tagIconPath = UploadController.uploadBase64File(tag.getTagIconPath(), 2); String tagIconPath = UploadController.uploadBase64File(tag.getTagIconPath(), 2);
newTag.setTagIconPath(tagIconPath); tag.setTagIconPath(tagIconPath);
} else { } else {
newTag.setTagIconPath(tag.getTagIconPath()); tag.setTagIconPath(tag.getTagIconPath());
} }
newTag.setTagStatus(tag.getTagStatus()); tag.setTagStatus(tag.getTagStatus());
newTag.setTagDescription(tag.getTagDescription()); tag.setTagDescription(tag.getTagDescription());
newTag.setTagReservation(tag.getTagReservation()); tag.setTagReservation(tag.getTagReservation());
newTag.setCreatedTime(new Date()); tag.setCreatedTime(new Date());
newTag.setUpdatedTime(tag.getCreatedTime()); tag.setUpdatedTime(tag.getCreatedTime());
result = tagMapper.insertSelective(newTag); result = tagMapper.insertSelective(tag);
} else { } else {
tag.setUpdatedTime(new Date()); tag.setUpdatedTime(new Date());
if (StringUtils.isNotBlank(tag.getTagIconPath()) && tag.getTagIconPath().contains("base64")) { if (StringUtils.isNotBlank(tag.getTagIconPath()) && tag.getTagIconPath().contains("base64")) {
@ -165,11 +157,9 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
result = tagMapper.update(tag.getIdTag(), tag.getTagUri(), tag.getTagIconPath(), tag.getTagStatus(), tag.getTagDescription(), tag.getTagReservation()); result = tagMapper.update(tag.getIdTag(), tag.getTagUri(), tag.getTagIconPath(), tag.getTagStatus(), tag.getTagDescription(), tag.getTagReservation());
} }
if (result == 0) { if (result == 0) {
map.put("message", "操作失败!"); throw new ServiceException("操作失败!");
} else {
map.put("tag", tag);
} }
return map; return tag;
} }
@Override @Override

View File

@ -1,8 +1,8 @@
package com.rymcu.forest.service.impl; package com.rymcu.forest.service.impl;
import cn.hutool.http.HtmlUtil;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.core.service.AbstractService; import com.rymcu.forest.core.service.AbstractService;
import com.rymcu.forest.dto.admin.TagDTO; import com.rymcu.forest.dto.admin.TagDTO;
import com.rymcu.forest.dto.admin.TopicDTO; import com.rymcu.forest.dto.admin.TopicDTO;
@ -20,9 +20,7 @@ import tk.mybatis.mapper.entity.Condition;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author ronger * @author ronger
@ -48,40 +46,37 @@ public class TopicServiceImpl extends AbstractService<Topic> implements TopicSer
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map saveTopic(Topic topic) { public Topic saveTopic(Topic topic) throws Exception {
Integer result; Integer result;
topic.setTopicDescriptionHtml(XssUtils.filterHtmlCode(topic.getTopicDescriptionHtml())); topic.setTopicDescriptionHtml(XssUtils.filterHtmlCode(topic.getTopicDescriptionHtml()));
Map map = new HashMap(1);
if (topic.getIdTopic() == null) { if (topic.getIdTopic() == null) {
if (StringUtils.isBlank(topic.getTopicTitle())) { if (StringUtils.isBlank(topic.getTopicTitle())) {
map.put("message","标签名不能为空!"); throw new ServiceException("标签名不能为空!");
return map;
} else { } else {
Condition topicCondition = new Condition(Topic.class); Condition topicCondition = new Condition(Topic.class);
topicCondition.createCriteria().andCondition("topic_title =", topic.getTopicTitle()); topicCondition.createCriteria().andCondition("topic_title =", topic.getTopicTitle());
List<Topic> topics = topicMapper.selectByCondition(topicCondition); List<Topic> topics = topicMapper.selectByCondition(topicCondition);
if (!topics.isEmpty()) { if (!topics.isEmpty()) {
map.put("message","专题 '" + topic.getTopicTitle() + "' 已存在!"); throw new ServiceException("专题 '" + topic.getTopicTitle() + "' 已存在!");
return map;
} }
} }
Topic newTopic = new Topic(); topic = new Topic();
newTopic.setTopicTitle(topic.getTopicTitle()); topic.setTopicTitle(topic.getTopicTitle());
newTopic.setTopicUri(topic.getTopicUri()); topic.setTopicUri(topic.getTopicUri());
if (StringUtils.isNotBlank(topic.getTopicIconPath()) && topic.getTopicIconPath().contains("base64")) { if (StringUtils.isNotBlank(topic.getTopicIconPath()) && topic.getTopicIconPath().contains("base64")) {
String topicIconPath = UploadController.uploadBase64File(topic.getTopicIconPath(), 3); String topicIconPath = UploadController.uploadBase64File(topic.getTopicIconPath(), 3);
newTopic.setTopicIconPath(topicIconPath); topic.setTopicIconPath(topicIconPath);
} else { } else {
newTopic.setTopicIconPath(topic.getTopicIconPath()); topic.setTopicIconPath(topic.getTopicIconPath());
} }
newTopic.setTopicNva(topic.getTopicNva()); topic.setTopicNva(topic.getTopicNva());
newTopic.setTopicStatus(topic.getTopicStatus()); topic.setTopicStatus(topic.getTopicStatus());
newTopic.setTopicSort(topic.getTopicSort()); topic.setTopicSort(topic.getTopicSort());
newTopic.setTopicDescription(topic.getTopicDescription()); topic.setTopicDescription(topic.getTopicDescription());
newTopic.setTopicDescriptionHtml(topic.getTopicDescriptionHtml()); topic.setTopicDescriptionHtml(topic.getTopicDescriptionHtml());
newTopic.setCreatedTime(new Date()); topic.setCreatedTime(new Date());
newTopic.setUpdatedTime(topic.getCreatedTime()); topic.setUpdatedTime(topic.getCreatedTime());
result = topicMapper.insertSelective(newTopic); result = topicMapper.insertSelective(topic);
} else { } else {
if (StringUtils.isNotBlank(topic.getTopicIconPath()) && topic.getTopicIconPath().contains("base64")) { if (StringUtils.isNotBlank(topic.getTopicIconPath()) && topic.getTopicIconPath().contains("base64")) {
String topicIconPath = UploadController.uploadBase64File(topic.getTopicIconPath(), 3); String topicIconPath = UploadController.uploadBase64File(topic.getTopicIconPath(), 3);
@ -93,11 +88,9 @@ public class TopicServiceImpl extends AbstractService<Topic> implements TopicSer
,topic.getTopicSort(),topic.getTopicDescription(),topic.getTopicDescriptionHtml()); ,topic.getTopicSort(),topic.getTopicDescription(),topic.getTopicDescriptionHtml());
} }
if (result == 0) { if (result == 0) {
map.put("message","操作失败!"); throw new ServiceException("操作失败!");
} else {
map.put("topic", topic);
} }
return map; return topic;
} }
@Override @Override
@ -110,46 +103,33 @@ public class TopicServiceImpl extends AbstractService<Topic> implements TopicSer
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map bindTopicTag(TopicTagDTO topicTag) { public TopicTagDTO bindTopicTag(TopicTagDTO topicTag) throws Exception {
Integer result = topicMapper.insertTopicTag(topicTag.getIdTopic(), topicTag.getIdTag()); Integer result = topicMapper.insertTopicTag(topicTag.getIdTopic(), topicTag.getIdTag());
Map map = new HashMap(1);
if (result == 0) { if (result == 0) {
map.put("message", "操作失败!"); throw new ServiceException("操作失败!");
} else {
map.put("topicTag", topicTag);
} }
return map; return topicTag;
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map unbindTopicTag(TopicTagDTO topicTag) { public TopicTagDTO unbindTopicTag(TopicTagDTO topicTag) throws Exception {
Integer result = topicMapper.deleteTopicTag(topicTag.getIdTopic(), topicTag.getIdTag()); Integer result = topicMapper.deleteTopicTag(topicTag.getIdTopic(), topicTag.getIdTag());
Map map = new HashMap(1);
if (result == 0) { if (result == 0) {
map.put("message", "操作失败!"); throw new ServiceException("操作失败!");
} else {
map.put("topicTag", topicTag);
} }
return map; return topicTag;
} }
@Override @Override
public Map findTagsByTopicUri(String topicUri, Integer page, Integer rows) { public PageInfo findTagsByTopicUri(String topicUri, Integer page, Integer rows) {
Map map = new HashMap(2);
TopicDTO topic = topicMapper.selectTopicByTopicUri(topicUri); TopicDTO topic = topicMapper.selectTopicByTopicUri(topicUri);
if (topic == null) { if (topic == null) {
return map; return null;
} }
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<TagDTO> list = topicMapper.selectTopicTag(topic.getIdTopic()); List<TagDTO> list = topicMapper.selectTopicTag(topic.getIdTopic());
PageInfo pageInfo = new PageInfo(list); PageInfo pageInfo = new PageInfo(list);
map.put("tags", pageInfo.getList()); return pageInfo;
Map pagination = new HashMap(3);
pagination.put("pageSize",pageInfo.getPageSize());
pagination.put("total",pageInfo.getTotal());
pagination.put("currentPage",pageInfo.getPageNum());
map.put("pagination", pagination);
return map;
} }
} }

View File

@ -2,6 +2,7 @@ package com.rymcu.forest.service.impl;
import com.rymcu.forest.core.exception.CaptchaException; import com.rymcu.forest.core.exception.CaptchaException;
import com.rymcu.forest.core.exception.ContentNotExistException; import com.rymcu.forest.core.exception.ContentNotExistException;
import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.core.service.AbstractService; import com.rymcu.forest.core.service.AbstractService;
import com.rymcu.forest.core.service.redis.RedisService; import com.rymcu.forest.core.service.redis.RedisService;
import com.rymcu.forest.dto.*; import com.rymcu.forest.dto.*;
@ -60,15 +61,13 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map register(String email, String password, String code) { public void register(String email, String password, String code) throws ServiceException {
Map map = new HashMap(2);
map.put("message", "验证码无效!");
String vCode = redisService.get(email); String vCode = redisService.get(email);
if (StringUtils.isNotBlank(vCode)) { if (StringUtils.isNotBlank(vCode)) {
if (vCode.equals(code)) { if (vCode.equals(code)) {
User user = userMapper.findByAccount(email); User user = userMapper.findByAccount(email);
if (user != null) { if (user != null) {
map.put("message", "该邮箱已被注册!"); throw new ServiceException("该邮箱已被注册!");
} else { } else {
user = new User(); user = new User();
String nickname = email.split("@")[0]; String nickname = email.split("@")[0];
@ -88,13 +87,12 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
.nickname(user.getNickname()) .nickname(user.getNickname())
.signature(user.getSignature()) .signature(user.getSignature())
.build()); .build());
map.put("message", "注册成功!");
map.put("flag", 1);
redisService.delete(email); redisService.delete(email);
return;
} }
} }
} }
return map; throw new ServiceException("验证码无效!");
} }
private String checkNickname(String nickname) { private String checkNickname(String nickname) {
@ -145,39 +143,34 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
} }
@Override @Override
public Map forgetPassword(String code, String password) { public String forgetPassword(String code, String password) throws ServiceException {
Map map = new HashMap<>(2);
String email = redisService.get(code); String email = redisService.get(code);
if (StringUtils.isBlank(email)) { if (StringUtils.isBlank(email)) {
map.put("message", "链接已失效"); throw new ServiceException("链接已失效");
} else { } else {
userMapper.updatePasswordByEmail(email, Utils.entryptPassword(password)); userMapper.updatePasswordByEmail(email, Utils.entryptPassword(password));
map.put("message", "修改成功,正在跳转登录登陆界面!"); return "修改成功,正在跳转登录登陆界面!";
map.put("flag", 1);
} }
return map;
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map updateUserRole(Long idUser, Long idRole) { public boolean updateUserRole(Long idUser, Long idRole) throws ServiceException {
Map map = new HashMap(2);
Integer result = userMapper.updateUserRole(idUser, idRole); Integer result = userMapper.updateUserRole(idUser, idRole);
if (result == 0) { if (result == 0) {
map.put("message", "更新失败!"); throw new ServiceException("更新失败!");
} }
return map; return true;
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map updateStatus(Long idUser, String status) { public boolean updateStatus(Long idUser, String status) throws ServiceException {
Map map = new HashMap(2);
Integer result = userMapper.updateStatus(idUser, status); Integer result = userMapper.updateStatus(idUser, status);
if (result == 0) { if (result == 0) {
map.put("message", "更新失败!"); throw new ServiceException("更新失败!");
} }
return map; return true;
} }
@Override @Override
@ -201,13 +194,11 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map updateUserInfo(UserInfoDTO user) { public UserInfoDTO updateUserInfo(UserInfoDTO user) throws Exception {
Map map = new HashMap(2);
user.setNickname(formatNickname(user.getNickname())); user.setNickname(formatNickname(user.getNickname()));
Integer number = userMapper.checkNicknameByIdUser(user.getIdUser(), user.getNickname()); Integer number = userMapper.checkNicknameByIdUser(user.getIdUser(), user.getNickname());
if (number > 0) { if (number > 0) {
map.put("message", "该昵称已使用!"); throw new ServiceException("该昵称已使用!");
return map;
} }
if (StringUtils.isNotBlank(user.getAvatarType()) && AVATAR_SVG_TYPE.equals(user.getAvatarType())) { if (StringUtils.isNotBlank(user.getAvatarType()) && AVATAR_SVG_TYPE.equals(user.getAvatarType())) {
String avatarUrl = UploadController.uploadBase64File(user.getAvatarUrl(), 0); String avatarUrl = UploadController.uploadBase64File(user.getAvatarUrl(), 0);
@ -221,11 +212,10 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
.signature(user.getSignature()) .signature(user.getSignature())
.build()); .build());
if (result == 0) { if (result == 0) {
map.put("message", "操作失败!"); throw new ServiceException("操作失败!");
return map;
} }
map.put("user", user);
return map; return user;
} }
private String formatNickname(String nickname) { private String formatNickname(String nickname) {
@ -233,13 +223,13 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
} }
@Override @Override
public Map checkNickname(Long idUser, String nickname) { public boolean checkNickname(Long idUser, String nickname) throws ServiceException {
Map map = new HashMap(2); Map map = new HashMap(2);
Integer number = userMapper.checkNicknameByIdUser(idUser, nickname); Integer number = userMapper.checkNicknameByIdUser(idUser, nickname);
if (number > 0) { if (number > 0) {
map.put("message", "该昵称已使用!"); throw new ServiceException("该昵称已使用!");
} }
return map; return true;
} }
@Override @Override
@ -253,15 +243,12 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
} }
@Override @Override
public Map updateUserExtend(UserExtend userExtend) { public UserExtend updateUserExtend(UserExtend userExtend) throws ServiceException {
Map map = new HashMap(2);
int result = userExtendMapper.updateByPrimaryKeySelective(userExtend); int result = userExtendMapper.updateByPrimaryKeySelective(userExtend);
if (result == 0) { if (result == 0) {
map.put("message", "操作失败!"); throw new ServiceException("操作失败!");
return map;
} }
map.put("userExtend", userExtend); return userExtend;
return map;
} }
@Override @Override
@ -270,29 +257,23 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
} }
@Override @Override
public Map updateEmail(ChangeEmailDTO changeEmailDTO) { public String updateEmail(ChangeEmailDTO changeEmailDTO) throws ServiceException {
Map map = new HashMap(2);
Long idUser = changeEmailDTO.getIdUser(); Long idUser = changeEmailDTO.getIdUser();
String email = changeEmailDTO.getEmail(); String email = changeEmailDTO.getEmail();
String code = changeEmailDTO.getCode(); String code = changeEmailDTO.getCode();
String vCode = redisService.get(email); String vCode = redisService.get(email);
if (StringUtils.isNotBlank(vCode) && StringUtils.isNotBlank(code)) { if (StringUtils.isNotBlank(vCode) && StringUtils.isNotBlank(code) && vCode.equals(code)) {
if (vCode.equals(code)) { userMapper.updateEmail(idUser, email);
userMapper.updateEmail(idUser, email); return email;
map.put("message", "更新成功!");
map.put("email", email);
}
} }
throw new CaptchaException(); throw new CaptchaException();
} }
@Override @Override
public Map updatePassword(UpdatePasswordDTO updatePasswordDTO) { public boolean updatePassword(UpdatePasswordDTO updatePasswordDTO) {
Map map = new HashMap(2);
String password = Utils.entryptPassword(updatePasswordDTO.getPassword()); String password = Utils.entryptPassword(updatePasswordDTO.getPassword());
userMapper.updatePasswordById(updatePasswordDTO.getIdUser(), password); userMapper.updatePasswordById(updatePasswordDTO.getIdUser(), password);
map.put("message", "更新成功!"); return true;
return map;
} }
@Override @Override

View File

@ -2,6 +2,7 @@ package com.rymcu.forest.web.api.admin;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.core.result.GlobalResult; import com.rymcu.forest.core.result.GlobalResult;
import com.rymcu.forest.core.result.GlobalResultGenerator; import com.rymcu.forest.core.result.GlobalResultGenerator;
import com.rymcu.forest.dto.*; import com.rymcu.forest.dto.*;
@ -9,15 +10,12 @@ import com.rymcu.forest.dto.admin.TopicTagDTO;
import com.rymcu.forest.dto.admin.UserRoleDTO; import com.rymcu.forest.dto.admin.UserRoleDTO;
import com.rymcu.forest.entity.*; import com.rymcu.forest.entity.*;
import com.rymcu.forest.service.*; import com.rymcu.forest.service.*;
import com.rymcu.forest.util.Utils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author ronger * @author ronger
@ -66,33 +64,33 @@ public class AdminController {
} }
@PatchMapping("/user/update-role") @PatchMapping("/user/update-role")
public GlobalResult<Map> updateUserRole(@RequestBody UserRoleDTO userRole){ public GlobalResult<Boolean> updateUserRole(@RequestBody UserRoleDTO userRole) throws ServiceException {
Map map = userService.updateUserRole(userRole.getIdUser(),userRole.getIdRole()); boolean flag = userService.updateUserRole(userRole.getIdUser(), userRole.getIdRole());
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(flag);
} }
@PatchMapping("/user/update-status") @PatchMapping("/user/update-status")
public GlobalResult<Map> updateUserStatus(@RequestBody User user){ public GlobalResult<Boolean> updateUserStatus(@RequestBody User user) throws ServiceException {
Map map = userService.updateStatus(user.getIdUser(),user.getStatus()); boolean flag = userService.updateStatus(user.getIdUser(), user.getStatus());
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(flag);
} }
@PatchMapping("/role/update-status") @PatchMapping("/role/update-status")
public GlobalResult<Map> updateRoleStatus(@RequestBody Role role){ public GlobalResult<Boolean> updateRoleStatus(@RequestBody Role role) throws Exception {
Map map = roleService.updateStatus(role.getIdRole(),role.getStatus()); boolean flag = roleService.updateStatus(role.getIdRole(), role.getStatus());
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(flag);
} }
@PostMapping("/role/post") @PostMapping("/role/post")
public GlobalResult<Map> addRole(@RequestBody Role role){ public GlobalResult<Role> addRole(@RequestBody Role role) throws Exception {
Map map = roleService.saveRole(role); boolean flag = roleService.saveRole(role);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(role);
} }
@PutMapping("/role/post") @PutMapping("/role/post")
public GlobalResult<Map> updateRole(@RequestBody Role role){ public GlobalResult<Role> updateRole(@RequestBody Role role) throws Exception {
Map map = roleService.saveRole(role); boolean flag = roleService.saveRole(role);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(role);
} }
@GetMapping("/topics") @GetMapping("/topics")
@ -113,12 +111,12 @@ public class AdminController {
} }
@GetMapping("/topic/{topicUri}/tags") @GetMapping("/topic/{topicUri}/tags")
public GlobalResult topicTags(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows,@PathVariable String topicUri){ public GlobalResult topicTags(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows,@PathVariable String topicUri) {
if (StringUtils.isBlank(topicUri)) { if (StringUtils.isBlank(topicUri)) {
return GlobalResultGenerator.genErrorResult("数据异常!"); return GlobalResultGenerator.genErrorResult("数据异常!");
} }
Map map = topicService.findTagsByTopicUri(topicUri,page,rows); PageInfo pageInfo = topicService.findTagsByTopicUri(topicUri, page, rows);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(pageInfo);
} }
@GetMapping("/topic/detail/{idTopic}") @GetMapping("/topic/detail/{idTopic}")
@ -138,27 +136,27 @@ public class AdminController {
} }
@PostMapping("/topic/bind-topic-tag") @PostMapping("/topic/bind-topic-tag")
public GlobalResult bindTopicTag(@RequestBody TopicTagDTO topicTag){ public GlobalResult bindTopicTag(@RequestBody TopicTagDTO topicTag) throws Exception {
Map map = topicService.bindTopicTag(topicTag); TopicTagDTO newTopicTagDTO = topicService.bindTopicTag(topicTag);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(newTopicTagDTO);
} }
@DeleteMapping("/topic/unbind-topic-tag") @DeleteMapping("/topic/unbind-topic-tag")
public GlobalResult unbindTopicTag(@RequestBody TopicTagDTO topicTag){ public GlobalResult unbindTopicTag(@RequestBody TopicTagDTO topicTag) throws Exception {
Map map = topicService.unbindTopicTag(topicTag); TopicTagDTO topicTagDTO = topicService.unbindTopicTag(topicTag);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(topicTagDTO);
} }
@PostMapping("/topic/post") @PostMapping("/topic/post")
public GlobalResult<Map> addTopic(@RequestBody Topic topic){ public GlobalResult<Topic> addTopic(@RequestBody Topic topic) throws Exception {
Map map = topicService.saveTopic(topic); Topic newTopic = topicService.saveTopic(topic);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(newTopic);
} }
@PutMapping("/topic/post") @PutMapping("/topic/post")
public GlobalResult<Map> updateTopic(@RequestBody Topic topic){ public GlobalResult<Topic> updateTopic(@RequestBody Topic topic) throws Exception {
Map map = topicService.saveTopic(topic); Topic newTopic = topicService.saveTopic(topic);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(newTopic);
} }
@GetMapping("/tags") @GetMapping("/tags")
@ -170,9 +168,9 @@ public class AdminController {
} }
@DeleteMapping("/tag/clean-unused") @DeleteMapping("/tag/clean-unused")
public GlobalResult cleanUnusedTag(){ public GlobalResult cleanUnusedTag() {
Map map = tagService.cleanUnusedTag(); boolean bool = tagService.cleanUnusedTag();
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(bool);
} }
@GetMapping("/tag/detail/{idTag}") @GetMapping("/tag/detail/{idTag}")
@ -182,15 +180,15 @@ public class AdminController {
} }
@PostMapping("/tag/post") @PostMapping("/tag/post")
public GlobalResult<Map> addTag(@RequestBody Tag tag){ public GlobalResult<Tag> addTag(@RequestBody Tag tag) throws Exception {
Map map = tagService.saveTag(tag); Tag newTag = tagService.saveTag(tag);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(newTag);
} }
@PutMapping("/tag/post") @PutMapping("/tag/post")
public GlobalResult<Map> updateTag(@RequestBody Tag tag){ public GlobalResult<Tag> updateTag(@RequestBody Tag tag) throws Exception {
Map map = tagService.saveTag(tag); Tag newTag = tagService.saveTag(tag);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(newTag);
} }
@GetMapping("/special-days") @GetMapping("/special-days")

View File

@ -24,7 +24,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
@ -106,15 +105,15 @@ public class ArticleController {
} }
@PostMapping("/thumbs-up") @PostMapping("/thumbs-up")
public GlobalResult thumbsUp(@RequestBody ArticleThumbsUp articleThumbsUp) throws BaseApiException { public GlobalResult thumbsUp(@RequestBody ArticleThumbsUp articleThumbsUp) throws Exception {
Map map = articleThumbsUpService.thumbsUp(articleThumbsUp); String str = articleThumbsUpService.thumbsUp(articleThumbsUp);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(str);
} }
@PostMapping("/sponsor") @PostMapping("/sponsor")
public GlobalResult sponsor(@RequestBody Sponsor sponsor) throws Exception { public GlobalResult sponsor(@RequestBody Sponsor sponsor) throws Exception {
Map map = sponsorService.sponsorship(sponsor); boolean flag = sponsorService.sponsorship(sponsor);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(flag);
} }
} }

View File

@ -2,6 +2,7 @@ package com.rymcu.forest.web.api.common;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.core.result.GlobalResult; import com.rymcu.forest.core.result.GlobalResult;
import com.rymcu.forest.core.result.GlobalResultGenerator; import com.rymcu.forest.core.result.GlobalResultGenerator;
import com.rymcu.forest.core.result.GlobalResultMessage; import com.rymcu.forest.core.result.GlobalResultMessage;
@ -68,13 +69,13 @@ public class CommonApiController {
} }
@PostMapping("/register") @PostMapping("/register")
public GlobalResult<Map> register(@RequestBody UserRegisterInfoDTO registerInfo) { public GlobalResult<Map> register(@RequestBody UserRegisterInfoDTO registerInfo) throws ServiceException {
Map map = userService.register(registerInfo.getEmail(), registerInfo.getPassword(), registerInfo.getCode()); userService.register(registerInfo.getEmail(), registerInfo.getPassword(), registerInfo.getCode());
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult();
} }
@PostMapping("/login") @PostMapping("/login")
public GlobalResult<TokenUser> login(@RequestBody User user) { public GlobalResult<TokenUser> login(@RequestBody User user) throws ServiceException {
TokenUser tokenUser = userService.login(user.getAccount(), user.getPassword()); TokenUser tokenUser = userService.login(user.getAccount(), user.getPassword());
return GlobalResultGenerator.genSuccessResult(tokenUser); return GlobalResultGenerator.genSuccessResult(tokenUser);
} }
@ -109,9 +110,9 @@ public class CommonApiController {
} }
@PatchMapping("/forget-password") @PatchMapping("/forget-password")
public GlobalResult<Map> forgetPassword(@RequestBody ForgetPasswordDTO forgetPassword) { public GlobalResult<String> forgetPassword(@RequestBody ForgetPasswordDTO forgetPassword) throws ServiceException {
Map map = userService.forgetPassword(forgetPassword.getCode(), forgetPassword.getPassword()); String str = userService.forgetPassword(forgetPassword.getCode(), forgetPassword.getPassword());
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(str);
} }
@GetMapping("/portfolio/{id}") @GetMapping("/portfolio/{id}")

View File

@ -1,5 +1,6 @@
package com.rymcu.forest.web.api.portfolio; package com.rymcu.forest.web.api.portfolio;
import com.github.pagehelper.PageInfo;
import com.rymcu.forest.core.result.GlobalResult; import com.rymcu.forest.core.result.GlobalResult;
import com.rymcu.forest.core.result.GlobalResultGenerator; import com.rymcu.forest.core.result.GlobalResultGenerator;
import com.rymcu.forest.core.service.security.annotation.AuthorshipInterceptor; import com.rymcu.forest.core.service.security.annotation.AuthorshipInterceptor;
@ -53,30 +54,30 @@ public class PortfolioController {
@GetMapping("/{idPortfolio}/unbind-articles") @GetMapping("/{idPortfolio}/unbind-articles")
@AuthorshipInterceptor(moduleName = Module.PORTFOLIO) @AuthorshipInterceptor(moduleName = Module.PORTFOLIO)
public GlobalResult unbindArticles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @RequestParam(defaultValue = "") String searchText,@PathVariable Long idPortfolio) throws BaseApiException { public GlobalResult unbindArticles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @RequestParam(defaultValue = "") String searchText, @PathVariable Long idPortfolio) throws Exception {
Map map = portfolioService.findUnbindArticles(page, rows, searchText, idPortfolio); PageInfo pageInfo = portfolioService.findUnbindArticles(page, rows, searchText, idPortfolio);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(pageInfo);
} }
@PostMapping("/bind-article") @PostMapping("/bind-article")
@AuthorshipInterceptor(moduleName = Module.PORTFOLIO) @AuthorshipInterceptor(moduleName = Module.PORTFOLIO)
public GlobalResult bindArticle(@RequestBody PortfolioArticleDTO portfolioArticle) { public GlobalResult bindArticle(@RequestBody PortfolioArticleDTO portfolioArticle) throws Exception {
Map map = portfolioService.bindArticle(portfolioArticle); boolean flag = portfolioService.bindArticle(portfolioArticle);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(flag);
} }
@PutMapping("/update-article-sort-no") @PutMapping("/update-article-sort-no")
@AuthorshipInterceptor(moduleName = Module.PORTFOLIO) @AuthorshipInterceptor(moduleName = Module.PORTFOLIO)
public GlobalResult updateArticleSortNo(@RequestBody PortfolioArticleDTO portfolioArticle) { public GlobalResult updateArticleSortNo(@RequestBody PortfolioArticleDTO portfolioArticle) throws Exception {
Map map = portfolioService.updateArticleSortNo(portfolioArticle); boolean flag = portfolioService.updateArticleSortNo(portfolioArticle);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(flag);
} }
@DeleteMapping("/unbind-article") @DeleteMapping("/unbind-article")
@AuthorshipInterceptor(moduleName = Module.PORTFOLIO) @AuthorshipInterceptor(moduleName = Module.PORTFOLIO)
public GlobalResult unbindArticle(Long idArticle, Long idPortfolio) { public GlobalResult unbindArticle(Long idArticle, Long idPortfolio) throws Exception {
Map map = portfolioService.unbindArticle(idPortfolio,idArticle); boolean flag = portfolioService.unbindArticle(idPortfolio, idArticle);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(flag);
} }
@DeleteMapping("/delete") @DeleteMapping("/delete")

View File

@ -2,6 +2,7 @@ package com.rymcu.forest.web.api.user;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.core.result.GlobalResult; import com.rymcu.forest.core.result.GlobalResult;
import com.rymcu.forest.core.result.GlobalResultGenerator; import com.rymcu.forest.core.result.GlobalResultGenerator;
import com.rymcu.forest.core.service.security.annotation.SecurityInterceptor; import com.rymcu.forest.core.service.security.annotation.SecurityInterceptor;
@ -41,37 +42,37 @@ public class UserInfoController {
@GetMapping("/check-nickname") @GetMapping("/check-nickname")
@SecurityInterceptor @SecurityInterceptor
public GlobalResult checkNickname(@RequestParam Long idUser, @RequestParam String nickname) { public GlobalResult checkNickname(@RequestParam Long idUser, @RequestParam String nickname) throws ServiceException {
Map map = userService.checkNickname(idUser, nickname); boolean flag = userService.checkNickname(idUser, nickname);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(flag);
} }
@PatchMapping("/update") @PatchMapping("/update")
@SecurityInterceptor @SecurityInterceptor
public GlobalResult updateUserInfo(@RequestBody UserInfoDTO user) { public GlobalResult updateUserInfo(@RequestBody UserInfoDTO user) throws Exception {
Map map = userService.updateUserInfo(user); UserInfoDTO newUsers = userService.updateUserInfo(user);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(newUsers);
} }
@PatchMapping("/update-extend") @PatchMapping("/update-extend")
@SecurityInterceptor @SecurityInterceptor
public GlobalResult updateUserExtend(@RequestBody UserExtend userExtend) { public GlobalResult updateUserExtend(@RequestBody UserExtend userExtend) throws ServiceException {
Map map = userService.updateUserExtend(userExtend); UserExtend map = userService.updateUserExtend(userExtend);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(map);
} }
@PatchMapping("/update-email") @PatchMapping("/update-email")
@SecurityInterceptor @SecurityInterceptor
public GlobalResult updateEmail(@RequestBody ChangeEmailDTO changeEmailDTO) { public GlobalResult updateEmail(@RequestBody ChangeEmailDTO changeEmailDTO) throws ServiceException {
Map map = userService.updateEmail(changeEmailDTO); String email = userService.updateEmail(changeEmailDTO);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(email);
} }
@PatchMapping("/update-password") @PatchMapping("/update-password")
@SecurityInterceptor @SecurityInterceptor
public GlobalResult updatePassword(@RequestBody UpdatePasswordDTO updatePasswordDTO) { public GlobalResult updatePassword(@RequestBody UpdatePasswordDTO updatePasswordDTO) {
Map map = userService.updatePassword(updatePasswordDTO); boolean flag = userService.updatePassword(updatePasswordDTO);
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(flag);
} }
@GetMapping("/login-records") @GetMapping("/login-records")