diff --git a/src/main/java/com/yutou/tools/bangumi/AnimationController.java b/src/main/java/com/yutou/tools/bangumi/AnimationController.java index 2c9988c..25b8985 100644 --- a/src/main/java/com/yutou/tools/bangumi/AnimationController.java +++ b/src/main/java/com/yutou/tools/bangumi/AnimationController.java @@ -3,14 +3,11 @@ 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.dao.BangumiItemDao; -import com.yutou.tools.mybatis.dao.BangumiListDao; import com.yutou.tools.mybatis.model.BangumiItem; -import com.yutou.tools.mybatis.model.BangumiItemExample; import com.yutou.tools.mybatis.model.BangumiList; -import com.yutou.tools.mybatis.model.BangumiListExample; import com.yutou.tools.services.interfaces.BangumiService; import com.yutou.tools.utils.BangumiTools; +import com.yutou.tools.utils.RedisTools; import org.springframework.stereotype.Controller; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; @@ -84,7 +81,20 @@ public class AnimationController { @ResponseBody @RequestMapping(value = "/anim/rss/add.do", method = RequestMethod.POST) - public String addAnimationRss(String bgmId, String title, String author, String categories, String titleKey, String bid) { + 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(title.split("\\?")[1]); + i = bangumiService.addBangumiItem(item); + json.put("msg", i == 0 ? "添加失败" : "添加成功"); + return json; + } + int id = 0; if (!StringUtils.isEmpty(bgmId)) { try { @@ -100,11 +110,9 @@ public class AnimationController { item.setTitlekey(titleKey); item.setBid(bid); item.setEnable(1); - int i = bangumiService.addBangumiItem(item); - JSONObject json = new JSONObject(); - json.put("code", 0); + i = bangumiService.addBangumiItem(item); json.put("msg", i == 0 ? "添加失败" : "添加成功"); - return json.toJSONString(); + return json; } @ResponseBody @@ -119,12 +127,18 @@ public class AnimationController { @ResponseBody @RequestMapping(value = "/anim/rss/del.do", method = RequestMethod.POST) - public String delAnimation(int id) { - int i = bangumiService.removeBangumiItem(id); + public JSONObject delAnimation(String id) { JSONObject json = new JSONObject(); json.put("code", 0); + if (id.startsWith("http")) { + 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.toJSONString(); + return json; } @ResponseBody diff --git a/src/main/java/com/yutou/tools/services/BangumiServiceImpl.java b/src/main/java/com/yutou/tools/services/BangumiServiceImpl.java index a31525e..f518029 100644 --- a/src/main/java/com/yutou/tools/services/BangumiServiceImpl.java +++ b/src/main/java/com/yutou/tools/services/BangumiServiceImpl.java @@ -14,7 +14,9 @@ import com.yutou.tools.utils.Tools; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; +import java.util.Set; @Service("BangumiService") public class BangumiServiceImpl implements BangumiService { @@ -36,7 +38,9 @@ public class BangumiServiceImpl implements BangumiService { @Override public int addBangumiItem(BangumiItem... list) { for (BangumiItem item : list) { - if (itemDao.insert(item) <= 0) { + if (item.getId().equals(-1)) { + RedisTools.list_add("anim_tmp_rss",item.getTitle()); + } else if (itemDao.insert(item) <= 0) { return 0; } } @@ -68,40 +72,59 @@ public class BangumiServiceImpl implements BangumiService { @Override public List getBangumiItemList(String type) { + List items; + if ("-1".equals(type)) { + Set strings = RedisTools.list_get("anim_tmp_rss"); + items=new ArrayList<>(); + for (String string : strings) { + BangumiItem item=new BangumiItem();; + item.setTitle(string); + items.add(item); + } + return items; + } BangumiItemExample example = new BangumiItemExample(); example.createCriteria().andBidEqualTo(type); - List items = itemDao.selectByExample(example); + items = itemDao.selectByExample(example); for (BangumiItem item : items) { - if(item.getEnable()==0||item.getBgmid()==0){ + if (item.getEnable() == 0 || item.getBgmid() == 0) { continue; } - String tmp=RedisTools.get(item.getBgmid()+"",1); - JSONObject bangumi= tmp==null?BangumiTools.getBangumiInfoSmall(item.getBgmid()):JSONObject.parseObject(tmp); - RedisTools.set(1,2592000,item.getBgmid()+"",bangumi.toJSONString()); - if(bangumi.containsKey("code")&&bangumi.getInteger("code")==404){ + String tmp = RedisTools.get(item.getBgmid() + "", 1); + JSONObject bangumi = tmp == null ? BangumiTools.getBangumiInfoSmall(item.getBgmid()) : JSONObject.parseObject(tmp); + RedisTools.set(1, 2592000, item.getBgmid() + "", bangumi.toJSONString()); + if (bangumi.containsKey("code") && bangumi.getInteger("code") == 404) { continue; } - int day=Tools.getWeekDay(); + int day = Tools.getWeekDay(); if (day == 0) { day = 7; } - if(bangumi.getInteger("air_weekday")==day) { + if (bangumi.getInteger("air_weekday") == day) { item.setUpdateDay("今天更新"); - }else{ - item.setUpdateDay("周"+getDay(bangumi.getInteger("air_weekday"))+"更新"); + } else { + item.setUpdateDay("周" + getDay(bangumi.getInteger("air_weekday")) + "更新"); } } return items; } - private String getDay(int day){ - switch (day){ - case 1:return "一"; - case 2:return "二"; - case 3:return "三"; - case 4:return "四"; - case 5:return "五"; - case 6:return "六"; - default:return "日"; + + private String getDay(int day) { + switch (day) { + case 1: + return "一"; + case 2: + return "二"; + case 3: + return "三"; + case 4: + return "四"; + case 5: + return "五"; + case 6: + return "六"; + default: + return "日"; } } @@ -112,6 +135,11 @@ public class BangumiServiceImpl implements BangumiService { @Override public List getAllBangumiList() { - return listDao.selectByExample(new BangumiListExample()); + List list = listDao.selectByExample(new BangumiListExample()); + BangumiList bangumi = new BangumiList(); + bangumi.setTitle("临时RSS"); + bangumi.setId(-1); + list.add(bangumi); + return list; } } diff --git a/web/html/body/nas/animrss.html b/web/html/body/nas/animrss.html index 8f0b30d..f8913ba 100644 --- a/web/html/body/nas/animrss.html +++ b/web/html/body/nas/animrss.html @@ -173,6 +173,11 @@ 查看 删除 +