| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package com.ylx.lottery.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.util.ObjectUtil;
- import cn.hutool.core.util.StrUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ylx.common.core.domain.model.WxLoginUser;
- import com.ylx.common.exception.ServiceException;
- import com.ylx.common.utils.SecurityUtils;
- import com.ylx.lottery.domain.LotteryCountLog;
- import com.ylx.lottery.domain.dto.IsLotteryDTO;
- import com.ylx.lottery.domain.vo.IsLotteryVO;
- import com.ylx.lottery.domain.vo.LotteryStatVO;
- import com.ylx.lottery.mapper.LotteryCountLogMapper;
- import com.ylx.lottery.service.LotteryCountLogService;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.Date;
- import java.util.List;
- import java.util.stream.Collectors;
- @Service
- public class LotteryCountLogServiceImpl extends ServiceImpl<LotteryCountLogMapper, LotteryCountLog> implements LotteryCountLogService {
- @Override
- public List<LotteryStatVO> selectSumByGroup(LambdaQueryWrapper<LotteryCountLog> queryWrapper) {
- return this.baseMapper.selectSumByGroup(queryWrapper);
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public IsLotteryVO isLottery(IsLotteryDTO dto) {
- IsLotteryVO vo = new IsLotteryVO();
- // 1. 获取当前登录用户
- WxLoginUser loginUser = SecurityUtils.getWxLoginUser();
- if (ObjectUtil.isNull(loginUser)) {
- throw new ServiceException("用户未登录或登录已过期");
- }
- String userId = loginUser.getId();
- if (StrUtil.isBlank(userId)) {
- throw new ServiceException("用户ID不合法");
- }
- // 2. 构建查询条件 (用于查找未弹窗的记录)
- LambdaQueryWrapper<LotteryCountLog> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(LotteryCountLog::getUserId, userId)
- .eq(LotteryCountLog::getIsLottery, 0) // 只查未弹窗的
- .eq(LotteryCountLog::getIsDelete, 0)
- .in(LotteryCountLog::getType, dto.getTypes());
- // 3.提取列表
- List<LotteryCountLog> lotteryCountLogs = this.baseMapper.selectList(queryWrapper);
- // 4. 设置返回结果
- if (CollUtil.isEmpty(lotteryCountLogs)) {
- vo.setIsLottery(0);
- return vo;
- }
- LotteryCountLog lotteryCountLog = CollUtil.getFirst(lotteryCountLogs);
- vo.setIsLottery(1);
- vo.setActivityId(lotteryCountLog.getLocalActivityTableId());
- vo.setActivityUrl(lotteryCountLog.getActivityUrl());
- // 5. 如果有记录,批量更新状态为“已弹窗”
- if (CollUtil.isNotEmpty(lotteryCountLogs)) {
- LambdaUpdateWrapper<LotteryCountLog> updateWrapper = new LambdaUpdateWrapper<>();
- updateWrapper.in(LotteryCountLog::getType, dto.getTypes())
- .eq(LotteryCountLog::getUserId, userId)
- .set(LotteryCountLog::getIsLottery, 1)
- .set(LotteryCountLog::getUpdateTime, new Date());
- this.update(updateWrapper);
- }
- return vo;
- }
- }
|