use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class SakuraController method findAll.
@Transactional
@GetMapping(value = "/api/sakuras", produces = MEDIA_TYPE)
public String findAll(@RequestParam(name = "public", defaultValue = "true") boolean isPublic) {
@SuppressWarnings("unchecked") List<Sakura> sakuras = dao.query(session -> {
Criteria criteria = session.createCriteria(Sakura.class);
if (isPublic) {
criteria.add(Restrictions.ne("viewType", ViewType.PrivateList));
criteria.add(Restrictions.eq("enabled", true));
}
return criteria.list();
});
JSONArray result = new JSONArray();
sakuras.forEach(sakura -> {
result.put(sakura.toJSON());
});
if (LOGGER.isDebugEnabled()) {
debugRequest("[获取多个列表成功][列表数量={}]", sakuras.size());
}
return objectResult(result);
}
use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class SakuraController method dropDiscs.
@Transactional
@PreAuthorize("hasRole('BASIC')")
@DeleteMapping(value = "/api/sakuras/{id}/discs/{discId}", produces = MEDIA_TYPE)
public String dropDiscs(@PathVariable("id") Long id, @PathVariable("discId") Long discId, @RequestParam(name = "discColumns", defaultValue = DISC_COLUMNS) String discColumns) {
Sakura sakura = dao.get(Sakura.class, id);
if (sakura == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[从列表移除碟片失败][指定的列表Id不存在][Id={}]", id);
}
return errorMessage("指定的列表Id不存在");
}
Disc disc = sakura.getDiscs().stream().filter(d -> d.getId().equals(discId)).findFirst().orElse(null);
if (disc == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[从列表移除碟片失败][指定的碟片不存在于列表][Id={}]", discId);
}
return errorMessage("指定的碟片不存在于列表");
}
sakura.getDiscs().remove(disc);
if (LOGGER.isInfoEnabled()) {
infoRequest("[从列表移除碟片成功][ASIN={}][列表={}]", disc.getAsin(), sakura.getTitle());
}
return objectResult(disc.toJSON(getColumns(discColumns)));
}
use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class SakuraController method delOne.
@Transactional
@PreAuthorize("hasRole('ADMIN')")
@DeleteMapping(value = "/api/sakuras/{id}", produces = MEDIA_TYPE)
public String delOne(@PathVariable("id") Long id) {
Sakura sakura = dao.get(Sakura.class, id);
if (dao.get(Sakura.class, id) == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[删除列表失败][指定的列表Id不存在][Key={}]", id);
}
return errorMessage("指定的列表Id不存在");
}
JSONObject before = sakura.toJSON();
if (LOGGER.isDebugEnabled()) {
debugRequest("[删除列表开始][删除前={}]", before);
}
sakura.getDiscs().clear();
dao.delete(sakura);
JSONObject result = sakura.toJSON();
if (LOGGER.isDebugEnabled()) {
debugRequest("[删除列表成功][修改后={}]", result);
}
return objectResult(result);
}
use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class AmazonScheduler method finishTheUpdate.
private void finishTheUpdate(Set<Disc> discs, Map<String, Integer> results) {
LOGGER.info("[正在写入Amazon(ALL)数据]]");
dao.execute(session -> {
discs.forEach(disc -> {
Integer rank = results.get(disc.getAsin());
dao.refresh(disc);
disc.setPrevRank(disc.getThisRank());
if (rank != null) {
disc.setThisRank(rank);
disc.setUpdateTime(fullUpdateTime.get());
}
if (!Objects.equals(disc.getThisRank(), disc.getPrevRank())) {
disc.setModifyTime(fullUpdateTime.get());
}
});
dao.findAll(Sakura.class).stream().filter(sakura -> sakura.getViewType() != ViewType.SakuraList).forEach(sakura -> {
sakura.setModifyTime(fullUpdateTime.get());
});
});
LOGGER.info("[成功更新Amazon(ALL)数据]");
service.infoStatus();
amazonFetchStatus = AmazonFetchStatus.waitingForUpdate;
}
use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class SakuraSpeedSpider method updateSakuraDiscs.
private void updateSakuraDiscs(Sakura sakura, Stream<Element> tableRows) {
Set<Disc> toAdd = new LinkedHashSet<>(sakura.getDiscs().size());
boolean isTop100 = "9999-99".equals(sakura.getKey());
tableRows.forEach(tr -> {
String href = tr.child(5).child(0).attr("href");
String asin = href.substring(href.length() - 10);
Disc disc = getOrCreateDisc(asin, tr);
if (disc.getUpdateType() == UpdateType.Both && !isTop100) {
disc.setUpdateType(UpdateType.Sakura);
}
if (disc.getUpdateType() == UpdateType.Sakura) {
String[] sakuraRank = tr.child(0).text().split("/");
disc.setThisRank(parseInteger(sakuraRank[0]));
disc.setPrevRank(parseInteger(sakuraRank[1]));
disc.setTotalPt(parseInteger(tr.child(2).text()));
disc.setNicoBook(parseInteger(tr.child(3).text()));
disc.setUpdateTime(sakura.getModifyTime());
if (!Objects.equals(disc.getThisRank(), disc.getPrevRank())) {
disc.setModifyTime(sakura.getModifyTime());
}
}
toAdd.add(disc);
});
if (isTop100) {
sakura.setDiscs(new LinkedList<>(toAdd));
} else {
boolean noExpiredSakura = noExpiredSakura(sakura);
sakura.getDiscs().stream().filter(disc -> {
return disc.getUpdateType() != UpdateType.Sakura || noExpiredSakura;
}).filter(disc -> !toAdd.contains(disc)).forEach(disc -> {
if (disc.getUpdateType() == UpdateType.Sakura) {
disc.setUpdateType(UpdateType.Both);
}
toAdd.add(disc);
});
sakura.setDiscs(toAdd.stream().sorted().collect(Collectors.toList()));
}
LOGGER.debug("成功更新[{}]列表", sakura.getTitle());
}
Aggregations