luodangjia
2024-07-29 dc9239d73b15b9a51c46a9e8d25c0d4400e613ce
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
package com.ruoyi.user.controller;
 
import cn.hutool.core.util.RandomUtil;
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.order.api.entity.EvaluateOrderInfoVO;
import com.ruoyi.order.api.entity.OrderEvaluateSubmitRequest;
import com.ruoyi.order.api.entity.OrderEvaluateVO;
import com.ruoyi.order.api.feignClient.EvaluateClient;
import com.ruoyi.system.api.model.LoginUserInfo;
import com.ruoyi.user.entity.RecoveryServe;
import com.ruoyi.user.request.OrderEvaluateRequest;
import com.ruoyi.user.service.RecoveryServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 用户评价表 前端控制器
 * </p>
 *
 * @author hjl
 * @since 2024-05-29
 */
@RestController
@RequestMapping("/evaluate")
@Api(tags = {"用户端-个人中心"})
public class EvaluateController {
 
    @Resource
    private TokenService tokenService;
    @Resource
    private EvaluateClient evaluateClient;
    @Resource
    private RecoveryServeService recoveryServeService;
 
    @GetMapping("/orderEvaluate")
    @ApiOperation(value = "订单评价列表", tags = {"用户端-个人中心"})
    public R<Page<OrderEvaluateVO>> orderEvaluate(@RequestParam("state") Integer state,
                                                  @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        Page<OrderEvaluateVO> list = evaluateClient.evaluateListByUser(loginUser.getUserid(), state, pageNum, pageSize).getData();
        if (null != list) {
            // 数据封装,减少循环io
            List<Integer> ids = list.getRecords().stream().map(data -> data.getOrderInfo().getServeId()).collect(Collectors.toList());
            if (!ids.isEmpty()) {
                List<RecoveryServe> serveList = recoveryServeService.lambdaQuery()
                        .in(RecoveryServe::getId, ids)
                        .eq(RecoveryServe::getIsDelete, 0).list();
                Map<Integer, RecoveryServe> map = serveList.stream().collect(Collectors.
                        toMap(RecoveryServe::getId, data -> data));
                for (OrderEvaluateVO data : list.getRecords()) {
                    Integer serveId = data.getOrderInfo().getServeId();
                    RecoveryServe recoveryServe = map.get(serveId);
                    if (null != recoveryServe) {
                        EvaluateOrderInfoVO orderInfo = data.getOrderInfo();
                        orderInfo.setServeName(recoveryServe.getServeName());
                        orderInfo.setServeDescribe(recoveryServe.getServeDescribe());
                        orderInfo.setCover(recoveryServe.getCover());
                    }
                }
            }
        }
        return R.ok(list);
    }
 
    @GetMapping("/conductEvaluation")
    @ApiOperation(value = "进行评价(服务单号)", tags = {"用户端-个人中心"})
    public R<String> conductEvaluation() {
        return R.ok(RandomUtil.randomNumbers(15));
    }
 
    @PostMapping("/submitEvaluation")
    @ApiOperation(value = "提交评价", tags = {"用户端-个人中心"})
    public R<String> submitEvaluation(@RequestBody @Validated OrderEvaluateRequest orderEvaluate) {
        Long orderId = orderEvaluate.getOrderId();
        String content = orderEvaluate.getContent();
        Double starRating = orderEvaluate.getStarRating();
        String serveNo = orderEvaluate.getServeNo();
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        boolean save = evaluateClient.evaluateSave(new OrderEvaluateSubmitRequest(orderId, content, starRating,
                serveNo, loginUser.getUserid())).getData();
        return save ? R.ok() : R.fail();
    }
 
}