use of mingzuozhibi.persist.disc.Disc 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.Disc in project mzzb-server by mingzuozhibi.
the class DiscController method getOne.
@Transactional
@GetMapping(value = "/api/discs/{id}", produces = MEDIA_TYPE)
public String getOne(@PathVariable Long id) {
Disc disc = dao.get(Disc.class, id);
if (disc == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[获取碟片失败][指定的碟片Id不存在][Id={}]", id);
}
return errorMessage("指定的碟片Id不存在");
}
JSONObject result = disc.toJSON();
if (LOGGER.isDebugEnabled()) {
debugRequest("[获取碟片成功][碟片信息={}]", result);
}
result.put("ranks", buildRanks(dao, disc));
return objectResult(result);
}
use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.
the class DiscController method setOne.
@Transactional
@PreAuthorize("hasRole('BASIC')")
@PutMapping(value = "/api/discs/{id}", produces = MEDIA_TYPE)
public String setOne(@PathVariable Long id, @JsonArg String titlePc, @JsonArg String titleMo, @JsonArg DiscType discType, @JsonArg UpdateType updateType, @JsonArg String releaseDate) {
if (releaseDate.isEmpty()) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[编辑碟片失败][发售日期不能为空]");
}
return errorMessage("发售日期不能为空");
}
LocalDate localDate;
try {
localDate = LocalDate.parse(releaseDate, formatter);
} catch (DateTimeParseException e) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[编辑碟片失败][发售日期格式不正确]");
}
return errorMessage("发售日期格式不正确");
}
Disc disc = dao.get(Disc.class, id);
if (disc == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[编辑碟片失败][指定的碟片Id不存在][Id={}]", id);
}
return errorMessage("指定的碟片Id不存在");
}
JSONObject before = disc.toJSON();
if (LOGGER.isDebugEnabled()) {
debugRequest("[编辑碟片开始][修改前={}]", before);
}
disc.setTitlePc(titlePc);
disc.setTitleMo(titleMo);
disc.setDiscType(discType);
disc.setUpdateType(updateType);
disc.setReleaseDate(localDate);
JSONObject result = disc.toJSON();
if (LOGGER.isDebugEnabled()) {
debugRequest("[编辑碟片成功][修改后={}]", result);
}
result.put("ranks", buildRanks(dao, disc));
return objectResult(result);
}
use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.
the class DiscController method search.
@Transactional
@PreAuthorize("hasRole('BASIC')")
@GetMapping(value = "/api/discs/search/{asin}", produces = MEDIA_TYPE)
public String search(@PathVariable String asin) {
AtomicReference<Disc> disc = new AtomicReference<>(dao.lookup(Disc.class, "asin", asin));
StringBuffer error = new StringBuffer();
if (disc.get() == null) {
searchFromAmazon(asin, disc, error);
waitForSearch(disc);
}
if (disc.get() == null) {
if (error.length() > 0) {
return errorMessage(error.toString());
}
if (LOGGER.isInfoEnabled()) {
infoRequest("[查找碟片][从Amazon查询超时][asin={}]]", asin);
}
return errorMessage("查询超时,你可以稍后再尝试");
}
JSONArray result = new JSONArray();
JSONObject discJSON = disc.get().toJSON();
if (LOGGER.isInfoEnabled()) {
infoRequest("[查找碟片成功][碟片信息={}]", discJSON);
}
result.put(discJSON);
return objectResult(result);
}
use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.
the class DiscController method mergeRanks.
@Transactional
@PutMapping(value = "/api/discs/{id}/ranks", produces = MEDIA_TYPE)
public String mergeRanks(@PathVariable Long id, @JsonArg String text) {
Disc disc = dao.get(Disc.class, id);
if (disc == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[提交排名失败][指定的碟片Id不存在][Id={}]", id);
}
return errorMessage("指定的碟片Id不存在");
}
int matchLine = mergeRankText(dao, disc, text);
computeAndUpdateAmazonPt(dao, disc);
JSONObject result = disc.toJSON();
if (LOGGER.isDebugEnabled()) {
debugRequest("[提交排名成功][提交记录数={}][碟片信息={}]", matchLine, result);
}
result.put("records", buildRecords(dao, disc));
return objectResult(result);
}
Aggregations