feat
parent
a8bf9b7390
commit
b164460829
|
@ -1,68 +0,0 @@
|
|||
package com.mcwl.web.controller.resource;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.mcwl.common.annotation.RepeatSubmit;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.resource.domain.ModelProduct;
|
||||
import com.mcwl.resource.domain.vo.MallProductVo;
|
||||
import com.mcwl.resource.service.MallProductLikeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 点赞商品
|
||||
* @author DaiZibo
|
||||
* @date 2025/1/2
|
||||
* @apiNote
|
||||
*/
|
||||
@Api(tags = "点赞商品")
|
||||
@RequestMapping("/like")
|
||||
@RestController
|
||||
public class MallProductLikeController {
|
||||
|
||||
@Autowired
|
||||
private MallProductLikeService mallProductLikeService;
|
||||
|
||||
/**
|
||||
* 查询用户点赞作品列表
|
||||
* @param mallProductVo
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "查询用户点赞作品列表")
|
||||
@PostMapping("/selectByUserLike")
|
||||
public AjaxResult selectByUserLike(@RequestBody MallProductVo mallProductVo){
|
||||
|
||||
Page<ModelProduct> mallProductPage = mallProductLikeService.selectByUserLike(mallProductVo);
|
||||
return AjaxResult.success(mallProductPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加/删除点赞商品
|
||||
* @param productId
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加/删除点赞商品")
|
||||
@RepeatSubmit
|
||||
@GetMapping("/addLike")
|
||||
public AjaxResult addLike(@RequestParam Long productId){
|
||||
|
||||
return mallProductLikeService.addLike(productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看作品是否点赞
|
||||
* @param productId
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "查看作品是否点赞")
|
||||
@GetMapping("/selectLike")
|
||||
public AjaxResult selectLike(@RequestParam Long productId){
|
||||
Boolean aBoolean = mallProductLikeService.selectLike(productId);
|
||||
return AjaxResult.success(aBoolean);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.mcwl.resource.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.resource.domain.ModelProduct;
|
||||
import com.mcwl.resource.domain.vo.MallProductVo;
|
||||
|
||||
/**
|
||||
* @author DaiZibo
|
||||
* @date 2025/1/2
|
||||
* @apiNote
|
||||
*/
|
||||
|
||||
public interface MallProductLikeService {
|
||||
Page<ModelProduct> selectByUserLike(MallProductVo mallProductVo);
|
||||
|
||||
AjaxResult addLike(Long productId);
|
||||
|
||||
AjaxResult deleteLike(Long productId);
|
||||
|
||||
Boolean selectLike(Long productId);
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package com.mcwl.resource.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.resource.domain.MallProductLike;
|
||||
import com.mcwl.resource.domain.ModelProduct;
|
||||
import com.mcwl.resource.domain.vo.MallProductVo;
|
||||
import com.mcwl.resource.mapper.MallProductLikeMapper;
|
||||
import com.mcwl.resource.service.MallProductLikeService;
|
||||
import com.mcwl.resource.service.ModelService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author DaiZibo
|
||||
* @date 2025/1/2
|
||||
* @apiNote
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class MallProductLikeServiceImpl implements MallProductLikeService {
|
||||
|
||||
@Autowired
|
||||
private MallProductLikeMapper mallProductLikeMapper;
|
||||
|
||||
@Autowired
|
||||
private ModelService mallProductService;
|
||||
|
||||
@Override
|
||||
public Page<ModelProduct> selectByUserLike(MallProductVo mallProductVo) {
|
||||
|
||||
//获取登录人
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
List<Long> list = mallProductLikeMapper.selectByUserId(userId);
|
||||
//分页查询作品数据
|
||||
return mallProductService.pageLike(mallProductVo, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AjaxResult addLike(Long productId) {
|
||||
|
||||
Boolean aBoolean = selectLike(productId);
|
||||
if (aBoolean == true){
|
||||
//删除点赞记录
|
||||
mallProductLikeMapper.deleteByUserIdAndProductId(productId,SecurityUtils.getUserId());
|
||||
return AjaxResult.success(false);
|
||||
}
|
||||
|
||||
MallProductLike mallProductLike = MallProductLike.builder().productId(productId)
|
||||
.userId(SecurityUtils.getUserId())
|
||||
.createName(SecurityUtils.getUsername())
|
||||
.createTime(new Date()).build();
|
||||
|
||||
int insert = mallProductLikeMapper.insert(mallProductLike);
|
||||
|
||||
if (insert<0){
|
||||
|
||||
return AjaxResult.error("点赞失败",false);
|
||||
}
|
||||
return AjaxResult.success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AjaxResult deleteLike(Long productId) {
|
||||
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean selectLike(Long productId) {
|
||||
|
||||
MallProductLike mallProductLike1 = mallProductLikeMapper.selectByUserIdAndProductId(SecurityUtils.getUserId(),productId);
|
||||
|
||||
if (mallProductLike1 == null){
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue