fix:修复修改rss时无bgmid的问题

This commit is contained in:
Yutousama 2022-07-11 14:02:30 +08:00
parent fefcfe6c35
commit 96b2ba371f

View File

@ -23,23 +23,23 @@ import java.util.Objects;
@Controller @Controller
public class AnimationController { public class AnimationController {
@Resource @Resource
BangumiService bangumiService; BangumiService bangumiService;
@ResponseBody @ResponseBody
@RequestMapping(value = "/anim/rss/data.do", method = RequestMethod.GET) @RequestMapping(value = "/anim/rss/data.do", method = RequestMethod.GET)
public String getAnimList(String key,String type,String team, int page) { public String getAnimList(String key, String type, String team, int page) {
boolean isNull = key.length() == 0; boolean isNull = key.length() == 0;
if(!StringUtils.isEmpty(type)&&type.length()>2) { if (!StringUtils.isEmpty(type) && type.length() > 2) {
type=type.substring(2); type = type.substring(2);
} }
if(!StringUtils.isEmpty(team)&&team.length()>2) { if (!StringUtils.isEmpty(team) && team.length() > 2) {
team=team.substring(2); team = team.substring(2);
} }
String[] keys = key.split(" "); String[] keys = key.split(" ");
JSONArray items = null; JSONArray items = null;
if (!isNull) { if (!isNull) {
items = new AnimationData().bangumiList(page,type,team, keys); items = new AnimationData().bangumiList(page, type, team, keys);
} }
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("data", Objects.requireNonNullElseGet(items, JSONArray::new)); json.put("data", Objects.requireNonNullElseGet(items, JSONArray::new));
@ -71,11 +71,12 @@ public class AnimationController {
json.put("data", JSON.toJSON(bangumiService.getAllBangumiList())); json.put("data", JSON.toJSON(bangumiService.getAllBangumiList()));
return json.toJSONString(); return json.toJSONString();
} }
@ResponseBody @ResponseBody
@RequestMapping(value = "/anim/type/del.do", method = RequestMethod.POST) @RequestMapping(value = "/anim/type/del.do", method = RequestMethod.POST)
public String delType(int id){ public String delType(int id) {
int i=bangumiService.removeBangumiType(id); int i = bangumiService.removeBangumiType(id);
JSONObject json=new JSONObject(); JSONObject json = new JSONObject();
json.put("code", 0); json.put("code", 0);
json.put("msg", i == 0 ? "删除失败" : "删除成功"); json.put("msg", i == 0 ? "删除失败" : "删除成功");
return json.toJSONString(); return json.toJSONString();
@ -83,12 +84,13 @@ public class AnimationController {
@ResponseBody @ResponseBody
@RequestMapping(value = "/anim/rss/add.do", method = RequestMethod.POST) @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 String addAnimationRss(String bgmId, String title, String author, String categories, String titleKey, String bid) {
int id=0; int id = 0;
if(!StringUtils.isEmpty(bgmId)){ if (!StringUtils.isEmpty(bgmId)) {
try { try {
id=Integer.parseInt(bgmId.trim()); id = Integer.parseInt(bgmId.trim());
}catch (Exception ignored){} } catch (Exception ignored) {
}
} }
BangumiItem item = new BangumiItem(); BangumiItem item = new BangumiItem();
item.setBgmid(id); item.setBgmid(id);
@ -114,62 +116,70 @@ public class AnimationController {
json.put("data", JSON.toJSON(bangumiService.getBangumiItemList(type))); json.put("data", JSON.toJSON(bangumiService.getBangumiItemList(type)));
return json.toJSONString(); return json.toJSONString();
} }
@ResponseBody @ResponseBody
@RequestMapping(value = "/anim/rss/del.do", method = RequestMethod.POST) @RequestMapping(value = "/anim/rss/del.do", method = RequestMethod.POST)
public String delAnimation(int id){ public String delAnimation(int id) {
int i=bangumiService.removeBangumiItem(id); int i = bangumiService.removeBangumiItem(id);
JSONObject json=new JSONObject(); JSONObject json = new JSONObject();
json.put("code", 0); json.put("code", 0);
json.put("msg", i == 0 ? "删除失败" : "删除成功"); json.put("msg", i == 0 ? "删除失败" : "删除成功");
return json.toJSONString(); return json.toJSONString();
} }
@ResponseBody @ResponseBody
@RequestMapping(value = "/anim/rss/edit.do",method = RequestMethod.POST) @RequestMapping(value = "/anim/rss/edit.do", method = RequestMethod.POST)
public JSONObject editAnimation(int id,int bgmId,String title, String author, String categories, String titleKey,String enable){ public JSONObject editAnimation(int id, String bgmId, String title, String author, String categories, String titleKey, String enable) {
JSONObject json=new JSONObject(); JSONObject json = new JSONObject();
BangumiItem item =bangumiService.getBangumiItem(id); BangumiItem item = bangumiService.getBangumiItem(id);
if(bgmId!=0){ if (!StringUtils.isEmpty(bgmId)) {
item.setBgmid(bgmId); try {
item.setBgmid(Integer.parseInt(bgmId));
} catch (Exception ignored) {
}
} }
if(!StringUtils.isEmpty(title)){ if (!StringUtils.isEmpty(title)) {
item.setTitle(title); item.setTitle(title);
} }
if(!StringUtils.isEmpty(author)){ if (!StringUtils.isEmpty(author)) {
item.setAuthor(author); item.setAuthor(author);
} }
if(!StringUtils.isEmpty(categories)){ if (!StringUtils.isEmpty(categories)) {
item.setCategories(categories); item.setCategories(categories);
} }
if(!StringUtils.isEmpty(titleKey)){ if (!StringUtils.isEmpty(titleKey)) {
item.setTitlekey(titleKey); item.setTitlekey(titleKey);
} }
if(!StringUtils.isEmpty(enable)){ if (!StringUtils.isEmpty(enable)) {
item.setEnable(Integer.parseInt(enable)); item.setEnable(Integer.parseInt(enable));
} }
int i=bangumiService.updateBangumiItem(item); int i = bangumiService.updateBangumiItem(item);
if(i>0){ if (i > 0) {
json.put("msg","操作成功"); json.put("msg", "操作成功");
}else{ } else {
json.put("msg","操作失败"); json.put("msg", "操作失败");
} }
json.put("code",1); json.put("code", 1);
return json; return json;
} }
@ResponseBody @ResponseBody
@RequestMapping(value = "/anim/client/get.do", method = RequestMethod.GET) @RequestMapping(value = "/anim/client/get.do", method = RequestMethod.GET)
public String clientApi(){ public String clientApi() {
AnimationData animationData=new AnimationData(); AnimationData animationData = new AnimationData();
List<BangumiItem> list=bangumiService.getAllBangumiItemList(); List<BangumiItem> list = bangumiService.getAllBangumiItemList();
for (BangumiItem item : list) { for (BangumiItem item : list) {
item.setCategories(animationData.nameToValue(item.getCategories(),false)+""); item.setCategories(animationData.nameToValue(item.getCategories(), false) + "");
item.setAuthor(animationData.nameToValue(item.getAuthor(),true)+""); item.setAuthor(animationData.nameToValue(item.getAuthor(), true) + "");
} }
JSONArray array= (JSONArray) JSON.toJSON(list); JSONArray array = (JSONArray) JSON.toJSON(list);
return array.toJSONString(); return array.toJSONString();
} }
@ResponseBody @ResponseBody
@RequestMapping(value = "/anim/getToDay.do", method = RequestMethod.GET) @RequestMapping(value = "/anim/getToDay.do", method = RequestMethod.GET)
public JSONObject getToDayAnim(){ public JSONObject getToDayAnim() {
return BangumiTools.getBangumi(0); return BangumiTools.getBangumi(0);
} }
} }