1.add journal filter option interface

main
Gary 10 months ago
parent 2a5259a9fe
commit 4368aa06c1

@ -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;
@ -83,6 +88,7 @@ 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<String, List<String>> journalTagMap = new HashMap<>();
@ -167,6 +173,18 @@ public class JournalController {
return Result.success(journalRespDTO);
}
@ApiOperation(value = "4.获取期刊筛选条件")
@GetMapping("/filter")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<JournalFilterDTO> 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<String> journalCollectSet) {
JournalRespDTO journalRespDTO = new JournalRespDTO();
journalRespDTO.setId(journal.getId());

@ -60,5 +60,8 @@ public interface JournalDao extends JpaRepository<Journal,String>,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();
}

@ -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<Tag, String>, JpaSpecificationExec
@Query(value = "select * from tb_tag_info where parent_id='' order by rand() limit ?1 ", nativeQuery = true)
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)
List<String> getLanguageList();
@Query(value = "select name_ch from tb_tag_info where level=1 and not name_ch='语言' ", nativeQuery = true)
List<String> getStyleList();
}

@ -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<String> styleList;
@ApiModelProperty(value = "语言筛选条件")
private List<String> languageList;
@ApiModelProperty(value = "期刊号筛选条件")
private List<String> journalNoList;
}

@ -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<Integer,List<String>> 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<String> getJournalNoList(int journalFilterNumberRange) {
//获取最大的期刊号
int maxJournalNo=journalDao.getMaxJournalNo();
if(JOURNAL_RANGE_MAP.containsKey(maxJournalNo)) {
return JOURNAL_RANGE_MAP.get(maxJournalNo);
}
JOURNAL_RANGE_MAP.clear();
List<String> journalNoList=new ArrayList<>();
int i=1;
int start=1;
int end=i*journalFilterNumberRange;
while(end<maxJournalNo) {
start=1==i?1:(i-1)*journalFilterNumberRange;
end=i*journalFilterNumberRange;
if(end>maxJournalNo) {
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;
}
}

@ -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<String> getLanguageList() {
return tagDao.getLanguageList();
}
public List<String> getStyleList() {
return tagDao.getStyleList();
}
}

@ -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<String> getJournalNoList(int journalFilterNumberRange) {
int maxJournalNo=1011;
List<String> journalNoList=new ArrayList<>();
int i=1;
int start=1;
int end=i*journalFilterNumberRange;
while(end<maxJournalNo) {
start=1==i?1:(i-1)*journalFilterNumberRange;
end=i*journalFilterNumberRange;
if(end>maxJournalNo) {
end=maxJournalNo;
}
StringBuilder sb=new StringBuilder();
sb.append(end);
sb.append("~");
sb.append(start);
journalNoList.add(sb.toString());
i++;
}
Collections.reverse(journalNoList);
return journalNoList;
}
}
Loading…
Cancel
Save