| | |
| | | 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.core.exception.GlobalException; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | 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.Evaluate; |
| | | import com.ruoyi.user.entity.Order; |
| | | import com.ruoyi.user.entity.RecoveryServe; |
| | | import com.ruoyi.user.request.OrderEvaluateRequest; |
| | | import com.ruoyi.user.service.EvaluateService; |
| | | import com.ruoyi.user.service.OrderService; |
| | | import com.ruoyi.user.vo.OrderEvaluateVO; |
| | | 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.math.BigDecimal; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | public class EvaluateController { |
| | | |
| | | @Resource |
| | | private EvaluateService evaluateService; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private OrderService orderService; |
| | | private EvaluateClient evaluateClient; |
| | | @Resource |
| | | private RecoveryServeService recoveryServeService; |
| | | |
| | | @GetMapping("/orderEvaluate") |
| | | @ApiOperation(value = "订单评价列表", tags = {"用户端-个人中心"}) |
| | | public R<List<OrderEvaluateVO>> orderEvaluate() { |
| | | 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("登录失效!"); |
| | | } |
| | | return R.ok(evaluateService.orderEvaluate(loginUser.getUserid())); |
| | | 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.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") |
| | |
| | | @PostMapping("/submitEvaluation") |
| | | @ApiOperation(value = "提交评价", tags = {"用户端-个人中心"}) |
| | | public R<String> submitEvaluation(@RequestBody @Validated OrderEvaluateRequest orderEvaluate) { |
| | | Integer orderId = orderEvaluate.getOrderId(); |
| | | Long orderId = orderEvaluate.getOrderId(); |
| | | String content = orderEvaluate.getContent(); |
| | | BigDecimal starRating = orderEvaluate.getStarRating(); |
| | | Double starRating = orderEvaluate.getStarRating(); |
| | | String serveNo = orderEvaluate.getServeNo(); |
| | | LoginUserInfo loginUser = tokenService.getLoginUserByUser(); |
| | | if (null == loginUser) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |
| | | // 订单详情 |
| | | Order order = orderService.lambdaQuery().eq(Order::getId, orderId).eq(Order::getIsDelete, 0).one(); |
| | | if (null == order) { |
| | | throw new GlobalException("订单异常!"); |
| | | } |
| | | Evaluate evaluate = new Evaluate(); |
| | | evaluate.setUserId(loginUser.getUserid()); |
| | | evaluate.setOrderId(orderId); |
| | | evaluate.setContent(content); |
| | | evaluate.setWorkerId(order.getServerId()); |
| | | evaluate.setStarRating(starRating); |
| | | evaluate.setServeNo(serveNo); |
| | | boolean save = evaluateService.save(evaluate); |
| | | boolean save = evaluateClient.evaluateSave(new OrderEvaluateSubmitRequest(orderId, content, starRating, |
| | | serveNo, loginUser.getUserid())).getData(); |
| | | return save ? R.ok() : R.fail(); |
| | | } |
| | | |