hjl
2024-07-18 b9da8289051937fbbbd47bbda97414ad6c769a90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.ruoyi.user.controller;
 
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.model.LoginUserInfo;
import com.ruoyi.user.entity.UserCollect;
import com.ruoyi.user.service.UserCollectService;
import com.ruoyi.user.vo.UserCollectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
 
/**
 * <p>
 * 用户收藏表 前端控制器
 * </p>
 *
 * @author hjl
 * @since 2024-06-07
 */
@RestController
@RequestMapping("/collect")
@Api(tags = {"用户端-收藏"})
public class UserCollectController {
 
    @Resource
    private UserCollectService userCollectService;
    @Resource
    private TokenService tokenService;
 
    /**
     * 获取服务详情
     */
    @GetMapping(value = "/haveCollect")
    @ApiOperation(value = "收藏", tags = {"用户端-收藏"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务id", name = "serveId", dataType = "Integer", required = true)
    })
    public R<Boolean> serveDetail(@RequestParam Integer serveId) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        UserCollect userCollect = new UserCollect(loginUser.getUserid(), serveId);
        return R.ok(userCollectService.save(userCollect));
    }
 
    /**
     * 取消收藏
     */
    @GetMapping(value = "/cancelCollect")
    @ApiOperation(value = "取消收藏", tags = {"用户端-收藏"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "收藏记录id", name = "collectId", dataType = "Integer", required = true)
    })
    public R<Boolean> cancelCollect(@RequestParam Integer collectId) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        return R.ok(userCollectService.lambdaUpdate().set(UserCollect::getIsDelete, 1)
                .eq(UserCollect::getIsDelete, collectId).update());
    }
 
    /**
     * 服务收藏列表
     */
    @GetMapping(value = "/collectList")
    @ApiOperation(value = "服务收藏列表", tags = {"用户端-收藏"})
    public R<IPage<UserCollectVO>> collectList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        IPage<UserCollectVO> collectList = userCollectService.collectList(loginUser.getUserid(), Page.of(pageNum, pageSize));
        return R.ok(collectList);
    }
 
    /**
     * 服务收藏列表
     */
    @GetMapping(value = "/detailHaveCollect")
    @ApiOperation(value = "服务详情取消/添加收藏", tags = {"用户端-收藏"})
    public R<IPage<UserCollectVO>> collectList(@RequestParam Integer serveId) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
//        IPage<UserCollectVO> collectList = userCollectService.collectList(loginUser.getUserid());
        return R.ok();
    }
 
}