feat(AnimeController): 新增 AnimeController 并更新版本号
- 添加 AnimeController 类,实现获取今日和明日番剧功能 - 更新项目版本号至 QQBot v.1.7.24
This commit is contained in:
parent
95a5bf5467
commit
7c49702d87
@ -0,0 +1,87 @@
|
||||
package com.yutou.qqbot.Controllers;
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.qqbot.utlis.BangumiTools;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/bgm")
|
||||
public class AnimeController {
|
||||
@GetMapping("/today")
|
||||
public Map<String, Object> getTodayAnim() {
|
||||
Map<String, Object> returnData = new HashMap<>();
|
||||
// 获取全部一周的数据
|
||||
JSONObject allData = BangumiTools.getBangumi(-1);
|
||||
|
||||
if (allData == null) {
|
||||
return returnData;
|
||||
}
|
||||
|
||||
JSONArray bangumiArray = allData.getJSONArray("bangumi");
|
||||
if (bangumiArray == null || bangumiArray.isEmpty()) {
|
||||
return returnData;
|
||||
}
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
|
||||
calendar.setFirstDayOfWeek(Calendar.MONDAY);
|
||||
calendar.setTime(new Date());
|
||||
|
||||
int todayId = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
if (todayId == 0) {
|
||||
todayId = 7; // 处理星期日的情况
|
||||
}
|
||||
|
||||
int tomorrowId = todayId % 7 + 1; // 计算明天对应的 weekday id
|
||||
|
||||
JSONObject todayData = null;
|
||||
JSONObject tomorrowData = null;
|
||||
|
||||
for (Object obj : bangumiArray) {
|
||||
JSONObject item = (JSONObject) obj;
|
||||
int weekdayId = item.getJSONObject("weekday").getInteger("id");
|
||||
|
||||
if (weekdayId == todayId) {
|
||||
todayData = item;
|
||||
}
|
||||
if (weekdayId == tomorrowId) {
|
||||
tomorrowData = item;
|
||||
}
|
||||
}
|
||||
|
||||
// 打印当日数据
|
||||
if (todayData != null) {
|
||||
JSONArray items = todayData.getJSONArray("items");
|
||||
if (items != null && !items.isEmpty()) {
|
||||
for (Object o : items) {
|
||||
JSONObject itemObj = (JSONObject) o;
|
||||
if (itemObj.getString("name_cn") == null || itemObj.getString("name_cn").isEmpty()) {
|
||||
itemObj.put("name_cn", itemObj.getString("name"));
|
||||
}
|
||||
}
|
||||
}
|
||||
returnData.put("today",todayData);
|
||||
}
|
||||
|
||||
// 打印明日数据
|
||||
if (tomorrowData != null) {
|
||||
JSONArray items = tomorrowData.getJSONArray("items");
|
||||
if (items != null && !items.isEmpty()) {
|
||||
for (Object o : items) {
|
||||
JSONObject itemObj = (JSONObject) o;
|
||||
if (itemObj.getString("name_cn") == null || itemObj.getString("name_cn").isEmpty()) {
|
||||
itemObj.put("name_cn", itemObj.getString("name"));
|
||||
}
|
||||
}
|
||||
}
|
||||
returnData.put("nextDay",tomorrowData);
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class QQBotApplication {
|
||||
public static final String version = "QQBot v.1.7.23";
|
||||
public static final String version = "QQBot v.1.7.24";
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("version = " + version);
|
||||
|
Loading…
x
Reference in New Issue
Block a user