废品二级类目功能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.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 <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) {
// 121.190912

@ -58,8 +58,9 @@ public class RecycleStationController {
});
List<RecycleStationRespVO> recycleStationRespVOList = recycleStationPageVO.getList();
recycleStationRespVOList.forEach(stationRespVO -> {
List<ProductRespVO> produceList = recycleStationService.getStationProduct(stationRespVO.getId());
stationRespVO.setStationProducts(produceList);
List<ProductRespVO> productList = recycleStationService.getStationProduct(stationRespVO.getId());
List<ProductRespVO> 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<ProductRespVO> produceList = recycleStationService.getStationProduct(station.getId());
recycleStationRespVO.setStationProducts(produceList);
List<ProductRespVO> productList = recycleStationService.getStationProduct(station.getId());
List<ProductRespVO> 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<List<ProductRespVO>> stationProduct(@RequestParam("stationId") String stationId) {
List<ProductRespVO> stationProduct = recycleStationService.getStationProduct(stationId);
return CommonResult.success(stationProduct);
List<ProductRespVO> productList = recycleStationService.getStationProduct(stationId);
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)
private String id;
@ApiModelProperty("父id")
@TableField("parent_id")
private String parentId;
@ApiModelProperty("编码")
@TableField("code")
private String code;

@ -12,6 +12,7 @@ import lombok.experimental.Accessors;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
/**
* <p>
@ -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<ProductRespVO> children;
}

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

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

Loading…
Cancel
Save