parent
2be18b3fd4
commit
6f791f4f97
@ -0,0 +1,57 @@
|
||||
package com.luoo.music.service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.luoo.music.dao.UserCollectDao;
|
||||
import com.luoo.music.pojo.UserCollect;
|
||||
|
||||
import enums.CollectTypeEnum;
|
||||
|
||||
@Service
|
||||
public class UserCollectService {
|
||||
@Autowired
|
||||
private UserCollectDao userCollectDao;
|
||||
|
||||
public Set<String> getCollectSet(String userId, CollectTypeEnum collectTypeEnum) {
|
||||
List<String> collectList = getCollectList(userId, null, null, collectTypeEnum);
|
||||
if (collectList.isEmpty()) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return new HashSet<>(collectList);
|
||||
}
|
||||
|
||||
public List<String> getCollectList(String userId, Integer pageNum, Integer pageSize,
|
||||
CollectTypeEnum collectTypeEnum) {
|
||||
if (null == userId) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
Optional<UserCollect> optional = userCollectDao.findById(userId);
|
||||
if (!optional.isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
UserCollect userCollect = optional.get();
|
||||
switch (collectTypeEnum) {
|
||||
case SONG:
|
||||
return getPageResult(pageNum, pageSize, userCollect.getSongs());
|
||||
case JOURNAL:
|
||||
return getPageResult(pageNum, pageSize, userCollect.getJournals());
|
||||
default:
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getPageResult(Integer pageNum, Integer pageSize, LinkedList<String> objectIds) {
|
||||
if (null != pageNum && null != pageSize && pageNum > 0 && pageSize > 0) {
|
||||
return objectIds.subList((pageNum - 1) * pageSize, pageNum * pageSize);
|
||||
}
|
||||
return objectIds;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue