Browse Source

Merge remote-tracking branch 'origin/master'

wangming 1 day ago
parent
commit
b03d8e296b

+ 32 - 30
yami-shop-api/src/main/java/com/yami/shop/api/config/SwaggerConfiguration.java

@@ -13,6 +13,8 @@ package com.yami.shop.api.config;
 import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+
+import org.springframework.context.annotation.Profile;
 import springfox.documentation.builders.ApiInfoBuilder;
 import springfox.documentation.builders.ParameterBuilder;
 import springfox.documentation.builders.PathSelectors;
@@ -37,35 +39,35 @@ import java.util.List;
 @EnableSwagger2
 @EnableKnife4j
 public class SwaggerConfiguration {
-	@Bean
-	public Docket createRestApi() {
-		ParameterBuilder t = new ParameterBuilder();
-		ParameterBuilder ticketPar = new ParameterBuilder();
-		List<Parameter> pars = new ArrayList<Parameter>();
-		ticketPar.name("authorization").description("authorization 拼接: bearer")//Token 以及Authorization 为自定义的参数,session保存的名字是哪个就可以写成那个
-				.modelRef(new ModelRef("string")).parameterType("header")
-				.required(true).build(); //header中的ticket参数非必填,传空也可以
-//		t.name("t").description("时间戳")//Token 以及Authorization 为自定义的参数,session保存的名字是哪个就可以写成那个
-//				.modelRef(new ModelRef("string")).parameterType("query")
-//				.required(true).build(); //header中的ticket参数非必填,传空也可以
-		pars.add(t.build());
-		return new Docket(DocumentationType.SWAGGER_2)
-				.apiInfo(apiInfo())
-				.select()
-				.apis(RequestHandlerSelectors.basePackage("com.yami.shop.api.controller"))
-				.paths(PathSelectors.any())
-				.build()
-				.globalOperationParameters(pars);
-	}
+    @Bean
+    public Docket createRestApi() {
+        ParameterBuilder t = new ParameterBuilder();
+        ParameterBuilder ticketPar = new ParameterBuilder();
+        List<Parameter> pars = new ArrayList<Parameter>();
+        ticketPar.name("authorization").description("authorization 拼接: bearer")//Token 以及Authorization 为自定义的参数,session保存的名字是哪个就可以写成那个
+                .modelRef(new ModelRef("string")).parameterType("header")
+                .required(true).build(); //header中的ticket参数非必填,传空也可以
+        t.name("t").description("时间戳")//Token 以及Authorization 为自定义的参数,session保存的名字是哪个就可以写成那个
+                .modelRef(new ModelRef("string")).parameterType("query")
+                .required(true).build(); //header中的ticket参数非必填,传空也可以
+        pars.add(t.build());
+        return new Docket(DocumentationType.SWAGGER_2)
+                .apiInfo(apiInfo())
+                .select()
+                .apis(RequestHandlerSelectors.basePackage("com.yami.shop.api.controller"))
+                .paths(PathSelectors.any())
+                .build()
+                .globalOperationParameters(pars);
+    }
 
-	 @Bean
-	 public ApiInfo apiInfo() {
-	     return new ApiInfoBuilder()
-	     .title("市民请集合用户端接口文档")
-	     .description("市民请集合用户端接口文档")
-	     .termsOfServiceUrl("")
-	     .contact(new Contact("","", ""))
-	     .version("1.0")
-	     .build();
-	 }
+    @Bean
+    public ApiInfo apiInfo() {
+        return new ApiInfoBuilder()
+                .title("市民请集合用户端接口文档")
+                .description("市民请集合用户端接口文档市民请集合用户端接口文档")
+                .termsOfServiceUrl("")
+                .contact(new Contact("","", ""))
+                .version("1.0")
+                .build();
+    }
 }

+ 3 - 0
yami-shop-api/src/main/java/com/yami/shop/api/controller/MyOrderController.java

@@ -13,6 +13,7 @@ package com.yami.shop.api.controller;
 import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.yami.shop.bean.app.dto.*;
 import com.yami.shop.bean.enums.OrderStatus;
 import com.yami.shop.bean.enums.RefundStatusEnum;
@@ -86,6 +87,7 @@ public class MyOrderController {
         OrderShopDto orderShopDto = new OrderShopDto();
 
         Order order = orderService.getOrderByOrderNumberAndUserId(orderNumber, userId, true);
+//        Order order = orderService.getOne(Wrappers.<Order>lambdaQuery().eq(Order::getOrderNumber, orderNumber));
         SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日$HH:mm");
         if (null != order.getPayTime()) {
             // 转换为 LocalDateTime 并增加 1 小时
@@ -200,6 +202,7 @@ public class MyOrderController {
         }
         orderShopDto.setTotal(total);
         orderShopDto.setTotalNum(totalNum);
+        orderShopDto.setCommSts(order.getCommSts());
 
         return ResponseEntity.ok(orderShopDto);
     }

+ 6 - 6
yami-shop-api/src/main/java/com/yami/shop/api/controller/ProdCommController.java

@@ -60,23 +60,23 @@ public class ProdCommController {
     public ResponseEntity<Void> saveProdCommPage(@Valid @RequestBody ProdCommParam prodCommParam) {
         Long orderItemId = prodCommParam.getOrderItemId();
 
-        OrderItem orderItem = orderItemService.getById(orderItemId);
-        if (orderItem == null) {
+        Order orderServiceById = orderService.getById(orderItemId);
+        if (orderServiceById == null) {
             throw new GlobalException("订单项不存在");
         }
-        if (Objects.equals(orderItem.getCommSts(), 1)) {
-            throw new GlobalException("订单项已评论,请勿重复评论");
+        if (Objects.equals(orderServiceById.getCommSts(), 1)) {
+            throw new GlobalException("订单项已评论,请勿重复评论");
         }
 
         String userId = SecurityUtils.getUser().getUserId();
 
-        Order order = orderService.getOrderByOrderNumberAndUserId(orderItem.getOrderNumber(),userId, true);
+        Order order = orderService.getOrderByOrderNumberAndUserId(orderServiceById.getOrderNumber(),userId, true);
 
         if (!Objects.equals(order.getHbOrderStatus(), OrderStatus.SUCCESS.value())) {
             throw new GlobalException("请确认收货后再进行评论");
         }
 
-        prodCommService.comm(orderItem, prodCommParam);
+        prodCommService.comm(orderServiceById, prodCommParam);
 
         return ResponseEntity.ok().build();
     }

+ 5 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/app/dto/MyOrderDto.java

@@ -82,4 +82,9 @@ public class MyOrderDto {
     @ApiModelProperty(value = "配送类型 1:快递 3:及时配送")
     private Integer dvyType;
 
+    /**
+     * 评论状态: 0 未评价  1 已评价
+     */
+    @ApiModelProperty(value = "评论状态: 0 未评价  1 已评价")
+    private Integer commSts;
 }

+ 6 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/app/dto/OrderShopDto.java

@@ -139,4 +139,10 @@ public class OrderShopDto implements Serializable {
 
     @ApiModelProperty(value = "订单预计送达时间", required = true, example = "10:40")
     private String estimatedTime;
+
+    /**
+     * 评论状态: 0 未评价  1 已评价
+     */
+    @ApiModelProperty(value = "评论状态: 0 未评价  1 已评价")
+    private Integer commSts;
 }

+ 4 - 1
yami-shop-bean/src/main/java/com/yami/shop/bean/model/Order.java

@@ -246,7 +246,10 @@ public class Order implements Serializable {
      */
     @TableField(exist = false)
     private Integer score;
-
+    /**
+     * 评论状态: 0 未评价  1 已评价
+     */
+    private Integer commSts;
     /**
      * 退款状态
      */

+ 2 - 1
yami-shop-service/src/main/java/com/yami/shop/service/ProdCommService.java

@@ -17,6 +17,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 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;
 
@@ -43,5 +44,5 @@ public interface ProdCommService extends IService<ProdComm> {
      * @param orderItem
      * @param prodCommParam
      */
-    void comm(OrderItem orderItem, ProdCommParam prodCommParam);
+    void comm(Order order, ProdCommParam prodCommParam);
 }

+ 38 - 29
yami-shop-service/src/main/java/com/yami/shop/service/impl/ProdCommServiceImpl.java

@@ -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);
     }
 }

+ 1 - 0
yami-shop-service/src/main/resources/mapper/OrderMapper.xml

@@ -638,6 +638,7 @@
         o.offset_points,
         o.pay_time,
         o.dvy_type,
+        o.comm_sts AS commSts,
         (SELECT r.refund_type FROM tz_order_refund r WHERE r.order_id =o.order_id ORDER BY r.update_time DESC LIMIT 0,1) AS refund_type,
         (SELECT r.return_money_sts FROM tz_order_refund r WHERE r.order_id =o.order_id ORDER BY r.update_time DESC LIMIT 0,1) AS return_money_sts,
         oi.pic,oi.price,oi.prod_name,oi.pic,oi.sku_name,ifnull(oi.use_score,0) as use_score,oi.prod_id,oi.rec_time,oi.prod_count,oi.order_item_id,oi.comm_sts,