From 6fdbb36e6b32e95c30d9d7a4d88baeec426c777b Mon Sep 17 00:00:00 2001 From: User_cyk <1020691186@qq.com> Date: Sun, 24 Dec 2023 18:19:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=BD=91=E7=AB=99=E5=88=86?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UrlAndCateController.java | 34 +++++++++++++------ .../java/com/lovenav/dao/UrlCateListDao.java | 3 ++ src/main/java/com/lovenav/dao/UrlListDao.java | 2 +- .../lovenav/service/UrlCateListService.java | 5 +++ .../com/lovenav/service/UrlListService.java | 3 ++ .../serviceImpl/UrlCateListServiceImpl.java | 12 +++++++ .../serviceImpl/UrlLiserServiceImpl.java | 8 +++++ src/main/resources/mybatis/UrlCateListDao.xml | 13 +++++++ src/main/resources/mybatis/UrlListDao.xml | 8 +++++ 9 files changed, 77 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/lovenav/controller/UrlAndCateController.java b/src/main/java/com/lovenav/controller/UrlAndCateController.java index 05fd880..a360782 100644 --- a/src/main/java/com/lovenav/controller/UrlAndCateController.java +++ b/src/main/java/com/lovenav/controller/UrlAndCateController.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.lovenav.dao.UserDao; import com.lovenav.entity.UrlCateList; import com.lovenav.entity.UrlList; import com.lovenav.service.UrlCateListService; @@ -48,8 +49,8 @@ public class UrlAndCateController { @Autowired UrlListService urlListService; - - + @Autowired + UserDao userDao; //处理JSON @RequestMapping("/disposeJson") public String disposeJson(@RequestBody String data2 ,String email) @@ -605,18 +606,31 @@ public class UrlAndCateController { } @RequestMapping("/deleteCateByCateId") - public String deleteCateByCateId(String cateId) + public String deleteCateByCateId(Integer Id,String userId) { - int flag = 0; HashMap result = new HashMap<>(); - if(flag == 1) - { + Set parentList = new HashSet<>(); + parentList.add(Integer.valueOf(Id)); + + List stringList = urlCateListService.selectChildrenByCateId(Id); + + String childrenString= String.join(",", stringList); + String [] strings = childrenString.split(","); + Set set = new HashSet<>(Arrays.asList(strings)); + for(String child : set){ + if(child.equals("")) { + urlListService.deleteByCateId(Long.valueOf(Id)); + urlCateListService.deleteByPrimaryKey(Id); + }else{ + urlListService.deleteByCateId(Long.valueOf(child)); + urlCateListService.deleteByPrimaryKey(Integer.valueOf(child)); + } + + } + + urlCateListService.countCateContainUrlNumber(userDao.selectByPrimaryKey(Integer.valueOf(userId)).getUserEmail()); 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/dao/UrlCateListDao.java b/src/main/java/com/lovenav/dao/UrlCateListDao.java index b7746d9..b0321f8 100644 --- a/src/main/java/com/lovenav/dao/UrlCateListDao.java +++ b/src/main/java/com/lovenav/dao/UrlCateListDao.java @@ -31,4 +31,7 @@ public interface UrlCateListDao { public List selectUrListByUserId(Integer userId); public String selectUrListCateByUrlCateId(Integer cateId); + + public List selectChildrenByCateId(Integer id); + } \ No newline at end of file diff --git a/src/main/java/com/lovenav/dao/UrlListDao.java b/src/main/java/com/lovenav/dao/UrlListDao.java index 5de98cc..a5093aa 100644 --- a/src/main/java/com/lovenav/dao/UrlListDao.java +++ b/src/main/java/com/lovenav/dao/UrlListDao.java @@ -31,5 +31,5 @@ public interface UrlListDao { public List selectUrListByNeedLogin(); - + public int deleteByCateId(Long id); } \ No newline at end of file diff --git a/src/main/java/com/lovenav/service/UrlCateListService.java b/src/main/java/com/lovenav/service/UrlCateListService.java index 1c7c5da..8f43c2c 100644 --- a/src/main/java/com/lovenav/service/UrlCateListService.java +++ b/src/main/java/com/lovenav/service/UrlCateListService.java @@ -20,4 +20,9 @@ public interface UrlCateListService { public int insertSelective(UrlCateList urlCateList); public int updateByUrlCateList(UrlCateList urlCateList); + + public List selectChildrenByCateId(Integer id); + + public int deleteByPrimaryKey(Integer id); + } diff --git a/src/main/java/com/lovenav/service/UrlListService.java b/src/main/java/com/lovenav/service/UrlListService.java index dc3e9bf..987f649 100644 --- a/src/main/java/com/lovenav/service/UrlListService.java +++ b/src/main/java/com/lovenav/service/UrlListService.java @@ -15,4 +15,7 @@ public interface UrlListService { public List selectUrListByNeedLogin(); public int insertUrlByUser(UrlList urlList); + public int deleteByPrimaryKey(Long id); + + public int deleteByCateId(Long id); } diff --git a/src/main/java/com/lovenav/service/serviceImpl/UrlCateListServiceImpl.java b/src/main/java/com/lovenav/service/serviceImpl/UrlCateListServiceImpl.java index 7b256c6..ef01e2b 100644 --- a/src/main/java/com/lovenav/service/serviceImpl/UrlCateListServiceImpl.java +++ b/src/main/java/com/lovenav/service/serviceImpl/UrlCateListServiceImpl.java @@ -72,6 +72,14 @@ public class UrlCateListServiceImpl implements UrlCateListService { { return urlCateListDao.updateByPrimaryKeySelective(urlCateList); } + + public List selectChildrenByCateId(Integer id) + { + return urlCateListDao.selectChildrenByCateId(id); + } + + + public UrlCateList selectByPrimaryKey(Integer id) { return urlCateListDao.selectByPrimaryKey(id); @@ -145,4 +153,8 @@ public class UrlCateListServiceImpl implements UrlCateListService { } return jsonArray; } + + public int deleteByPrimaryKey(Integer id){ + return urlCateListDao.deleteByPrimaryKey(id); + } } diff --git a/src/main/java/com/lovenav/service/serviceImpl/UrlLiserServiceImpl.java b/src/main/java/com/lovenav/service/serviceImpl/UrlLiserServiceImpl.java index 5f3245e..7b1bf6a 100644 --- a/src/main/java/com/lovenav/service/serviceImpl/UrlLiserServiceImpl.java +++ b/src/main/java/com/lovenav/service/serviceImpl/UrlLiserServiceImpl.java @@ -79,4 +79,12 @@ public class UrlLiserServiceImpl implements UrlListService { } } + public int deleteByPrimaryKey(Long id){ + return urlListDao.deleteByPrimaryKey(id); + } + + public int deleteByCateId(Long id) + { + return urlListDao.deleteByCateId(id); + } } diff --git a/src/main/resources/mybatis/UrlCateListDao.xml b/src/main/resources/mybatis/UrlCateListDao.xml index 672a111..5bb1111 100644 --- a/src/main/resources/mybatis/UrlCateListDao.xml +++ b/src/main/resources/mybatis/UrlCateListDao.xml @@ -53,6 +53,19 @@ WHERE t3.isparent != '0' and t3.id =#{cateId ,jdbcType=INTEGER} + + + + delete from ln_url_cate_list diff --git a/src/main/resources/mybatis/UrlListDao.xml b/src/main/resources/mybatis/UrlListDao.xml index e8d6074..bc93167 100644 --- a/src/main/resources/mybatis/UrlListDao.xml +++ b/src/main/resources/mybatis/UrlListDao.xml @@ -64,6 +64,14 @@ delete from ln_url_list where id = #{id,jdbcType=BIGINT} + + + delete from ln_url_list + where cate_id = #{id,jdbcType=BIGINT} + + + + insert into ln_url_list (`name`, icon, cate_id, url, createtime, views,