Bladeren bron

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/chelvc/cloud/maintain/controller/GoodsController.java
liude 1 jaar geleden
bovenliggende
commit
6c968e4ba1

+ 14 - 1
pom.xml

@@ -20,8 +20,9 @@
         <vehicle-api.version>1.0.0-SNAPSHOT</vehicle-api.version>
         <framework-redis.version>1.0.0-RELEASE</framework-redis.version>
         <framework-upload.version>1.0.0-RELEASE</framework-upload.version>
+        <framework-oauth.version>1.0.0-RELEASE</framework-oauth.version>
         <framework-security.version>1.0.0-RELEASE</framework-security.version>
-        <framework-database.version>1.0.0-RELEASE</framework-database.version>
+        <framework-location.version>1.0.0-RELEASE</framework-location.version>
     </properties>
 
     <dependencies>
@@ -49,11 +50,23 @@
             <version>${framework-upload.version}</version>
             <optional>true</optional>
         </dependency>
+        <dependency>
+            <groupId>com.chelvc.framework</groupId>
+            <artifactId>framework-oauth</artifactId>
+            <version>${framework-oauth.version}</version>
+            <optional>true</optional>
+        </dependency>
         <dependency>
             <groupId>com.chelvc.framework</groupId>
             <artifactId>framework-security</artifactId>
             <version>${framework-security.version}</version>
             <optional>true</optional>
         </dependency>
+        <dependency>
+            <groupId>com.chelvc.framework</groupId>
+            <artifactId>framework-location</artifactId>
+            <version>${framework-location.version}</version>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
 </project>

+ 44 - 0
src/main/java/com/chelvc/cloud/maintain/controller/CommentController.java

@@ -0,0 +1,44 @@
+package com.chelvc.cloud.maintain.controller;
+
+import java.util.List;
+import javax.validation.Valid;
+import javax.validation.constraints.Min;
+
+import com.chelvc.cloud.maintain.copier.CommentCopier;
+import com.chelvc.cloud.maintain.vo.CommentVO;
+import com.chelvc.cloud.vehicle.api.param.CommentQueryParam;
+import com.chelvc.cloud.vehicle.api.service.CommentService;
+import com.chelvc.framework.base.annotation.UnifiedResponseBody;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 商品评价接口
+ *
+ * @author Woody
+ * @date 2023/8/7
+ */
+@Validated
+@RestController
+@UnifiedResponseBody
+public class CommentController {
+    @DubboReference
+    private CommentService commentService;
+
+    /**
+     * 获取商品评价列表
+     *
+     * @param goodsId 商品ID
+     * @param param   查询参数
+     * @return 商品评价列表
+     */
+    @GetMapping("/goods/{goodsId}/comments")
+    public List<CommentVO> listGoodsComments(
+            @PathVariable("goodsId") @Min(value = 1, message = "商品ID不能小于1") Long goodsId,
+            @Valid CommentQueryParam param) {
+        return CommentCopier.INSTANCE.copying(this.commentService.listGoodsComments(goodsId, param));
+    }
+}

+ 27 - 22
src/main/java/com/chelvc/cloud/maintain/controller/GoodsController.java

@@ -1,23 +1,26 @@
 package com.chelvc.cloud.maintain.controller;
-import com.chelvc.cloud.vehicle.api.dto.GoodsDTO;
-import com.chelvc.cloud.vehicle.api.param.GoodsPagingParam;
+
+import java.util.List;
+import javax.validation.Valid;
+import javax.validation.constraints.Min;
+
+import com.chelvc.cloud.maintain.copier.GoodsCopier;
+import com.chelvc.cloud.maintain.vo.GoodsDetailVO;
+import com.chelvc.cloud.maintain.vo.SimpleGoodsVO;
+import com.chelvc.cloud.vehicle.api.param.GoodsQueryParam;
 import com.chelvc.cloud.vehicle.api.service.GoodsService;
 import com.chelvc.framework.base.annotation.UnifiedResponseBody;
-import com.chelvc.framework.base.model.Pagination;
-import com.chelvc.framework.base.util.ErrorUtils;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RestController;
-import javax.validation.Valid;
-import javax.validation.constraints.Min;
 
 /**
- * 商接口
+ * 商接口
  *
- * @author liude
- * @date 2023/7/20
+ * @author Woody
+ * @date 2023/8/6
  */
 @Validated
 @RestController
@@ -27,25 +30,27 @@ public class GoodsController {
     private GoodsService goodsService;
 
     /**
-     * 获取商品信息
+     * 获取商品详情
      *
-     * @param id 商品主键
-     * @return 商品信息
+     * @param id 商品ID
+     * @return 商品详情
      */
     @GetMapping("/goods/{id}")
-    public GoodsDTO getGoods(@PathVariable("id") @Min(value = 1, message = "商品主键不能小于1") Long id) {
-        GoodsDTO goods = this.goodsService.getGoods(id);
-        ErrorUtils.requireResource(goods, "商品不存在");
-        return goods;
+    public GoodsDetailVO getGoodsDetail(@PathVariable("id") @Min(value = 1, message = "商品ID不能小于1") Long id) {
+        return GoodsCopier.INSTANCE.copying(this.goodsService.getGoodsDetail(id));
     }
+
     /**
-     * 查询商品分页
+     * 获取商家商品列表
      *
-     * @param param 查询参数
-     * @return 商品分页信息
+     * @param merchantId 商家ID
+     * @param param      查询参数
+     * @return 商品信息列表
      */
-    @GetMapping("/goods/paging")
-    public Pagination<GoodsDTO> getGoodsPaging(@Valid GoodsPagingParam param) {
-        return this.goodsService.getGoodsPaging(param);
+    @GetMapping("/merchant/{merchantId}/goods")
+    public List<SimpleGoodsVO> listMerchantSimpleGoods(
+            @PathVariable("merchantId") @Min(value = 1, message = "商家ID不能小于1") Long merchantId,
+            @Valid GoodsQueryParam param) {
+        return GoodsCopier.INSTANCE.copying(this.goodsService.listMerchantSimpleGoods(merchantId, param));
     }
 }

+ 36 - 19
src/main/java/com/chelvc/cloud/maintain/controller/IndexController.java

@@ -1,23 +1,31 @@
 package com.chelvc.cloud.maintain.controller;
 
+import java.util.List;
 import javax.validation.Valid;
 
 import com.chelvc.cloud.maintain.copier.CategoryCopier;
 import com.chelvc.cloud.maintain.copier.MerchantCopier;
-import com.chelvc.cloud.maintain.param.CustomerIndexParam;
 import com.chelvc.cloud.maintain.vo.ConfigurationVO;
 import com.chelvc.cloud.maintain.vo.CustomerIndexVO;
 import com.chelvc.cloud.uc.api.service.UsageService;
-import com.chelvc.cloud.vehicle.api.param.NearbyQueryParam;
+import com.chelvc.cloud.vehicle.api.dto.CategoryDTO;
+import com.chelvc.cloud.vehicle.api.dto.MerchantDTO;
+import com.chelvc.cloud.vehicle.api.param.LocationQueryParam;
 import com.chelvc.cloud.vehicle.api.service.CategoryService;
 import com.chelvc.cloud.vehicle.api.service.MerchantService;
 import com.chelvc.framework.base.annotation.UnifiedResponseBody;
-import com.chelvc.framework.base.context.ApplicationContextHolder;
+import com.chelvc.framework.base.context.SessionContextHolder;
+import com.chelvc.framework.location.Address;
+import com.chelvc.framework.location.LocationHandler;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
@@ -30,7 +38,10 @@ import org.springframework.web.bind.annotation.RestController;
 @Validated
 @RestController
 @UnifiedResponseBody
+@RequiredArgsConstructor(onConstructor = @__(@Autowired))
 public class IndexController {
+    private final LocationHandler locationHandler;
+
     @DubboReference
     private UsageService usageService;
 
@@ -40,15 +51,6 @@ public class IndexController {
     @DubboReference
     private MerchantService merchantService;
 
-    /**
-     * 获取附近距离配置
-     *
-     * @return 距离(米)
-     */
-    private int getNearbyDistance() {
-        return ApplicationContextHolder.getSafeProperty("platform.nearby.distance", int.class, 20000);
-    }
-
     /**
      * 获取系统配置
      *
@@ -59,11 +61,25 @@ public class IndexController {
         return ConfigurationVO.builder().build();
     }
 
+    /**
+     * 获取当前位置
+     *
+     * @param point 经纬度(如:30.563443,104.009457),如果为空则根据IP获取位置信息
+     * @return 位置信息
+     */
+    @GetMapping("/location")
+    public Address getLocation(@RequestParam(value = "point", required = false) String point) {
+        if (StringUtils.isEmpty(point)) {
+            return this.locationHandler.ip2address(SessionContextHolder.getHost());
+        }
+        return this.locationHandler.location2address(point);
+    }
+
     /**
      * 刷新用户使用记录
      */
     @PostMapping("/usage")
-    public void using() {
+    public void refreshUsage() {
         this.usageService.refresh();
     }
 
@@ -74,28 +90,29 @@ public class IndexController {
      * @return 首页信息
      */
     @GetMapping("/customer/index")
-    public CustomerIndexVO getCustomerIndex(@Valid CustomerIndexParam param) {
-        NearbyQueryParam query = NearbyQueryParam.builder().longitude(param.getLongitude())
-                .latitude(param.getLatitude()).distance(this.getNearbyDistance()).build();
+    public CustomerIndexVO getCustomerIndex(@Valid LocationQueryParam param) {
         CustomerIndexVO index = CustomerIndexVO.builder().build();
 
         // 加载推荐分类列表
         try {
-            index.setCategories(CategoryCopier.INSTANCE.copying(this.categoryService.listRecommendCategories(15)));
+            List<CategoryDTO> categories = this.categoryService.listRecommendCategories(15);
+            index.setCategories(CategoryCopier.INSTANCE.copying(categories));
         } catch (Exception e) {
             log.error("Load recommend categories failed", e);
         }
 
         // 加载附近商家列表
         try {
-            index.setNears(MerchantCopier.INSTANCE.copying(this.merchantService.listNearbyMerchants(query, 4)));
+            List<MerchantDTO> merchants = this.merchantService.listNearbyMerchants(param, 4);
+            index.setNears(MerchantCopier.INSTANCE.copying(merchants));
         } catch (Exception e) {
             log.error("Load nearby merchants failed", e);
         }
 
         // 加载推荐商家列表
         try {
-            index.setRecommends(MerchantCopier.INSTANCE.copying(this.merchantService.listRecommendMerchants(query, 4)));
+            List<MerchantDTO> merchants = this.merchantService.listRecommendMerchants(param, 4);
+            index.setRecommends(MerchantCopier.INSTANCE.copying(merchants));
         } catch (Exception e) {
             log.error("Load recommend merchants failed", e);
         }

+ 32 - 0
src/main/java/com/chelvc/cloud/maintain/copier/CommentCopier.java

@@ -0,0 +1,32 @@
+package com.chelvc.cloud.maintain.copier;
+
+import java.util.Collection;
+import java.util.List;
+
+import com.chelvc.cloud.maintain.vo.CommentVO;
+import com.chelvc.cloud.vehicle.api.dto.CommentDTO;
+import org.mapstruct.Builder;
+import org.mapstruct.Mapper;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * 评价信息拷贝接口
+ *
+ * @author Woody
+ * @date 2023/8/7
+ */
+@Mapper(builder = @Builder(disableBuilder = true))
+public interface CommentCopier {
+    /**
+     * 对象拷贝接口实例
+     */
+    CommentCopier INSTANCE = Mappers.getMapper(CommentCopier.class);
+
+    /**
+     * 评价信息拷贝
+     *
+     * @param comments 评价信息集合
+     * @return 评价信息列表
+     */
+    List<CommentVO> copying(Collection<CommentDTO> comments);
+}

+ 42 - 0
src/main/java/com/chelvc/cloud/maintain/copier/GoodsCopier.java

@@ -0,0 +1,42 @@
+package com.chelvc.cloud.maintain.copier;
+
+import java.util.Collection;
+import java.util.List;
+
+import com.chelvc.cloud.maintain.vo.GoodsDetailVO;
+import com.chelvc.cloud.maintain.vo.SimpleGoodsVO;
+import com.chelvc.cloud.vehicle.api.dto.GoodsDTO;
+import com.chelvc.cloud.vehicle.api.dto.GoodsDetailDTO;
+import org.mapstruct.Builder;
+import org.mapstruct.Mapper;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * 商品信息拷贝接口
+ *
+ * @author Woody
+ * @date 2023/8/6
+ */
+@Mapper(builder = @Builder(disableBuilder = true))
+public interface GoodsCopier {
+    /**
+     * 对象拷贝接口实例
+     */
+    GoodsCopier INSTANCE = Mappers.getMapper(GoodsCopier.class);
+
+    /**
+     * 商品信息拷贝
+     *
+     * @param detail 商品详情
+     * @return 商品信息
+     */
+    GoodsDetailVO copying(GoodsDetailDTO detail);
+
+    /**
+     * 商品信息拷贝
+     *
+     * @param goods 商品信息集合
+     * @return 商品信息列表
+     */
+    List<SimpleGoodsVO> copying(Collection<GoodsDTO> goods);
+}

+ 5 - 0
src/main/java/com/chelvc/cloud/maintain/vo/CategoryVO.java

@@ -29,6 +29,11 @@ public class CategoryVO implements Serializable {
      */
     private CategoryType type;
 
+    /**
+     * 分类图标
+     */
+    private String icon;
+
     /**
      * 分类名称
      */

+ 53 - 0
src/main/java/com/chelvc/cloud/maintain/vo/CommentVO.java

@@ -0,0 +1,53 @@
+package com.chelvc.cloud.maintain.vo;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+import com.chelvc.framework.base.model.File;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.SuperBuilder;
+
+/**
+ * 商品评价信息
+ *
+ * @author Woody
+ * @date 2023/8/6
+ */
+@Data
+@SuperBuilder
+@NoArgsConstructor
+@AllArgsConstructor
+public class CommentVO implements Serializable {
+    /**
+     * 评价ID
+     */
+    private Long id;
+
+    /**
+     * 用户信息
+     */
+    private UserVO user;
+
+    /**
+     * 评价打分
+     */
+    private Double score;
+
+    /**
+     * 评价内容
+     */
+    private String content;
+
+    /**
+     * 附件列表
+     */
+    private List<File> attachments;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+}

+ 57 - 0
src/main/java/com/chelvc/cloud/maintain/vo/CouponVO.java

@@ -0,0 +1,57 @@
+package com.chelvc.cloud.maintain.vo;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import com.chelvc.cloud.vehicle.api.constant.CouponType;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.SuperBuilder;
+
+/**
+ * 优惠券信息
+ *
+ * @author Woody
+ * @date 2023/8/6
+ */
+@Data
+@SuperBuilder
+@NoArgsConstructor
+@AllArgsConstructor
+public class CouponVO implements Serializable {
+    /**
+     * 优惠券ID
+     */
+    private Long id;
+
+    /**
+     * 优惠券类型
+     */
+    private CouponType type;
+
+    /**
+     * 优惠券名称
+     */
+    private String name;
+
+    /**
+     * 优惠金额
+     */
+    private Double amount;
+
+    /**
+     * 满减金额
+     */
+    private Double reduce;
+
+    /**
+     * 优惠折扣
+     */
+    private Double discount;
+
+    /**
+     * 过期时间
+     */
+    private Date expiration;
+}

+ 36 - 0
src/main/java/com/chelvc/cloud/maintain/vo/GoodsDetailVO.java

@@ -0,0 +1,36 @@
+package com.chelvc.cloud.maintain.vo;
+
+import java.io.Serializable;
+import java.util.List;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.SuperBuilder;
+
+/**
+ * 商品详情
+ *
+ * @author Woody
+ * @date 2023/8/6
+ */
+@Data
+@SuperBuilder
+@NoArgsConstructor
+@AllArgsConstructor
+public class GoodsDetailVO implements Serializable {
+    /**
+     * 商品信息
+     */
+    private GoodsVO goods;
+
+    /**
+     * 优惠券列表
+     */
+    private List<CouponVO> coupons;
+
+    /**
+     * 评价列表
+     */
+    private List<CommentVO> comments;
+}

+ 57 - 0
src/main/java/com/chelvc/cloud/maintain/vo/GoodsVO.java

@@ -0,0 +1,57 @@
+package com.chelvc.cloud.maintain.vo;
+
+import java.io.Serializable;
+import java.util.List;
+
+import com.chelvc.framework.base.model.File;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.SuperBuilder;
+
+/**
+ * 商品信息
+ *
+ * @author Woody
+ * @date 2023/8/6
+ */
+@Data
+@SuperBuilder
+@NoArgsConstructor
+@AllArgsConstructor
+public class GoodsVO implements Serializable {
+    /**
+     * 商品ID
+     */
+    private Long id;
+
+    /**
+     * 商品名称
+     */
+    private String name;
+
+    /**
+     * 商品评分
+     */
+    private Double score;
+
+    /**
+     * 商品原价
+     */
+    private Double originalPrice;
+
+    /**
+     * 优惠价格
+     */
+    private Double specialPrice;
+
+    /**
+     * 商品描述
+     */
+    private String description;
+
+    /**
+     * 轮播图列表
+     */
+    private List<File> banners;
+}

+ 5 - 4
src/main/java/com/chelvc/cloud/maintain/vo/MerchantDetailVO.java

@@ -3,6 +3,7 @@ package com.chelvc.cloud.maintain.vo;
 import java.io.Serializable;
 import java.util.List;
 
+import com.chelvc.cloud.vehicle.api.constant.CategoryType;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -25,12 +26,12 @@ public class MerchantDetailVO implements Serializable {
     private MerchantVO merchant;
 
     /**
-     * 分类列表
+     * 商品列表
      */
-    private List<CategoryVO> categories;
+    private List<SimpleGoodsVO> goods;
 
     /**
-     * 商品信息
+     * 分类类型列表
      */
-    private MerchantGoodsVO goods;
+    private List<CategoryType> categories;
 }

+ 12 - 8
src/main/java/com/chelvc/cloud/maintain/vo/MerchantGoodsVO.java → src/main/java/com/chelvc/cloud/maintain/vo/UserVO.java

@@ -1,7 +1,6 @@
 package com.chelvc.cloud.maintain.vo;
 
 import java.io.Serializable;
-import java.util.List;
 
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -9,23 +8,28 @@ import lombok.NoArgsConstructor;
 import lombok.experimental.SuperBuilder;
 
 /**
- * 商家商品信息
+ * 用户信息
  *
  * @author Woody
- * @date 2023/7/20
+ * @date 2023/8/6
  */
 @Data
 @SuperBuilder
 @NoArgsConstructor
 @AllArgsConstructor
-public class MerchantGoodsVO implements Serializable {
+public class UserVO implements Serializable {
     /**
-     * 商品总数
+     * 用户ID
      */
-    private Integer total;
+    private Long id;
 
     /**
-     * 商品列表
+     * 用户头像
      */
-    private List<SimpleGoodsVO> goods;
+    private String avatar;
+
+    /**
+     * 用户昵称
+     */
+    private String nickname;
 }

+ 4 - 1
src/main/resources/application-dev.yml

@@ -17,10 +17,13 @@ nacos:
     server-addr: 47.108.128.78:6848
 
 platform:
-  security:
+  oauth:
     token:
       secret: oauth.token.secret@chelvc!@#2023
   upload:
     standard:
       path: /home/chelvc/upload
       domain: http://file.chelvc.com
+  location:
+    tencent:
+      key: VPKBZ-CR3CG-R23QE-QK2IY-LNXKZ-GCB34

+ 4 - 1
src/main/resources/application-pre.yml

@@ -17,10 +17,13 @@ nacos:
     server-addr: 127.0.0.1:6848
 
 platform:
-  security:
+  oauth:
     token:
       secret: oauth.token.secret@chelvc!@#2023
   upload:
     standard:
       path: /home/chelvc/upload
       domain: http://file.chelvc.com
+  location:
+    tencent:
+      key: VPKBZ-CR3CG-R23QE-QK2IY-LNXKZ-GCB34

+ 4 - 1
src/main/resources/application-prod.yml

@@ -17,10 +17,13 @@ nacos:
     server-addr: 127.0.0.1:6848
 
 platform:
-  security:
+  oauth:
     token:
       secret: oauth.token.secret@chelvc!@#2023
   upload:
     standard:
       path: /home/chelvc/upload
       domain: http://file.chelvc.com
+  location:
+    tencent:
+      key: VPKBZ-CR3CG-R23QE-QK2IY-LNXKZ-GCB34

+ 4 - 1
src/main/resources/application-test.yml

@@ -17,10 +17,13 @@ nacos:
     server-addr: 127.0.0.1:6848
 
 platform:
-  security:
+  oauth:
     token:
       secret: oauth.token.secret@chelvc!@#2023
   upload:
     standard:
       path: /home/chelvc/upload
       domain: http://file.chelvc.com
+  location:
+    tencent:
+      key: VPKBZ-CR3CG-R23QE-QK2IY-LNXKZ-GCB34

+ 1 - 1
src/main/resources/application.yml

@@ -43,6 +43,6 @@ dubbo:
     retries: 0
 
 platform:
-  security:
+  oauth:
     resource:
       permit: "/**/index,/**/configuration,/**/categories"