无关风月
2025-04-09 2ae88fdd57aca6abd2b9d3b158389f435127e3ca
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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.constant.Constants;
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.RecoveryClassify;
import com.ruoyi.user.entity.RecoveryServe;
import com.ruoyi.user.entity.UserCollect;
import com.ruoyi.user.entity.UserRecipient;
import com.ruoyi.user.service.RecoveryClassifyService;
import com.ruoyi.user.service.RecoveryServeService;
import com.ruoyi.user.service.UserCollectService;
import com.ruoyi.user.service.UserRecipientService;
import com.ruoyi.user.vo.ServeDetailVO;
import com.ruoyi.user.vo.ServeListVO;
import com.ruoyi.user.vo.UserServeTypeVO;
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;
import java.util.ArrayList;
import java.util.List;
 
/**
 * <p>
 * 回收服务列表 前端控制器
 * </p>
 *
 * @author hjl
 * @since 2024-06-06
 */
@RestController
@RequestMapping("/serve")
@Api(tags = {"用户端-服务"})
public class RecoveryServeController {
 
    @Resource
    private RecoveryServeService recoveryServeService;
    @Resource
    private RecoveryClassifyService recoveryClassifyService;
    @Resource
    private UserCollectService collectService;
    @Resource
    private TokenService tokenService;
    @Resource
    private UserRecipientService userRecipientService;
 
    /**
     * 获取服务列表
     */
    @GetMapping(value = "/serveType")
    @ApiOperation(value = "获取服务分类", tags = {"用户端-服务"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务类型(0:以旧换新;1:家电回收)", name = "type", dataType = "Integer", required = true)
    })
    public R<List<UserServeTypeVO>> serveType(@RequestParam("type") Integer type) {
        String serveType;
        if (Constants.ZERO.equals(type)) {
            serveType = Constants.TRADE_IN;
        } else {
            serveType = Constants.RECOVERY;
        }
        List<RecoveryClassify> serveList = recoveryClassifyService.lambdaQuery()
                .eq(RecoveryClassify::getIsDelete, 0)
                .eq(RecoveryClassify::getSupClassify, serveType)
                .orderByDesc(RecoveryClassify::getSort)
                .orderByDesc(RecoveryClassify::getCreateTime).list();
        List<UserServeTypeVO> list = new ArrayList<>();
        for (RecoveryClassify classify : serveList) {
            list.add(new UserServeTypeVO(classify.getId(), classify.getSubClassify(),
                    classify.getClassificationPicture(), classify.getTypeDescribe(), type));
        }
        return R.ok(list);
    }
 
    /**
     * 获取服务列表
     */
    @GetMapping(value = "/servePage")
    @ApiOperation(value = "根据所选分类获取服务列表", tags = {"用户端-服务"})
    public R<IPage<RecoveryServe>> servePage(@RequestParam("id") String id,
                                             @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<RecoveryServe> page = recoveryServeService.lambdaQuery()
                .eq(RecoveryServe::getClassifyId, id)
                .eq(RecoveryServe::getIsDelete, 0)
                .orderByDesc(RecoveryServe::getSort)
                .orderByDesc(RecoveryServe::getCreateTime).page(Page.of(pageNum, pageSize));
        return R.ok(page);
    }
 
    /**
     * 获取服务列表
     */
    @GetMapping(value = "/serveList")
    @ApiOperation(value = "获取服务列表", tags = {"用户端-服务"})
    public R<List<ServeListVO>> serveList() {
        return R.ok(recoveryServeService.serveList());
    }
 
    /**
     * 获取服务详情
     */
    @GetMapping(value = "/serveDetail")
    @ApiOperation(value = "获取服务详情", tags = {"用户端-服务"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务id", name = "serveId", dataType = "String", required = true)
    })
    public R<ServeDetailVO> serveDetail(@RequestParam String serveId) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            RecoveryServe recoveryServe = recoveryServeService.lambdaQuery().eq(RecoveryServe::getId, serveId)
                    .eq(RecoveryServe::getIsDelete, 0).one();
                recoveryServe.setIsCollect(Boolean.FALSE);
 
            // 获取服务分类
            Integer classifyId = recoveryServe.getClassifyId();
            RecoveryClassify classify = recoveryClassifyService.lambdaQuery()
                    .eq(RecoveryClassify::getId, classifyId).one();
            if (classify.getSupClassify().equals(Constants.TRADE_IN)) {
                recoveryServe.setType(Constants.ZERO);
            } else {
                recoveryServe.setType(Constants.ONE);
            }
 
 
            return R.ok(new ServeDetailVO(recoveryServe, null));
        }
        RecoveryServe recoveryServe = recoveryServeService.lambdaQuery().eq(RecoveryServe::getId, serveId)
                .eq(RecoveryServe::getIsDelete, 0).one();
        // 用户是否收藏
        UserCollect one = collectService.lambdaQuery()
                .eq(UserCollect::getServeId, serveId)
                .eq(UserCollect::getUserId, loginUser.getUserid())
                .eq(UserCollect::getIsDelete, 0).one();
        if (null != one) {
            recoveryServe.setIsCollect(Boolean.TRUE);
        } else {
            recoveryServe.setIsCollect(Boolean.FALSE);
        }
        // 获取服务分类
        Integer classifyId = recoveryServe.getClassifyId();
        RecoveryClassify classify = recoveryClassifyService.lambdaQuery()
                .eq(RecoveryClassify::getId, classifyId).one();
        if (classify.getSupClassify().equals(Constants.TRADE_IN)) {
            recoveryServe.setType(Constants.ZERO);
        } else {
            recoveryServe.setType(Constants.ONE);
        }
        // 获取用户默认收货地址
        UserRecipient userRecipient = userRecipientService.lambdaQuery()
                .eq(UserRecipient::getIsDefault, Constants.ONE)
                .eq(UserRecipient::getUserId, loginUser.getUserid())
                .eq(UserRecipient::getIsDelete, Constants.ZERO)
                .last("limit 1")
                .one();
        return R.ok(new ServeDetailVO(recoveryServe, userRecipient));
    }
 
    /**
     * 服务收藏
     */
    @GetMapping(value = "/serveCollect")
    @ApiOperation(value = "服务收藏", tags = {"用户端-服务"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务id", name = "serveId", dataType = "Integer", required = true)
    })
    public R<String> serveCollect(@RequestParam Integer serveId) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        UserCollect collect = collectService.lambdaQuery()
                .eq(UserCollect::getUserId, loginUser.getUserid())
                .eq(UserCollect::getServeId, serveId)
                .eq(UserCollect::getIsDelete, 0).one();
        boolean result;
        if (null != collect) {
            collect.setIsDelete(Constants.ONE);
            result = collectService.updateById(collect);
        } else {
            collect = new UserCollect(loginUser.getUserid(), serveId);
            result = collectService.save(collect);
        }
 
        return result ? R.ok() : R.fail();
    }
 
}