diff --git a/src/main/java/com/lovenav/controller/UrlAndCateController.java b/src/main/java/com/lovenav/controller/UrlAndCateController.java index 1bc50c2..0c4e1eb 100644 --- a/src/main/java/com/lovenav/controller/UrlAndCateController.java +++ b/src/main/java/com/lovenav/controller/UrlAndCateController.java @@ -584,7 +584,7 @@ public class UrlAndCateController { } @RequestMapping("/insertCateByUser") - public String disposeBookmarkToJsonByUserId(UrlCateList urlCateList) + public String insertCateByUser(UrlCateList urlCateList) { int flag = 0; Date date = new Date(); diff --git a/src/main/java/com/lovenav/controller/UrlListController.java b/src/main/java/com/lovenav/controller/UrlListController.java index 601f5e3..3124c38 100644 --- a/src/main/java/com/lovenav/controller/UrlListController.java +++ b/src/main/java/com/lovenav/controller/UrlListController.java @@ -1,15 +1,25 @@ package com.lovenav.controller; +import com.alibaba.fastjson2.JSONObject; +import com.lovenav.entity.UrlCateList; import com.lovenav.entity.UrlList; +import com.lovenav.service.UrlCateListService; import com.lovenav.service.UrlListService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + @RestController public class UrlListController { @Autowired UrlListService urlListService; + @Autowired + UrlCateListService urlCateListService; //后台修改网站状态 @RequestMapping("/admin/weblist/alterUrlStatus") public String setUrlStatus(UrlList urlList){ @@ -20,4 +30,75 @@ public class UrlListController { return "修改失败"; } } + @RequestMapping("/admin/weblist/deleteUrl") + public String deleteUrl(String urlId) + { + int flag = 0; + HashMap result = new HashMap<>(); + UrlList urlList = urlListService.selectUrlListByUrlId(Long.valueOf(urlId)); + String parentString = urlCateListService.selectUrListCateByUrlCateId(urlList.getCateId()); + String [] parentList = parentString.split(","); + System.out.println(parentString); + for(String parent : parentList) + { + if(parent.equals("0")){ + continue; + } + UrlCateList urlCateList =urlCateListService.selectByPrimaryKey(Integer.valueOf(parent)); + if(urlCateListService.updateByUrlCateList(urlCateList) == 0) + { + flag = 0; + }else{ + flag = 1; + } + } + if(flag == 1) + { + result.put("code", 200); + result.put("msg", "处理成功"); + }else{ + result.put("code", 500); + result.put("msg", "处理失败"); + } + + return JSONObject.toJSONString(result); + } + @RequestMapping("/admin/weblist/insertUrlByUser") + public String insertUrlByUser(UrlList urlList) + { + int flag = 0; + Date date = new Date(); + urlList.setCreatetime(date.getTime()); + urlList.setViews(Long.valueOf(0)); + urlList.setNeedLogin(Byte.valueOf(flag+"")); + HashMap result = new HashMap<>(); + flag = urlListService.insertUrlByUser(urlList); + String parentString = urlCateListService.selectUrListCateByUrlCateId(urlList.getCateId()); + String [] parentList = parentString.split(","); + System.out.println(parentString); + for(String parent : parentList) + { + if(parent.equals("0")){ + continue; + } + UrlCateList urlCateList =urlCateListService.selectByPrimaryKey(Integer.valueOf(parent)); + if(urlCateListService.updateByUrlCateList(urlCateList) == 0) + { + flag = 0; + }else{ + flag = 1; + } + } + if(flag == 1) + { + result.put("code", 200); + result.put("msg", "处理成功"); + + }else{ + result.put("code", 500); + result.put("msg", "处理失败"); + + } + return JSONObject.toJSONString(result); + } } diff --git a/src/main/java/com/lovenav/service/UrlCateListService.java b/src/main/java/com/lovenav/service/UrlCateListService.java index 1060c4a..1c7c5da 100644 --- a/src/main/java/com/lovenav/service/UrlCateListService.java +++ b/src/main/java/com/lovenav/service/UrlCateListService.java @@ -18,5 +18,6 @@ public interface UrlCateListService { public UrlCateList selectByPrimaryKey(Integer id); public int insertSelective(UrlCateList urlCateList); + public int updateByUrlCateList(UrlCateList urlCateList); } diff --git a/src/main/java/com/lovenav/service/UrlListService.java b/src/main/java/com/lovenav/service/UrlListService.java index 821cfa5..dc3e9bf 100644 --- a/src/main/java/com/lovenav/service/UrlListService.java +++ b/src/main/java/com/lovenav/service/UrlListService.java @@ -14,4 +14,5 @@ public interface UrlListService { public int updateUrlStatusListById(UrlList urlList); public List selectUrListByNeedLogin(); + public int insertUrlByUser(UrlList urlList); } diff --git a/src/main/java/com/lovenav/service/serviceImpl/UrlCateListServiceImpl.java b/src/main/java/com/lovenav/service/serviceImpl/UrlCateListServiceImpl.java index 79742d2..7b256c6 100644 --- a/src/main/java/com/lovenav/service/serviceImpl/UrlCateListServiceImpl.java +++ b/src/main/java/com/lovenav/service/serviceImpl/UrlCateListServiceImpl.java @@ -67,6 +67,11 @@ public class UrlCateListServiceImpl implements UrlCateListService { { return urlCateListDao.insertSelective(urlCateList); } + + public int updateByUrlCateList(UrlCateList urlCateList) + { + return urlCateListDao.updateByPrimaryKeySelective(urlCateList); + } public UrlCateList selectByPrimaryKey(Integer id) { return urlCateListDao.selectByPrimaryKey(id); diff --git a/src/main/java/com/lovenav/service/serviceImpl/UrlLiserServiceImpl.java b/src/main/java/com/lovenav/service/serviceImpl/UrlLiserServiceImpl.java index 5cc230e..5f3245e 100644 --- a/src/main/java/com/lovenav/service/serviceImpl/UrlLiserServiceImpl.java +++ b/src/main/java/com/lovenav/service/serviceImpl/UrlLiserServiceImpl.java @@ -56,7 +56,7 @@ public class UrlLiserServiceImpl implements UrlListService { return urlListDao.selectUrListByNeedLogin(); } - + public int insertUrlByUser(UrlList urlList){return urlListDao.insertSelective(urlList);} public UrlList selectUrListByInput(String input) {