|
|
@@ -18,12 +18,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.yami.shop.bean.app.dto.ProdCommDataDto;
|
|
|
import com.yami.shop.bean.app.dto.ProdCommDto;
|
|
|
import com.yami.shop.bean.app.param.ProdCommParam;
|
|
|
+import com.yami.shop.bean.model.Order;
|
|
|
import com.yami.shop.bean.model.OrderItem;
|
|
|
import com.yami.shop.bean.model.ProdComm;
|
|
|
import com.yami.shop.common.util.Arith;
|
|
|
import com.yami.shop.common.util.HttpContextUtils;
|
|
|
import com.yami.shop.common.util.IPHelper;
|
|
|
import com.yami.shop.dao.OrderItemMapper;
|
|
|
+import com.yami.shop.dao.OrderMapper;
|
|
|
import com.yami.shop.dao.ProdCommMapper;
|
|
|
import com.yami.shop.service.ProdCommService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -31,7 +33,9 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 商品评论
|
|
|
@@ -47,6 +51,8 @@ public class ProdCommServiceImpl extends ServiceImpl<ProdCommMapper, ProdComm> i
|
|
|
|
|
|
private final OrderItemMapper orderItemMapper;
|
|
|
|
|
|
+ private final OrderMapper orderMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public ProdCommDataDto getProdCommDataByProdId(Long prodId) {
|
|
|
ProdCommDataDto prodCommDataDto=prodCommMapper.getProdCommDataByProdId(prodId);
|
|
|
@@ -86,37 +92,40 @@ public class ProdCommServiceImpl extends ServiceImpl<ProdCommMapper, ProdComm> i
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void comm(OrderItem orderItem, ProdCommParam prodCommParam) {
|
|
|
- // 插入评论
|
|
|
- ProdComm prodComm = new ProdComm();
|
|
|
- prodComm.setProdId(orderItem.getProdId());
|
|
|
- prodComm.setOrderItemId(orderItem.getOrderItemId());
|
|
|
- prodComm.setUserId(orderItem.getUserId());
|
|
|
- prodComm.setScore(prodCommParam.getScore());
|
|
|
- prodComm.setContent(prodCommParam.getContent());
|
|
|
+ public void comm(Order order, ProdCommParam prodCommParam) {
|
|
|
+ List<OrderItem> listByOrderNumber = orderItemMapper.getListByOrderNumber(order.getOrderNumber());
|
|
|
+ listByOrderNumber.forEach(orderItem -> {
|
|
|
+ // 插入评论
|
|
|
+ ProdComm prodComm = new ProdComm();
|
|
|
+ prodComm.setProdId(orderItem.getProdId());
|
|
|
+ prodComm.setOrderItemId(orderItem.getOrderItemId());
|
|
|
+ prodComm.setUserId(order.getUserId());
|
|
|
+ prodComm.setScore(prodCommParam.getScore());
|
|
|
+ prodComm.setContent(prodCommParam.getContent());
|
|
|
// prodComm.setPics(prodCommParam.getPics());
|
|
|
- prodComm.setPics(StrUtil.isBlank(prodCommParam.getPics()) ?null:prodCommParam.getPics());
|
|
|
- prodComm.setIsAnonymous(prodCommParam.getIsAnonymous());
|
|
|
- prodComm.setRecTime(new Date());
|
|
|
- // 平台不需要控评
|
|
|
- prodComm.setStatus(1);
|
|
|
- prodComm.setPostip(IPHelper.getIpAddr());
|
|
|
- // 好评
|
|
|
- if (Objects.equals(prodComm.getScore(), 5) || Objects.equals(prodComm.getScore(), 4)) {
|
|
|
- prodComm.setEvaluate(0);
|
|
|
- }
|
|
|
- // 中评
|
|
|
- else if(Objects.equals(prodComm.getScore(), 3)) {
|
|
|
- prodComm.setEvaluate(1);
|
|
|
- }
|
|
|
- // 差评
|
|
|
- else if(Objects.equals(prodComm.getScore(), 1) || Objects.equals(prodComm.getScore(), 2)) {
|
|
|
- prodComm.setEvaluate(2);
|
|
|
- }
|
|
|
- prodCommMapper.insert(prodComm);
|
|
|
+ prodComm.setPics(StrUtil.isBlank(prodCommParam.getPics()) ?null:prodCommParam.getPics());
|
|
|
+ prodComm.setIsAnonymous(prodCommParam.getIsAnonymous());
|
|
|
+ prodComm.setRecTime(new Date());
|
|
|
+ // 平台不需要控评
|
|
|
+ prodComm.setStatus(1);
|
|
|
+ prodComm.setPostip(IPHelper.getIpAddr());
|
|
|
+ // 好评
|
|
|
+ if (Objects.equals(prodComm.getScore(), 5) || Objects.equals(prodComm.getScore(), 4)) {
|
|
|
+ prodComm.setEvaluate(0);
|
|
|
+ }
|
|
|
+ // 中评
|
|
|
+ else if(Objects.equals(prodComm.getScore(), 3)) {
|
|
|
+ prodComm.setEvaluate(1);
|
|
|
+ }
|
|
|
+ // 差评
|
|
|
+ else if(Objects.equals(prodComm.getScore(), 1) || Objects.equals(prodComm.getScore(), 2)) {
|
|
|
+ prodComm.setEvaluate(2);
|
|
|
+ }
|
|
|
+ prodCommMapper.insert(prodComm);
|
|
|
+ });
|
|
|
|
|
|
// 更新订单项评论状态
|
|
|
- orderItem.setCommSts(1);
|
|
|
- orderItemMapper.updateById(orderItem);
|
|
|
+ order.setCommSts(1);
|
|
|
+ orderMapper.updateById(order);
|
|
|
}
|
|
|
}
|