|
|
@@ -11,17 +11,14 @@
|
|
|
package com.yami.shop.api.controller;
|
|
|
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.yami.shop.bean.app.dto.ProdCommDto;
|
|
|
import com.yami.shop.bean.app.param.ProdCommParam;
|
|
|
import com.yami.shop.bean.enums.OrderStatus;
|
|
|
import com.yami.shop.bean.model.Order;
|
|
|
import com.yami.shop.bean.model.ProdComm;
|
|
|
import com.yami.shop.common.exception.GlobalException;
|
|
|
import com.yami.shop.common.util.PageParam;
|
|
|
-import com.yami.shop.security.api.util.SecurityUtils;
|
|
|
-import com.yami.shop.service.OrderItemService;
|
|
|
import com.yami.shop.service.OrderService;
|
|
|
import com.yami.shop.service.ProdCommService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
@@ -31,54 +28,42 @@ import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
@RestController
|
|
|
-@RequestMapping("/p/prodComm")
|
|
|
+//@RequestMapping("/p/prodComm")
|
|
|
+@RequestMapping("/prodComm")
|
|
|
@Api(tags = "评论接口")
|
|
|
@AllArgsConstructor
|
|
|
public class ProdCommController {
|
|
|
|
|
|
private final ProdCommService prodCommService;
|
|
|
|
|
|
- private final OrderItemService orderItemService;
|
|
|
-
|
|
|
private final OrderService orderService;
|
|
|
|
|
|
- @GetMapping("/prodCommPageByUser")
|
|
|
- @ApiOperation(value = "根据用户返回评论分页数据", notes = "传入页码")
|
|
|
- public ResponseEntity<IPage<ProdCommDto>> getProdCommPage(PageParam page) {
|
|
|
- return ResponseEntity.ok(prodCommService.getProdCommDtoPageByUserId(page, SecurityUtils.getUser().getUserId()));
|
|
|
- }
|
|
|
-
|
|
|
@PostMapping
|
|
|
@ApiOperation(value = "添加评论")
|
|
|
public ResponseEntity<Void> saveProdCommPage(@Valid @RequestBody ProdCommParam prodCommParam) {
|
|
|
- Long orderItemId = prodCommParam.getOrderItemId();
|
|
|
- Order orderServiceById = orderService.getById(orderItemId);
|
|
|
- if (orderServiceById == null) {
|
|
|
- throw new GlobalException("订单项不存在");
|
|
|
+ List<ProdComm> commList = prodCommService.list(
|
|
|
+ new LambdaQueryWrapper<ProdComm>().eq(ProdComm::getOrderNumber, prodCommParam.getOrderNumber()));
|
|
|
+ if (!commList.isEmpty()) {
|
|
|
+ throw new GlobalException("该订单已评论...");
|
|
|
}
|
|
|
- if (Objects.equals(orderServiceById.getCommSts(), 1)) {
|
|
|
- throw new GlobalException("该订单项已评论,请勿重复评论");
|
|
|
+ Order order = orderService.getOrderByOrderNumber(prodCommParam.getOrderNumber());
|
|
|
+ if (order == null) {
|
|
|
+ throw new GlobalException("订单不存在");
|
|
|
}
|
|
|
-
|
|
|
- String userId = SecurityUtils.getUser().getUserId();
|
|
|
- Order order = orderService.getOrderByOrderNumberAndUserId(orderServiceById.getOrderNumber(),userId, true);
|
|
|
if (!Objects.equals(order.getHbOrderStatus(), OrderStatus.SUCCESS.value())) {
|
|
|
throw new GlobalException("请确认收货后再进行评论");
|
|
|
}
|
|
|
-
|
|
|
- prodCommService.comm(orderServiceById, prodCommParam);
|
|
|
+ prodCommService.comm(order, prodCommParam);
|
|
|
return ResponseEntity.ok().build();
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/getProdComment")
|
|
|
- @ApiOperation(value = "根据itemId获取评论", notes = "根据itemId获取评论")
|
|
|
- public ResponseEntity<ProdComm> getProdComment(Long orderItemId) {
|
|
|
- ProdComm prodComm = prodCommService.getOne(new LambdaUpdateWrapper<ProdComm>()
|
|
|
- .eq(ProdComm::getOrderItemId, orderItemId)
|
|
|
- .eq(ProdComm::getUserId,SecurityUtils.getUser().getUserId()));
|
|
|
- return ResponseEntity.ok(prodComm);
|
|
|
+ @GetMapping("/commList")
|
|
|
+ @ApiOperation(value = "商品详情-查看商品评价-评价(0好评 1中评 2差评 3有图)")
|
|
|
+ public ResponseEntity<IPage<ProdComm>> commList(PageParam<ProdComm> page, Long skuId, Integer commStatus) {
|
|
|
+ return ResponseEntity.ok(prodCommService.commList(page,skuId,commStatus));
|
|
|
}
|
|
|
}
|