废品二级类目功能v1

master
LI-CCONG\李聪聪 6 months ago
parent 45269fb21e
commit 673c73a3d3

@ -14,8 +14,7 @@ import java.lang.reflect.Field;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.*;
import java.util.Random;
/** /**
* *
@ -105,6 +104,43 @@ public class CommonUtil {
return field.get(obj); return field.get(obj);
} }
/**
*
* @param parentId
* @param dataList
* @return
*/
public static <T> List<T> getChildrenList(String parentId, List<T> dataList) {
List<T> voList = new ArrayList<>();
dataList.forEach(v -> {
String pid = (String) obtainField(v, "parentId");
if (Objects.equals(pid, parentId)) {
String id = (String) obtainField(v, "id");
List<T> children = getChildrenList(id, dataList);
assignField(v, "children", children);
voList.add(v);
}
});
return voList;
}
/**
*
* @param thisId
* @param dataList
* @param parentList
*/
public static <T> void getParent(String thisId, List<T> dataList, List<T> 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) { public static void main(String[] args) {
// 121.190912 // 121.190912

@ -58,8 +58,9 @@ public class RecycleStationController {
}); });
List<RecycleStationRespVO> recycleStationRespVOList = recycleStationPageVO.getList(); List<RecycleStationRespVO> recycleStationRespVOList = recycleStationPageVO.getList();
recycleStationRespVOList.forEach(stationRespVO -> { recycleStationRespVOList.forEach(stationRespVO -> {
List<ProductRespVO> produceList = recycleStationService.getStationProduct(stationRespVO.getId()); List<ProductRespVO> productList = recycleStationService.getStationProduct(stationRespVO.getId());
stationRespVO.setStationProducts(produceList); List<ProductRespVO> productTreeList = CommonUtil.getChildrenList(null, productList);
stationRespVO.setStationProducts(productTreeList);
}); // 性能优化 todo }); // 性能优化 todo
return CommonResult.success(recycleStationPageVO); return CommonResult.success(recycleStationPageVO);
} }
@ -72,8 +73,9 @@ public class RecycleStationController {
RecycleStationRespVO recycleStationRespVO = BeanUtils.copyBean(station, RecycleStationRespVO.class); RecycleStationRespVO recycleStationRespVO = BeanUtils.copyBean(station, RecycleStationRespVO.class);
if (ObjectUtil.isNotEmpty(station)) { if (ObjectUtil.isNotEmpty(station)) {
recycleStationRespVO = BeanUtils.copyBean(station, RecycleStationRespVO.class); recycleStationRespVO = BeanUtils.copyBean(station, RecycleStationRespVO.class);
List<ProductRespVO> produceList = recycleStationService.getStationProduct(station.getId()); List<ProductRespVO> productList = recycleStationService.getStationProduct(station.getId());
recycleStationRespVO.setStationProducts(produceList); List<ProductRespVO> productTreeList = CommonUtil.getChildrenList(null, productList);
recycleStationRespVO.setStationProducts(productTreeList);
this.computeStationDistance(recycleStationRespVO, location); this.computeStationDistance(recycleStationRespVO, location);
} }
return CommonResult.success(recycleStationRespVO); return CommonResult.success(recycleStationRespVO);
@ -83,8 +85,9 @@ public class RecycleStationController {
@ApiOperation("回收站废品价格类目") @ApiOperation("回收站废品价格类目")
@GetMapping("/price-product") @GetMapping("/price-product")
public CommonResult<List<ProductRespVO>> stationProduct(@RequestParam("stationId") String stationId) { public CommonResult<List<ProductRespVO>> stationProduct(@RequestParam("stationId") String stationId) {
List<ProductRespVO> stationProduct = recycleStationService.getStationProduct(stationId); List<ProductRespVO> productList = recycleStationService.getStationProduct(stationId);
return CommonResult.success(stationProduct); List<ProductRespVO> productTreeList = CommonUtil.getChildrenList(null, productList);
return CommonResult.success(productTreeList);
} }

@ -28,6 +28,10 @@ public class Product {
@TableId(value = "id", type = IdType.ASSIGN_ID) @TableId(value = "id", type = IdType.ASSIGN_ID)
private String id; private String id;
@ApiModelProperty("父id")
@TableField("parent_id")
private String parentId;
@ApiModelProperty("编码") @ApiModelProperty("编码")
@TableField("code") @TableField("code")
private String code; private String code;

@ -12,6 +12,7 @@ import lombok.experimental.Accessors;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* <p> * <p>
@ -21,11 +22,14 @@ import java.util.Date;
* @author ccongli * @author ccongli
* @since 2024-03-01 11:15:39 * @since 2024-03-01 11:15:39
*/ */
@ApiModel(description = "回收站 Response VO") @ApiModel(description = "类目 Response VO")
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class ProductRespVO { public class ProductRespVO {
@ApiModelProperty("废品id")
private String id;
@ApiModelProperty("价格id") @ApiModelProperty("价格id")
private String priceId; private String priceId;
@ -58,4 +62,10 @@ public class ProductRespVO {
@ApiModelProperty("废品定价时间") @ApiModelProperty("废品定价时间")
private LocalDateTime creatorTime; private LocalDateTime creatorTime;
@ApiModelProperty("父id")
private String parentId;
@ApiModelProperty("子分类")
private List<ProductRespVO> children;
} }

@ -35,6 +35,7 @@ public class PriceProductServiceImpl extends ServiceImpl<PriceProductMapper, Pri
public List<Product> queryProductList() { public List<Product> queryProductList() {
LambdaQueryWrapperX<Product> wrapperX = new LambdaQueryWrapperX<>(); LambdaQueryWrapperX<Product> wrapperX = new LambdaQueryWrapperX<>();
wrapperX.isNull(Product::getDeleted); wrapperX.isNull(Product::getDeleted);
wrapperX.isNull(Product::getParentId); // 只查一级类目
return productMapper.selectList(wrapperX); return productMapper.selectList(wrapperX);
} }
@ -49,4 +50,7 @@ public class PriceProductServiceImpl extends ServiceImpl<PriceProductMapper, Pri
wrapperX.in(Product::getId, productIds); wrapperX.in(Product::getId, productIds);
return productMapper.selectList(wrapperX); return productMapper.selectList(wrapperX);
} }
} }

@ -110,7 +110,7 @@ public class RecycleStationServiceImpl extends ServiceImpl<RecycleStationMapper,
@Override @Override
public List<ProductRespVO> getStationProduct(String stationId) { public List<ProductRespVO> getStationProduct(String stationId) {
QueryWrapper<Price> wrapper = new QueryWrapper<Price>().eq("a.status", GlobalStatusEnum.VALID); QueryWrapper<Price> wrapper = new QueryWrapper<Price>().eq("a.status", GlobalStatusEnum.VALID);
String priceId = recycleStationPriceMapper.getLatestPriceByStationId(stationId,wrapper); String priceId = recycleStationPriceMapper.getLatestPriceByStationId(stationId, wrapper);
// if (ObjectUtil.isEmpty(priceId)) { // if (ObjectUtil.isEmpty(priceId)) {
// throw new BizIllegalException("回收站点未配置有效价目信息"); // throw new BizIllegalException("回收站点未配置有效价目信息");
// } // }
@ -129,13 +129,12 @@ public class RecycleStationServiceImpl extends ServiceImpl<RecycleStationMapper,
.in(Product::getId, priceProductMap.keySet()).list(); .in(Product::getId, priceProductMap.keySet()).list();
for (Product product : productList) { for (Product product : productList) {
PriceProduct priceProduct = priceProductMap.get(product.getId()); PriceProduct priceProduct = priceProductMap.get(product.getId());
ProductRespVO productRespVO = BeanUtils.copyBean(priceProduct, ProductRespVO.class); ProductRespVO productRespVO = BeanUtils.copyBean(product, ProductRespVO.class);
productRespVO.setCode(product.getCode()) productRespVO.setPriceId(priceProduct.getPriceId())
.setName(product.getName()) .setProductId(priceProduct.getProductId())
.setSpec(product.getSpec()) .setRecoveryPrice(priceProduct.getRecoveryPrice())
.setUnit(product.getUnit()) .setRewardPoints(priceProduct.getRewardPoints())
.setPhoto(product.getPhoto()) .setCreatorTime(priceProduct.getFCreatorTime());
.setDescription(product.getDescription());
productRespVOList.add(productRespVO); productRespVOList.add(productRespVO);
} }
} }

Loading…
Cancel
Save