| | |
| | | package com.ruoyi.goods.service.impl.lottery; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.core.utils.uuid.IdUtils; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.goods.api.domain.LotteryEvent; |
| | | import com.ruoyi.goods.api.domain.LotteryEventPrize; |
| | | import com.ruoyi.goods.api.domain.UserLotteryEvent; |
| | | import com.ruoyi.goods.api.domain.UserLotteryEventQuestions; |
| | | import com.ruoyi.goods.domain.vo.AppLotteryEventPageVo; |
| | | import com.ruoyi.goods.domain.vo.LotteryEventVo; |
| | | import com.ruoyi.goods.domain.vo.ShopLotteryDrawListVo; |
| | | import com.ruoyi.goods.domain.vo.UserLotteryEventVo; |
| | | import com.ruoyi.goods.api.domain.*; |
| | | import com.ruoyi.goods.domain.dto.MgtLotteryEventEditDTO; |
| | | import com.ruoyi.goods.domain.dto.MgtLotteryEventPageDto; |
| | | import com.ruoyi.goods.domain.dto.MgtLotteryEventQuestionDTO; |
| | | import com.ruoyi.goods.domain.vo.*; |
| | | import com.ruoyi.goods.mapper.lottery.LotteryEventMapper; |
| | | import com.ruoyi.goods.service.lottery.ILotteryEventPrizeService; |
| | | import com.ruoyi.goods.service.lottery.ILotteryEventService; |
| | | import com.ruoyi.goods.service.lottery.IUserLotteryEventQuestionsService; |
| | | import com.ruoyi.goods.service.lottery.IUserLotteryEventService; |
| | | import com.ruoyi.goods.service.lottery.*; |
| | | import com.ruoyi.system.api.domain.poji.member.Member; |
| | | import com.ruoyi.system.api.domain.poji.member.MemberGiftRecord; |
| | | import com.ruoyi.system.api.domain.poji.shop.Shop; |
| | |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | * @Date 2025/5/8 18:05 |
| | | */ |
| | | @Service |
| | | public class LotteryEventServiceImpl extends ServiceImpl<LotteryEventMapper, LotteryEvent> implements ILotteryEventService { |
| | | public class LotteryEventServiceImpl extends ServiceImpl<LotteryEventMapper, TLotteryEvent> implements ILotteryEventService { |
| | | |
| | | @Resource |
| | | private IUserLotteryEventService userLotteryEventService; |
| | |
| | | |
| | | @Resource |
| | | private RemoteShopService remoteShopService; |
| | | |
| | | |
| | | @Resource |
| | | private ILotteryEventQuestionsAnswersService lotteryEventQuestionsAnswersService; |
| | | |
| | | @Resource |
| | | private ILotteryEventQuestionsService lotteryEventQuestionsService; |
| | | |
| | | /** |
| | | * 根据id查询抽奖活动信息 |
| | |
| | | @Override |
| | | public LotteryEventVo getLotteryEvent(String id) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | LotteryEvent lotteryEvent = this.getById(id); |
| | | TLotteryEvent lotteryEvent = this.getById(id); |
| | | //构建返回结果 |
| | | LotteryEventVo vo = new LotteryEventVo(); |
| | | vo.setId(lotteryEvent.getId()); |
| | | vo.setName(lotteryEvent.getName()); |
| | | vo.setActivityProfile(lotteryEvent.getActivityProfile()); |
| | | List<UserLotteryEvent> userLotteryEvents = userLotteryEventService.list(new QueryWrapper<UserLotteryEvent>().eq("lottery_event_id", id)); |
| | | List<TUserLotteryEvent> userLotteryEvents = userLotteryEventService.list(new QueryWrapper<TUserLotteryEvent>().eq("lottery_event_id", id)); |
| | | vo.setLaveTimes(lotteryEvent.getTimes() - userLotteryEvents.size()); |
| | | //查询抽检活动奖品 |
| | | List<LotteryEventPrize> lotteryEventPrizeList = lotteryEventPrizeService.list(new QueryWrapper<LotteryEventPrize>().eq("lottery_event_id", id)); |
| | | List<TLotteryEventPrize> lotteryEventPrizeList = lotteryEventPrizeService.list(new QueryWrapper<TLotteryEventPrize>().eq("lottery_event_id", id)); |
| | | vo.setPrizeList(lotteryEventPrizeList); |
| | | //答题正确率 |
| | | if (5 == lotteryEvent.getActivityType()) { |
| | | UserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<UserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | if (null == questionsServiceOne) { |
| | | TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | if (null != questionsServiceOne) { |
| | | vo.setCorrectAnswerRate(questionsServiceOne.getCorrectAnswerRate()); |
| | | } |
| | | } |
| | |
| | | userLotteryEventVo.setName(s.getObjectName()); |
| | | userLotteryEventVo.setPrizeType(s.getPrizeType()); |
| | | userLotteryEventVo.setNumber(s.getNumber()); |
| | | MemberGiftRecord memberGiftRecord = remoteMemberService.getVerifyPrizeByGiftId(s.getId()).getData(); |
| | | userLotteryEventVo.setVerifyCode("3-" + memberGiftRecord.getPrizeId()); |
| | | userLotteryEventVo.setIsVerify(1 == memberGiftRecord.getVerifyStatus() ? 0 : 1); |
| | | userLotteryEventVo.setVerifyTime(null == memberGiftRecord.getVerifyTime() ? "" : sdf.format(memberGiftRecord.getVerifyTime())); |
| | | if (Arrays.asList(2, 3).contains(s.getPrizeType())) { |
| | | MemberGiftRecord memberGiftRecord = remoteMemberService.getVerifyPrizeByGiftId(s.getId()).getData(); |
| | | userLotteryEventVo.setVerifyCode("3-" + memberGiftRecord.getPrizeId()); |
| | | userLotteryEventVo.setIsVerify(1 == memberGiftRecord.getVerifyStatus() ? 0 : 1); |
| | | userLotteryEventVo.setVerifyTime(null == memberGiftRecord.getVerifyTime() ? "" : sdf.format(memberGiftRecord.getVerifyTime())); |
| | | } |
| | | Member member = remoteMemberService.getMember(userId).getData(); |
| | | userLotteryEventVo.setVerifyShop("全部门店"); |
| | | if (null != member && null != member.getRelationShopId()) { |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R lotteryDraw(String id) { |
| | | public R<TLotteryEventPrize> lotteryDraw(String id) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | Member member = remoteMemberService.getMember(userId).getData(); |
| | | LotteryEvent lotteryEvent = this.getById(id); |
| | | TLotteryEvent lotteryEvent = this.getById(id); |
| | | //判断答题抽奖是否满足抽奖条件 |
| | | if (lotteryEvent.getActivityType() == 5) { |
| | | UserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<UserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | if (questionsServiceOne.getCorrectAnswerRate().compareTo(lotteryEvent.getAccuracy()) < 0) { |
| | | return R.fail("答题抽奖失败,答题正确率低于活动要求"); |
| | | } |
| | |
| | | boolean tryLock = lock.tryLock(30, TimeUnit.SECONDS); |
| | | if (tryLock) { |
| | | //判断抽奖次数是否用完 |
| | | int count = userLotteryEventService.count(new QueryWrapper<UserLotteryEvent>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | int count = userLotteryEventService.count(new QueryWrapper<TUserLotteryEvent>().eq("lottery_event_id", id).eq("user_id", userId)); |
| | | if (lotteryEvent.getTimes() <= count) { |
| | | return R.fail("抽奖次数已用完"); |
| | | } |
| | | List<LotteryEventPrize> lotteryEventPrizeList = lotteryEventPrizeService.list(new QueryWrapper<LotteryEventPrize>().eq("lottery_event_id", id)); |
| | | List<TLotteryEventPrize> lotteryEventPrizeList = lotteryEventPrizeService.list(new QueryWrapper<TLotteryEventPrize>().eq("lottery_event_id", id)); |
| | | //开始抽奖,根据中奖概率来抽奖 |
| | | List<LotteryEventPrize> list = new ArrayList<>(); |
| | | for (LotteryEventPrize lotteryEventPrize : lotteryEventPrizeList) { |
| | | List<TLotteryEventPrize> list = new ArrayList<>(); |
| | | for (TLotteryEventPrize lotteryEventPrize : lotteryEventPrizeList) { |
| | | int winRate = lotteryEventPrize.getWinRate().intValue(); |
| | | for (int i = 0; i < winRate; i++) { |
| | | LotteryEventPrize event = new LotteryEventPrize(); |
| | | TLotteryEventPrize event = new TLotteryEventPrize(); |
| | | BeanUtil.copyProperties(lotteryEventPrize, event); |
| | | list.add(event); |
| | | } |
| | |
| | | Collections.shuffle(list); |
| | | //开始获取随机数 |
| | | int random = new Random().nextInt(list.size()); |
| | | LotteryEventPrize lotteryEventPrize = lotteryEventPrizeList.get(random); |
| | | TLotteryEventPrize lotteryEventPrize = list.get(random); |
| | | //添加中奖商品 |
| | | UserLotteryEvent userLotteryEvent = new UserLotteryEvent(); |
| | | TUserLotteryEvent userLotteryEvent = new TUserLotteryEvent(); |
| | | userLotteryEvent.setId(IdUtils.simpleUUID()); |
| | | userLotteryEvent.setUserId(userId); |
| | | userLotteryEvent.setLotteryEventId(id); |
| | |
| | | memberGiftRecord.setCreateTime(new Date()); |
| | | memberGiftRecord.setVerifyStatus(1); |
| | | remoteMemberService.saveMemberGiftRecord(memberGiftRecord); |
| | | return R.ok(); |
| | | return R.ok(lotteryEventPrize); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | public List<ShopLotteryDrawListVo> getShopLotteryDrawList(Page<ShopLotteryDrawListVo> page, Long shopId) { |
| | | return this.baseMapper.getShopLotteryDrawList(page, shopId); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public R editLotteryEvent(MgtLotteryEventEditDTO dto) { |
| | | //先检查开始-结束时间范围内,系统中是否有该活动 |
| | | List<TLotteryEvent> lotteryEvents = this.baseMapper.selectList(new LambdaQueryWrapper<TLotteryEvent>() |
| | | .eq(TLotteryEvent::getDelFlag, 0)//未删除的 |
| | | .eq(TLotteryEvent::getActivityType, dto.getActivityType())//类型相同的 |
| | | .between(TLotteryEvent::getStartTime, dto.getStartTime(), dto.getEndTime())//开始时间在这个活动的(开始-结束)范围内的 |
| | | .or() |
| | | .eq(TLotteryEvent::getDelFlag, 0)//未删除的 |
| | | .eq(TLotteryEvent::getActivityType, dto.getActivityType())//类型相同的 |
| | | .between(TLotteryEvent::getEndTime, dto.getStartTime(), dto.getEndTime())//结束时间在这个活动的(开始-结束)范围内的 |
| | | ); |
| | | if (null != lotteryEvents && !lotteryEvents.isEmpty()) { |
| | | // 新增记录时直接返回错误 |
| | | if (dto.getId() == null) { |
| | | return R.fail("新增抽奖活动与现有抽奖活动时间范围冲突"); |
| | | } |
| | | // 更新记录时,检查是否与其他记录(非自身)冲突 |
| | | boolean hasConflict = lotteryEvents.stream() |
| | | .anyMatch(event -> !event.getId().equals(dto.getId())); |
| | | if (hasConflict) { |
| | | return R.fail("编辑抽奖活动与现有其他活动时间范围冲突"); |
| | | } |
| | | } |
| | | TLotteryEvent lotteryEvent = new TLotteryEvent(); |
| | | if (null != dto.getId()) { |
| | | //编辑 |
| | | lotteryEvent=this.baseMapper.selectById(dto.getId()); |
| | | if (null == lotteryEvent || lotteryEvent.getDelFlag() != 0) { |
| | | return R.fail("该抽奖活动已被删除"); |
| | | } |
| | | if (!lotteryEvent.getActivityType().equals(dto.getActivityType())) { |
| | | return R.fail("编辑抽奖活动不能修改开启方式"); |
| | | } |
| | | if (!lotteryEvent.getName().equals(dto.getName())) { |
| | | return R.fail("编辑抽奖活动不能修改抽奖名称"); |
| | | } |
| | | //答题类型 |
| | | if (lotteryEvent.getActivityType().equals(5)) { |
| | | //将之前的题干数据、答案选项数据删除 |
| | | //先删除答案选项数据 |
| | | lotteryEventQuestionsAnswersService.remove(new LambdaQueryWrapper<TLotteryEventQuestionsAnswers>() |
| | | .eq(TLotteryEventQuestionsAnswers::getLotteryEventId, lotteryEvent.getId())); |
| | | //再删除题干数据 |
| | | lotteryEventQuestionsService.remove(new LambdaQueryWrapper<TLotteryEventQuestions>() |
| | | .eq(TLotteryEventQuestions::getLotteryEventId, lotteryEvent.getId())); |
| | | } |
| | | //奖品数据删除 |
| | | /*lotteryEventPrizeService.remove(new LambdaQueryWrapper<TLotteryEventPrize>() |
| | | .eq(TLotteryEventPrize::getLotteryEventId,lotteryEvent.getId()));*/ |
| | | lotteryEventPrizeService.deleteByLotteryEventId(lotteryEvent.getId()); |
| | | } |
| | | //新增 |
| | | BeanUtils.copyProperties(dto, lotteryEvent); |
| | | lotteryEvent.setDelFlag(0); |
| | | if (dto.getId() == null) { |
| | | lotteryEvent.setId(IdUtils.simpleUUID()); |
| | | lotteryEvent.setCreateTime(LocalDateTime.now()); |
| | | lotteryEvent.setCreateUserId(dto.getUserId()); |
| | | } else { |
| | | lotteryEvent.setUpdateTime(LocalDateTime.now()); |
| | | lotteryEvent.setUpdateUserId(dto.getUserId()); |
| | | } |
| | | //保存抽奖活动 |
| | | this.saveOrUpdate(lotteryEvent); |
| | | // 保存奖品数据 |
| | | TLotteryEvent finalLotteryEvent = lotteryEvent;//jdk8及之后 变量在初始化后确实没有被重新赋值,可直接引用,无需显式声明为 final |
| | | List<TLotteryEventPrize> prizeList = dto.getMgtLotteryEventPrizeDTOList().stream() |
| | | .map(prizeDTO -> { |
| | | TLotteryEventPrize prize = new TLotteryEventPrize(); |
| | | prize.setId(IdUtils.simpleUUID()); |
| | | prize.setLotteryEventId(finalLotteryEvent.getId()); |
| | | prize.setPrizeType(prizeDTO.getPrizeType()); |
| | | if (null != prizeDTO.getObjectId()) { |
| | | prize.setObjectId(prizeDTO.getObjectId()); |
| | | } |
| | | prize.setObjectName(prizeDTO.getObjectName()); |
| | | prize.setNumber(prizeDTO.getNumber()); |
| | | prize.setWinRate(prizeDTO.getWinRate()); |
| | | return prize; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | // lotteryEventPrizeService.saveBatch(prizeList); |
| | | lotteryEventPrizeService.savePrizeList(prizeList); |
| | | if (dto.getActivityType().equals(5)) { |
| | | //保存题干数据 |
| | | for (MgtLotteryEventQuestionDTO questionDTO : dto.getMgtLotteryQuestionDTOList()) { |
| | | TLotteryEventQuestions question = new TLotteryEventQuestions(); |
| | | question.setId(IdUtils.simpleUUID()); |
| | | question.setLotteryEventId(finalLotteryEvent.getId()); |
| | | question.setName(questionDTO.getName()); |
| | | question.setSort(questionDTO.getSort()); |
| | | lotteryEventQuestionsService.save(question); |
| | | //保存答案选项数据 |
| | | List<TLotteryEventQuestionsAnswers> answersList = questionDTO.getAnswersDTOList().stream() |
| | | .map(answersDTO -> { |
| | | TLotteryEventQuestionsAnswers answer = new TLotteryEventQuestionsAnswers(); |
| | | answer.setId(IdUtils.simpleUUID()); |
| | | answer.setLotteryEventId(finalLotteryEvent.getId()); |
| | | answer.setLotteryEventQuestionsId(question.getId()); |
| | | answer.setAnswers(answersDTO.getAnswers()); |
| | | answer.setIsRight(answersDTO.getIsRight()); |
| | | return answer; |
| | | }).collect(Collectors.toList()); |
| | | lotteryEventQuestionsAnswersService.saveBatch(answersList); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public Page<MgtLotteryEventPageVo> pageMgtLotteryEvent( MgtLotteryEventPageDto dto) { |
| | | Map<Long,Shop> map; |
| | | List<Shop> shopList; |
| | | Page<MgtLotteryEventPageVo> page = new Page<>(); |
| | | page.setSize(dto.getPageSize()); |
| | | page.setCurrent(dto.getPageNum()); |
| | | page.setOptimizeCountSql(false); |
| | | |
| | | if (dto.getCreateObject()!=null){ |
| | | //根据 条件-创建对象 模糊查找门店集合 |
| | | shopList=remoteShopService.getShopListByShopName(dto.getCreateObject()); |
| | | if (null != shopList && !shopList.isEmpty()) { |
| | | List<Long> shopIds = shopList.stream().map(Shop::getShopId).collect(Collectors.toList()); |
| | | dto.setShopIds(shopIds); |
| | | //转为map 方便后续取商户名称 |
| | | map = shopList.stream().collect(Collectors.toMap(Shop::getShopId, shop -> shop)); |
| | | } else { |
| | | map = new HashMap<>(); |
| | | } |
| | | //判断“平台创建”是否包含了 条件-创建对象 |
| | | if (!"平台创建".contains(dto.getCreateObject())){ |
| | | dto.setFlag(0);//未包含,只查找门店ids |
| | | } |
| | | } else { |
| | | map = new HashMap<>(); |
| | | } |
| | | //获取分页数据 |
| | | Long total=this.baseMapper.pageMgtLotteryEventCount( dto); |
| | | page.setTotal(total); |
| | | page.setCurrent(dto.getPageNum()); |
| | | page.setPages(total/dto.getPageSize()); |
| | | //获取分页信息 |
| | | dto.setOffset((dto.getPageNum() - 1) * dto.getPageSize()); |
| | | List<MgtLotteryEventPageVo> voList = this.baseMapper.pageMgtLotteryEvent(dto); |
| | | //填充创建对象 |
| | | voList.forEach(x->{ |
| | | if (null == x.getShopId()){ |
| | | x.setCreateObject("平台创建"); |
| | | }else { |
| | | //线下抽奖,获取门店名称 |
| | | if(map.containsKey(Long.valueOf(x.getShopId()))){ |
| | | x.setCreateObject(map.get(Long.valueOf(x.getShopId())).getShopName()); |
| | | }else { |
| | | Shop shop = remoteShopService.getShop(Long.valueOf(x.getShopId())).getData(); |
| | | if (null != shop){ |
| | | x.setCreateObject(shop.getShopName()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | }); |
| | | page.setRecords(voList); |
| | | return page; |
| | | } |
| | | |
| | | @Override |
| | | public R<MgtLotteryEventDetailVO> getLotteryEventDetailById(String id) { |
| | | TLotteryEvent lotteryEvent = this.getById(id); |
| | | if (null == lotteryEvent) { |
| | | return R.fail("该抽奖活动不存在"); |
| | | } |
| | | MgtLotteryEventDetailVO vo = new MgtLotteryEventDetailVO(); |
| | | BeanUtils.copyProperties(lotteryEvent, vo); |
| | | if (lotteryEvent.getActivityType()==6) { |
| | | //线下抽奖 取商户名称 |
| | | Shop data = remoteShopService.getShop(Long.valueOf(lotteryEvent.getShopId())).getData(); |
| | | if (null != data) { |
| | | vo.setShopName(data.getShopName()); |
| | | } |
| | | } |
| | | if(lotteryEvent.getActivityType()==5){ |
| | | //题干数据 |
| | | List<TLotteryEventQuestions> questionsList = lotteryEventQuestionsService.getBaseMapper().selectList(new LambdaQueryWrapper<TLotteryEventQuestions>().eq(TLotteryEventQuestions::getLotteryEventId, lotteryEvent.getId())); |
| | | |
| | | List<MgtLotteryEventQuestionVO> questionsVOList = questionsList.stream().map(question -> { |
| | | MgtLotteryEventQuestionVO questionVO = new MgtLotteryEventQuestionVO(); |
| | | BeanUtils.copyProperties(question, questionVO); |
| | | //答案选项数据 |
| | | List<TLotteryEventQuestionsAnswers> answersList = lotteryEventQuestionsAnswersService.getBaseMapper().selectList(new LambdaQueryWrapper<TLotteryEventQuestionsAnswers>() |
| | | .eq(TLotteryEventQuestionsAnswers::getLotteryEventId, lotteryEvent.getId()) |
| | | .eq(TLotteryEventQuestionsAnswers::getLotteryEventQuestionsId, questionVO.getId())); |
| | | questionVO.setAnswersVOList(answersList); |
| | | return questionVO; |
| | | }).collect(Collectors.toList()); |
| | | //题干数据排序 |
| | | // 自定义 Comparator 实现 |
| | | Comparator<TLotteryEventQuestions> sortComparator = new Comparator<TLotteryEventQuestions>() { |
| | | @Override |
| | | public int compare(TLotteryEventQuestions q1, TLotteryEventQuestions q2) { |
| | | return Integer.compare(q1.getSort(), q2.getSort()); |
| | | } |
| | | }; |
| | | // 应用排序 |
| | | Collections.sort(questionsList, sortComparator); |
| | | vo.setMgtLotteryQuestionVOList(questionsVOList); |
| | | } |
| | | //奖项信息 |
| | | /*List<TLotteryEventPrize> prizeList = lotteryEventPrizeService.getBaseMapper().selectList(new LambdaQueryWrapper<TLotteryEventPrize>() |
| | | .eq(TLotteryEventPrize::getLotteryEventId, lotteryEvent.getId()));*/ |
| | | List<TLotteryEventPrize> prizeList = lotteryEventPrizeService.getPrizeListByLotteryEventId(lotteryEvent.getId()); |
| | | vo.setLotteryEventPrizeList(prizeList); |
| | | |
| | | return R.ok(vo); |
| | | } |
| | | |
| | | @Override |
| | | public R deleteMgtLotteryEvent(String id) { |
| | | TLotteryEvent lotteryEvent = this.getById(id); |
| | | if (null == lotteryEvent || lotteryEvent.getDelFlag()!=0) { |
| | | return R.ok(); |
| | | } |
| | | |
| | | //1.奖品数据删除 |
| | | /* lotteryEventPrizeService.remove(new LambdaQueryWrapper<TLotteryEventPrize>() |
| | | .eq(TLotteryEventPrize::getLotteryEventId,lotteryEvent.getId()));*/ |
| | | |
| | | lotteryEventPrizeService.deleteByLotteryEventId(lotteryEvent.getId()); |
| | | //2.答题类型 |
| | | if (lotteryEvent.getActivityType().equals(5)) { |
| | | //先删除答案选项数据 |
| | | lotteryEventQuestionsAnswersService.remove(new LambdaQueryWrapper<TLotteryEventQuestionsAnswers>() |
| | | .eq(TLotteryEventQuestionsAnswers::getLotteryEventId, lotteryEvent.getId())); |
| | | //再删除题干数据 |
| | | lotteryEventQuestionsService.remove(new LambdaQueryWrapper<TLotteryEventQuestions>() |
| | | .eq(TLotteryEventQuestions::getLotteryEventId, lotteryEvent.getId())); |
| | | } |
| | | //3.抽奖活动删除 |
| | | lotteryEvent.setDelFlag(1); |
| | | this.updateById(lotteryEvent); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public R endImmediatelyLotteryEvent(String id) { |
| | | TLotteryEvent lotteryEvent = this.getById(id); |
| | | if (null == lotteryEvent || lotteryEvent.getDelFlag()!=0) { |
| | | return R.fail("该抽奖活动不存在"); |
| | | } |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | if (now.isBefore(lotteryEvent.getStartTime()) && now.isAfter(lotteryEvent.getEndTime())) { |
| | | return R.fail("该抽奖活动不在活动时间范围内"); |
| | | } |
| | | lotteryEvent.setEndTime(now);//将结束时间设置为当前时间 |
| | | lotteryEvent.setUpdateUserId(SecurityUtils.getUserId()); |
| | | lotteryEvent.setUpdateTime(now); |
| | | this.updateById(lotteryEvent); |
| | | return R.ok(); |
| | | } |
| | | } |