Browse Source

修bug

lh_java
lenghui 5 months ago
parent
commit
cf3970d0ab
  1. 3
      src/main/java/com/lh/mapper/CrowdfundingMapper.java
  2. 14
      src/main/java/com/lh/service/CrowdfundingServiceImpl.java
  3. 3
      src/main/resources/com/lh/mapper/CrowdfundingMapper.xml

3
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);

14
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<Participant> 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<Participant> participants = crowdfundingMapper.queryCrowdUser(new Participant(null, jwcode, null, null));

3
src/main/resources/com/lh/mapper/CrowdfundingMapper.xml

@ -16,6 +16,9 @@
<update id="updateNowNumber">
update crowdfundinginfo set now_number=now_number+1
</update>
<update id="updateStatus">
update crowdfundinginfo set status=#{status}
</update>
<delete id="deleteCrowdUser">
delete from participants where jwcode=#{jwcode}
</delete>

Loading…
Cancel
Save