|
@@ -0,0 +1,44 @@
|
|
|
+package cn.iselab.mooctest.site.web.data.wrapper.fromDev;
|
|
|
+
|
|
|
+import cn.iselab.mooctest.site.models.Tag;
|
|
|
+import cn.iselab.mooctest.site.service.TagService;
|
|
|
+import cn.iselab.mooctest.site.web.data.TagVO;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Stack;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created on 2018/10/25
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class TagVOWrapper {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ TagService tagService;
|
|
|
+
|
|
|
+ public TagVO wrapTag2VORecurse(Tag tag){
|
|
|
+ if(tag == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ TagVO tagVO = new TagVO();
|
|
|
+ BeanUtils.copyProperties(tag,tagVO,"parentId","subTags");
|
|
|
+
|
|
|
+ List<TagVO> subTagVOs = new ArrayList<>();
|
|
|
+ List<Tag> subTags = tagService.getDirectSubTagsByParent(tagVO.getId());
|
|
|
+ if(!CollectionUtils.isEmpty(subTags)){
|
|
|
+ for(Tag subTag: subTags){
|
|
|
+ TagVO subTagVO = wrapTag2VORecurse(subTag);
|
|
|
+ subTagVOs.add(subTagVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tagVO.setSubTags(subTagVOs);
|
|
|
+
|
|
|
+ return tagVO;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|