1.add search interafce

main
Gary 10 months ago
parent 18b2ce25da
commit f5a2b242ff

@ -23,7 +23,7 @@ import com.luoo.music.dao.TagDao;
import com.luoo.music.dto.request.JournalQueryReq; import com.luoo.music.dto.request.JournalQueryReq;
import com.luoo.music.dto.response.JournalFilterDTO; import com.luoo.music.dto.response.JournalFilterDTO;
import com.luoo.music.dto.response.JournalRespDTO; import com.luoo.music.dto.response.JournalRespDTO;
import com.luoo.music.dto.response.TagDTO;
import com.luoo.music.dto.response.TotalCommentVo; import com.luoo.music.dto.response.TotalCommentVo;
import com.luoo.music.pojo.Comment; import com.luoo.music.pojo.Comment;
import io.swagger.annotations.*; import io.swagger.annotations.*;
@ -121,8 +121,7 @@ public class JournalController {
@VerifyParam JournalQueryReq queryReq) { @VerifyParam JournalQueryReq queryReq) {
UserLoginDto user = jwtUtil.getUserLoginDto(authorization); UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
if (null == user) { if (null == user) {
queryReq.setLanguage(null); queryReq.setCategoryId(null);
queryReq.setStyle(null);
queryReq.setPageNum(1); queryReq.setPageNum(1);
queryReq.setPageSize(10); queryReq.setPageSize(10);
} }
@ -179,11 +178,17 @@ public class JournalController {
@RequestHeader(value = "Authorization", required = false) String authorization) { @RequestHeader(value = "Authorization", required = false) String authorization) {
JournalFilterDTO journalFilterDTO=new JournalFilterDTO(); JournalFilterDTO journalFilterDTO=new JournalFilterDTO();
journalFilterDTO.setJournalNoList(journalService.getJournalNoList(JOURNAL_FILTER_NUMBER_RANGE)); journalFilterDTO.setJournalNoList(journalService.getJournalNoList(JOURNAL_FILTER_NUMBER_RANGE));
journalFilterDTO.setLanguageList(tagService.getLanguageList());
journalFilterDTO.setStyleList(tagService.getStyleList()); journalFilterDTO.setLanguageList(tagService.getLanguageList().stream().map(this::getTagDto).collect(Collectors.toList()));
journalFilterDTO.setStyleList(tagService.getStyleList().stream().map(this::getTagDto).collect(Collectors.toList()));
return Result.success(journalFilterDTO); return Result.success(journalFilterDTO);
} }
private TagDTO getTagDto(Tag tag) {
TagDTO tagDTO=new TagDTO();
tagDTO.setName(tag.getNameCh());
tagDTO.setId(tag.getId());
return tagDTO;
}
private JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet) { private JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet) {
JournalRespDTO journalRespDTO = new JournalRespDTO(); JournalRespDTO journalRespDTO = new JournalRespDTO();
journalRespDTO.setId(journal.getId()); journalRespDTO.setId(journal.getId());

@ -0,0 +1,100 @@
package com.luoo.music.controller;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import com.apifan.common.random.RandomSource;
import com.apifan.common.random.entity.Poem;
import com.luoo.music.dao.CommentDao;
import com.luoo.music.dao.TagDao;
import com.luoo.music.dto.request.JournalQueryReq;
import com.luoo.music.dto.response.JournalFilterDTO;
import com.luoo.music.dto.response.JournalRespDTO;
import com.luoo.music.dto.response.SearchCategoryDTO;
import com.luoo.music.dto.response.TotalCommentVo;
import com.luoo.music.pojo.Comment;
import io.swagger.annotations.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.web.bind.annotation.*;
import com.luoo.music.pojo.Journal;
import com.luoo.music.pojo.Tag;
import com.luoo.music.service.JournalService;
import com.luoo.music.service.JournalSongService;
import com.luoo.music.service.TagService;
import com.luoo.music.service.UserCollectInfoService;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.PageResult;
import api.Result;
import constants.Constants;
import dto.UserLoginDto;
import enums.CollectTypeEnum;
import enums.DateTimePatternEnum;
import lombok.SneakyThrows;
import util.DateUtil;
import util.JwtUtil;
import util.StringTools;
/**
*
*
* @author Administrator
*
*/
@RestController
@CrossOrigin
@Api(tags = "雀跃APP搜索 APIs")
@RequestMapping("/search")
public class SearchController {
@Autowired
private UserCollectInfoService userCollectInfoService;
@Autowired
private JournalController journalController;
@Autowired
private JournalService journalService;
@Autowired
private JournalSongService journalSongService;
@Autowired
private TagService tagService;
@ApiOperation(value = "1.查询搜索大类", notes = "如 ‘民谣’,‘电子’")
@GetMapping("/category")
@GlobalInterceptor
public Result<List<SearchCategoryDTO>> getCategory() {
List<Tag> tags=tagService.getLevel1Tags();
List<SearchCategoryDTO> searchCategoryDTOs=tags.stream().map(this::getSearchCategoryDTO).collect(Collectors.toList());
return Result.success(searchCategoryDTOs);
}
private SearchCategoryDTO getSearchCategoryDTO(Tag tag) {
SearchCategoryDTO searchCategoryDTO=new SearchCategoryDTO();
BeanUtils.copyProperties(tag, searchCategoryDTO);
return searchCategoryDTO;
}
}

@ -29,6 +29,6 @@ public interface JournalTagDao extends JpaRepository<JournalTag,String>, JpaSpec
@Query("DELETE FROM JournalTag jt WHERE jt.journalId = :journalId") @Query("DELETE FROM JournalTag jt WHERE jt.journalId = :journalId")
int deleteByJournalId(@Param("journalId") String journalId); int deleteByJournalId(@Param("journalId") String journalId);
@Query(value = "select journal_id FROM tb_journal_tag where tag_id=(select id from tb_tag_info where level=?1 and name_ch=?2 limit 1)", nativeQuery = true) @Query(value = "select journal_id FROM tb_journal_tag where tag_id=?1", nativeQuery = true)
List<String> getJournalIdByLevelAndChName(int level,String chName); List<String> getJournalIdByTagId(String tagId);
} }

@ -18,9 +18,12 @@ public interface TagDao extends JpaRepository<Tag, String>, JpaSpecificationExec
@Query(value = "select * from tb_tag_info where parent_id='' order by rand() limit ?1 ", nativeQuery = true) @Query(value = "select * from tb_tag_info where parent_id='' order by rand() limit ?1 ", nativeQuery = true)
List<Tag> random(int limit); List<Tag> random(int limit);
@Query(value = "select name_ch from tb_tag_info where parent_id=(select id from tb_tag_info where name_ch='语言' and level=1 limit 1) ", nativeQuery = true) @Query(value = "select * from tb_tag_info where parent_id=(select id from tb_tag_info where name_ch='语言' and level=1 limit 1) ", nativeQuery = true)
List<String> getLanguageList(); List<Tag> getLanguageList();
@Query(value = "select name_ch from tb_tag_info where level=1 and not name_ch='语言' ", nativeQuery = true) @Query(value = "select * from tb_tag_info where level=1 and not name_ch='语言' ", nativeQuery = true)
List<String> getStyleList(); List<Tag> getStyleList();
@Query(value = "select * from tb_tag_info where level=1", nativeQuery = true)
List<Tag> getLevel1Tags();
} }

@ -12,10 +12,8 @@ import java.io.Serializable;
@ApiModel @ApiModel
public class JournalQueryReq implements Serializable { public class JournalQueryReq implements Serializable {
private static final long serialVersionUID = -1198060864891902188L; private static final long serialVersionUID = -1198060864891902188L;
@ApiModelProperty(value = "筛选条件:风格", example = "民谣") @ApiModelProperty(value = "筛选条件类目Id", example = "民谣/国语 id")
private String style; private String categoryId;
@ApiModelProperty(value = "筛选条件:语言", example = "国语")
private String language;
@ApiModelProperty(value = "筛选条件:期刊号范围", example = "900~800") @ApiModelProperty(value = "筛选条件:期刊号范围", example = "900~800")
private String journalNoRange; private String journalNoRange;
@ApiModelProperty(value = "分页: 页码以1开始即获取最新的几期", example = "1") @ApiModelProperty(value = "分页: 页码以1开始即获取最新的几期", example = "1")

@ -8,9 +8,9 @@ import lombok.Data;
@Data @Data
public class JournalFilterDTO { public class JournalFilterDTO {
@ApiModelProperty(value = "风格筛选条件") @ApiModelProperty(value = "风格筛选条件")
private List<String> styleList; private List<TagDTO> styleList;
@ApiModelProperty(value = "语言筛选条件") @ApiModelProperty(value = "语言筛选条件")
private List<String> languageList; private List<TagDTO> languageList;
@ApiModelProperty(value = "期刊号筛选条件") @ApiModelProperty(value = "期刊号筛选条件")
private List<String> journalNoList; private List<String> journalNoList;
} }

@ -0,0 +1,18 @@
package com.luoo.music.dto.response;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class SearchCategoryDTO {
@ApiModelProperty(value = "ID")
private String id;
@ApiModelProperty(value = "中文名")
private String nameCh;
@ApiModelProperty(value = "英文名")
private String nameEn;
@ApiModelProperty(value = "图片路径")
private String image;
@ApiModelProperty(value = "说明文案")
private String description;
}

@ -0,0 +1,12 @@
package com.luoo.music.dto.response;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class TagDTO {
@ApiModelProperty(value = "ID")
private String id;
@ApiModelProperty(value = "中文名")
private String name;
}

@ -1,7 +1,7 @@
package com.luoo.music.pojo; package com.luoo.music.pojo;
import lombok.Data; import lombok.*;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.annotation.LastModifiedDate;
@ -15,11 +15,10 @@ import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Objects; import java.util.Objects;
/** @Getter
* @Setter
* @author locust @ToString
*/ @RequiredArgsConstructor
@Data
@Entity @Entity
@Table(name = "tb_tag_info") @Table(name = "tb_tag_info")
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
@ -54,6 +53,16 @@ public class Tag implements Serializable {
*/ */
private Integer state; private Integer state;
/**
*
*/
private String description;
/**
*
*/
private String image;
/** /**
* ID * ID
*/ */

@ -205,11 +205,8 @@ public class JournalService {
private List<String> getJournalIds(JournalQueryReq queryReq) { private List<String> getJournalIds(JournalQueryReq queryReq) {
if(StringUtils.isNotBlank(queryReq.getLanguage())){ if(StringUtils.isNotBlank(queryReq.getCategoryId())){
return journalTagDao.getJournalIdByLevelAndChName(2,queryReq.getLanguage()); return journalTagDao.getJournalIdByTagId(queryReq.getCategoryId());
}
if(StringUtils.isNotBlank(queryReq.getStyle())){
return journalTagDao.getJournalIdByLevelAndChName(1,queryReq.getStyle());
} }
return Collections.emptyList(); return Collections.emptyList();
} }

@ -6,17 +6,22 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.luoo.music.dao.TagDao; import com.luoo.music.dao.TagDao;
import com.luoo.music.pojo.Tag;
@Service @Service
public class TagService { public class TagService {
@Autowired @Autowired
private TagDao tagDao; private TagDao tagDao;
public List<String> getLanguageList() { public List<Tag> getLanguageList() {
return tagDao.getLanguageList(); return tagDao.getLanguageList();
} }
public List<String> getStyleList() { public List<Tag> getStyleList() {
return tagDao.getStyleList(); return tagDao.getStyleList();
} }
public List<Tag> getLevel1Tags() {
return tagDao.getLevel1Tags();
}
} }

Loading…
Cancel
Save