From 1a902ca4a6074d8e8addf1019833e76b946f2300 Mon Sep 17 00:00:00 2001 From: User_cyk <1020691186@qq.com> Date: Wed, 5 Jul 2023 17:49:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=80project=E4=B8=AD=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/hellogithub/dao/projectDao.java | 29 +++++++++++++++++++ .../hellogithub/service/supportService.java | 8 +++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/com/hellogithub/dao/projectDao.java b/src/com/hellogithub/dao/projectDao.java index d5c3380..8b57b38 100644 --- a/src/com/hellogithub/dao/projectDao.java +++ b/src/com/hellogithub/dao/projectDao.java @@ -236,4 +236,33 @@ public class projectDao { } return projectEntityList; } + public int addStarNum(int proId) + { + int num ; + try { + Connection conn = JdbcUtils.getConnection(); + QueryRunner runner = new QueryRunner(); + String sql = "update project set starNum = starNum + 1 where isValid = 1 and projectId= ?"; + num = runner.update(conn, sql,proId); + conn.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + return num; + } + + public int cancelStarNum(int proId) + { + int num ; + try { + Connection conn = JdbcUtils.getConnection(); + QueryRunner runner = new QueryRunner(); + String sql = "update project set starNum = starNum - 1 where isValid = 1 and projectId= ?"; + num = runner.update(conn, sql,proId); + conn.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + return num; + } } diff --git a/src/com/hellogithub/service/supportService.java b/src/com/hellogithub/service/supportService.java index 40b8f9d..d4d887b 100644 --- a/src/com/hellogithub/service/supportService.java +++ b/src/com/hellogithub/service/supportService.java @@ -1,12 +1,14 @@ package com.hellogithub.service; import com.hellogithub.dao.UserDao; +import com.hellogithub.dao.projectDao; import com.hellogithub.dao.supportDao; import com.hellogithub.entity.supportEntity; public class supportService { private supportDao supportDao = new supportDao(); private UserDao userDao = new UserDao(); + private projectDao projectDao = new projectDao(); public int retNum(String username,int projectId){ int num ; supportEntity supportEntity = supportDao.selectSupport(userDao.selectIdByName(username),projectId); @@ -24,7 +26,8 @@ public class supportService { { String tip; int num = supportDao.insertSupport(userDao.selectIdByName(username),projectId); - if(num == 1) + int numm = projectDao.addStarNum(projectId); + if(num == 1 & numm == 1) { tip="点赞成功"; } @@ -38,7 +41,8 @@ public class supportService { { String tip; int num = supportDao.deleteSupport(userDao.selectIdByName(username),projectId); - if(num == 1) + int numm = projectDao.cancelStarNum(projectId); + if(num == 1 & numm == 1) { tip="取消成功"; }