|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.luoo.music.service;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
|
@ -9,6 +10,9 @@ import javax.persistence.criteria.Predicate;
|
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
|
|
|
|
|
import api.Result;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
@ -19,6 +23,8 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import util.IdWorker;
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.dao.JournalDao;
|
|
|
|
|
import com.luoo.music.dao.JournalTagDao;
|
|
|
|
|
import com.luoo.music.dao.TagDao;
|
|
|
|
|
import com.luoo.music.dto.request.JournalQueryReq;
|
|
|
|
|
import com.luoo.music.pojo.Journal;
|
|
|
|
|
|
|
|
|
@ -36,8 +42,8 @@ public class JournalService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IdWorker idWorker;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private JournalTagDao journalTagDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
@ -152,29 +158,64 @@ public class JournalService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<Journal> queryPage(JournalQueryReq queryReq) {
|
|
|
|
|
Specification<Journal> specification = createJournalSpecification(queryReq);
|
|
|
|
|
public List<Journal> queryPage(JournalQueryReq queryReq) {
|
|
|
|
|
List<String> ids=getJournalIds(queryReq);
|
|
|
|
|
Pair<Integer,Integer> journalNoRange=getJournalNoRange(queryReq.getJournalNoRange());
|
|
|
|
|
Specification<Journal> specification = createJournalSpecification(ids,journalNoRange);
|
|
|
|
|
if(null==queryReq.getPageNum()||queryReq.getPageNum()<1||null==queryReq.getPageSize()||queryReq.getPageSize()<1) {
|
|
|
|
|
return journalDao.findAll(specification);
|
|
|
|
|
}
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum()-1, queryReq.getPageSize());
|
|
|
|
|
return journalDao.findAll(specification, pageRequest);
|
|
|
|
|
return journalDao.findAll(specification, pageRequest).getContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* as journal do not support style and langauge, only sort the result
|
|
|
|
|
*/
|
|
|
|
|
private Specification<Journal> createJournalSpecification(JournalQueryReq queryReq) {
|
|
|
|
|
private Specification<Journal> createJournalSpecification(List<String> ids, Pair<Integer, Integer> journalNoRange) {
|
|
|
|
|
return new Specification<Journal>() {
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
@Override
|
|
|
|
|
public Predicate toPredicate(Root<Journal> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
|
|
public Predicate toPredicate(Root<Journal> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
|
query.orderBy(cb.desc(root.get("journalNo").as(Integer.class)));
|
|
|
|
|
return cb.and( predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
if(!ids.isEmpty()) {
|
|
|
|
|
predicateList.add(criteriaBuilder.in(root.get("id")).value(ids));
|
|
|
|
|
}
|
|
|
|
|
if(Objects.nonNull(journalNoRange)) {
|
|
|
|
|
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("journalNo").as(Integer.class),
|
|
|
|
|
journalNoRange.getLeft()));
|
|
|
|
|
|
|
|
|
|
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("journalNo").as(Integer.class),
|
|
|
|
|
journalNoRange.getRight()));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
query.orderBy(criteriaBuilder.desc(root.get("journalNo").as(Integer.class)));
|
|
|
|
|
return criteriaBuilder.and( predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Pair<Integer, Integer> getJournalNoRange(String range) {
|
|
|
|
|
if(StringUtils.isNotBlank(range)){
|
|
|
|
|
String[] segs=range.split("~");
|
|
|
|
|
int start=Integer.valueOf(segs[0]);
|
|
|
|
|
int end=Integer.valueOf(segs[1]);
|
|
|
|
|
return start<end?Pair.of(start, end):Pair.of(end, start);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> getJournalIds(JournalQueryReq queryReq) {
|
|
|
|
|
if(StringUtils.isNotBlank(queryReq.getLanguage())){
|
|
|
|
|
return journalTagDao.getJournalIdByLevelAndChName(2,queryReq.getLanguage());
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isNotBlank(queryReq.getStyle())){
|
|
|
|
|
return journalTagDao.getJournalIdByLevelAndChName(1,queryReq.getStyle());
|
|
|
|
|
}
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isLatest10(String journalNo) {
|
|
|
|
|
return null!=journalDao.isLatest10(journalNo);
|
|
|
|
|
}
|
|
|
|
|