Commit 9841c869a2ef457eab3be7ff3224c32f7ac78126
1 parent
a8c87d16
【功能新增】IoT:产品详情,优化相关展示
Showing
4 changed files
with
55 additions
and
2 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductController.java
| ... | ... | @@ -2,11 +2,14 @@ package cn.iocoder.yudao.module.iot.controller.admin.product; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | |
| 5 | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | 7 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductPageReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductRespVO; |
| 8 | 9 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductSaveReqVO; |
| 10 | +import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; | |
| 9 | 11 | import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; |
| 12 | +import cn.iocoder.yudao.module.iot.service.product.IotProductCategoryService; | |
| 10 | 13 | import cn.iocoder.yudao.module.iot.service.product.IotProductService; |
| 11 | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 12 | 15 | import io.swagger.v3.oas.annotations.Parameter; |
| ... | ... | @@ -18,6 +21,7 @@ import org.springframework.validation.annotation.Validated; |
| 18 | 21 | import org.springframework.web.bind.annotation.*; |
| 19 | 22 | |
| 20 | 23 | import java.util.List; |
| 24 | +import java.util.Map; | |
| 21 | 25 | |
| 22 | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 23 | 27 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| ... | ... | @@ -30,6 +34,8 @@ public class IotProductController { |
| 30 | 34 | |
| 31 | 35 | @Resource |
| 32 | 36 | private IotProductService productService; |
| 37 | + @Resource | |
| 38 | + private IotProductCategoryService categoryService; | |
| 33 | 39 | |
| 34 | 40 | @PostMapping("/create") |
| 35 | 41 | @Operation(summary = "创建产品") |
| ... | ... | @@ -72,7 +78,13 @@ public class IotProductController { |
| 72 | 78 | @PreAuthorize("@ss.hasPermission('iot:product:query')") |
| 73 | 79 | public CommonResult<IotProductRespVO> getProduct(@RequestParam("id") Long id) { |
| 74 | 80 | IotProductDO product = productService.getProduct(id); |
| 75 | - return success(BeanUtils.toBean(product, IotProductRespVO.class)); | |
| 81 | + // 拼接数据 | |
| 82 | + IotProductCategoryDO category = categoryService.getProductCategory(product.getCategoryId()); | |
| 83 | + return success(BeanUtils.toBean(product, IotProductRespVO.class, bean -> { | |
| 84 | + if (category != null) { | |
| 85 | + bean.setCategoryName(category.getName()); | |
| 86 | + } | |
| 87 | + })); | |
| 76 | 88 | } |
| 77 | 89 | |
| 78 | 90 | @GetMapping("/page") |
| ... | ... | @@ -80,7 +92,13 @@ public class IotProductController { |
| 80 | 92 | @PreAuthorize("@ss.hasPermission('iot:product:query')") |
| 81 | 93 | public CommonResult<PageResult<IotProductRespVO>> getProductPage(@Valid IotProductPageReqVO pageReqVO) { |
| 82 | 94 | PageResult<IotProductDO> pageResult = productService.getProductPage(pageReqVO); |
| 83 | - return success(BeanUtils.toBean(pageResult, IotProductRespVO.class)); | |
| 95 | + // 拼接数据 | |
| 96 | + Map<Long, IotProductCategoryDO> categoryMap = categoryService.getProductCategoryMap( | |
| 97 | + convertList(pageResult.getList(), IotProductDO::getCategoryId)); | |
| 98 | + return success(BeanUtils.toBean(pageResult, IotProductRespVO.class, bean -> { | |
| 99 | + MapUtils.findAndThen(categoryMap, bean.getCategoryId(), | |
| 100 | + category -> bean.setCategoryName(category.getName())); | |
| 101 | + })); | |
| 84 | 102 | } |
| 85 | 103 | |
| 86 | 104 | @GetMapping("/simple-list") | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductRespVO.java
| ... | ... | @@ -27,6 +27,9 @@ public class IotProductRespVO { |
| 27 | 27 | @Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 28 | 28 | private Long categoryId; |
| 29 | 29 | |
| 30 | + @Schema(description = "产品分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 31 | + private String categoryName; | |
| 32 | + | |
| 30 | 33 | @Schema(description = "产品图标", example = "https://iocoder.cn/1.svg") |
| 31 | 34 | private String icon; |
| 32 | 35 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java
| ... | ... | @@ -6,7 +6,11 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProdu |
| 6 | 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; |
| 7 | 7 | import jakarta.validation.Valid; |
| 8 | 8 | |
| 9 | +import java.util.Collection; | |
| 9 | 10 | import java.util.List; |
| 11 | +import java.util.Map; | |
| 12 | + | |
| 13 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 10 | 14 | |
| 11 | 15 | /** |
| 12 | 16 | * IoT 产品分类 Service 接口 |
| ... | ... | @@ -46,6 +50,24 @@ public interface IotProductCategoryService { |
| 46 | 50 | IotProductCategoryDO getProductCategory(Long id); |
| 47 | 51 | |
| 48 | 52 | /** |
| 53 | + * 获得产品分类列表 | |
| 54 | + * | |
| 55 | + * @param ids 编号 | |
| 56 | + * @return 产品分类列表 | |
| 57 | + */ | |
| 58 | + List<IotProductCategoryDO> getProductCategoryList(Collection<Long> ids); | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * 获得产品分类 Map | |
| 62 | + * | |
| 63 | + * @param ids 编号 | |
| 64 | + * @return 产品分类 Map | |
| 65 | + */ | |
| 66 | + default Map<Long, IotProductCategoryDO> getProductCategoryMap(Collection<Long> ids) { | |
| 67 | + return convertMap(getProductCategoryList(ids), IotProductCategoryDO::getId); | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 49 | 71 | * 获得产品分类分页 |
| 50 | 72 | * |
| 51 | 73 | * @param pageReqVO 分页查询 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.service.product; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | 6 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategoryPageReqVO; |
| ... | ... | @@ -10,6 +11,7 @@ import jakarta.annotation.Resource; |
| 10 | 11 | import org.springframework.stereotype.Service; |
| 11 | 12 | import org.springframework.validation.annotation.Validated; |
| 12 | 13 | |
| 14 | +import java.util.Collection; | |
| 13 | 15 | import java.util.List; |
| 14 | 16 | |
| 15 | 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -65,6 +67,14 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService |
| 65 | 67 | } |
| 66 | 68 | |
| 67 | 69 | @Override |
| 70 | + public List<IotProductCategoryDO> getProductCategoryList(Collection<Long> ids) { | |
| 71 | + if (CollUtil.isEmpty(ids)) { | |
| 72 | + return CollUtil.newArrayList(); | |
| 73 | + } | |
| 74 | + return productCategoryMapper.selectBatchIds(ids); | |
| 75 | + } | |
| 76 | + | |
| 77 | + @Override | |
| 68 | 78 | public PageResult<IotProductCategoryDO> getProductCategoryPage(IotProductCategoryPageReqVO pageReqVO) { |
| 69 | 79 | return productCategoryMapper.selectPage(pageReqVO); |
| 70 | 80 | } | ... | ... |