Commit c7dc9411 by 胡学良

修改标签,话题的接收形式

parent cf7653bd
......@@ -72,7 +72,7 @@ public class QuestionApi {
question.setUserId((String) subject.getId());
//祛除重复标签
HashSet<String> tags = QuestionUtils.toHashSet(questionForm.getTags());
HashSet<String> tags = QuestionUtils.toHashSet(questionForm.getTagIds());
//祛除重复话题
HashSet<String> topicIds = QuestionUtils.toHashSet(questionForm.getTopicIds());
......@@ -132,11 +132,14 @@ public class QuestionApi {
question.setUserId((String) subject.getId());
//4.祛除重复标签
HashSet<String> tags = QuestionUtils.toHashSet(questionForm.getTags());
HashSet<String> tags = QuestionUtils.toHashSet(questionForm.getTagIds());
//5.修改问题
//5.祛除重复话题
HashSet<String> topicIds = QuestionUtils.toHashSet(questionForm.getTopicIds());
//6.修改问题
try {
questionService.updateQuestion(question, questionForm.getQuestionDetail(), tags);
questionService.updateQuestion(question, questionForm.getQuestionDetail(), tags, topicIds);
return Response.success();
} catch (QuestionServiceException e) {
e.printStackTrace();
......
......@@ -2,6 +2,7 @@ package cn.meteor.beyondclouds.modules.question.bean;
import cn.meteor.beyondclouds.modules.question.entity.Question;
import cn.meteor.beyondclouds.modules.tag.entity.Tag;
import cn.meteor.beyondclouds.modules.topic.entity.Topic;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -25,4 +26,7 @@ public class QuestionDetails extends Question {
@ApiModelProperty("标签")
private List<Tag> tags;
@ApiModelProperty("话题")
private List<Topic> topics;
}
......@@ -35,11 +35,11 @@ public class QuestionForm {
@ApiModelProperty("标签")
@Size(max = 12, message = "问题标签个数不能超过5个")
private String tags;
private List<String> tagIds;
@ApiModelProperty("详情")
private String questionDetail;
@ApiModelProperty("话题ID")
private String topicIds;
private List<String> topicIds;
}
......@@ -45,9 +45,10 @@ public interface IQuestionService extends IService<Question> {
* @param question 问题基本信息
* @param questionDetail 问题详细信息
* @param tags 问题标签
* @param topicIds 话题ID
* @throws QuestionServiceException 问题业务异常
*/
void updateQuestion(Question question, String questionDetail, HashSet<String> tags) throws QuestionServiceException;
void updateQuestion(Question question, String questionDetail, HashSet<String> tags, HashSet<String> topicIds) throws QuestionServiceException;
/**
......
......@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
......@@ -110,10 +111,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
Iterator<String> iterator = topicIds.iterator();
TopicReference topicReference = null;
while (iterator.hasNext()) {
System.out.println("============");
Topic topic = topicService.getById(iterator.next());
if (topic == null) {
System.out.println("111111111111");
continue;
}
......@@ -165,10 +164,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
//7.删除question表中的问题信息
removeById(questionId);
//8.删除话题引用表中的问题信息
topicReferenceService.remove(QuestionUtils.getWrapper("referencer_id",question.getQuestionId()));
}
@Override
public void updateQuestion(Question question, String questionDetail, HashSet<String> tags) throws QuestionServiceException {
public void updateQuestion(Question question, String questionDetail, HashSet<String> tags, HashSet<String> topicIds) throws QuestionServiceException {
//1.判断自己是否发布过此问题
QueryWrapper<Question> questionQueryWrapper = new QueryWrapper<>();
questionQueryWrapper.eq("question_id",question.getQuestionId())
......@@ -205,6 +207,34 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
//4.更新问题标签
questionTagService.remove(QuestionUtils.getWrapper("question_id",question.getQuestionId()));
questionTagService.saveQuestionTag(tags,question.getQuestionId());
//5.更新话题
//删除以前的话题信息
topicReferenceService.remove(QuestionUtils.getWrapper("referencer_id",question.getQuestionId()));
//保存更新后的话题信息
Iterator<String> iterator = topicIds.iterator();
TopicReference topicReference = null;
while (iterator.hasNext()) {
Topic topic = topicService.getById(iterator.next());
if (topic == null) {
continue;
}
//保存话题引用信息
topicReference = new TopicReference();
topicReference.setTopicId(topic.getTopicId());
topicReference.setReferencerId(question.getQuestionId());
topicReference.setReferencerType(2);
topicReferenceService.save(topicReference);
//更新话题引用次数
UpdateWrapper<Topic> updateWrapper = new UpdateWrapper<>();
updateWrapper.set("reference_count",topic.getReferenceCount()+1)
.eq("topic_id",topic.getTopicId());
topicService.update(updateWrapper);
}
}
@Override
......@@ -223,12 +253,20 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
//4.获取问题标签
List<Tag> tags = questionTagService.getQuestionTags(questionId);
//5.获取话题详情
List<TopicReference> references = topicReferenceService.list(QuestionUtils.getWrapper("referencer_id", question.getQuestionId()));
List<Topic> topics = new ArrayList<>();
for (TopicReference topicReference : references ) {
topics.add(topicService.getById(topicReference.getTopicId()));
}
//5.生成问题详情对象
QuestionDetails questionDetails = new QuestionDetails();
BeanUtils.copyProperties(question,questionDetails);
questionDetails.setQuestionDetail(questionExt.getQuestionDetail());
questionDetails.setTags(tags);
questionDetails.setCategory(questionCategoryService.getById(question.getCategoryId()).getCategory());
questionDetails.setTopics(topics);
return questionDetails;
}
......
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
/**
* @author 胡学良
......@@ -26,15 +27,13 @@ public class QuestionUtils {
/**
* 处理标签
* @param tags 标签
* @return
* @param tagIdList 标签
* @return Set
*/
public static HashSet<String> toHashSet(String tags){
StringBuilder stringBuilder = new StringBuilder(tags);
stringBuilder.deleteCharAt(0);
stringBuilder.deleteCharAt(stringBuilder.length()-1);
String[] tag = stringBuilder.toString().split(",");
return new HashSet<String>(Arrays.asList(tag));
public static HashSet<String> toHashSet(List<String> tagIdList){
HashSet<String> tagIds = new HashSet<>();
tagIds.addAll(tagIdList);
return tagIds;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment