From 594090c626408cda071138e07fab035a90a32526 Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 3 Aug 2020 10:19:29 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rymcu/vertical/config/ShiroConfig.java | 1 - .../vertical/config/WebMvcConfigurer.java | 12 +-- .../service/redis/impl/RedisServiceImpl.java | 2 + .../com/rymcu/vertical/dto/ArticleDTO.java | 2 - .../rymcu/vertical/mapper/ArticleMapper.java | 3 +- .../vertical/service/ArticleService.java | 6 +- .../service/impl/ArticleServiceImpl.java | 15 ++-- .../java/com/rymcu/vertical/util/Utils.java | 78 ++++++++++--------- .../web/api/common/CommonApiController.java | 12 +-- .../web/api/common/UploadController.java | 2 +- 10 files changed, 71 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/config/ShiroConfig.java b/src/main/java/com/rymcu/vertical/config/ShiroConfig.java index 25b48ce..9fda51a 100644 --- a/src/main/java/com/rymcu/vertical/config/ShiroConfig.java +++ b/src/main/java/com/rymcu/vertical/config/ShiroConfig.java @@ -55,7 +55,6 @@ public class ShiroConfig implements EnvironmentAware { filterChainDefinitionMap.put("/api/**", "anon"); filterChainDefinitionMap.put("/ws/**", "anon"); - filterChainDefinitionMap.put("/wx/**", "anon"); filterChainDefinitionMap.put("/**", "auth"); //配置shiro默认登录界面地址,前后端分离中登录界面跳转应由前端路由控制,后台仅返回json数据 shiroFilterFactoryBean.setLoginUrl("/login"); diff --git a/src/main/java/com/rymcu/vertical/config/WebMvcConfigurer.java b/src/main/java/com/rymcu/vertical/config/WebMvcConfigurer.java index c45c0b0..8c053f0 100644 --- a/src/main/java/com/rymcu/vertical/config/WebMvcConfigurer.java +++ b/src/main/java/com/rymcu/vertical/config/WebMvcConfigurer.java @@ -23,6 +23,7 @@ import java.util.List; /** * Spring MVC 配置 + * * @author ronger */ @Configuration @@ -49,7 +50,7 @@ public class WebMvcConfigurer extends WebMvcConfigurationSupport { /** * 解决跨域问题 - * */ + */ @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") @@ -65,17 +66,18 @@ public class WebMvcConfigurer extends WebMvcConfigurationSupport { /** * 添加拦截器 - * */ + */ @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(restAuthTokenInterceptor()).addPathPatterns("/api/**") - .excludePathPatterns("/api/v1/console/**","/api/v1/article/articles/**","/api/v1/article/detail/**","/api/v1/topic/**","/api/v1/user/**"); + .excludePathPatterns("/api/v1/console/**", "/api/v1/article/articles/**", "/api/v1/article/detail/**" + , "/api/v1/topic/**", "/api/v1/user/**", "/api/v1/article/*/comments"); } /** * 访问静态资源 - * */ + */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { /** @@ -89,7 +91,7 @@ public class WebMvcConfigurer extends WebMvcConfigurationSupport { registry.addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/"); //将所有/static/** 访问都映射到classpath:/static/ 目录下 - registry.addResourceHandler("/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX +"/static/"); + registry.addResourceHandler("/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/static/"); super.addResourceHandlers(registry); } } diff --git a/src/main/java/com/rymcu/vertical/core/service/redis/impl/RedisServiceImpl.java b/src/main/java/com/rymcu/vertical/core/service/redis/impl/RedisServiceImpl.java index 90ef3af..85dc35a 100644 --- a/src/main/java/com/rymcu/vertical/core/service/redis/impl/RedisServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/core/service/redis/impl/RedisServiceImpl.java @@ -9,6 +9,7 @@ import com.rymcu.vertical.core.service.redis.RedisService; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import redis.clients.jedis.Jedis; @@ -27,6 +28,7 @@ import java.util.*; * 16/10/30 下午5:28 */ @Component("redisService") +@EnableConfigurationProperties({RedisProperties.class}) public class RedisServiceImpl implements RedisService { private static final Logger logger = LoggerFactory.getLogger(RedisServiceImpl.class); diff --git a/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java b/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java index aaa0759..ac89644 100644 --- a/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java +++ b/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java @@ -50,8 +50,6 @@ public class ArticleDTO { private List tags; - private List articleComments; - private List portfolios; private Integer sortNo; diff --git a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java index 6194cee..8c74ece 100644 --- a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java @@ -19,9 +19,10 @@ public interface ArticleMapper extends Mapper
{ * 获取文章列表 * @param searchText * @param tag + * @param topicUri * @return */ - List selectArticles(@Param("searchText") String searchText, @Param("tag") String tag); + List selectArticles(@Param("searchText") String searchText, @Param("tag") String tag, @Param("topicUri") String topicUri); /** * 根据文章 ID 查询文章 diff --git a/src/main/java/com/rymcu/vertical/service/ArticleService.java b/src/main/java/com/rymcu/vertical/service/ArticleService.java index 497cdf8..65f6718 100644 --- a/src/main/java/com/rymcu/vertical/service/ArticleService.java +++ b/src/main/java/com/rymcu/vertical/service/ArticleService.java @@ -2,6 +2,7 @@ package com.rymcu.vertical.service; import com.rymcu.vertical.core.service.Service; import com.rymcu.vertical.dto.ArticleDTO; +import com.rymcu.vertical.dto.ArticleSearchDTO; import com.rymcu.vertical.entity.Article; import com.rymcu.vertical.web.api.exception.BaseApiException; @@ -17,11 +18,10 @@ public interface ArticleService extends Service
{ /** * 根据检索内容/标签查询文章列表 - * @param searchText - * @param tag + * @param searchDTO * @return * */ - List findArticles(String searchText, String tag); + List findArticles(ArticleSearchDTO searchDTO); /** * 查询文章详情信息 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 271c40d..ef3808d 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java @@ -52,10 +52,16 @@ public class ArticleServiceImpl extends AbstractService
implements Arti private static final int MAX_PREVIEW = 200; private static final String defaultStatus = "0"; + private static final String defaultTopicUri = "news"; @Override - public List findArticles(String searchText, String tag) { - List list = articleMapper.selectArticles(searchText, tag); + public List findArticles(ArticleSearchDTO searchDTO) { + List list; + if (StringUtils.isNotBlank(searchDTO.getTopicUri()) && !defaultTopicUri.equals(searchDTO.getTopicUri())) { + list = articleMapper.selectArticlesByTopicUri(searchDTO.getTopicUri()); + } else { + list = articleMapper.selectArticles(searchDTO.getSearchText(), searchDTO.getTag(), searchDTO.getTopicUri()); + } list.forEach(article->{ genArticle(article,0); }); @@ -292,14 +298,13 @@ public class ArticleServiceImpl extends AbstractService
implements Arti ArticleContent articleContent = articleMapper.selectArticleContent(article.getIdArticle()); if (type.equals(ARTICLE_VIEW)){ article.setArticleContent(articleContent.getArticleContentHtml()); - // 获取评论列表数据 - List commentDTOList = commentService.getArticleComments(article.getIdArticle()); - article.setArticleComments(commentDTOList); // 获取所属作品集列表数据 List portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle()); article.setPortfolios(portfolioArticleDTOList); } else if (type.equals(ARTICLE_EDIT)) { article.setArticleContent(articleContent.getArticleContent()); + } else { + article.setArticleContent(articleContent.getArticleContentHtml()); } } return article; diff --git a/src/main/java/com/rymcu/vertical/util/Utils.java b/src/main/java/com/rymcu/vertical/util/Utils.java index c4b6983..e3554c0 100644 --- a/src/main/java/com/rymcu/vertical/util/Utils.java +++ b/src/main/java/com/rymcu/vertical/util/Utils.java @@ -34,19 +34,20 @@ public class Utils { String plain = Encodes.unescapeHtml(plainPassword); byte[] salt = Digests.generateSalt(SALT_SIZE); byte[] hashPassword = Digests.sha1(plain.getBytes(), salt, HASH_INTERATIONS); - return Encodes.encodeHex(salt)+Encodes.encodeHex(hashPassword); + return Encodes.encodeHex(salt) + Encodes.encodeHex(hashPassword); } /** - *一般检查工具密码比对 add by xlf 2018-11-8 + * 一般检查工具密码比对 add by xlf 2018-11-8 + * * @param pwd - * @param enpwd 加密的密码 + * @param enpwd 加密的密码 * @return */ - public static boolean comparePwd(String pwd,String enpwd){ - byte[] salt = Encodes.decodeHex(enpwd.substring(0,16)); + public static boolean comparePwd(String pwd, String enpwd) { + byte[] salt = Encodes.decodeHex(enpwd.substring(0, 16)); byte[] hashPassword = Digests.sha1(pwd.getBytes(), salt, HASH_INTERATIONS); - return enpwd.equals(Encodes.encodeHex(salt)+Encodes.encodeHex(hashPassword)); + return enpwd.equals(Encodes.encodeHex(salt) + Encodes.encodeHex(hashPassword)); } public static User getCurrentUser() { @@ -54,33 +55,34 @@ public class Utils { } public static Session getSession() { - try{ + try { Subject subject = SecurityUtils.getSubject(); Session session = subject.getSession(false); - if (session == null){ + if (session == null) { session = subject.getSession(); } - if (session != null){ + if (session != null) { return session; } subject.logout(); - }catch (InvalidSessionException e){ + } catch (InvalidSessionException e) { } return null; } public static Integer genCode() { - Integer code = (int)((Math.random()*9+1)*100000); + Integer code = (int) ((Math.random() * 9 + 1) * 100000); return code; } /** * 获取配置文件内属性 + * * @param key 键值 * @return 属性值 - * */ - public static String getProperty(String key){ + */ + public static String getProperty(String key) { return env.getProperty(key); } @@ -96,24 +98,24 @@ public class Utils { LocalDate today = LocalDate.now(); Period p = Period.between(oldLocalDate, today); - if(p.getYears() > 0){ - timeAgo = p.getYears()+" 年前 "; - }else if(p.getMonths() > 0){ - timeAgo = p.getMonths()+" 月前 "; - }else if(p.getDays() > 0){ - timeAgo = p.getDays()+" 天前 "; - }else { + if (p.getYears() > 0) { + timeAgo = p.getYears() + " 年前 "; + } else if (p.getMonths() > 0) { + timeAgo = p.getMonths() + " 月前 "; + } else if (p.getDays() > 0) { + timeAgo = p.getDays() + " 天前 "; + } else { long to = System.currentTimeMillis(); long from = date.getTime(); - int hours = (int) ((to - from)/(1000 * 60 * 60)); - if(hours > 0){ - timeAgo = hours+" 小时前 "; - }else { - int minutes = (int) ((to - from)/(1000 * 60)); - if(minutes == 0){ + int hours = (int) ((to - from) / (1000 * 60 * 60)); + if (hours > 0) { + timeAgo = hours + " 小时前 "; + } else { + int minutes = (int) ((to - from) / (1000 * 60)); + if (minutes < 5) { timeAgo = " 刚刚 "; - }else { - timeAgo = minutes+" 分钟前 "; + } else { + timeAgo = minutes + " 分钟前 "; } } } @@ -122,13 +124,13 @@ public class Utils { 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()); + pagination.put("pageSize", pageInfo.getPageSize()); + pagination.put("total", pageInfo.getTotal()); + pagination.put("currentPage", pageInfo.getPageNum()); return pagination; } - public static void main(String[] args){ + public static void main(String[] args) { LocalDate localDate = LocalDate.parse("2019-11-15"); ZoneId zone = ZoneId.systemDefault(); Instant instant = localDate.atStartOfDay().atZone(zone).toInstant(); @@ -140,9 +142,9 @@ public class Utils { Map map = new HashMap(2); map.put("articles", pageInfo.getList()); Map pagination = new HashMap(4); - pagination.put("pageSize",pageInfo.getPageSize()); - pagination.put("total",pageInfo.getTotal()); - pagination.put("currentPage",pageInfo.getPageNum()); + pagination.put("pageSize", pageInfo.getPageSize()); + pagination.put("total", pageInfo.getTotal()); + pagination.put("currentPage", pageInfo.getPageNum()); map.put("pagination", pagination); return map; } @@ -151,9 +153,9 @@ public class Utils { Map map = new HashMap(2); map.put("notifications", pageInfo.getList()); Map pagination = new HashMap(4); - pagination.put("pageSize",pageInfo.getPageSize()); - pagination.put("total",pageInfo.getTotal()); - pagination.put("currentPage",pageInfo.getPageNum()); + 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/common/CommonApiController.java b/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java index 722b5bc..34f4971 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 @@ -43,14 +43,14 @@ public class CommonApiController { @GetMapping("/get-email-code") public GlobalResult> getEmailCode(@RequestParam("email") String email) throws MessagingException { Map map = new HashMap<>(1); - map.put("message",GlobalResultMessage.SEND_SUCCESS.getMessage()); + map.put("message", GlobalResultMessage.SEND_SUCCESS.getMessage()); User user = userService.findByAccount(email); if (user != null) { map.put("message","该邮箱已被注册!"); } else { Integer result = javaMailService.sendEmailCode(email); if(result == 0){ - map.put("message",GlobalResultMessage.SEND_FAIL.getMessage()); + map.put("message", GlobalResultMessage.SEND_FAIL.getMessage()); } } return GlobalResultGenerator.genSuccessResult(map); @@ -60,12 +60,12 @@ public class CommonApiController { @GetMapping("/get-forget-password-email") public GlobalResult> getForgetPasswordEmail(@RequestParam("email") String email) throws MessagingException { Map map = new HashMap<>(1); - map.put("message",GlobalResultMessage.SEND_SUCCESS.getMessage()); + map.put("message", GlobalResultMessage.SEND_SUCCESS.getMessage()); User user = userService.findByAccount(email); if (user != null) { Integer result = javaMailService.sendForgetPasswordEmail(email); if(result == 0){ - map.put("message",GlobalResultMessage.SEND_FAIL.getMessage()); + map.put("message", GlobalResultMessage.SEND_FAIL.getMessage()); } } else { map.put("message","该邮箱未注册!"); @@ -92,9 +92,9 @@ public class CommonApiController { @GetMapping("/articles") @VisitLogger - 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, ArticleSearchDTO searchDTO){ PageHelper.startPage(page, rows); - List list = articleService.findArticles(searchText,tag); + List list = articleService.findArticles(searchDTO); 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/common/UploadController.java b/src/main/java/com/rymcu/vertical/web/api/common/UploadController.java index e2ae5c9..f8f9ddf 100644 --- a/src/main/java/com/rymcu/vertical/web/api/common/UploadController.java +++ b/src/main/java/com/rymcu/vertical/web/api/common/UploadController.java @@ -33,7 +33,7 @@ public class UploadController { private final static String UPLOAD_SIMPLE_URL = "/api/upload/file"; private final static String UPLOAD_URL = "/api/upload/file/batch"; - public static final String ctxHeadPicPath = "/usr/local/src/tomcat-hp/webapps/vertical"; + public static final String ctxHeadPicPath = "/usr/local/src/nebula/static"; @PostMapping("/file") public GlobalResult uploadPicture(@RequestParam(value = "file", required = false) MultipartFile multipartFile,@RequestParam(defaultValue = "1")Integer type, HttpServletRequest request){