|
|
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
|
|
|
|
import java.io.StringReader;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
@ -23,12 +24,15 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
import com.luoo.music.dao.JournalDao;
|
|
|
|
|
import com.luoo.music.dao.JournalSongDao;
|
|
|
|
|
import com.luoo.music.dao.TagDao;
|
|
|
|
|
import com.luoo.music.dao.UserCollectInfoDao;
|
|
|
|
|
import com.luoo.music.ik.lucene.IKAnalyzer;
|
|
|
|
|
import com.luoo.music.listener.CleanJournalCache;
|
|
|
|
|
import com.luoo.music.pojo.Journal;
|
|
|
|
|
import com.luoo.music.pojo.JournalSong;
|
|
|
|
|
import com.luoo.music.pojo.UserCollectInfo;
|
|
|
|
|
import com.luoo.music.util.Constants;
|
|
|
|
|
|
|
|
|
|
import enums.CollectTypeEnum;
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
|
import net.oschina.j2cache.CacheChannel;
|
|
|
|
|
import util.StringTools;
|
|
|
|
@ -44,19 +48,20 @@ public class SaticScheduleTask {
|
|
|
|
|
private CacheChannel cacheChannel;
|
|
|
|
|
@Autowired
|
|
|
|
|
private TagDao tagDao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserCollectInfoDao userCollectInfoDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private CleanJournalCache cleanJournalCache;
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
|
private void init() {
|
|
|
|
|
//updateAutoComplete();
|
|
|
|
|
// updateAutoComplete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 1.凌晨4点执行更新期刊tag
|
|
|
|
|
// 1.凌晨4点执行更新期刊tag, 更新收藏数
|
|
|
|
|
@Scheduled(cron = "0 0 4 * * *")
|
|
|
|
|
private void updateJouranlTag() {
|
|
|
|
|
journalDao.findValidJournals().parallelStream().forEach(this::updateJouranlTag);
|
|
|
|
|
journalDao.findValidJournals().parallelStream().forEach(this::updateJouranlTagAndCollectCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2.凌晨4:20点执行更新分词
|
|
|
|
@ -98,6 +103,24 @@ public class SaticScheduleTask {
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateJouranlTagAndCollectCount(Journal journal) {
|
|
|
|
|
updateJouranlTag(journal);
|
|
|
|
|
updateUserCollectCount(journal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateUserCollectCount(Journal journal) {
|
|
|
|
|
List<UserCollectInfo> userCollectInfos = userCollectInfoDao.findByObjectIdAndCollectType(journal.getId(),
|
|
|
|
|
CollectTypeEnum.JOURNAL.getType());
|
|
|
|
|
Set<String> set = userCollectInfos.stream().map(UserCollectInfo::getUserId)
|
|
|
|
|
.collect(Collectors.toCollection(LinkedHashSet::new));
|
|
|
|
|
int dbCount = journal.getUserCollectCount();
|
|
|
|
|
if (userCollectInfos.size() != dbCount || set.size() != dbCount) {
|
|
|
|
|
journal.setUserCollectCount(set.size());
|
|
|
|
|
journalDao.save(journal);
|
|
|
|
|
cleanJournalCache.clean(journal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateJouranlTag(Journal journal) {
|
|
|
|
|
List<String> tags = tagDao.getTagNameChByJournalId(journal.getId());
|
|
|
|
|
if (!tags.isEmpty()) {
|
|
|
|
|