|
|
@@ -0,0 +1,202 @@
|
|
|
+package org.dromara.business.service.impl;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import org.dromara.business.domain.UserCheckRecord;
|
|
|
+import org.dromara.business.domain.bo.UserCheckRecordBo;
|
|
|
+import org.dromara.business.domain.vo.PlayerItemsVo;
|
|
|
+import org.dromara.business.domain.vo.UserCheckRecordVo;
|
|
|
+import org.dromara.business.mapper.PlayerItemsMapper;
|
|
|
+import org.dromara.business.mapper.UserCheckRecordMapper;
|
|
|
+import org.dromara.business.service.IUserCheckRecordService;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Collection;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户核销记录Service业务层处理
|
|
|
+ *
|
|
|
+ * @author Lion Li
|
|
|
+ * @date 2025-08-15
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class UserCheckRecordServiceImpl implements IUserCheckRecordService {
|
|
|
+
|
|
|
+ private final UserCheckRecordMapper baseMapper;
|
|
|
+
|
|
|
+ private final PlayerItemsMapper playerItemsMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询用户核销记录
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 用户核销记录
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public UserCheckRecordVo queryById(Long id){
|
|
|
+ return baseMapper.selectCheckRecordById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询用户核销记录列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 用户核销记录分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<UserCheckRecordVo> queryPageList(UserCheckRecordBo bo, PageQuery pageQuery) {
|
|
|
+ Wrapper<UserCheckRecord> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<UserCheckRecordVo> result = baseMapper.selectCheckRecordList(pageQuery.build(), lqw);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的用户核销记录列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 用户核销记录列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<UserCheckRecordVo> queryList(UserCheckRecordBo bo) {
|
|
|
+ Wrapper<UserCheckRecord> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectCheckRecordAllList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Wrapper<UserCheckRecord> buildQueryWrapper(UserCheckRecordBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ QueryWrapper<UserCheckRecord> wrapper = new QueryWrapper<>();
|
|
|
+
|
|
|
+ // 排序:id ASC
|
|
|
+ wrapper.orderByAsc("a.id");
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(bo.getUserIds())) {
|
|
|
+ wrapper.and(wrapper1 ->
|
|
|
+ wrapper1.like("b.phone", bo.getUserIds())
|
|
|
+ .or()
|
|
|
+ .like("b.nick_name", bo.getUserIds())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // a.user_id
|
|
|
+ if (bo.getUserId() != null) {
|
|
|
+ wrapper.eq("a.user_id", bo.getUserId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // a.num
|
|
|
+ if (bo.getNum() != null) {
|
|
|
+ wrapper.eq("a.num", bo.getNum());
|
|
|
+ }
|
|
|
+
|
|
|
+ // a.item_id
|
|
|
+ if (bo.getItemId() != null) {
|
|
|
+ wrapper.eq("a.item_id", bo.getItemId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // a.created_at
|
|
|
+ if (bo.getCreatedAt() != null) {
|
|
|
+ wrapper.eq("a.created_at", bo.getCreatedAt());
|
|
|
+ }
|
|
|
+
|
|
|
+ // a.updated_at
|
|
|
+ if (bo.getUpdatedAt() != null) {
|
|
|
+ wrapper.eq("a.updated_at", bo.getUpdatedAt());
|
|
|
+ }
|
|
|
+
|
|
|
+ // a.create_user_id
|
|
|
+ if (bo.getCreateUserId() != null) {
|
|
|
+ wrapper.eq("a.create_user_id", bo.getCreateUserId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // a.create_user_name (模糊匹配)
|
|
|
+ if (StringUtils.isNotBlank(bo.getCreateUserName())) {
|
|
|
+ wrapper.like("a.create_user_name", bo.getCreateUserName());
|
|
|
+ }
|
|
|
+
|
|
|
+ return wrapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增用户核销记录
|
|
|
+ *
|
|
|
+ * @param bo 用户核销记录
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(UserCheckRecordBo bo) {
|
|
|
+ //核销的时候判断数量是否足够,不够的话,提示用户
|
|
|
+ Long userId = bo.getUserId();
|
|
|
+ Long num = bo.getNum();
|
|
|
+
|
|
|
+ PlayerItemsVo playerItemsVo = playerItemsMapper.selectPlayerItemsInfo(userId, 1001L);
|
|
|
+ if(playerItemsVo.getQuantity()<0 || playerItemsVo.getQuantity()<num){
|
|
|
+ throw new RuntimeException("数量不足!!!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //todo 需要继续做扣减相关操作
|
|
|
+ UserCheckRecord add = MapstructUtils.convert(bo, UserCheckRecord.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insertCheckRecord(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ //核销完成之后 记录道具流水日志 扣减用户道具表数量
|
|
|
+
|
|
|
+
|
|
|
+ bo.setId(add.getId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改用户核销记录
|
|
|
+ *
|
|
|
+ * @param bo 用户核销记录
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(UserCheckRecordBo bo) {
|
|
|
+ UserCheckRecord update = MapstructUtils.convert(bo, UserCheckRecord.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateCheckRecordById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(UserCheckRecord entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除用户核销记录信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteCheckRecordById(ids) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PlayerItemsVo> selectPlayerItemsListByUser(String userIds) {
|
|
|
+
|
|
|
+ return playerItemsMapper.selectPlayerItemsListByUser(userIds);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|