diff --git a/README.md b/README.md index 9b61f42..525c8ce 100644 --- a/README.md +++ b/README.md @@ -1 +1,27 @@ -"# vertical" +# vertical +vertical [vərtikəl],取纵横之`纵`,寓为奔放自如、笔意纵横 +## 开发计划 +### 已完成 +- [x] 首页 +- [x] 会员登录/注册 +- [x] 文章发布/编辑/详情/删除 +- [x] 个人主页 +- [x] 找回密码 +- [x] 用户管理 +- [x] 角色/权限管理 (2019/12/05 21:52 更新) +- [x] 专题管理 (2019/12/05 21:52 更新) +### 待完成 +- [ ] 个人信息修改 +- [ ] 标签管理 +- [ ] 专题-标签管理 +- [ ] 用户-标签管理 +- [ ] 消息系统 +- [ ] 评论系统 +- [ ] SEO 优化 +- [ ] 分享功能 +- [ ] 数据统计 +### 构想 +- [ ] 专业知识题库 +- [ ] 社区贡献系统 +- [ ] 会员系统 +- [ ] 勋章系统 diff --git a/src/main/java/com/rymcu/vertical/entity/Article.java b/src/main/java/com/rymcu/vertical/entity/Article.java index aa63e9b..e389d2c 100644 --- a/src/main/java/com/rymcu/vertical/entity/Article.java +++ b/src/main/java/com/rymcu/vertical/entity/Article.java @@ -9,6 +9,9 @@ import javax.persistence.Table; import java.io.Serializable; import java.util.Date; +/** + * @author ronger + */ @Data @Table(name = "vertical_article") public class Article implements Serializable,Cloneable { diff --git a/src/main/java/com/rymcu/vertical/entity/ArticleContent.java b/src/main/java/com/rymcu/vertical/entity/ArticleContent.java index 5e4d080..baf2790 100644 --- a/src/main/java/com/rymcu/vertical/entity/ArticleContent.java +++ b/src/main/java/com/rymcu/vertical/entity/ArticleContent.java @@ -8,6 +8,9 @@ import javax.persistence.Id; import javax.persistence.Table; import java.util.Date; +/** + * @author ronger + */ @Data @Table(name = "vertical_article_content") public class ArticleContent { diff --git a/src/main/java/com/rymcu/vertical/entity/BaseDO.java b/src/main/java/com/rymcu/vertical/entity/BaseDO.java index d2abf51..650d48b 100644 --- a/src/main/java/com/rymcu/vertical/entity/BaseDO.java +++ b/src/main/java/com/rymcu/vertical/entity/BaseDO.java @@ -8,12 +8,15 @@ import java.io.Serializable; /** * 基础DO类,提供toString快方法 - * Created by liwei on 2015/6/16. + * + * @author liwei + * @date 2015/6/16 */ public class BaseDO implements Serializable { private static final long serialVersionUID = -1394589131426860408L; + @Override public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); } diff --git a/src/main/java/com/rymcu/vertical/entity/Tag.java b/src/main/java/com/rymcu/vertical/entity/Tag.java index 3ce0f77..2b6f113 100644 --- a/src/main/java/com/rymcu/vertical/entity/Tag.java +++ b/src/main/java/com/rymcu/vertical/entity/Tag.java @@ -9,6 +9,9 @@ import javax.persistence.Table; import java.io.Serializable; import java.util.Date; +/** + * @author ronger + */ @Data @Table(name = "vertical_tag") public class Tag implements Serializable,Cloneable { diff --git a/src/main/java/com/rymcu/vertical/entity/User.java b/src/main/java/com/rymcu/vertical/entity/User.java index ad78aa1..1faaf98 100644 --- a/src/main/java/com/rymcu/vertical/entity/User.java +++ b/src/main/java/com/rymcu/vertical/entity/User.java @@ -12,6 +12,9 @@ import javax.persistence.Table; import java.io.Serializable; import java.util.Date; +/** + * @author ronger + */ @Table(name = "vertical_user") @Data public class User implements Serializable,Cloneable { diff --git a/src/main/java/com/rymcu/vertical/jwt/def/JwtConstants.java b/src/main/java/com/rymcu/vertical/jwt/def/JwtConstants.java index ba75eab..cdee8a1 100644 --- a/src/main/java/com/rymcu/vertical/jwt/def/JwtConstants.java +++ b/src/main/java/com/rymcu/vertical/jwt/def/JwtConstants.java @@ -1,5 +1,8 @@ package com.rymcu.vertical.jwt.def; +/** + * @author ronger + */ public class JwtConstants { /** diff --git a/src/main/java/com/rymcu/vertical/jwt/model/TokenModel.java b/src/main/java/com/rymcu/vertical/jwt/model/TokenModel.java index c6ec64a..85e7f7f 100644 --- a/src/main/java/com/rymcu/vertical/jwt/model/TokenModel.java +++ b/src/main/java/com/rymcu/vertical/jwt/model/TokenModel.java @@ -7,10 +7,8 @@ package com.rymcu.vertical.jwt.model; */ public class TokenModel { - //用户id private String username; - //随机生成的uuid private String token; public TokenModel(String username, String token) { diff --git a/src/main/java/com/rymcu/vertical/service/ArticleService.java b/src/main/java/com/rymcu/vertical/service/ArticleService.java index a885547..6f217fc 100644 --- a/src/main/java/com/rymcu/vertical/service/ArticleService.java +++ b/src/main/java/com/rymcu/vertical/service/ArticleService.java @@ -10,16 +10,55 @@ import java.io.UnsupportedEncodingException; import java.util.List; import java.util.Map; +/** + * @author ronger + */ public interface ArticleService extends Service
{ + + /** + * 根据检索内容/标签查询文章列表 + * @param searchText + * @param tag + * @return + * */ List findArticles(String searchText, String tag); + /** + * 查询文章详情信息 + * @param id + * @param i + * @return + * */ ArticleDTO findArticleDTOById(Integer id, int i); + /** + * 查询主题下文章列表 + * @param name + * @return + * */ List findArticlesByTopicName(String name); + /** + * 查询标签下文章列表 + * @param name + * @return + * */ List findArticlesByTagName(String name); + /** + * 查询用户文章列表 + * @param idUser + * @return + * */ List findUserArticlesByIdUser(Integer idUser); + /** + * 新增/更新文章 + * @param article + * @param request + * @throws UnsupportedEncodingException + * @throws BaseApiException + * @return + * */ Map postArticle(ArticleDTO article, HttpServletRequest request) throws UnsupportedEncodingException, BaseApiException; } diff --git a/src/main/java/com/rymcu/vertical/service/PermissionService.java b/src/main/java/com/rymcu/vertical/service/PermissionService.java index 8f5f7b2..74eea8c 100644 --- a/src/main/java/com/rymcu/vertical/service/PermissionService.java +++ b/src/main/java/com/rymcu/vertical/service/PermissionService.java @@ -8,7 +8,9 @@ import java.util.List; /** - * Created by CodeGenerator on 2018/05/29. + * + * @author CodeGenerator + * @date 2018/05/29 */ public interface PermissionService extends Service { diff --git a/src/main/java/com/rymcu/vertical/service/RoleService.java b/src/main/java/com/rymcu/vertical/service/RoleService.java index 066f8e3..0bac4f7 100644 --- a/src/main/java/com/rymcu/vertical/service/RoleService.java +++ b/src/main/java/com/rymcu/vertical/service/RoleService.java @@ -9,15 +9,38 @@ import java.util.Map; /** - * Created by CodeGenerator on 2018/05/29. + * + * @author CodeGenerator + * @date 2018/05/29 */ public interface RoleService extends Service { - List selectRoleByUser(User sysUser); + /** + * 查询用户角色 + * @param user + * @return + * */ + List selectRoleByUser(User user); + /** + * 查询用户角色 + * @param idUser + * @return + * */ List findByIdUser(Integer idUser); + /** + * 更新用户状态 + * @param idRole + * @param status + * @return + * */ Map updateStatus(Integer idRole, String status); + /** + * 添加/更新角色 + * @param role + * @return + * */ Map saveRole(Role role); } diff --git a/src/main/java/com/rymcu/vertical/service/TagService.java b/src/main/java/com/rymcu/vertical/service/TagService.java index e7ff321..b83a5cf 100644 --- a/src/main/java/com/rymcu/vertical/service/TagService.java +++ b/src/main/java/com/rymcu/vertical/service/TagService.java @@ -7,7 +7,17 @@ import com.rymcu.vertical.web.api.exception.BaseApiException; import java.io.UnsupportedEncodingException; +/** + * @author ronger + */ public interface TagService extends Service { - void saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException; + /** + * 保存文章标签 + * @param article + * @throws UnsupportedEncodingException + * @throws BaseApiException + * @return + * */ + Integer saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException; } diff --git a/src/main/java/com/rymcu/vertical/service/TopicService.java b/src/main/java/com/rymcu/vertical/service/TopicService.java index 5192e8f..8b8a6e5 100644 --- a/src/main/java/com/rymcu/vertical/service/TopicService.java +++ b/src/main/java/com/rymcu/vertical/service/TopicService.java @@ -26,5 +26,10 @@ public interface TopicService extends Service { * */ Map findTopicByTopicUri(String topicUri, Integer page, Integer rows); + /** + * 新增/更新主题信息 + * @param topic 主题信息 + * @return + * */ Map saveTopic(Topic topic); } diff --git a/src/main/java/com/rymcu/vertical/service/UserService.java b/src/main/java/com/rymcu/vertical/service/UserService.java index 21e4685..96d7afa 100644 --- a/src/main/java/com/rymcu/vertical/service/UserService.java +++ b/src/main/java/com/rymcu/vertical/service/UserService.java @@ -9,21 +9,65 @@ import java.util.Map; /** - * Created by CodeGenerator on 2018/05/29. + * + * @author CodeGenerator + * @date 2018/05/29 */ public interface UserService extends Service { + /** + * 通过账号查询用户信息 + * @param account + * @throws TooManyResultsException + * @return User + * */ User findByAccount(String account) throws TooManyResultsException; + /** + * 注册接口 + * @param email 邮箱 + * @param password 密码 + * @param code 验证码 + * @return Map + * */ Map register(String email, String password, String code); + /** + * 登录接口 + * @param account 邮箱 + * @param password 密码 + * @return Map + * */ Map login(String account, String password); + /** + * 通过 nickname 获取用户信息接口 + * @param nickname 昵称 + * @return UserDTO + * */ UserDTO findUserDTOByNickname(String nickname); + /** + * 找回密码接口 + * @param code 验证码 + * @param password 密码 + * @return Map + * */ Map forgetPassword(String code, String password); + /** + * 更新用户角色接口 + * @param idUser 用户 id + * @param idRole 角色 id + * @return Map + * */ Map updateUserRole(Integer idUser, Integer idRole); + /** + * 更新用户状态 + * @param idUser 用户 id + * @param status 状态 + * @return Map + * */ Map updateStatus(Integer idUser, String status); } diff --git a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java index 026699b..8dc7c6e 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java @@ -26,6 +26,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +/** + * @author ronger + */ @Service public class ArticleServiceImpl extends AbstractService
implements ArticleService { @@ -78,7 +81,7 @@ public class ArticleServiceImpl extends AbstractService
implements Arti } @Override - @Transactional(rollbackFor = Exception.class) + @Transactional(rollbackFor = { UnsupportedEncodingException.class,BaseApiException.class }) public Map postArticle(ArticleDTO article, HttpServletRequest request) throws UnsupportedEncodingException, BaseApiException { Map map = new HashMap(1); if(StringUtils.isBlank(article.getArticleTitle())){ diff --git a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java index ae4a882..345e813 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java @@ -17,6 +17,9 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Date; +/** + * @author ronger + */ @Service public class TagServiceImpl extends AbstractService implements TagService { @@ -24,8 +27,8 @@ public class TagServiceImpl extends AbstractService implements TagService { private TagMapper tagMapper; @Override - @Transactional - public void saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException { + @Transactional(rollbackFor = { UnsupportedEncodingException.class,BaseApiException.class }) + public Integer saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException { User user = UserUtils.getWxCurrentUser(); String articleTags = article.getArticleTags(); if(StringUtils.isNotBlank(articleTags)){ @@ -62,6 +65,8 @@ public class TagServiceImpl extends AbstractService implements TagService { tagMapper.insertUserTag(tag.getIdTag(),user.getIdUser(),1); } } + return 1; } + return 0; } } diff --git a/src/main/java/com/rymcu/vertical/util/Digests.java b/src/main/java/com/rymcu/vertical/util/Digests.java index 99b42bf..2629d1a 100644 --- a/src/main/java/com/rymcu/vertical/util/Digests.java +++ b/src/main/java/com/rymcu/vertical/util/Digests.java @@ -12,7 +12,8 @@ import java.security.SecureRandom; * 支持SHA-1/MD5消息摘要的工具类. * * 返回ByteSource,可进一步被编码为Hex, Base64或UrlSafeBase64 - * + * + * @author ronger */ public class Digests { diff --git a/src/main/java/com/rymcu/vertical/util/Encodes.java b/src/main/java/com/rymcu/vertical/util/Encodes.java index 5893aa2..8c42241 100644 --- a/src/main/java/com/rymcu/vertical/util/Encodes.java +++ b/src/main/java/com/rymcu/vertical/util/Encodes.java @@ -18,6 +18,7 @@ import java.net.URLEncoder; * 2.自制的base62 编码 * 3.Commons-Lang的xml/html escape * 4.JDK提供的URLEncoder + * @author ronger */ public class Encodes { diff --git a/src/main/java/com/rymcu/vertical/util/ErrorCode.java b/src/main/java/com/rymcu/vertical/util/ErrorCode.java index 96a8e48..86a36ad 100644 --- a/src/main/java/com/rymcu/vertical/util/ErrorCode.java +++ b/src/main/java/com/rymcu/vertical/util/ErrorCode.java @@ -1,7 +1,9 @@ package com.rymcu.vertical.util; /** - * Created by kaenry on 2016/9/20. + * + * @author kaenry + * @date 2016/9/20 * ErrorCode */ public enum ErrorCode { diff --git a/src/main/java/com/rymcu/vertical/util/Exceptions.java b/src/main/java/com/rymcu/vertical/util/Exceptions.java index 4cbd14c..6d3c30d 100644 --- a/src/main/java/com/rymcu/vertical/util/Exceptions.java +++ b/src/main/java/com/rymcu/vertical/util/Exceptions.java @@ -9,6 +9,7 @@ import java.io.StringWriter; /** * 关于异常的工具类. + * @author ronger */ public class Exceptions { diff --git a/src/main/java/com/rymcu/vertical/util/FileUtils.java b/src/main/java/com/rymcu/vertical/util/FileUtils.java index d8426fd..137c0c3 100644 --- a/src/main/java/com/rymcu/vertical/util/FileUtils.java +++ b/src/main/java/com/rymcu/vertical/util/FileUtils.java @@ -1,6 +1,8 @@ package com.rymcu.vertical.util; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.web.multipart.MultipartFile; import java.io.*; @@ -12,6 +14,8 @@ import java.net.URLEncoder; * */ public class FileUtils { + + private static final Logger logger = LoggerFactory.getLogger(FileUtils.class); /** * 获取文件扩展名 * @@ -159,7 +163,7 @@ public class FileUtils { File fileDelete = new File(strFileName); if (!fileDelete.exists() || !fileDelete.isFile()) { - //LogUtil.info("错误: " + strFileName + "不存在!"); + logger.info("错误: " + strFileName + "不存在!"); return false; } diff --git a/src/main/java/com/rymcu/vertical/util/Html2TextUtil.java b/src/main/java/com/rymcu/vertical/util/Html2TextUtil.java index 2ac84cd..6248990 100644 --- a/src/main/java/com/rymcu/vertical/util/Html2TextUtil.java +++ b/src/main/java/com/rymcu/vertical/util/Html2TextUtil.java @@ -4,6 +4,9 @@ import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.parser.ParserDelegator; import java.io.*; +/** + * @author ronger + */ public class Html2TextUtil extends HTMLEditorKit.ParserCallback { private static Html2TextUtil html2Text = new Html2TextUtil(); diff --git a/src/main/java/com/rymcu/vertical/util/MailSSLSocketFactory.java b/src/main/java/com/rymcu/vertical/util/MailSSLSocketFactory.java deleted file mode 100644 index a724cd0..0000000 --- a/src/main/java/com/rymcu/vertical/util/MailSSLSocketFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.rymcu.vertical.util; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import java.io.IOException; -import java.net.InetAddress; -import java.net.Socket; -import java.net.UnknownHostException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; - -public class MailSSLSocketFactory extends SSLSocketFactory { - - private SSLSocketFactory factory; - - public MailSSLSocketFactory() throws NoSuchAlgorithmException, KeyManagementException { - SSLContext sslcontext = SSLContext.getInstance("TLS"); - sslcontext.init(null, new TrustManager[] { new MailTrustManager() }, null); - factory = sslcontext.getSocketFactory(); - } - - @Override - public String[] getDefaultCipherSuites() { - return factory.getDefaultCipherSuites(); - } - - @Override - public String[] getSupportedCipherSuites() { - return factory.getSupportedCipherSuites(); - } - - @Override - public Socket createSocket(Socket socket, String s, int i, boolean b) throws IOException { - return factory.createSocket(socket, s, i, b); - } - - @Override - public Socket createSocket(String s, int i) throws IOException, UnknownHostException { - return factory.createSocket(s, i); - } - - @Override - public Socket createSocket(String s, int i, InetAddress inetAddress, int i1) throws IOException, UnknownHostException { - return factory.createSocket(s, i, inetAddress, i1); - } - - @Override - public Socket createSocket(InetAddress inetAddress, int i) throws IOException { - return factory.createSocket(inetAddress, i); - } - - @Override - public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddress1, int i1) throws IOException { - return factory.createSocket(inetAddress, i, inetAddress1, i1); - } -} diff --git a/src/main/java/com/rymcu/vertical/util/MailTrustManager.java b/src/main/java/com/rymcu/vertical/util/MailTrustManager.java deleted file mode 100644 index 5deb42c..0000000 --- a/src/main/java/com/rymcu/vertical/util/MailTrustManager.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.rymcu.vertical.util; - -import javax.net.ssl.X509TrustManager; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; - -public class MailTrustManager implements X509TrustManager { - @Override - public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { - - } - - @Override - public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { - - } - - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } -} diff --git a/src/main/java/com/rymcu/vertical/util/SpringContextHolder.java b/src/main/java/com/rymcu/vertical/util/SpringContextHolder.java index b8b398e..561e66f 100644 --- a/src/main/java/com/rymcu/vertical/util/SpringContextHolder.java +++ b/src/main/java/com/rymcu/vertical/util/SpringContextHolder.java @@ -19,7 +19,8 @@ import java.util.Date; /** * 以静态变量保存Spring ApplicationContext, 可在任何代码任何地方任何时候取出ApplicaitonContext. - * + * + * @author ronger */ @Service @Lazy(false) diff --git a/src/main/java/com/rymcu/vertical/util/Utils.java b/src/main/java/com/rymcu/vertical/util/Utils.java index 3b8c66b..37e4409 100644 --- a/src/main/java/com/rymcu/vertical/util/Utils.java +++ b/src/main/java/com/rymcu/vertical/util/Utils.java @@ -1,5 +1,7 @@ package com.rymcu.vertical.util; +import com.github.pagehelper.PageInfo; +import com.rymcu.vertical.dto.ArticleDTO; import com.rymcu.vertical.entity.User; import org.apache.shiro.SecurityUtils; import org.apache.shiro.session.InvalidSessionException; @@ -9,7 +11,12 @@ import org.springframework.core.env.Environment; import java.time.*; import java.util.Date; +import java.util.HashMap; +import java.util.Map; +/** + * @author ronger + */ public class Utils { public static final String HASH_ALGORITHM = "SHA-1"; public static final int HASH_INTERATIONS = 1024; @@ -53,7 +60,7 @@ public class Utils { if (session != null){ return session; } -// subject.logout(); + subject.logout(); }catch (InvalidSessionException e){ } @@ -110,6 +117,14 @@ public class Utils { return timeAgo; } + public static Map getPagination(PageInfo pageInfo) { + Map pagination = new HashMap(3); + pagination.put("pageSize",pageInfo.getPageSize()); + pagination.put("total",pageInfo.getTotal()); + pagination.put("currentPage",pageInfo.getPageNum()); + return pagination; + } + public static void main(String[] args){ LocalDate localDate = LocalDate.parse("2019-11-15"); ZoneId zone = ZoneId.systemDefault(); @@ -117,4 +132,15 @@ public class Utils { String s = getTimeAgo(Date.from(instant)); System.out.println(s); } + + public static Map getArticlesGlobalResult(PageInfo pageInfo) { + Map map = new HashMap(2); + map.put("articles", pageInfo.getList()); + 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; + } } diff --git a/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java b/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java index e4a2c7a..68c2cf1 100644 --- a/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java +++ b/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java @@ -11,6 +11,7 @@ import com.rymcu.vertical.entity.User; import com.rymcu.vertical.service.RoleService; import com.rymcu.vertical.service.TopicService; import com.rymcu.vertical.service.UserService; +import com.rymcu.vertical.util.Utils; import org.apache.commons.lang.StringUtils; import org.springframework.web.bind.annotation.*; @@ -34,13 +35,13 @@ public class AdminController { private TopicService topicService; @GetMapping("/users") - public GlobalResult users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){ + public GlobalResult> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){ PageHelper.startPage(page, rows); List list = userService.findAll(); - PageInfo pageInfo = new PageInfo(list); - Map map = new HashMap(2); + PageInfo pageInfo = new PageInfo<>(list); + Map map = new HashMap(2); map.put("users", pageInfo.getList()); - Map pagination = new HashMap(3); + Map pagination = new HashMap<>(3); pagination.put("pageSize",pageInfo.getPageSize()); pagination.put("total",pageInfo.getTotal()); pagination.put("currentPage",pageInfo.getPageNum()); @@ -49,67 +50,61 @@ public class AdminController { } @GetMapping("/user/{idUser}/role") - public GlobalResult userRole(@PathVariable Integer idUser){ + public GlobalResult> userRole(@PathVariable Integer idUser){ List roles = roleService.findByIdUser(idUser); return GlobalResultGenerator.genSuccessResult(roles); } @GetMapping("/roles") - public GlobalResult roles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){ + public GlobalResult> roles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){ PageHelper.startPage(page, rows); List list = roleService.findAll(); - PageInfo pageInfo = new PageInfo(list); - Map map = new HashMap(2); + PageInfo pageInfo = new PageInfo<>(list); + Map map = new HashMap(2); map.put("roles", pageInfo.getList()); - Map pagination = new HashMap(3); - pagination.put("pageSize",pageInfo.getPageSize()); - pagination.put("total",pageInfo.getTotal()); - pagination.put("currentPage",pageInfo.getPageNum()); + Map pagination = Utils.getPagination(pageInfo); map.put("pagination", pagination); return GlobalResultGenerator.genSuccessResult(map); } @PatchMapping("/user/update-role") - public GlobalResult updateUserRole(@RequestBody UserRoleDTO userRole){ + public GlobalResult updateUserRole(@RequestBody UserRoleDTO userRole){ Map map = userService.updateUserRole(userRole.getIdUser(),userRole.getIdRole()); return GlobalResultGenerator.genSuccessResult(map); } @PatchMapping("/user/update-status") - public GlobalResult updateUserStatus(@RequestBody User user){ + public GlobalResult updateUserStatus(@RequestBody User user){ Map map = userService.updateStatus(user.getIdUser(),user.getStatus()); return GlobalResultGenerator.genSuccessResult(map); } @PatchMapping("/role/update-status") - public GlobalResult updateRoleStatus(@RequestBody Role role){ + public GlobalResult updateRoleStatus(@RequestBody Role role){ Map map = roleService.updateStatus(role.getIdRole(),role.getStatus()); return GlobalResultGenerator.genSuccessResult(map); } @PostMapping("/role/post") - public GlobalResult addRole(@RequestBody Role role){ + public GlobalResult addRole(@RequestBody Role role){ Map map = roleService.saveRole(role); return GlobalResultGenerator.genSuccessResult(map); } @PutMapping("/role/post") - public GlobalResult updateRole(@RequestBody Role role){ + public GlobalResult updateRole(@RequestBody Role role){ Map map = roleService.saveRole(role); return GlobalResultGenerator.genSuccessResult(map); } @GetMapping("/topics") - public GlobalResult topics(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){ + public GlobalResult> topics(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){ PageHelper.startPage(page, rows); List list = topicService.findAll(); - PageInfo pageInfo = new PageInfo(list); - Map map = new HashMap(2); + PageInfo pageInfo = new PageInfo<>(list); + Map map = new HashMap<>(2); map.put("topics", pageInfo.getList()); - Map pagination = new HashMap(3); - pagination.put("pageSize",pageInfo.getPageSize()); - pagination.put("total",pageInfo.getTotal()); - pagination.put("currentPage",pageInfo.getPageNum()); + Map pagination = Utils.getPagination(pageInfo); map.put("pagination", pagination); return GlobalResultGenerator.genSuccessResult(map); } @@ -124,19 +119,19 @@ public class AdminController { } @GetMapping("/topic/detail/{idTopic}") - public GlobalResult topicDetail(@PathVariable Integer idTopic){ + public GlobalResult topicDetail(@PathVariable Integer idTopic){ Topic topic = topicService.findById(idTopic.toString()); return GlobalResultGenerator.genSuccessResult(topic); } @PostMapping("/topic/post") - public GlobalResult addTopic(@RequestBody Topic topic){ + public GlobalResult addTopic(@RequestBody Topic topic){ Map map = topicService.saveTopic(topic); return GlobalResultGenerator.genSuccessResult(map); } @PutMapping("/topic/post") - public GlobalResult updateTopic(@RequestBody Topic topic){ + public GlobalResult updateTopic(@RequestBody Topic topic){ Map map = topicService.saveTopic(topic); return GlobalResultGenerator.genSuccessResult(map); } diff --git a/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java b/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java index 345ea23..a911e6e 100644 --- a/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java +++ b/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java @@ -12,6 +12,9 @@ import javax.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; import java.util.Map; +/** + * @author ronger + */ @RestController @RequestMapping("/api/v1/article") public class ArticleController { diff --git a/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java b/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java index 3946017..88397d0 100644 --- a/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java +++ b/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java @@ -13,6 +13,7 @@ import com.rymcu.vertical.service.ArticleService; import com.rymcu.vertical.service.JavaMailService; import com.rymcu.vertical.service.UserService; import com.rymcu.vertical.util.UserUtils; +import com.rymcu.vertical.util.Utils; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; @@ -22,6 +23,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +/** + * @author ronger + */ @RestController @RequestMapping("/api/v1/console") public class CommonApiController { @@ -35,8 +39,8 @@ public class CommonApiController { @ApiOperation(value = "获取邮件验证码") @PostMapping("/get-email-code") - public GlobalResult getEmailCode(@RequestParam("email") String email) throws MessagingException { - Map map = new HashMap(); + public GlobalResult> getEmailCode(@RequestParam("email") String email) throws MessagingException { + Map map = new HashMap<>(1); map.put("message",GlobalResultMessage.SEND_SUCCESS.getMessage()); User user = userService.findByAccount(email); if (user != null) { @@ -52,8 +56,8 @@ public class CommonApiController { @ApiOperation(value = "获取找回密码邮件") @PostMapping("/get-forget-password-email") - public GlobalResult getForgetPasswordEmail(@RequestParam("email") String email) throws MessagingException { - Map map = new HashMap<>(1); + public GlobalResult> getForgetPasswordEmail(@RequestParam("email") String email) throws MessagingException { + Map map = new HashMap<>(1); map.put("message",GlobalResultMessage.SEND_SUCCESS.getMessage()); User user = userService.findByAccount(email); if (user != null) { @@ -68,13 +72,13 @@ public class CommonApiController { } @PostMapping("/register") - public GlobalResult register(@RequestParam("email") String email, @RequestParam("password") String password, @RequestParam("code") String code){ + public GlobalResult register(@RequestParam("email") String email, @RequestParam("password") String password, @RequestParam("code") String code){ Map map = userService.register(email,password,code); return GlobalResultGenerator.genSuccessResult(map); } @PostMapping("/login") - public GlobalResult login(@RequestParam("account") String account, @RequestParam("password") String password){ + public GlobalResult login(@RequestParam("account") String account, @RequestParam("password") String password){ Map map = userService.login(account,password); return GlobalResultGenerator.genSuccessResult(map); } @@ -85,32 +89,26 @@ public class CommonApiController { } @GetMapping("/articles") - public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page,@RequestParam(defaultValue = "10") Integer rows,@RequestParam(defaultValue = "") String searchText,@RequestParam(defaultValue = "") String tag){ + public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @RequestParam(defaultValue = "") String searchText, @RequestParam(defaultValue = "") String tag){ PageHelper.startPage(page, rows); List list = articleService.findArticles(searchText,tag); - PageInfo pageInfo = new PageInfo(list); - Map map = new HashMap(2); - map.put("articles", pageInfo.getList()); - Map pagination = new HashMap(3); - pagination.put("pageSize",pageInfo.getPageSize()); - pagination.put("total",pageInfo.getTotal()); - pagination.put("currentPage",pageInfo.getPageNum()); - map.put("pagination", pagination); + PageInfo pageInfo = new PageInfo(list); + Map map = Utils.getArticlesGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(map); } @GetMapping("/article/{id}") - public GlobalResult detail(@PathVariable Integer id){ + public GlobalResult> detail(@PathVariable Integer id){ ArticleDTO articleDTO = articleService.findArticleDTOById(id,1); - Map map = new HashMap<>(1); + Map map = new HashMap<>(1); map.put("article", articleDTO); return GlobalResultGenerator.genSuccessResult(map); } @GetMapping("/update/{id}") - public GlobalResult update(@PathVariable Integer id){ + public GlobalResult> update(@PathVariable Integer id){ ArticleDTO articleDTO = articleService.findArticleDTOById(id,2); Map map = new HashMap<>(1); map.put("article", articleDTO); @@ -118,13 +116,13 @@ public class CommonApiController { } @GetMapping("/token/{token}") - public GlobalResult token(@PathVariable String token){ + public GlobalResult token(@PathVariable String token){ TokenUser tokenUser = UserUtils.getTokenUser(token); return GlobalResultGenerator.genSuccessResult(tokenUser); } @PatchMapping("/forget-password") - public GlobalResult forgetPassword(@RequestBody ForgetPasswordDTO forgetPassword){ + public GlobalResult forgetPassword(@RequestBody ForgetPasswordDTO forgetPassword){ Map map = userService.forgetPassword(forgetPassword.getCode(), forgetPassword.getPassword()); return GlobalResultGenerator.genSuccessResult(map); } diff --git a/src/main/java/com/rymcu/vertical/web/api/tag/TagController.java b/src/main/java/com/rymcu/vertical/web/api/tag/TagController.java index cdf128e..700bac3 100644 --- a/src/main/java/com/rymcu/vertical/web/api/tag/TagController.java +++ b/src/main/java/com/rymcu/vertical/web/api/tag/TagController.java @@ -6,13 +6,16 @@ import com.rymcu.vertical.core.result.GlobalResult; import com.rymcu.vertical.core.result.GlobalResultGenerator; import com.rymcu.vertical.dto.ArticleDTO; import com.rymcu.vertical.service.ArticleService; +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/tag") public class TagController { @@ -24,14 +27,8 @@ public class TagController { public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @PathVariable String name){ PageHelper.startPage(page, rows); List list = articleService.findArticlesByTagName(name); - PageInfo pageInfo = new PageInfo(list); - Map map = new HashMap(2); - map.put("articles", pageInfo.getList()); - Map pagination = new HashMap(3); - pagination.put("pageSize",pageInfo.getPageSize()); - pagination.put("total",pageInfo.getTotal()); - pagination.put("currentPage",pageInfo.getPageNum()); - map.put("pagination", pagination); + PageInfo pageInfo = new PageInfo(list); + Map map = Utils.getArticlesGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(map); } } diff --git a/src/main/java/com/rymcu/vertical/web/api/topic/TopicController.java b/src/main/java/com/rymcu/vertical/web/api/topic/TopicController.java index 611e520..0f580e6 100644 --- a/src/main/java/com/rymcu/vertical/web/api/topic/TopicController.java +++ b/src/main/java/com/rymcu/vertical/web/api/topic/TopicController.java @@ -8,14 +8,16 @@ import com.rymcu.vertical.dto.ArticleDTO; import com.rymcu.vertical.entity.Topic; import com.rymcu.vertical.service.ArticleService; import com.rymcu.vertical.service.TopicService; +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; -@SuppressWarnings("ALL") +/** + * @author ronger + */ @RestController @RequestMapping("/api/v1/topic") public class TopicController { @@ -34,14 +36,8 @@ public class TopicController { public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @PathVariable String name){ PageHelper.startPage(page, rows); List list = articleService.findArticlesByTopicName(name); - PageInfo pageInfo = new PageInfo(list); - Map map = new HashMap(2); - map.put("articles", pageInfo.getList()); - Map pagination = new HashMap(3); - pagination.put("pageSize",pageInfo.getPageSize()); - pagination.put("total",pageInfo.getTotal()); - pagination.put("currentPage",pageInfo.getPageNum()); - map.put("pagination", pagination); + PageInfo pageInfo = new PageInfo(list); + Map map = Utils.getArticlesGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(map); } } diff --git a/src/main/java/com/rymcu/vertical/web/api/user/UserController.java b/src/main/java/com/rymcu/vertical/web/api/user/UserController.java index 32f051f..026b2fc 100644 --- a/src/main/java/com/rymcu/vertical/web/api/user/UserController.java +++ b/src/main/java/com/rymcu/vertical/web/api/user/UserController.java @@ -8,14 +8,16 @@ import com.rymcu.vertical.dto.ArticleDTO; import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.service.ArticleService; 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.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; +/** + * @author ronger + */ @RestController @RequestMapping("/api/v1/user") public class UserController { @@ -39,14 +41,8 @@ public class UserController { } PageHelper.startPage(page, rows); List list = articleService.findUserArticlesByIdUser(userDTO.getIdUser()); - PageInfo pageInfo = new PageInfo(list); - Map map = new HashMap(2); - map.put("articles", pageInfo.getList()); - Map pagination = new HashMap(3); - pagination.put("pageSize",pageInfo.getPageSize()); - pagination.put("total",pageInfo.getTotal()); - pagination.put("currentPage",pageInfo.getPageNum()); - map.put("pagination", pagination); + PageInfo pageInfo = new PageInfo(list); + Map map = Utils.getArticlesGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(map); }