From d654190e3fa7e9aa4137b2f27d398cc0b015579f Mon Sep 17 00:00:00 2001
From: lenghui <h280650@163.com>
Date: Fri, 20 Dec 2024 23:53:13 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=83=A8=E5=88=86=E9=85=8D?=
 =?UTF-8?q?=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pom.xml                                                   |  2 +-
 src/main/java/com/lh/mapper/CrowdfundingMapper.java       |  2 ++
 src/main/java/com/lh/service/CrowdfundingServiceImpl.java | 11 ++++++++---
 src/main/resources/com/lh/mapper/CrowdfundingMapper.xml   |  3 +++
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 6d6c306..2954025 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,7 +43,7 @@
         <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
-            <version>5.1.49</version>
+            <version>8.0.26</version>
             <scope>runtime</scope>
         </dependency>
     </dependencies>
diff --git a/src/main/java/com/lh/mapper/CrowdfundingMapper.java b/src/main/java/com/lh/mapper/CrowdfundingMapper.java
index 31a3136..9f22d46 100644
--- a/src/main/java/com/lh/mapper/CrowdfundingMapper.java
+++ b/src/main/java/com/lh/mapper/CrowdfundingMapper.java
@@ -19,6 +19,8 @@ public interface CrowdfundingMapper {
     //当前众筹数量+1
     void updateNowNumber();
 
+    //当前众筹数量-1
+    void updateMinusNowNumber();
     //修改状态
     void updateStatus(Integer status);
 
diff --git a/src/main/java/com/lh/service/CrowdfundingServiceImpl.java b/src/main/java/com/lh/service/CrowdfundingServiceImpl.java
index 1916d36..1e4121b 100644
--- a/src/main/java/com/lh/service/CrowdfundingServiceImpl.java
+++ b/src/main/java/com/lh/service/CrowdfundingServiceImpl.java
@@ -15,12 +15,15 @@ public class CrowdfundingServiceImpl implements CrowdfundingService {
     @Autowired
     private CrowdfundingMapper crowdfundingMapper;
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public CrowdfundingInfo loadPage() {
-        CrowdfundingInfo crowdfundingInfoList = crowdfundingMapper.loadPage();
-        //如果当前进度大于等于目标人数,将status变更为0
-        if (crowdfundingInfoList != null && crowdfundingInfoList.getNowNumber() >= crowdfundingInfoList.getTargetNumber()) {
+        CrowdfundingInfo crowdfundingInfoList1 = crowdfundingMapper.loadPage();
+        if (crowdfundingInfoList1 != null && crowdfundingInfoList1.getNowNumber() >= crowdfundingInfoList1.getTargetNumber()) {
+            crowdfundingMapper.updateStatus(1);
+        }else {
             crowdfundingMapper.updateStatus(0);
         }
+        CrowdfundingInfo crowdfundingInfoList = crowdfundingMapper.loadPage();
         List<Participant> participants = crowdfundingMapper.queryCrowdUser(null);
         if (crowdfundingInfoList != null) {
             crowdfundingInfoList.setParticipantList(participants);
@@ -79,6 +82,7 @@ public class CrowdfundingServiceImpl implements CrowdfundingService {
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void deleteCrowdUser(String jwcode) throws MyException {
         if (CollectionUtils.isEmpty(crowdfundingMapper.queryCrowdUser(new Participant(null,jwcode,null,null)))) {
             throw new MyException("删除失败,用户不存在");
@@ -86,6 +90,7 @@ public class CrowdfundingServiceImpl implements CrowdfundingService {
         List<Participant> participants = crowdfundingMapper.queryCrowdUser(new Participant(null, jwcode, null, null));
         Participant participant = participants.get(0);
         crowdfundingMapper.saveDeleteCrowdUser(participant);
+        crowdfundingMapper.updateMinusNowNumber();
         crowdfundingMapper.deleteCrowdUser(jwcode);
     }
 
diff --git a/src/main/resources/com/lh/mapper/CrowdfundingMapper.xml b/src/main/resources/com/lh/mapper/CrowdfundingMapper.xml
index d78b394..98a62d2 100644
--- a/src/main/resources/com/lh/mapper/CrowdfundingMapper.xml
+++ b/src/main/resources/com/lh/mapper/CrowdfundingMapper.xml
@@ -19,6 +19,9 @@
     <update id="updateStatus">
         update crowdfundinginfo set status=#{status}
     </update>
+    <update id="updateMinusNowNumber">
+    update crowdfundinginfo set now_number=now_number-1
+    </update>
     <delete id="deleteCrowdUser">
         delete from participants where jwcode=#{jwcode}
     </delete>