diff --git a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java index 7b22f81..5adde7f 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java @@ -32,6 +32,7 @@ import exception.BizException; import java.io.IOException; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; import javax.persistence.criteria.CriteriaBuilder; @@ -194,6 +195,7 @@ public class LotteryService { */ @Transactional(rollbackFor = Exception.class) public void edit(Lottery lottery, String token) { + String id = lottery.getId(); if (lottery.getDrawTime().isBefore(lottery.getApplyEndTime())) { throw new BizException(ErrorConstants.DRAW_TIME_CANNOT_BE_BEFORE_APPLY_END_TIME); @@ -208,12 +210,12 @@ public class LotteryService { UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); - if (lottery.getStatus() != null && !Objects.equals(lottery.getStatus(), PointEnums.LOTTERY_STATUS_EDITING.getCode())) { + List canEditStatusList = Arrays.asList(PointEnums.LOTTERY_STATUS_EDITING.getCode(), PointEnums.LOTTERY_STATUS_SIGN.getCode()); + Lottery oldLottery = lotteryDao.getOne(id); + if (oldLottery.getStatus() != null && !canEditStatusList.contains(oldLottery.getStatus())) { throw new BizException(ErrorConstants.CAN_NOT_EDIT); } - String id = lottery.getId(); - StringBuilder regionCode = new StringBuilder(); StringBuilder regionName = new StringBuilder(); @@ -258,12 +260,6 @@ public class LotteryService { } } - Lottery oldLottery = lotteryDao.getOne(id); - if (!Objects.equals(PointEnums.LOTTERY_STATUS_EDITING.getCode(), oldLottery.getStatus())) { - // 不是编辑中,不允许修改 - throw new BizException(ErrorConstants.CAN_NOT_EDIT); - } - lottery.setCreateTime(oldLottery.getCreateTime()); lottery.setCreateUser(oldLottery.getCreateUser()); lottery.setCreateUserName(oldLottery.getCreateUserName()); @@ -273,7 +269,20 @@ public class LotteryService { lottery.setCode(oldLottery.getCode()); lottery.setType(oldLottery.getType()); - lotteryDao.save(lottery); + if (Objects.equals(oldLottery.getStatus(), PointEnums.LOTTERY_STATUS_SIGN.getCode())) { + // 报名中只允许修改 title,description,num,drawTime + Lottery result = new Lottery(); + BeanUtils.copyProperties(oldLottery, result); + result.setTitle(lottery.getTitle()); + result.setDescription(lottery.getDescription()); + result.setDrawTime(lottery.getDrawTime()); + + lotteryDao.save(result); + } else { + lottery.setStatus(PointEnums.LOTTERY_STATUS_EDITING.getCode()); + lotteryDao.save(lottery); + } + }