Merge pull request '完成我的收藏模块开发' (#64) from Brunch_LPQ into main
commit
dbcac59eea
@ -0,0 +1,82 @@
|
|||||||
|
package com.itmk.web.user_collect.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.itmk.utils.ResultUtils;
|
||||||
|
import com.itmk.utils.ResultVo;
|
||||||
|
import com.itmk.web.user_collect.entity.UserCollect;
|
||||||
|
import com.itmk.web.user_collect.service.UserCollectService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author java实战基地
|
||||||
|
* @Version 2383404558
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/wxapi/collect")
|
||||||
|
public class UserCollectController {
|
||||||
|
@Autowired
|
||||||
|
private UserCollectService userCollectService;
|
||||||
|
|
||||||
|
//收藏
|
||||||
|
@PostMapping("/addCollect")
|
||||||
|
public ResultVo addCollect(@RequestBody UserCollect userCollect){
|
||||||
|
//查询是否收藏
|
||||||
|
QueryWrapper<UserCollect> query = new QueryWrapper<>();
|
||||||
|
query.lambda().eq(UserCollect::getGoodsId,userCollect.getGoodsId())
|
||||||
|
.eq(UserCollect::getOpenid,userCollect.getOpenid());
|
||||||
|
UserCollect one = userCollectService.getOne(query);
|
||||||
|
if(one != null){
|
||||||
|
return ResultUtils.error("您已经收藏该商品!");
|
||||||
|
}
|
||||||
|
if(userCollectService.save(userCollect)){
|
||||||
|
return ResultUtils.success("收藏成功!");
|
||||||
|
}
|
||||||
|
return ResultUtils.error("收藏失败!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
public ResultVo getList(String openid){
|
||||||
|
List<UserCollect> list = userCollectService.getList(openid);
|
||||||
|
return ResultUtils.success("查询成功!",list);
|
||||||
|
}
|
||||||
|
@GetMapping("/hasCollect")
|
||||||
|
public ResultVo hasCollect(UserCollect userCollect){
|
||||||
|
QueryWrapper<UserCollect> query = new QueryWrapper<>();
|
||||||
|
query.lambda().eq(UserCollect::getOpenid,userCollect.getOpenid())
|
||||||
|
.eq(UserCollect::getGoodsId,userCollect.getGoodsId());
|
||||||
|
UserCollect list = userCollectService.getOne(query);
|
||||||
|
if(list != null){
|
||||||
|
return ResultUtils.success("查询成功!","1");
|
||||||
|
}else{
|
||||||
|
return ResultUtils.success("查询成功!","0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//取消收藏
|
||||||
|
@PostMapping("/cancelCollect")
|
||||||
|
public ResultVo cancelCollect(@RequestBody UserCollect userCollect){
|
||||||
|
//查询是否收藏
|
||||||
|
QueryWrapper<UserCollect> query = new QueryWrapper<>();
|
||||||
|
query.lambda().eq(UserCollect::getGoodsId,userCollect.getGoodsId())
|
||||||
|
.eq(UserCollect::getOpenid,userCollect.getOpenid());
|
||||||
|
if(userCollectService.remove(query)){
|
||||||
|
return ResultUtils.success("取消收藏成功!");
|
||||||
|
}else{
|
||||||
|
return ResultUtils.error("取消收藏失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除收藏
|
||||||
|
@PostMapping("/deleteCollect")
|
||||||
|
public ResultVo deleteCollect(@RequestBody UserCollect userCollect){
|
||||||
|
|
||||||
|
if(userCollectService.removeById(userCollect.getCollectId())){
|
||||||
|
return ResultUtils.success("删除收藏成功!");
|
||||||
|
}else{
|
||||||
|
return ResultUtils.error("删除收藏失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.itmk.web.user_collect.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("user_collect")
|
||||||
|
public class UserCollect {
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long collectId;
|
||||||
|
private String openid;
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String goodsName;
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String goodsImage;
|
||||||
|
private Long goodsId;
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.itmk.web.user_collect.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.itmk.web.user_collect.entity.UserCollect;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface UserCollectMapper extends BaseMapper<UserCollect> {
|
||||||
|
List<UserCollect> getList(@Param("openid") String openid);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.itmk.web.user_collect.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.itmk.web.user_collect.entity.UserCollect;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface UserCollectService extends IService<UserCollect> {
|
||||||
|
List<UserCollect> getList(String openid);
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.itmk.web.user_collect.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.itmk.web.user_collect.entity.UserCollect;
|
||||||
|
import com.itmk.web.user_collect.mapper.UserCollectMapper;
|
||||||
|
import com.itmk.web.user_collect.service.UserCollectService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserCollectServiceImpl extends ServiceImpl<UserCollectMapper, UserCollect> implements UserCollectService {
|
||||||
|
@Override
|
||||||
|
public List<UserCollect> getList(String openid) {
|
||||||
|
return this.baseMapper.getList(openid);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
|
||||||
|
<mapper namespace="com.itmk.web.user_collect.mapper.UserCollectMapper">
|
||||||
|
<select id="getList" resultType="com.itmk.web.user_collect.entity.UserCollect">
|
||||||
|
select g.goods_name,g.goods_image,c.* from user_collect as c inner join sys_goods as g on c.goods_id = g.goods_id
|
||||||
|
where c.openid =#{openid}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
Loading…
Reference in new issue