commit
7704cf0a1c
@ -8,12 +8,9 @@ import com.rymcu.vertical.service.ArticleService;
|
||||
import com.rymcu.vertical.service.VisitService;
|
||||
import com.rymcu.vertical.util.UserUtils;
|
||||
import com.rymcu.vertical.util.Utils;
|
||||
import com.rymcu.vertical.web.api.exception.BaseApiException;
|
||||
import com.rymcu.vertical.web.api.exception.ErrorCode;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -42,4 +42,6 @@ public class Tag implements Serializable,Cloneable {
|
||||
private Date createdTime;
|
||||
/** 更新时间 */
|
||||
private Date updatedTime;
|
||||
/** 保留标签 */
|
||||
private String tagReservation;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@ public interface TagMapper extends Mapper<Tag> {
|
||||
|
||||
Integer deleteUnusedTag();
|
||||
|
||||
Integer update(@Param("idTag") Integer idTag, @Param("tagUri") String tagUri, @Param("tagIconPath") String tagIconPath, @Param("tagStatus") String tagStatus, @Param("tagDescription") String tagDescription);
|
||||
Integer update(@Param("idTag") Integer idTag, @Param("tagUri") String tagUri, @Param("tagIconPath") String tagIconPath, @Param("tagStatus") String tagStatus, @Param("tagDescription") String tagDescription, @Param("tagReservation") String tagReservation);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.rymcu.vertical.dto.ArticleTagDTO;
|
||||
import com.rymcu.vertical.dto.Author;
|
||||
import com.rymcu.vertical.entity.Article;
|
||||
import com.rymcu.vertical.entity.ArticleContent;
|
||||
import com.rymcu.vertical.entity.Tag;
|
||||
import com.rymcu.vertical.entity.User;
|
||||
import com.rymcu.vertical.mapper.ArticleMapper;
|
||||
import com.rymcu.vertical.service.ArticleService;
|
||||
@ -19,6 +20,7 @@ import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -40,10 +42,9 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
||||
private TagService tagService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Value("${reserved-words}")
|
||||
private String reservedWords;
|
||||
|
||||
private static final String DOMAIN = "https://rymcu.com";
|
||||
@Value("${resource.domain}")
|
||||
private static String domain;
|
||||
|
||||
private static final int MAX_PREVIEW = 200;
|
||||
|
||||
@ -101,82 +102,92 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
||||
String articleContent = article.getArticleContent();
|
||||
String articleContentHtml = article.getArticleContentHtml();
|
||||
User user = UserUtils.getWxCurrentUser();
|
||||
boolean checkTags = checkTags(articleTags);
|
||||
String reservedTag = checkTags(articleTags);
|
||||
boolean notification = false;
|
||||
if (checkTags) {
|
||||
if (StringUtils.isNotBlank(reservedTag)) {
|
||||
Integer roleWeights = userService.findRoleWeightsByUser(user.getIdUser());
|
||||
if (roleWeights > 2) {
|
||||
map.put("message", StringEscapeUtils.unescapeJava(reservedWords) + "标签为系统保留标签!");
|
||||
map.put("message", StringEscapeUtils.unescapeJava(reservedTag) + "标签为系统保留标签!");
|
||||
return map;
|
||||
} else {
|
||||
notification = true;
|
||||
}
|
||||
}
|
||||
Article article1;
|
||||
Article newArticle;
|
||||
if(article.getIdArticle() == null || article.getIdArticle() == 0){
|
||||
article1 = new Article();
|
||||
article1.setArticleTitle(articleTitle);
|
||||
article1.setArticleAuthorId(user.getIdUser());
|
||||
article1.setArticleTags(articleTags);
|
||||
article1.setCreatedTime(new Date());
|
||||
article1.setUpdatedTime(article1.getCreatedTime());
|
||||
articleMapper.insertSelective(article1);
|
||||
article1.setArticlePermalink(DOMAIN + "/article/"+article1.getIdArticle());
|
||||
article1.setArticleLink("/article/"+article1.getIdArticle());
|
||||
articleMapper.insertArticleContent(article1.getIdArticle(),articleContent,articleContentHtml);
|
||||
BaiDuUtils.sendSEOData(article1.getArticlePermalink());
|
||||
newArticle = new Article();
|
||||
newArticle.setArticleTitle(articleTitle);
|
||||
newArticle.setArticleAuthorId(user.getIdUser());
|
||||
newArticle.setArticleTags(articleTags);
|
||||
newArticle.setCreatedTime(new Date());
|
||||
newArticle.setUpdatedTime(newArticle.getCreatedTime());
|
||||
articleMapper.insertSelective(newArticle);
|
||||
newArticle.setArticlePermalink(domain + "/article/"+newArticle.getIdArticle());
|
||||
newArticle.setArticleLink("/article/"+newArticle.getIdArticle());
|
||||
articleMapper.insertArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml);
|
||||
BaiDuUtils.sendSEOData(newArticle.getArticlePermalink());
|
||||
} else {
|
||||
article1 = articleMapper.selectByPrimaryKey(article.getIdArticle());
|
||||
if(!user.getIdUser().equals(article1.getArticleAuthorId())){
|
||||
newArticle = articleMapper.selectByPrimaryKey(article.getIdArticle());
|
||||
if(!user.getIdUser().equals(newArticle.getArticleAuthorId())){
|
||||
map.put("message","非法访问!");
|
||||
return map;
|
||||
}
|
||||
article1.setArticleTitle(articleTitle);
|
||||
article1.setArticleTags(articleTags);
|
||||
newArticle.setArticleTitle(articleTitle);
|
||||
newArticle.setArticleTags(articleTags);
|
||||
if(StringUtils.isNotBlank(articleContentHtml)){
|
||||
Integer length = articleContentHtml.length();
|
||||
if(length > MAX_PREVIEW){
|
||||
length = 200;
|
||||
}
|
||||
String articlePreviewContent = articleContentHtml.substring(0,length);
|
||||
article1.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent));
|
||||
newArticle.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent));
|
||||
}
|
||||
article1.setUpdatedTime(new Date());
|
||||
articleMapper.updateArticleContent(article1.getIdArticle(),articleContent,articleContentHtml);
|
||||
newArticle.setUpdatedTime(new Date());
|
||||
articleMapper.updateArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml);
|
||||
BaiDuUtils.updateSEOData(newArticle.getArticlePermalink());
|
||||
}
|
||||
|
||||
if (notification) {
|
||||
NotificationUtils.sendAnnouncement(article1.getIdArticle(), NotificationConstant.Article, article1.getArticleTitle());
|
||||
NotificationUtils.sendAnnouncement(newArticle.getIdArticle(), NotificationConstant.Article, newArticle.getArticleTitle());
|
||||
}
|
||||
|
||||
tagService.saveTagArticle(article1);
|
||||
articleMapper.updateByPrimaryKeySelective(article1);
|
||||
tagService.saveTagArticle(newArticle);
|
||||
articleMapper.updateByPrimaryKeySelective(newArticle);
|
||||
|
||||
map.put("id", article1.getIdArticle());
|
||||
map.put("id", newArticle.getIdArticle());
|
||||
return map;
|
||||
}
|
||||
|
||||
private boolean checkTags(String articleTags) {
|
||||
if (StringUtils.isNotBlank(reservedWords) && StringUtils.isNotBlank(articleTags)) {
|
||||
String[] words = StringEscapeUtils.unescapeJava(reservedWords).split(",");
|
||||
String[] tags = articleTags.split(",");
|
||||
for(String word: words) {
|
||||
if (StringUtils.isBlank(word)) {
|
||||
private String checkTags(String articleTags) {
|
||||
// 判断文章是否有标签
|
||||
if(StringUtils.isBlank(articleTags)){
|
||||
return "";
|
||||
}
|
||||
// 判断是否存在系统配置的保留标签词
|
||||
Condition condition = new Condition(Tag.class);
|
||||
condition.createCriteria().andEqualTo("tagReservation", "1");
|
||||
List<Tag> tags = tagService.findByCondition(condition);
|
||||
if (tags.isEmpty()) {
|
||||
return "";
|
||||
} else {
|
||||
String[] articleTagArr = articleTags.split(",");
|
||||
for (Tag tag : tags) {
|
||||
if (StringUtils.isBlank(tag.getTagTitle())) {
|
||||
continue;
|
||||
}
|
||||
for (String tag: tags) {
|
||||
if (StringUtils.isBlank(tag)) {
|
||||
|
||||
for (String articleTag: articleTagArr) {
|
||||
if (StringUtils.isBlank(articleTag)) {
|
||||
continue;
|
||||
}
|
||||
if (tag.equals(word)) {
|
||||
return true;
|
||||
if (articleTag.equals(tag.getTagTitle())) {
|
||||
return tag.getTagTitle();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,12 +11,14 @@ import com.rymcu.vertical.web.api.exception.BaseApiException;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -87,15 +89,35 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Map saveTag(Tag tag) {
|
||||
Integer result = 0;
|
||||
|
||||
Map map = new HashMap(1);
|
||||
if (tag.getIdTag() == null) {
|
||||
tag.setCreatedTime(new Date());
|
||||
tag.setUpdatedTime(tag.getCreatedTime());
|
||||
result = tagMapper.insertSelective(tag);
|
||||
if (StringUtils.isBlank(tag.getTagTitle())) {
|
||||
map.put("message","标签名不能为空!");
|
||||
return map;
|
||||
} else {
|
||||
Condition tagCondition = new Condition(Tag.class);
|
||||
tagCondition.createCriteria().andCondition("tag_title =", tag.getTagTitle());
|
||||
List<Tag> tags = tagMapper.selectByCondition(tagCondition);
|
||||
if (!tags.isEmpty()) {
|
||||
map.put("message","标签 '" + tag.getTagTitle() + "' 已存在!");
|
||||
return map;
|
||||
}
|
||||
}
|
||||
Tag newTag = new Tag();
|
||||
newTag.setTagTitle(tag.getTagTitle());
|
||||
newTag.setTagUri(tag.getTagUri());
|
||||
newTag.setTagIconPath(tag.getTagIconPath());
|
||||
newTag.setTagStatus(tag.getTagStatus());
|
||||
newTag.setTagDescription(tag.getTagDescription());
|
||||
newTag.setTagReservation(tag.getTagReservation());
|
||||
newTag.setCreatedTime(new Date());
|
||||
newTag.setUpdatedTime(tag.getCreatedTime());
|
||||
result = tagMapper.insertSelective(newTag);
|
||||
} else {
|
||||
tag.setUpdatedTime(new Date());
|
||||
result = tagMapper.update(tag.getIdTag(),tag.getTagUri(),tag.getTagIconPath(),tag.getTagStatus(),tag.getTagDescription());
|
||||
result = tagMapper.update(tag.getIdTag(),tag.getTagUri(),tag.getTagIconPath(),tag.getTagStatus(),tag.getTagDescription(),tag.getTagReservation());
|
||||
}
|
||||
Map map = new HashMap(1);
|
||||
if (result == 0) {
|
||||
map.put("message","操作失败!");
|
||||
} else {
|
||||
|
@ -13,6 +13,7 @@ import com.rymcu.vertical.service.TopicService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
@ -59,17 +60,37 @@ public class TopicServiceImpl extends AbstractService<Topic> implements TopicSer
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Map saveTopic(Topic topic) {
|
||||
Integer result = 0;
|
||||
Map map = new HashMap(1);
|
||||
if (topic.getIdTopic() == null) {
|
||||
topic.setCreatedTime(new Date());
|
||||
topic.setUpdatedTime(topic.getCreatedTime());
|
||||
result = topicMapper.insertSelective(topic);
|
||||
if (StringUtils.isBlank(topic.getTopicTitle())) {
|
||||
map.put("message","标签名不能为空!");
|
||||
return map;
|
||||
} else {
|
||||
Condition topicCondition = new Condition(Topic.class);
|
||||
topicCondition.createCriteria().andCondition("topic_title =", topic.getTopicTitle());
|
||||
List<Topic> topics = topicMapper.selectByCondition(topicCondition);
|
||||
if (!topics.isEmpty()) {
|
||||
map.put("message","专题 '" + topic.getTopicTitle() + "' 已存在!");
|
||||
return map;
|
||||
}
|
||||
}
|
||||
Topic newTopic = new Topic();
|
||||
newTopic.setTopicTitle(topic.getTopicTitle());
|
||||
newTopic.setTopicUri(topic.getTopicUri());
|
||||
newTopic.setTopicIconPath(topic.getTopicIconPath());
|
||||
newTopic.setTopicNva(topic.getTopicNva());
|
||||
newTopic.setTopicStatus(topic.getTopicStatus());
|
||||
newTopic.setTopicSort(topic.getTopicSort());
|
||||
newTopic.setTopicDescription(topic.getTopicDescription());
|
||||
newTopic.setCreatedTime(new Date());
|
||||
newTopic.setUpdatedTime(topic.getCreatedTime());
|
||||
result = topicMapper.insertSelective(newTopic);
|
||||
} else {
|
||||
topic.setCreatedTime(new Date());
|
||||
result = topicMapper.update(topic.getIdTopic(),topic.getTopicTitle(),topic.getTopicUri()
|
||||
,topic.getTopicIconPath(),topic.getTopicNva(),topic.getTopicStatus()
|
||||
,topic.getTopicSort(),topic.getTopicDescription());
|
||||
}
|
||||
Map map = new HashMap(1);
|
||||
if (result == 0) {
|
||||
map.put("message","操作失败!");
|
||||
} else {
|
||||
|
24
src/main/java/com/rymcu/vertical/task/BaiduCronTask.java
Normal file
24
src/main/java/com/rymcu/vertical/task/BaiduCronTask.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.rymcu.vertical.task;
|
||||
|
||||
import com.rymcu.vertical.util.BaiDuUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class BaiduCronTask {
|
||||
|
||||
@Value("${resource.domain}")
|
||||
private String domain;
|
||||
|
||||
/**
|
||||
* 定时推送首页更新
|
||||
* */
|
||||
@Scheduled(cron = "0 0 10,14,18 * * ?")
|
||||
public void pushHome() {
|
||||
BaiDuUtils.updateSEOData(domain);
|
||||
}
|
||||
|
||||
}
|
@ -35,6 +35,48 @@ public class BaiDuUtils {
|
||||
},executor);
|
||||
}
|
||||
|
||||
public static void updateSEOData(String permalink) {
|
||||
if (StringUtils.isBlank(permalink) || StringUtils.isBlank(token)) {
|
||||
return;
|
||||
}
|
||||
ExecutorService executor= new ThreadPoolExecutor(1,1,0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
|
||||
CompletableFuture.supplyAsync(()-> {
|
||||
try {
|
||||
HttpResponse response = HttpRequest.post("http://data.zz.baidu.com/update?site=" + site + "&token=" + token).
|
||||
header("User-Agent", "curl/7.12.1").
|
||||
header("Host", "data.zz.baidu.com").
|
||||
header("Content-Type", "text/plain").
|
||||
header("Connection", "close").body(permalink.getBytes(), "text/plain").timeout(30000).send();
|
||||
response.charset("UTF-8");
|
||||
System.out.println(response.bodyText());
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
},executor);
|
||||
}
|
||||
|
||||
public static void deleteSEOData(String permalink) {
|
||||
if (StringUtils.isBlank(permalink) || StringUtils.isBlank(token)) {
|
||||
return;
|
||||
}
|
||||
ExecutorService executor= new ThreadPoolExecutor(1,1,0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
|
||||
CompletableFuture.supplyAsync(()-> {
|
||||
try {
|
||||
HttpResponse response = HttpRequest.post("http://data.zz.baidu.com/del?site=" + site + "&token=" + token).
|
||||
header("User-Agent", "curl/7.12.1").
|
||||
header("Host", "data.zz.baidu.com").
|
||||
header("Content-Type", "text/plain").
|
||||
header("Connection", "close").body(permalink.getBytes(), "text/plain").timeout(30000).send();
|
||||
response.charset("UTF-8");
|
||||
System.out.println(response.bodyText());
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
},executor);
|
||||
}
|
||||
|
||||
public static void main(String agrs[]){
|
||||
sendSEOData("https://rymcu.com/article/31");
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
<id column="tag_view_count" property="tagViewCount"/>
|
||||
<id column="tag_article_count" property="tagArticleCount"/>
|
||||
<id column="tag_ad" property="tagAd"/>
|
||||
<id column="tag_reservation" property="tagReservation"/>
|
||||
<id column="tag_show_side_ad" property="tagShowSideAd"/>
|
||||
<id column="created_time" property="createdTime"/>
|
||||
<id column="updated_time" property="updatedTime"/>
|
||||
@ -24,10 +25,10 @@
|
||||
insert into vertical_user_tag (id_tag,id_user,type,created_time,updated_time) values (#{idTag},#{idUser},#{type},sysdate(),sysdate())
|
||||
</insert>
|
||||
<update id="update">
|
||||
update vertical_tag set tag_uri = #{tagUri}, tag_icon_path = #{tagIconPath}, tag_status = #{tagStatus}, tag_description = #{tagDescription} where id = #{idTag}
|
||||
update vertical_tag set tag_uri = #{tagUri}, tag_icon_path = #{tagIconPath}, tag_status = #{tagStatus}, tag_description = #{tagDescription}, tag_reservation = #{tagReservation} where id = #{idTag}
|
||||
</update>
|
||||
<delete id="deleteUnusedTag">
|
||||
delete from vertical_tag where id not in (select * from (select id_tag from vertical_tag_article vta left join vertical_article va on vta.id_article = va.id where va.id is not null) tmp);
|
||||
delete from vertical_tag where tag_reservation = 0 and id not in (select * from (select id_tag from vertical_tag_article vta left join vertical_article va on vta.id_article = va.id where va.id is not null) tmp);
|
||||
</delete>
|
||||
<select id="selectCountTagArticleById" resultType="java.lang.Integer">
|
||||
select count(*) from vertical_tag_article where id_tag = #{idTag} and id_article = #{idArticle}
|
||||
|
Loading…
x
Reference in New Issue
Block a user