|
|
@@ -1,17 +1,29 @@
|
|
|
package com.yhlxj.service.task;//package com.cyksj.task;
|
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import com.yhlxj.service.midjourney.MidjourneyAccountService;
|
|
|
import com.yhlxj.service.midjourney.MidjourneyService;
|
|
|
+import lombok.Data;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+
|
|
|
@Component
|
|
|
@Slf4j
|
|
|
@RequiredArgsConstructor
|
|
|
public class Scheduler {
|
|
|
|
|
|
+ public static final Map<String, MjVersionStatus> MJ_VERSION_STATUS_MAP = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
private final MidjourneyService midjourneyService;
|
|
|
|
|
|
private final MidjourneyAccountService midjourneyAccountService;
|
|
|
@@ -26,6 +38,64 @@ public class Scheduler {
|
|
|
midjourneyAccountService.syncAccountByMJPlus();
|
|
|
}
|
|
|
|
|
|
+ @Scheduled(cron = "0 0/2 * * * ?")
|
|
|
+ public void getMjStatus() throws Exception {
|
|
|
+ String url = "https://storage.googleapis.com/midjourney-status/status.json";
|
|
|
+ String res = HttpUtil.get(url);
|
|
|
+ JSONObject json = new JSONObject(res);
|
|
|
+ JSONArray metrics = json.getJSONArray("metrics");
|
|
|
+ List<MjVersionStatus> list = metrics.toList(MjVersionStatus.class);
|
|
|
+ for (MjVersionStatus mjVersionStatus : list) {
|
|
|
+ if (mjVersionStatus.getName().contains("jobs.v6")) {
|
|
|
+ // 分类数据并组合键
|
|
|
+ String[] parts = mjVersionStatus.getName().split("\\.");
|
|
|
+ String mainCategory = parts[1];
|
|
|
+ String subCategory = parts[2] + "-" + parts[3];
|
|
|
+ String key = mainCategory + "-" + subCategory;
|
|
|
+ MJ_VERSION_STATUS_MAP
|
|
|
+ .putIfAbsent(key, mjVersionStatus);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
+@Data
|
|
|
+class MjVersionStatus {
|
|
|
+ //{
|
|
|
+ // "name": "jobs.time_to_start.fast.10min.job_type_kdpt_diffusion_anime",
|
|
|
+ // "date": "2024-07-11T03:24:01.784Z",
|
|
|
+ // "value": "N/A"
|
|
|
+ //}
|
|
|
+
|
|
|
+ private String name;
|
|
|
+
|
|
|
+ private String date;
|
|
|
+
|
|
|
+ private String value;
|
|
|
+ /**
|
|
|
+ * 转换为秒
|
|
|
+ */
|
|
|
+ private Long second;
|
|
|
+
|
|
|
+
|
|
|
+ public void setValue(String value) {
|
|
|
+ this.value = value;
|
|
|
+ // 转换为秒并设置 second
|
|
|
+ if (value != null && !value.equals("N/A")) {
|
|
|
+ try {
|
|
|
+ double minutes = Double.parseDouble(value);
|
|
|
+ this.second = Math.round(minutes * 60);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ this.second = null;
|
|
|
+ System.err.println("Invalid value format: " + value);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.second = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|