Search in sources :

Example 1 with Disc

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)));
}
Also used : Disc(mingzuozhibi.persist.disc.Disc) Sakura(mingzuozhibi.persist.disc.Sakura) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Disc

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);
}
Also used : JSONObject(org.json.JSONObject) Disc(mingzuozhibi.persist.disc.Disc) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Disc

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);
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) JSONObject(org.json.JSONObject) Disc(mingzuozhibi.persist.disc.Disc) LocalDate(java.time.LocalDate) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Disc

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);
}
Also used : JSONObject(org.json.JSONObject) Disc(mingzuozhibi.persist.disc.Disc) JSONArray(org.json.JSONArray) AtomicReference(java.util.concurrent.atomic.AtomicReference) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Disc

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);
}
Also used : JSONObject(org.json.JSONObject) Disc(mingzuozhibi.persist.disc.Disc) PutMapping(org.springframework.web.bind.annotation.PutMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Disc (mingzuozhibi.persist.disc.Disc)27 Transactional (org.springframework.transaction.annotation.Transactional)14 JSONObject (org.json.JSONObject)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 LocalDate (java.time.LocalDate)8 Sakura (mingzuozhibi.persist.disc.Sakura)6 LocalDateTime (java.time.LocalDateTime)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 PutMapping (org.springframework.web.bind.annotation.PutMapping)4 LinkedHashSet (java.util.LinkedHashSet)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 UpdateType (mingzuozhibi.persist.disc.Disc.UpdateType)3 DiscGroup (mingzuozhibi.persist.disc.DiscGroup)3 ViewType (mingzuozhibi.persist.disc.Sakura.ViewType)3 DateTimeFormatter (java.time.format.DateTimeFormatter)2 java.util (java.util)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 DiscType (mingzuozhibi.persist.disc.Disc.DiscType)2