236 lines
8.4 KiB
Java
236 lines
8.4 KiB
Java
package com.yutou.tools.bangumi;
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.yutou.tools.mybatis.model.BangumiItem;
|
|
import com.yutou.tools.mybatis.model.BangumiList;
|
|
import com.yutou.tools.nas.UpdateIp;
|
|
import com.yutou.tools.services.interfaces.BangumiService;
|
|
import com.yutou.tools.utils.BangumiTools;
|
|
import com.yutou.tools.utils.HttpTools;
|
|
import com.yutou.tools.utils.RedisTools;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
@Controller
|
|
public class AnimationController {
|
|
@Resource
|
|
BangumiService bangumiService;
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/anim/rss/data.do", method = RequestMethod.GET)
|
|
public String getAnimList(String key, String type, String team, int page) {
|
|
boolean isNull = key.length() == 0;
|
|
if (!StringUtils.isEmpty(type) && type.length() > 2) {
|
|
type = type.substring(2);
|
|
}
|
|
if (!StringUtils.isEmpty(team) && team.length() > 2) {
|
|
team = team.substring(2);
|
|
}
|
|
String[] keys = key.split(" ");
|
|
JSONArray items = null;
|
|
if (!isNull) {
|
|
items = new AnimationData().bangumiList(page, type, team, keys);
|
|
}
|
|
JSONObject json = new JSONObject();
|
|
json.put("data", Objects.requireNonNullElseGet(items, JSONArray::new));
|
|
json.put("count", 999);
|
|
json.put("code", 0);
|
|
json.put("msg", "ok");
|
|
return json.toJSONString();
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/anim/type/add.do", method = RequestMethod.POST)
|
|
public String addRssType(String title) {
|
|
BangumiList bangumiList = new BangumiList();
|
|
bangumiList.setTitle(title);
|
|
bangumiList.setStatus(1);
|
|
int i = bangumiService.addBangumiList(bangumiList);
|
|
JSONObject json = new JSONObject();
|
|
json.put("code", 0);
|
|
json.put("msg", i == 0 ? "添加失败" : "添加成功");
|
|
return json.toJSONString();
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/anim/type/list.do", method = RequestMethod.GET)
|
|
public String getRssTypeList() {
|
|
JSONObject json = new JSONObject();
|
|
json.put("code", 0);
|
|
json.put("msg", "ok");
|
|
json.put("data", JSON.toJSON(bangumiService.getAllBangumiList()));
|
|
return json.toJSONString();
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/anim/type/del.do", method = RequestMethod.POST)
|
|
public String delType(int id) {
|
|
int i = bangumiService.removeBangumiType(id);
|
|
JSONObject json = new JSONObject();
|
|
json.put("code", 0);
|
|
json.put("msg", i == 0 ? "删除失败" : "删除成功");
|
|
return json.toJSONString();
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/anim/rss/add.do", method = RequestMethod.POST)
|
|
public JSONObject addAnimationRss(String bgmId, String title, String author, String categories, String titleKey, String bid) {
|
|
int i = 0;
|
|
JSONObject json = new JSONObject();
|
|
json.put("code", 0);
|
|
if ("-1".equals(bid)) {
|
|
BangumiItem item = new BangumiItem();
|
|
item.setId(-1);
|
|
item.setTitle(title);
|
|
item.setTitlekey(titleKey);
|
|
i = bangumiService.addBangumiItem(item);
|
|
json.put("msg", i == 0 ? "添加失败" : "添加成功");
|
|
return json;
|
|
}
|
|
|
|
int id = 0;
|
|
if (!StringUtils.isEmpty(bgmId)) {
|
|
try {
|
|
id = Integer.parseInt(bgmId.trim());
|
|
} catch (Exception ignored) {
|
|
}
|
|
}
|
|
BangumiItem item = new BangumiItem();
|
|
item.setBgmid(id);
|
|
item.setTitle(title);
|
|
item.setAuthor(author);
|
|
item.setCategories(categories);
|
|
item.setTitlekey(titleKey);
|
|
item.setBid(bid);
|
|
item.setEnable(1);
|
|
i = bangumiService.addBangumiItem(item);
|
|
json.put("msg", i == 0 ? "添加失败" : "添加成功");
|
|
return json;
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/anim/rss/list.do", method = RequestMethod.GET)
|
|
public String getAnimationRssList(String type) {
|
|
JSONObject json = new JSONObject();
|
|
json.put("code", 0);
|
|
json.put("msg", "ok");
|
|
json.put("data", JSON.toJSON(bangumiService.getBangumiItemList(type)));
|
|
return json.toJSONString();
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/anim/rss/del.do", method = RequestMethod.POST)
|
|
public JSONObject delAnimation(String id) {
|
|
JSONObject json = new JSONObject();
|
|
json.put("code", 0);
|
|
if (id.startsWith("{")) {
|
|
boolean tmpRss = RedisTools.list_remove("anim_tmp_rss", id);
|
|
json.put("msg", tmpRss ? "删除成功" : "删除失败");
|
|
return json;
|
|
}
|
|
int i = bangumiService.removeBangumiItem(Integer.parseInt(id));
|
|
|
|
json.put("msg", i == 0 ? "删除失败" : "删除成功");
|
|
return json;
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/anim/rss/edit.do", method = RequestMethod.POST)
|
|
public JSONObject editAnimation(int id, String bgmId, String title, String author, String categories, String titleKey, String enable) {
|
|
JSONObject json = new JSONObject();
|
|
BangumiItem item = bangumiService.getBangumiItem(id);
|
|
if (!StringUtils.isEmpty(bgmId)) {
|
|
try {
|
|
item.setBgmid(Integer.parseInt(bgmId));
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
|
}
|
|
if (!StringUtils.isEmpty(title)) {
|
|
item.setTitle(title);
|
|
}
|
|
if (!StringUtils.isEmpty(author)) {
|
|
item.setAuthor(author);
|
|
}
|
|
if (!StringUtils.isEmpty(categories)) {
|
|
item.setCategories(categories);
|
|
}
|
|
if (!StringUtils.isEmpty(titleKey)) {
|
|
item.setTitlekey(titleKey);
|
|
}
|
|
if (!StringUtils.isEmpty(enable)) {
|
|
item.setEnable(Integer.parseInt(enable));
|
|
}
|
|
int i = bangumiService.updateBangumiItem(item);
|
|
if (i > 0) {
|
|
json.put("msg", "操作成功");
|
|
} else {
|
|
json.put("msg", "操作失败");
|
|
}
|
|
json.put("code", 1);
|
|
return json;
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/anim/client/get.do", method = RequestMethod.GET)
|
|
public String clientApi() {
|
|
AnimationData animationData = new AnimationData();
|
|
List<BangumiItem> list = bangumiService.getAllBangumiItemList();
|
|
for (BangumiItem item : list) {
|
|
item.setCategories(animationData.nameToValue(item.getCategories(), false) + "");
|
|
item.setAuthor(animationData.nameToValue(item.getAuthor(), true) + "");
|
|
}
|
|
JSONArray array = (JSONArray) JSON.toJSON(list);
|
|
return array.toJSONString();
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/anim/getToDay.do", method = RequestMethod.GET)
|
|
public JSONObject getToDayAnim() {
|
|
return BangumiTools.getBangumi(0);
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/anim/setDownload.do", method = RequestMethod.POST)
|
|
public JSONObject setDownload(int id, String url) {
|
|
String serverUrl = "http://" + UpdateIp.nas_ip + ":8000/bt/download.do";
|
|
JSONObject json = new JSONObject();
|
|
json.put("id", id);
|
|
json.put("url", url);
|
|
String post = HttpTools.post(serverUrl, HttpTools.toUrlParams(json).getBytes(StandardCharsets.UTF_8));
|
|
json.clear();
|
|
json.put("code", 0);
|
|
json.put("msg", post);
|
|
return json;
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/anim/rssdata.do", method = RequestMethod.POST)
|
|
public JSONObject getRssData(int id) {
|
|
JSONObject json = new JSONObject();
|
|
BangumiItem item = bangumiService.getBangumiItem(id);
|
|
if (item != null) {
|
|
String key = item.getTitle().split("/")[0];
|
|
AnimationData animationData = new AnimationData();
|
|
JSONArray array = animationData.bangumiList(1, "0", "0", ","+key.replace(" ","+"));
|
|
json.put("code",0);
|
|
json.put("data", array);
|
|
json.put("msg","ok");
|
|
}else{
|
|
json.put("code",-1);
|
|
json.put("msg","id错误");
|
|
}
|
|
return json;
|
|
}
|
|
}
|