Compare commits
No commits in common. "dc2b5c9daaa83316020738c7537b319cb4ee9d0c" and "b30dbfbe2e7044b1f7f772e98c32a715ea5c0169" have entirely different histories.
dc2b5c9daa
...
b30dbfbe2e
|
@ -0,0 +1,68 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
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);
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
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