From cf3970d0ab25d448d8bb3a6c52753584502ed549 Mon Sep 17 00:00:00 2001 From: lenghui Date: Fri, 20 Dec 2024 18:55:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lh/mapper/CrowdfundingMapper.java | 3 +++ src/main/java/com/lh/service/CrowdfundingServiceImpl.java | 14 +++++++++++++- src/main/resources/com/lh/mapper/CrowdfundingMapper.xml | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/lh/mapper/CrowdfundingMapper.java b/src/main/java/com/lh/mapper/CrowdfundingMapper.java index 202634f..31a3136 100644 --- a/src/main/java/com/lh/mapper/CrowdfundingMapper.java +++ b/src/main/java/com/lh/mapper/CrowdfundingMapper.java @@ -19,6 +19,9 @@ public interface CrowdfundingMapper { //当前众筹数量+1 void updateNowNumber(); + //修改状态 + void updateStatus(Integer status); + //添加众筹用户 void addCrowdUser(Participant participant); diff --git a/src/main/java/com/lh/service/CrowdfundingServiceImpl.java b/src/main/java/com/lh/service/CrowdfundingServiceImpl.java index f1f0977..433b657 100644 --- a/src/main/java/com/lh/service/CrowdfundingServiceImpl.java +++ b/src/main/java/com/lh/service/CrowdfundingServiceImpl.java @@ -7,6 +7,7 @@ import com.lh.mapper.CrowdfundingMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import java.util.List; @Service @@ -16,6 +17,10 @@ public class CrowdfundingServiceImpl implements CrowdfundingService { @Override public CrowdfundingInfo loadPage() { CrowdfundingInfo crowdfundingInfoList = crowdfundingMapper.loadPage(); + //如果当前进度大于等于目标人数,将status变更为0 + if (crowdfundingInfoList.getNowNumber() >= crowdfundingInfoList.getTargetNumber()) { + crowdfundingMapper.updateStatus(0); + } List participants = crowdfundingMapper.queryCrowdUser(null); crowdfundingInfoList.setParticipantList(participants); return crowdfundingInfoList; @@ -26,6 +31,9 @@ public class CrowdfundingServiceImpl implements CrowdfundingService { if (title.length() == 0) { throw new MyException("标题不能为空"); } + if (title.length() > 25) { + throw new MyException("标题不能超过25个字"); + } crowdfundingMapper.updateTitle(title); } @@ -48,6 +56,10 @@ public class CrowdfundingServiceImpl implements CrowdfundingService { @Override @Transactional(rollbackFor = Exception.class) public void addCrowdUser(Participant participant) throws MyException { + //当前人数等于目标人数不可继续添加 + if (crowdfundingMapper.loadPage().getNowNumber() >= crowdfundingMapper.loadPage().getTargetNumber()) { + throw new MyException("当前人数已达到目标人数,不可继续添加"); + } //精网号重复 if (!crowdfundingMapper.queryCrowdUser(participant).isEmpty()) { throw new MyException("精网号重复"); @@ -66,7 +78,7 @@ public class CrowdfundingServiceImpl implements CrowdfundingService { @Override public void deleteCrowdUser(String jwcode) throws MyException { - if (crowdfundingMapper.queryCrowdUser(new Participant(null,jwcode,null,null)) == null) { + if (CollectionUtils.isEmpty(crowdfundingMapper.queryCrowdUser(new Participant(null,jwcode,null,null)))) { throw new MyException("删除失败,用户不存在"); } List participants = crowdfundingMapper.queryCrowdUser(new Participant(null, jwcode, null, null)); diff --git a/src/main/resources/com/lh/mapper/CrowdfundingMapper.xml b/src/main/resources/com/lh/mapper/CrowdfundingMapper.xml index 7fbcf8c..d78b394 100644 --- a/src/main/resources/com/lh/mapper/CrowdfundingMapper.xml +++ b/src/main/resources/com/lh/mapper/CrowdfundingMapper.xml @@ -16,6 +16,9 @@ update crowdfundinginfo set now_number=now_number+1 + + update crowdfundinginfo set status=#{status} + delete from participants where jwcode=#{jwcode}