mirror of https://gitee.com/stylefeng/roses
【8.0.4】【fav模块】更新绑定接口和取消绑定
parent
99dfbe2468
commit
5e57f76383
|
@ -0,0 +1,53 @@
|
|||
package cn.stylefeng.roses.kernel.favorite.modular.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.favorite.modular.pojo.request.SysUserFavoriteRequest;
|
||||
import cn.stylefeng.roses.kernel.favorite.modular.service.SysUserFavoriteService;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 通用收藏控制器
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/21 22:36
|
||||
*/
|
||||
@RestController
|
||||
@ApiResource(name = "通用收藏控制器")
|
||||
public class FavoriteController {
|
||||
|
||||
@Resource
|
||||
private SysUserFavoriteService sysUserFavoriteService;
|
||||
|
||||
/**
|
||||
* 绑定用户收藏
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/21 22:46
|
||||
*/
|
||||
@PostResource(name = "绑定用户收藏", path = "/favorite/bind")
|
||||
public ResponseData<?> bind(@RequestBody @Validated(BaseRequest.add.class) SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
sysUserFavoriteService.bind(sysUserFavoriteRequest);
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消用户绑定的收藏
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/21 22:46
|
||||
*/
|
||||
@PostResource(name = "取消用户绑定的收藏", path = "/favorite/unBind")
|
||||
public ResponseData<?> unBind(@RequestBody @Validated(BaseRequest.delete.class) SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
sysUserFavoriteService.unBind(sysUserFavoriteRequest);
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
}
|
|
@ -22,42 +22,32 @@ public class SysUserFavoriteRequest extends BaseRequest {
|
|||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@NotNull(message = "主键id不能为空", groups = {edit.class, delete.class})
|
||||
@ChineseDescription("主键id")
|
||||
private Long favoriteId;
|
||||
|
||||
/**
|
||||
* 收藏业务的类型,存业务编码
|
||||
*/
|
||||
@NotBlank(message = "收藏业务的类型,存业务编码不能为空", groups = {add.class, edit.class})
|
||||
@ChineseDescription("收藏业务的类型,存业务编码")
|
||||
@NotBlank(message = "收藏业务类型不能为空", groups = {add.class, delete.class})
|
||||
private String favType;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@NotNull(message = "用户id不能为空", groups = {add.class, edit.class})
|
||||
@ChineseDescription("用户id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 具体业务id
|
||||
*/
|
||||
@NotNull(message = "具体业务id不能为空", groups = {add.class, edit.class})
|
||||
@ChineseDescription("具体业务id")
|
||||
@NotNull(message = "具体业务id不能为空", groups = {add.class, delete.class})
|
||||
private Long businessId;
|
||||
|
||||
/**
|
||||
* 收藏时间
|
||||
*/
|
||||
@ChineseDescription("收藏时间")
|
||||
private String favTime;
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除用的id集合
|
||||
*/
|
||||
@NotNull(message = "批量删除id集合不能为空", groups = batchDelete.class)
|
||||
@ChineseDescription("批量删除用的id集合")
|
||||
private List<Long> batchDeleteIdList;
|
||||
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
package cn.stylefeng.roses.kernel.favorite.modular.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.favorite.modular.api.UserFavoriteApi;
|
||||
import cn.stylefeng.roses.kernel.favorite.modular.entity.SysUserFavorite;
|
||||
import cn.stylefeng.roses.kernel.favorite.modular.pojo.request.SysUserFavoriteRequest;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户收藏信息服务类
|
||||
*
|
||||
|
@ -17,68 +14,19 @@ import java.util.List;
|
|||
public interface SysUserFavoriteService extends IService<SysUserFavorite>, UserFavoriteApi {
|
||||
|
||||
/**
|
||||
* 新增用户收藏信息
|
||||
* 绑定用户收藏信息
|
||||
*
|
||||
* @param sysUserFavoriteRequest 请求参数
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/21 22:09
|
||||
* @since 2023/11/21 22:48
|
||||
*/
|
||||
void add(SysUserFavoriteRequest sysUserFavoriteRequest);
|
||||
void bind(SysUserFavoriteRequest sysUserFavoriteRequest);
|
||||
|
||||
/**
|
||||
* 删除用户收藏信息
|
||||
* 取消用户绑定的收藏
|
||||
*
|
||||
* @param sysUserFavoriteRequest 请求参数
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/21 22:09
|
||||
* @since 2023/11/21 22:54
|
||||
*/
|
||||
void del(SysUserFavoriteRequest sysUserFavoriteRequest);
|
||||
|
||||
/**
|
||||
* 批量删除用户收藏信息
|
||||
*
|
||||
* @param sysUserFavoriteRequest 请求参数
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/21 22:09
|
||||
*/
|
||||
void batchDelete(SysUserFavoriteRequest sysUserFavoriteRequest);
|
||||
|
||||
/**
|
||||
* 编辑用户收藏信息
|
||||
*
|
||||
* @param sysUserFavoriteRequest 请求参数
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/21 22:09
|
||||
*/
|
||||
void edit(SysUserFavoriteRequest sysUserFavoriteRequest);
|
||||
|
||||
/**
|
||||
* 查询详情用户收藏信息
|
||||
*
|
||||
* @param sysUserFavoriteRequest 请求参数
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/21 22:09
|
||||
*/
|
||||
SysUserFavorite detail(SysUserFavoriteRequest sysUserFavoriteRequest);
|
||||
|
||||
/**
|
||||
* 获取用户收藏信息列表
|
||||
*
|
||||
* @param sysUserFavoriteRequest 请求参数
|
||||
* @return List<SysUserFavorite> 返回结果
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/21 22:09
|
||||
*/
|
||||
List<SysUserFavorite> findList(SysUserFavoriteRequest sysUserFavoriteRequest);
|
||||
|
||||
/**
|
||||
* 获取用户收藏信息分页列表
|
||||
*
|
||||
* @param sysUserFavoriteRequest 请求参数
|
||||
* @return PageResult<SysUserFavorite> 返回结果
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/21 22:09
|
||||
*/
|
||||
PageResult<SysUserFavorite> findPage(SysUserFavoriteRequest sysUserFavoriteRequest);
|
||||
void unBind(SysUserFavoriteRequest sysUserFavoriteRequest);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,25 +1,18 @@
|
|||
package cn.stylefeng.roses.kernel.favorite.modular.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.favorite.modular.entity.SysUserFavorite;
|
||||
import cn.stylefeng.roses.kernel.favorite.modular.enums.SysUserFavoriteExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.favorite.modular.mapper.SysUserFavoriteMapper;
|
||||
import cn.stylefeng.roses.kernel.favorite.modular.pojo.request.SysUserFavoriteRequest;
|
||||
import cn.stylefeng.roses.kernel.favorite.modular.service.SysUserFavoriteService;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -32,64 +25,6 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
public class SysUserFavoriteServiceImpl extends ServiceImpl<SysUserFavoriteMapper, SysUserFavorite> implements SysUserFavoriteService {
|
||||
|
||||
@Override
|
||||
public void add(SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
SysUserFavorite sysUserFavorite = new SysUserFavorite();
|
||||
BeanUtil.copyProperties(sysUserFavoriteRequest, sysUserFavorite);
|
||||
this.save(sysUserFavorite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void del(SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
SysUserFavorite sysUserFavorite = this.querySysUserFavorite(sysUserFavoriteRequest);
|
||||
this.removeById(sysUserFavorite.getFavoriteId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchDelete(SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
this.removeByIds(sysUserFavoriteRequest.getBatchDeleteIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edit(SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
SysUserFavorite sysUserFavorite = this.querySysUserFavorite(sysUserFavoriteRequest);
|
||||
BeanUtil.copyProperties(sysUserFavoriteRequest, sysUserFavorite);
|
||||
this.updateById(sysUserFavorite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserFavorite detail(SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
return this.querySysUserFavorite(sysUserFavoriteRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysUserFavorite> findPage(SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
LambdaQueryWrapper<SysUserFavorite> wrapper = createWrapper(sysUserFavoriteRequest);
|
||||
Page<SysUserFavorite> pageList = this.page(PageFactory.defaultPage(), wrapper);
|
||||
return PageResultFactory.createPageResult(pageList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserFavorite> findList(SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
LambdaQueryWrapper<SysUserFavorite> wrapper = this.createWrapper(sysUserFavoriteRequest);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/21 22:09
|
||||
*/
|
||||
private SysUserFavorite querySysUserFavorite(SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
SysUserFavorite sysUserFavorite = this.getById(sysUserFavoriteRequest.getFavoriteId());
|
||||
if (ObjectUtil.isEmpty(sysUserFavorite)) {
|
||||
throw new ServiceException(SysUserFavoriteExceptionEnum.SYS_USER_FAVORITE_NOT_EXISTED);
|
||||
}
|
||||
return sysUserFavorite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getFavoriteBusinessId(Long userId, String favType) {
|
||||
|
||||
|
@ -126,27 +61,55 @@ public class SysUserFavoriteServiceImpl extends ServiceImpl<SysUserFavoriteMappe
|
|||
return this.getFavoriteBusinessId(loginUserNullable.getUserId(), favType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
|
||||
String favType = sysUserFavoriteRequest.getFavType();
|
||||
Long businessId = sysUserFavoriteRequest.getBusinessId();
|
||||
Long userId = LoginContext.me().getLoginUser().getUserId();
|
||||
|
||||
// 查询是否用户已经绑定了收藏
|
||||
LambdaQueryWrapper<SysUserFavorite> sysUserFavoriteLambdaQueryWrapper = createCommonUserBindWrapper(
|
||||
userId, businessId, favType);
|
||||
long count = this.count(sysUserFavoriteLambdaQueryWrapper);
|
||||
if (count > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 新绑定用户收藏
|
||||
SysUserFavorite sysUserFavorite = new SysUserFavorite();
|
||||
sysUserFavorite.setFavType(favType);
|
||||
sysUserFavorite.setUserId(userId);
|
||||
sysUserFavorite.setBusinessId(businessId);
|
||||
sysUserFavorite.setFavTime(new Date());
|
||||
this.save(sysUserFavorite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unBind(SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
|
||||
String favType = sysUserFavoriteRequest.getFavType();
|
||||
Long businessId = sysUserFavoriteRequest.getBusinessId();
|
||||
Long userId = LoginContext.me().getLoginUser().getUserId();
|
||||
|
||||
// 直接取消绑定
|
||||
LambdaQueryWrapper<SysUserFavorite> sysUserFavoriteLambdaQueryWrapper = createCommonUserBindWrapper(
|
||||
userId, businessId, favType);
|
||||
this.remove(sysUserFavoriteLambdaQueryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建查询wrapper
|
||||
* 创建通用wrapper
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/21 22:09
|
||||
* @since 2023/11/21 22:55
|
||||
*/
|
||||
private LambdaQueryWrapper<SysUserFavorite> createWrapper(SysUserFavoriteRequest sysUserFavoriteRequest) {
|
||||
LambdaQueryWrapper<SysUserFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
Long favoriteId = sysUserFavoriteRequest.getFavoriteId();
|
||||
String favType = sysUserFavoriteRequest.getFavType();
|
||||
Long userId = sysUserFavoriteRequest.getUserId();
|
||||
Long businessId = sysUserFavoriteRequest.getBusinessId();
|
||||
String favTime = sysUserFavoriteRequest.getFavTime();
|
||||
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(favoriteId), SysUserFavorite::getFavoriteId, favoriteId);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(favType), SysUserFavorite::getFavType, favType);
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(userId), SysUserFavorite::getUserId, userId);
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(businessId), SysUserFavorite::getBusinessId, businessId);
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(favTime), SysUserFavorite::getFavTime, favTime);
|
||||
|
||||
return queryWrapper;
|
||||
private static LambdaQueryWrapper<SysUserFavorite> createCommonUserBindWrapper(Long userId, Long businessId, String favType) {
|
||||
LambdaQueryWrapper<SysUserFavorite> sysUserFavoriteLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysUserFavoriteLambdaQueryWrapper.eq(SysUserFavorite::getUserId, userId);
|
||||
sysUserFavoriteLambdaQueryWrapper.eq(SysUserFavorite::getBusinessId, businessId);
|
||||
sysUserFavoriteLambdaQueryWrapper.eq(SysUserFavorite::getFavType, favType);
|
||||
return sysUserFavoriteLambdaQueryWrapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue