diff --git a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java index 37e81d8..229ff1a 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java @@ -21,6 +21,7 @@ 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.TotalCommentVo; @@ -39,6 +40,7 @@ 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.TagService; import com.luoo.music.service.UserCollectInfoService; import annotation.GlobalInterceptor; import annotation.VerifyParam; @@ -73,6 +75,9 @@ public class JournalController { @Autowired private TagDao tagDao; + @Autowired + private TagService tagService; + @Autowired private JwtUtil jwtUtil; @@ -82,7 +87,8 @@ public class JournalController { @Autowired private CommentDao commentDao; - + + private static final int JOURNAL_FILTER_NUMBER_RANGE=100; // mock data private static final String JOURNAL_TAG_FILE_PATH = "journalTags.txt"; private Map> journalTagMap = new HashMap<>(); @@ -167,6 +173,18 @@ public class JournalController { return Result.success(journalRespDTO); } + @ApiOperation(value = "4.获取期刊筛选条件") + @GetMapping("/filter") + @GlobalInterceptor(checkAppUserLogin = true) + public Result getFilterList( + @RequestHeader(value = "Authorization", required = false) String authorization) { + JournalFilterDTO journalFilterDTO=new JournalFilterDTO(); + journalFilterDTO.setJournalNoList(journalService.getJournalNoList(JOURNAL_FILTER_NUMBER_RANGE)); + journalFilterDTO.setLanguageList(tagService.getLanguageList()); + journalFilterDTO.setStyleList(tagService.getStyleList()); + return Result.success(journalFilterDTO); + } + private JournalRespDTO getJournalRespDTO(Journal journal, Set journalCollectSet) { JournalRespDTO journalRespDTO = new JournalRespDTO(); journalRespDTO.setId(journal.getId()); diff --git a/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java b/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java index 0fecd77..f46a7e5 100644 --- a/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java +++ b/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java @@ -60,5 +60,8 @@ public interface JournalDao extends JpaRepository,JpaSpecificati @Transactional @Query("UPDATE Journal j SET j.comment = j.comment - 1 WHERE j.id = :journalId") int decreaseCommentCount(@Param("journalId") String journalId); + + @Query(value = "select max(ABS(journal_no)) FROM tb_journal", nativeQuery = true) + int getMaxJournalNo(); } diff --git a/luoo_music/src/main/java/com/luoo/music/dao/TagDao.java b/luoo_music/src/main/java/com/luoo/music/dao/TagDao.java index d45968f..c888f53 100644 --- a/luoo_music/src/main/java/com/luoo/music/dao/TagDao.java +++ b/luoo_music/src/main/java/com/luoo/music/dao/TagDao.java @@ -1,6 +1,5 @@ package com.luoo.music.dao; -import com.luoo.music.pojo.Song; import com.luoo.music.pojo.Tag; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; @@ -18,4 +17,10 @@ public interface TagDao extends JpaRepository, JpaSpecificationExec @Query(value = "select * from tb_tag_info where parent_id='' order by rand() limit ?1 ", nativeQuery = true) List 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) + List getLanguageList(); + + @Query(value = "select name_ch from tb_tag_info where level=1 and not name_ch='语言' ", nativeQuery = true) + List getStyleList(); } diff --git a/luoo_music/src/main/java/com/luoo/music/dto/response/JournalFilterDTO.java b/luoo_music/src/main/java/com/luoo/music/dto/response/JournalFilterDTO.java new file mode 100644 index 0000000..05de373 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/dto/response/JournalFilterDTO.java @@ -0,0 +1,16 @@ +package com.luoo.music.dto.response; + +import java.util.List; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class JournalFilterDTO { + @ApiModelProperty(value = "风格筛选条件") + private List styleList; + @ApiModelProperty(value = "语言筛选条件") + private List languageList; + @ApiModelProperty(value = "期刊号筛选条件") + private List journalNoList; +} diff --git a/luoo_music/src/main/java/com/luoo/music/service/JournalService.java b/luoo_music/src/main/java/com/luoo/music/service/JournalService.java index 98cf0a2..c634140 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/JournalService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/JournalService.java @@ -1,6 +1,7 @@ package com.luoo.music.service; import java.util.*; +import java.util.stream.IntStream; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; @@ -40,6 +41,7 @@ public class JournalService { @Autowired private RedisTemplate redisTemplate; + private Map> JOURNAL_RANGE_MAP=new HashMap<>(); /* * public void updateState(String id) { journalDao.updateState(id); } * @@ -205,4 +207,34 @@ public class JournalService { } return Result.success(); } + + + public List getJournalNoList(int journalFilterNumberRange) { + //获取最大的期刊号 + int maxJournalNo=journalDao.getMaxJournalNo(); + if(JOURNAL_RANGE_MAP.containsKey(maxJournalNo)) { + return JOURNAL_RANGE_MAP.get(maxJournalNo); + } + JOURNAL_RANGE_MAP.clear(); + List journalNoList=new ArrayList<>(); + int i=1; + int start=1; + int end=i*journalFilterNumberRange; + while(endmaxJournalNo) { + end=maxJournalNo; + } + StringBuilder sb=new StringBuilder(); + sb.append(end); + sb.append("~"); + sb.append(start); + journalNoList.add(sb.toString()); + i++; + } + Collections.reverse(journalNoList); + JOURNAL_RANGE_MAP.put(maxJournalNo, journalNoList); + return journalNoList; + } } diff --git a/luoo_music/src/main/java/com/luoo/music/service/TagService.java b/luoo_music/src/main/java/com/luoo/music/service/TagService.java new file mode 100644 index 0000000..d85e5b3 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/service/TagService.java @@ -0,0 +1,22 @@ +package com.luoo.music.service; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.luoo.music.dao.TagDao; + +@Service +public class TagService { + @Autowired + private TagDao tagDao; + public List getLanguageList() { + return tagDao.getLanguageList(); + } + + public List getStyleList() { + return tagDao.getStyleList(); + } + +} diff --git a/luoo_music/src/test/java/com/luoo/music/service/JournalSongServiceTest.java b/luoo_music/src/test/java/com/luoo/music/service/JournalSongServiceTest.java new file mode 100644 index 0000000..dc7d11a --- /dev/null +++ b/luoo_music/src/test/java/com/luoo/music/service/JournalSongServiceTest.java @@ -0,0 +1,39 @@ +package com.luoo.music.service; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.junit.Test; + +public class JournalSongServiceTest { + + @Test + public void testJournalNoList() { + getJournalNoList(100).forEach(System.out::println); + } + public List getJournalNoList(int journalFilterNumberRange) { + int maxJournalNo=1011; + List journalNoList=new ArrayList<>(); + int i=1; + int start=1; + int end=i*journalFilterNumberRange; + while(endmaxJournalNo) { + end=maxJournalNo; + } + StringBuilder sb=new StringBuilder(); + sb.append(end); + sb.append("~"); + sb.append(start); + journalNoList.add(sb.toString()); + i++; + } + Collections.reverse(journalNoList); + return journalNoList; + } +}