|
@ -1,24 +1,21 @@ |
|
|
package com.lottery.admin.service.Impl; |
|
|
package com.lottery.admin.service.Impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.annotation.TableId; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.lottery.admin.mapper.AdminGradeMapper; |
|
|
|
|
|
import com.lottery.admin.mapper.AdminPrizeMapper; |
|
|
|
|
|
import com.lottery.admin.mapper.AdminUserDetailMapper; |
|
|
|
|
|
import com.lottery.admin.mapper.AdminUserMapper; |
|
|
|
|
|
|
|
|
import com.lottery.admin.mapper.*; |
|
|
import com.lottery.admin.service.AdminPrizeService; |
|
|
import com.lottery.admin.service.AdminPrizeService; |
|
|
import com.lottery.dto.PrizeDto; |
|
|
import com.lottery.dto.PrizeDto; |
|
|
import com.lottery.dto.FixUserDto; |
|
|
import com.lottery.dto.FixUserDto; |
|
|
import com.lottery.entity.Grade; |
|
|
|
|
|
import com.lottery.entity.Prize; |
|
|
|
|
|
import com.lottery.entity.User; |
|
|
|
|
|
import com.lottery.entity.UserDetail; |
|
|
|
|
|
|
|
|
import com.lottery.entity.*; |
|
|
import com.lottery.utils.ConvertBeanUtil; |
|
|
import com.lottery.utils.ConvertBeanUtil; |
|
|
import com.lottery.vo.PageInfo; |
|
|
import com.lottery.vo.PageInfo; |
|
|
import com.lottery.vo.PrizeVo; |
|
|
import com.lottery.vo.PrizeVo; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
import java.util.Date; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
@ -45,6 +42,8 @@ public class AdminPrizeServiceImpl extends ServiceImpl<AdminPrizeMapper, Prize> |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private AdminUserMapper adminUserMapper; |
|
|
private AdminUserMapper adminUserMapper; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private AdminWinMapper adminWinMapper; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public PageInfo<PrizeVo> pageListPrize(int pageNum, int pageSize) { |
|
|
public PageInfo<PrizeVo> pageListPrize(int pageNum, int pageSize) { |
|
@ -60,20 +59,36 @@ public class AdminPrizeServiceImpl extends ServiceImpl<AdminPrizeMapper, Prize> |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean add(PrizeDto prizeDto) { |
|
|
public boolean add(PrizeDto prizeDto) { |
|
|
Long gradeId = prizeDto.getGradeId(); |
|
|
|
|
|
Grade grade = adminGradeMapper.selectById(gradeId); |
|
|
|
|
|
|
|
|
// Long gradeId = prizeDto.getGradeId(); |
|
|
|
|
|
// Grade grade = adminGradeMapper.selectById(gradeId); |
|
|
// if (grade == null) { |
|
|
// if (grade == null) { |
|
|
//// return Result.failure("等级不存在"); |
|
|
//// return Result.failure("等级不存在"); |
|
|
// throw new SomeException("heheh"); |
|
|
// throw new SomeException("heheh"); |
|
|
// } |
|
|
// } |
|
|
|
|
|
|
|
|
// 3. 检查该等级是否已有奖品 |
|
|
// 3. 检查该等级是否已有奖品 |
|
|
LambdaQueryWrapper<Prize> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
wrapper.eq(Prize::getGradeId, grade.getId()); |
|
|
|
|
|
if (this.count(wrapper) > 0) { |
|
|
|
|
|
// return Result.failure("该等级已存在奖品,不能重复添加"); |
|
|
|
|
|
// throw new SomeException("heheh"); |
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// LambdaQueryWrapper<Prize> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
// wrapper.eq(Prize::getGradeId, grade.getId()); |
|
|
|
|
|
// if (this.count(wrapper) > 0) { |
|
|
|
|
|
//// return Result.failure("该等级已存在奖品,不能重复添加"); |
|
|
|
|
|
//// throw new SomeException("heheh"); |
|
|
|
|
|
// return false; |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// 1. 查询关联的等级(grade)状态 |
|
|
|
|
|
Grade grade = adminGradeMapper.selectById(prizeDto.getGradeId()); // 假设 gradeId 是传入的等级ID |
|
|
|
|
|
if (grade == null) { |
|
|
|
|
|
return false; // 等级不存在,直接返回失败 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 2. 检查逻辑:仅当等级未删除(is_del=0)且已存在奖品时,才拒绝添加 |
|
|
|
|
|
if (grade.getIsDel() == 0) { // 等级未删除 |
|
|
|
|
|
LambdaQueryWrapper<Prize> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
wrapper.eq(Prize::getGradeId, prizeDto.getGradeId()); |
|
|
|
|
|
if (this.count(wrapper) > 0) { |
|
|
|
|
|
return false; // 等级未删除且已有奖品,拒绝添加 |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Prize prize = Prize.builder() |
|
|
Prize prize = Prize.builder() |
|
@ -82,12 +97,20 @@ public class AdminPrizeServiceImpl extends ServiceImpl<AdminPrizeMapper, Prize> |
|
|
.imageUrl(prizeDto.getImageUrl()) |
|
|
.imageUrl(prizeDto.getImageUrl()) |
|
|
.createTime(new Date()) |
|
|
.createTime(new Date()) |
|
|
.updateTime(new Date()) |
|
|
.updateTime(new Date()) |
|
|
|
|
|
.is_del(0) |
|
|
.build(); |
|
|
.build(); |
|
|
|
|
|
|
|
|
return this.save(prize); |
|
|
|
|
|
|
|
|
boolean isPrizeSaved = this.save(prize); |
|
|
|
|
|
// if (isPrizeSaved && grade.getIsDel() == 1) { |
|
|
|
|
|
// grade.setIsDel(0); // 恢复等级为未删除 |
|
|
|
|
|
// grade.setUpdateTime(new Date()); |
|
|
|
|
|
// adminGradeMapper.updateById(grade); |
|
|
|
|
|
// } |
|
|
|
|
|
return isPrizeSaved; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
|
|
|
@Transactional |
|
|
public boolean updatePrize(PrizeDto prizeDto) { |
|
|
public boolean updatePrize(PrizeDto prizeDto) { |
|
|
Long gradeId = prizeDto.getGradeId(); |
|
|
Long gradeId = prizeDto.getGradeId(); |
|
|
Grade grade = adminGradeMapper.selectById(gradeId); |
|
|
Grade grade = adminGradeMapper.selectById(gradeId); |
|
@ -99,12 +122,20 @@ public class AdminPrizeServiceImpl extends ServiceImpl<AdminPrizeMapper, Prize> |
|
|
return false; // 原奖品不存在 |
|
|
return false; // 原奖品不存在 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 查询目标等级信息 |
|
|
// 2. 查询目标等级信息 |
|
|
Grade targetGrade = adminGradeMapper.selectById(gradeId); |
|
|
Grade targetGrade = adminGradeMapper.selectById(gradeId); |
|
|
if (targetGrade == null) { |
|
|
if (targetGrade == null) { |
|
|
return false; // 目标等级不存在 |
|
|
return false; // 目标等级不存在 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// :如果目标等级已删除(is_del=1),禁止修改 |
|
|
|
|
|
if (targetGrade.getIsDel() == 1) { |
|
|
|
|
|
return false; // 目标等级已删除,不允许修改 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 3. 如果修改后的等级和原等级不同,检查目标等级是否已有奖品 |
|
|
// 3. 如果修改后的等级和原等级不同,检查目标等级是否已有奖品 |
|
|
if (!targetGrade.getId().equals(originalPrize.getGradeId())) { |
|
|
if (!targetGrade.getId().equals(originalPrize.getGradeId())) { |
|
|
LambdaQueryWrapper<Prize> wrapper = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<Prize> wrapper = new LambdaQueryWrapper<>(); |
|
@ -175,4 +206,21 @@ public class AdminPrizeServiceImpl extends ServiceImpl<AdminPrizeMapper, Prize> |
|
|
userDetail.setIsFixed(1); |
|
|
userDetail.setIsFixed(1); |
|
|
adminUserDetailMapper.insert(userDetail); |
|
|
adminUserDetailMapper.insert(userDetail); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean removePrizeById(Long id) { |
|
|
|
|
|
|
|
|
|
|
|
//把关联的win_record表删了 |
|
|
|
|
|
LambdaUpdateWrapper<WinnerRecord> updateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
updateWrapper.eq(WinnerRecord::getPrizeId, id).set(WinnerRecord::getIsDel, 1); |
|
|
|
|
|
adminWinMapper.update(null, updateWrapper); |
|
|
|
|
|
|
|
|
|
|
|
// //把关联的user_detail表删了 |
|
|
|
|
|
// LambdaUpdateWrapper<UserDetail> wrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
// wrapper.eq(UserDetail::getUserId, id); |
|
|
|
|
|
// adminUserDetailMapper.update(null, wrapper); |
|
|
|
|
|
|
|
|
|
|
|
//最后逻辑删除奖品 |
|
|
|
|
|
return adminPrizeMapper.deletePrizeById(id); |
|
|
|
|
|
} |
|
|
} |
|
|
} |