|
@@ -1,171 +0,0 @@
|
|
|
-package com.ruoyi.userCollect.service.impl;
|
|
|
-
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.ruoyi.common.core.domain.PageQuery;
|
|
|
-import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
-import com.ruoyi.common.enums.collect.CollectEntityType;
|
|
|
-import com.ruoyi.common.exception.ServiceException;
|
|
|
-import com.ruoyi.common.utils.BeanCopyUtils;
|
|
|
-import com.ruoyi.userCollect.domain.UserCollect;
|
|
|
-import com.ruoyi.userCollect.domain.bo.UserCollectBo;
|
|
|
-import com.ruoyi.userCollect.domain.vo.UserCollectVo;
|
|
|
-import com.ruoyi.userCollect.exception.UserCollectExceptionEnum;
|
|
|
-import com.ruoyi.userCollect.mapper.UserCollectMapper;
|
|
|
-import com.ruoyi.userCollect.service.IUserCollectService;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * 用户收藏Service业务层处理
|
|
|
- *
|
|
|
- * @author ruoyi
|
|
|
- * @date 2025-04-18
|
|
|
- */
|
|
|
-@RequiredArgsConstructor
|
|
|
-@Service
|
|
|
-public class UserCollectServiceImpl implements IUserCollectService {
|
|
|
-
|
|
|
- private final UserCollectMapper baseMapper;
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询用户收藏分页
|
|
|
- *
|
|
|
- * @param bo 用户收藏
|
|
|
- * @return 用户收藏
|
|
|
- */
|
|
|
- @Override
|
|
|
- public TableDataInfo<UserCollectVo> queryPageList(UserCollectBo bo, PageQuery pageQuery) {
|
|
|
- LambdaQueryWrapper<UserCollect> lqw = buildQueryWrapper(bo);
|
|
|
- Page<UserCollectVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
- return TableDataInfo.build(result);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询用户收藏列表
|
|
|
- *
|
|
|
- * @param bo 用户收藏
|
|
|
- * @return 用户收藏
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<UserCollectVo> queryList(UserCollectBo bo) {
|
|
|
- LambdaQueryWrapper<UserCollect> lqw = buildQueryWrapper(bo);
|
|
|
- return baseMapper.selectVoList(lqw);
|
|
|
- }
|
|
|
-
|
|
|
- private LambdaQueryWrapper<UserCollect> buildQueryWrapper(UserCollectBo bo) {
|
|
|
- Map<String, Object> params = bo.getParams();
|
|
|
- LambdaQueryWrapper<UserCollect> lqw = Wrappers.lambdaQuery();
|
|
|
- lqw.eq(bo.getUserId() != null, UserCollect::getUserId, bo.getUserId());
|
|
|
- lqw.eq(bo.getEntityId() != null, UserCollect::getEntityId, bo.getEntityId());
|
|
|
- lqw.eq(bo.getEntityType() != null, UserCollect::getEntityType, bo.getEntityType());
|
|
|
- return lqw;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询用户收藏
|
|
|
- *
|
|
|
- * @param id 用户收藏主键
|
|
|
- * @return 用户收藏
|
|
|
- */
|
|
|
- @Override
|
|
|
- public UserCollectVo queryById(Long id){
|
|
|
- return baseMapper.selectVoById(id);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 详情用户收藏
|
|
|
- *
|
|
|
- * @param id 用户收藏主键
|
|
|
- * @return 用户收藏
|
|
|
- */
|
|
|
- @Override
|
|
|
- public UserCollect loadById(Long id, Boolean tw){
|
|
|
- UserCollect info = this.baseMapper.selectById(id);
|
|
|
- if(ObjectUtil.isEmpty(info) && tw){
|
|
|
- throw new ServiceException(UserCollectExceptionEnum.UserCollect_IS_NOT_EXISTS);
|
|
|
- }
|
|
|
- return info;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 新增用户收藏
|
|
|
- *
|
|
|
- * @param bo 用户收藏
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Boolean insertByBo(UserCollectBo bo) {
|
|
|
- UserCollect add = BeanUtil.toBean(bo, UserCollect.class);
|
|
|
- validEntityBeforeSave(add);
|
|
|
- boolean flag = baseMapper.insert(add) > 0;
|
|
|
- if (flag) {
|
|
|
- bo.setId(add.getId());
|
|
|
- }
|
|
|
- return flag;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改用户收藏
|
|
|
- *
|
|
|
- * @param bo 用户收藏
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Boolean updateByBo(UserCollectBo bo) {
|
|
|
- UserCollect userCollect = baseMapper.selectById(bo.getId());
|
|
|
- UserCollect update = BeanCopyUtils.copy(bo, userCollect);
|
|
|
- validEntityBeforeSave(update);
|
|
|
- return baseMapper.updateById(update) > 0;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 保存前的数据校验
|
|
|
- *
|
|
|
- * @param entity 实体类数据
|
|
|
- */
|
|
|
- private void validEntityBeforeSave(UserCollect entity){
|
|
|
- //TODO 做一些数据校验,如唯一约束
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 批量删除用户收藏
|
|
|
- *
|
|
|
- * @param ids 需要删除的用户收藏主键
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
- if(isValid){
|
|
|
- //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
- }
|
|
|
- return baseMapper.deleteBatchIds(ids) > 0;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public UserCollectVo getUserCollect(UserCollectBo bo) {
|
|
|
- return baseMapper.selectVoOne(Wrappers.lambdaQuery(UserCollect.class).eq(UserCollect::getUserId, bo.getUserId())
|
|
|
- .eq(UserCollect::getEntityId, bo.getEntityId())
|
|
|
- .eq(UserCollect::getEntityType, bo.getEntityType())
|
|
|
- .last("limit 1")
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public UserCollectVo getUserCollect(Long userId, CollectEntityType entityType, Long entityId) {
|
|
|
- return this.baseMapper.selectVoOne(new LambdaQueryWrapper<UserCollect>()
|
|
|
- .eq(UserCollect::getUserId, userId)
|
|
|
- .eq(UserCollect::getEntityType, entityType)
|
|
|
- .eq(UserCollect::getEntityId, entityId)
|
|
|
- .last("limit 1")
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
-}
|