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,11 +2,14 @@ package cn.iocoder.yudao.module.iot.controller.admin.product; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | ||
| 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductPageReqVO; | 7 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductPageReqVO; |
| 7 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductRespVO; | 8 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductRespVO; |
| 8 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductSaveReqVO; | 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 | import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; | 11 | import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; |
| 12 | +import cn.iocoder.yudao.module.iot.service.product.IotProductCategoryService; | ||
| 10 | import cn.iocoder.yudao.module.iot.service.product.IotProductService; | 13 | import cn.iocoder.yudao.module.iot.service.product.IotProductService; |
| 11 | import io.swagger.v3.oas.annotations.Operation; | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 12 | import io.swagger.v3.oas.annotations.Parameter; | 15 | import io.swagger.v3.oas.annotations.Parameter; |
| @@ -18,6 +21,7 @@ import org.springframework.validation.annotation.Validated; | @@ -18,6 +21,7 @@ import org.springframework.validation.annotation.Validated; | ||
| 18 | import org.springframework.web.bind.annotation.*; | 21 | import org.springframework.web.bind.annotation.*; |
| 19 | 22 | ||
| 20 | import java.util.List; | 23 | import java.util.List; |
| 24 | +import java.util.Map; | ||
| 21 | 25 | ||
| 22 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 23 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | 27 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| @@ -30,6 +34,8 @@ public class IotProductController { | @@ -30,6 +34,8 @@ public class IotProductController { | ||
| 30 | 34 | ||
| 31 | @Resource | 35 | @Resource |
| 32 | private IotProductService productService; | 36 | private IotProductService productService; |
| 37 | + @Resource | ||
| 38 | + private IotProductCategoryService categoryService; | ||
| 33 | 39 | ||
| 34 | @PostMapping("/create") | 40 | @PostMapping("/create") |
| 35 | @Operation(summary = "创建产品") | 41 | @Operation(summary = "创建产品") |
| @@ -72,7 +78,13 @@ public class IotProductController { | @@ -72,7 +78,13 @@ public class IotProductController { | ||
| 72 | @PreAuthorize("@ss.hasPermission('iot:product:query')") | 78 | @PreAuthorize("@ss.hasPermission('iot:product:query')") |
| 73 | public CommonResult<IotProductRespVO> getProduct(@RequestParam("id") Long id) { | 79 | public CommonResult<IotProductRespVO> getProduct(@RequestParam("id") Long id) { |
| 74 | IotProductDO product = productService.getProduct(id); | 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 | @GetMapping("/page") | 90 | @GetMapping("/page") |
| @@ -80,7 +92,13 @@ public class IotProductController { | @@ -80,7 +92,13 @@ public class IotProductController { | ||
| 80 | @PreAuthorize("@ss.hasPermission('iot:product:query')") | 92 | @PreAuthorize("@ss.hasPermission('iot:product:query')") |
| 81 | public CommonResult<PageResult<IotProductRespVO>> getProductPage(@Valid IotProductPageReqVO pageReqVO) { | 93 | public CommonResult<PageResult<IotProductRespVO>> getProductPage(@Valid IotProductPageReqVO pageReqVO) { |
| 82 | PageResult<IotProductDO> pageResult = productService.getProductPage(pageReqVO); | 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 | @GetMapping("/simple-list") | 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,6 +27,9 @@ public class IotProductRespVO { | ||
| 27 | @Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | 27 | @Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 28 | private Long categoryId; | 28 | private Long categoryId; |
| 29 | 29 | ||
| 30 | + @Schema(description = "产品分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 31 | + private String categoryName; | ||
| 32 | + | ||
| 30 | @Schema(description = "产品图标", example = "https://iocoder.cn/1.svg") | 33 | @Schema(description = "产品图标", example = "https://iocoder.cn/1.svg") |
| 31 | private String icon; | 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,7 +6,11 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProdu | ||
| 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; | 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; |
| 7 | import jakarta.validation.Valid; | 7 | import jakarta.validation.Valid; |
| 8 | 8 | ||
| 9 | +import java.util.Collection; | ||
| 9 | import java.util.List; | 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 | * IoT 产品分类 Service 接口 | 16 | * IoT 产品分类 Service 接口 |
| @@ -46,6 +50,24 @@ public interface IotProductCategoryService { | @@ -46,6 +50,24 @@ public interface IotProductCategoryService { | ||
| 46 | IotProductCategoryDO getProductCategory(Long id); | 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 | * @param pageReqVO 分页查询 | 73 | * @param pageReqVO 分页查询 |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java
| 1 | package cn.iocoder.yudao.module.iot.service.product; | 1 | package cn.iocoder.yudao.module.iot.service.product; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategoryPageReqVO; | 6 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategoryPageReqVO; |
| @@ -10,6 +11,7 @@ import jakarta.annotation.Resource; | @@ -10,6 +11,7 @@ import jakarta.annotation.Resource; | ||
| 10 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 11 | import org.springframework.validation.annotation.Validated; | 12 | import org.springframework.validation.annotation.Validated; |
| 12 | 13 | ||
| 14 | +import java.util.Collection; | ||
| 13 | import java.util.List; | 15 | import java.util.List; |
| 14 | 16 | ||
| 15 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -65,6 +67,14 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService | @@ -65,6 +67,14 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService | ||
| 65 | } | 67 | } |
| 66 | 68 | ||
| 67 | @Override | 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 | public PageResult<IotProductCategoryDO> getProductCategoryPage(IotProductCategoryPageReqVO pageReqVO) { | 78 | public PageResult<IotProductCategoryDO> getProductCategoryPage(IotProductCategoryPageReqVO pageReqVO) { |
| 69 | return productCategoryMapper.selectPage(pageReqVO); | 79 | return productCategoryMapper.selectPage(pageReqVO); |
| 70 | } | 80 | } |