From 5295e9cf5e8c192deee79cb2fc112c8e5ed8371c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LI-CCONG=5C=E6=9D=8E=E8=81=AA=E8=81=AA?= <1441652193@qq.com> Date: Mon, 15 Apr 2024 08:39:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=9F=E5=93=81=E4=BA=8C=E7=BA=A7=E7=B1=BB?= =?UTF-8?q?=E7=9B=AE=E5=8A=9F=E8=83=BDv1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cc/yunxi/common/utils/CommonUtil.java | 40 ++++++++++++++++++- .../controller/RecycleStationController.java | 15 ++++--- .../main/java/cc/yunxi/domain/po/Product.java | 4 ++ .../domain/vo/priceproduct/ProductRespVO.java | 12 +++++- .../service/impl/PriceProductServiceImpl.java | 4 ++ .../impl/RecycleStationServiceImpl.java | 15 ++++--- 6 files changed, 73 insertions(+), 17 deletions(-) diff --git a/nxhs-common/src/main/java/cc/yunxi/common/utils/CommonUtil.java b/nxhs-common/src/main/java/cc/yunxi/common/utils/CommonUtil.java index 07a37b2..e3f3445 100644 --- a/nxhs-common/src/main/java/cc/yunxi/common/utils/CommonUtil.java +++ b/nxhs-common/src/main/java/cc/yunxi/common/utils/CommonUtil.java @@ -14,8 +14,7 @@ import java.lang.reflect.Field; import java.math.BigDecimal; import java.math.RoundingMode; import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Random; +import java.util.*; /** * 自定义全局函数 @@ -105,6 +104,43 @@ public class CommonUtil { return field.get(obj); } + /** + * 获取子节点 + * @param parentId + * @param dataList + * @return + */ + public static List getChildrenList(String parentId, List dataList) { + List voList = new ArrayList<>(); + dataList.forEach(v -> { + String pid = (String) obtainField(v, "parentId"); + if (Objects.equals(pid, parentId)) { + String id = (String) obtainField(v, "id"); + List children = getChildrenList(id, dataList); + assignField(v, "children", children); + voList.add(v); + } + }); + return voList; + } + + /** + * 获取父节点 + * @param thisId + * @param dataList + * @param parentList + */ + public static void getParent(String thisId, List dataList, List parentList) { + dataList.forEach(v -> { + String id = (String) obtainField(v, "id"); + if (Objects.equals(id, thisId)) { + parentList.add(v); + String pid = (String) obtainField(v, "parentId"); + getParent(pid, dataList, parentList); + } + }); + } + public static void main(String[] args) { // 121.190912 diff --git a/nxhs-service/src/main/java/cc/yunxi/controller/RecycleStationController.java b/nxhs-service/src/main/java/cc/yunxi/controller/RecycleStationController.java index 9ca66b8..819f6b9 100644 --- a/nxhs-service/src/main/java/cc/yunxi/controller/RecycleStationController.java +++ b/nxhs-service/src/main/java/cc/yunxi/controller/RecycleStationController.java @@ -58,8 +58,9 @@ public class RecycleStationController { }); List recycleStationRespVOList = recycleStationPageVO.getList(); recycleStationRespVOList.forEach(stationRespVO -> { - List produceList = recycleStationService.getStationProduct(stationRespVO.getId()); - stationRespVO.setStationProducts(produceList); + List productList = recycleStationService.getStationProduct(stationRespVO.getId()); + List productTreeList = CommonUtil.getChildrenList(null, productList); + stationRespVO.setStationProducts(productTreeList); }); // 性能优化 todo return CommonResult.success(recycleStationPageVO); } @@ -72,8 +73,9 @@ public class RecycleStationController { RecycleStationRespVO recycleStationRespVO = BeanUtils.copyBean(station, RecycleStationRespVO.class); if (ObjectUtil.isNotEmpty(station)) { recycleStationRespVO = BeanUtils.copyBean(station, RecycleStationRespVO.class); - List produceList = recycleStationService.getStationProduct(station.getId()); - recycleStationRespVO.setStationProducts(produceList); + List productList = recycleStationService.getStationProduct(station.getId()); + List productTreeList = CommonUtil.getChildrenList(null, productList); + recycleStationRespVO.setStationProducts(productTreeList); this.computeStationDistance(recycleStationRespVO, location); } return CommonResult.success(recycleStationRespVO); @@ -83,8 +85,9 @@ public class RecycleStationController { @ApiOperation("回收站废品价格类目") @GetMapping("/price-product") public CommonResult> stationProduct(@RequestParam("stationId") String stationId) { - List stationProduct = recycleStationService.getStationProduct(stationId); - return CommonResult.success(stationProduct); + List productList = recycleStationService.getStationProduct(stationId); + List productTreeList = CommonUtil.getChildrenList(null, productList); + return CommonResult.success(productTreeList); } diff --git a/nxhs-service/src/main/java/cc/yunxi/domain/po/Product.java b/nxhs-service/src/main/java/cc/yunxi/domain/po/Product.java index c2fb831..f7df347 100644 --- a/nxhs-service/src/main/java/cc/yunxi/domain/po/Product.java +++ b/nxhs-service/src/main/java/cc/yunxi/domain/po/Product.java @@ -28,6 +28,10 @@ public class Product { @TableId(value = "id", type = IdType.ASSIGN_ID) private String id; + @ApiModelProperty("父id") + @TableField("parent_id") + private String parentId; + @ApiModelProperty("编码") @TableField("code") private String code; diff --git a/nxhs-service/src/main/java/cc/yunxi/domain/vo/priceproduct/ProductRespVO.java b/nxhs-service/src/main/java/cc/yunxi/domain/vo/priceproduct/ProductRespVO.java index e346542..41395fe 100644 --- a/nxhs-service/src/main/java/cc/yunxi/domain/vo/priceproduct/ProductRespVO.java +++ b/nxhs-service/src/main/java/cc/yunxi/domain/vo/priceproduct/ProductRespVO.java @@ -12,6 +12,7 @@ import lombok.experimental.Accessors; import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.Date; +import java.util.List; /** *

@@ -21,11 +22,14 @@ import java.util.Date; * @author ccongli * @since 2024-03-01 11:15:39 */ -@ApiModel(description = "回收站 Response VO") +@ApiModel(description = "类目 Response VO") @Data @Accessors(chain = true) public class ProductRespVO { + @ApiModelProperty("废品id") + private String id; + @ApiModelProperty("价格id") private String priceId; @@ -58,4 +62,10 @@ public class ProductRespVO { @ApiModelProperty("废品定价时间") private LocalDateTime creatorTime; + + @ApiModelProperty("父id") + private String parentId; + + @ApiModelProperty("子分类") + private List children; } diff --git a/nxhs-service/src/main/java/cc/yunxi/service/impl/PriceProductServiceImpl.java b/nxhs-service/src/main/java/cc/yunxi/service/impl/PriceProductServiceImpl.java index 03adb87..abde12b 100644 --- a/nxhs-service/src/main/java/cc/yunxi/service/impl/PriceProductServiceImpl.java +++ b/nxhs-service/src/main/java/cc/yunxi/service/impl/PriceProductServiceImpl.java @@ -35,6 +35,7 @@ public class PriceProductServiceImpl extends ServiceImpl queryProductList() { LambdaQueryWrapperX wrapperX = new LambdaQueryWrapperX<>(); wrapperX.isNull(Product::getDeleted); + wrapperX.isNull(Product::getParentId); // 只查一级类目 return productMapper.selectList(wrapperX); } @@ -49,4 +50,7 @@ public class PriceProductServiceImpl extends ServiceImpl getStationProduct(String stationId) { QueryWrapper wrapper = new QueryWrapper().eq("a.status", GlobalStatusEnum.VALID); - String priceId = recycleStationPriceMapper.getLatestPriceByStationId(stationId,wrapper); + String priceId = recycleStationPriceMapper.getLatestPriceByStationId(stationId, wrapper); // if (ObjectUtil.isEmpty(priceId)) { // throw new BizIllegalException("回收站点未配置有效价目信息"); // } @@ -129,13 +129,12 @@ public class RecycleStationServiceImpl extends ServiceImpl