package mingzuozhibi.action;

import mingzuozhibi.persist.Disc;
import mingzuozhibi.persist.Sakura;
import mingzuozhibi.support.Dao;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@RestController
public class SakuraController extends BaseController {

    @Autowired
    private Dao dao;

    @GetMapping(value = "/api/sakuras", produces = CONTENT_TYPE)
    public String listSakura(@RequestParam("discColumns") String discColumns) {
        JSONArray data = new JSONArray();
        List<Sakura> sakuras = dao.findBy(Sakura.class, "enabled", true);
        LOGGER.debug("获取sakura数据, 共{}个列表, 请求参数: {}", sakuras.size(), discColumns);
        Set<String> columns = Arrays.stream(discColumns.split(",")).collect(Collectors.toSet());
        sakuras.forEach(sakura -> {
            data.put(sakura.toJSON().put("discs", buildDiscs(sakura, columns)));
            LOGGER.debug("列表[{}]共{}个碟片", sakura.getTitle(), sakura.getDiscs().size());
        });
        return objectResult(data);
    }

    @GetMapping(value = "/api/basic/sakuras", produces = CONTENT_TYPE)
    public String listBasicSakura() {
        JSONArray data = new JSONArray();
        List<Sakura> sakuras = dao.findAll(Sakura.class);
        sakuras.forEach(sakura -> data.put(sakura.toJSON()));
        return objectResult(data);
    }

    private JSONArray buildDiscs(Sakura sakura, Set<String> columns) {
        JSONArray discs = new JSONArray();
        sakura.getDiscs().stream()
                .filter(disc -> disc.getUpdateType() != Disc.UpdateType.None)
                .forEach(disc -> discs.put(disc.toJSON(columns)));
        return discs;
    }

}

@@ -126,16 +126,53 @@
 rt.Dao;%0A
+import mingzuozhibi.support.JsonArg;%0A
 import o
@@ -312,16 +312,76 @@
 apping;%0A
+import org.springframework.web.bind.annotation.PostMapping;%0A
 import o
@@ -1721,24 +1721,467 @@
 ta);%0A    %7D%0A%0A
+    @PostMapping(value = %22/api/basic/sakuras%22, produces = CONTENT_TYPE)%0A    public String saveBasicSakura(%0A            @JsonArg(%22$.key%22) String key,%0A            @JsonArg(%22$.title%22) String title) %7B%0A        if (dao.lookup(Sakura.class, %22key%22, key) != null) %7B%0A            return errorMessage(%22%E8%AF%A5Sakura%E5%88%97%E8%A1%A8%E5%B7%B2%E5%AD%98%E5%9C%A8%22);%0A        %7D%0A        Sakura sakura = new Sakura(key, title);%0A        dao.save(sakura);%0A        return objectResult(sakura.toJSON());%0A    %7D%0A%0A
     private 

Add post /api/admin/sakuras Api