From fc8b51f40e71aa09bb49f407c1e9f68ac94ceb58 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期一, 29 七月 2024 18:51:32 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsBrandServiceImpl.java | 82 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 79 insertions(+), 3 deletions(-) diff --git a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsBrandServiceImpl.java b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsBrandServiceImpl.java index b9c86d5..2b6135e 100644 --- a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsBrandServiceImpl.java +++ b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsBrandServiceImpl.java @@ -1,9 +1,22 @@ package com.ruoyi.goods.service.impl; -import com.ruoyi.goods.domain.pojo.GoodsBrand; -import com.ruoyi.goods.mapper.GoodsBrandMapper; -import com.ruoyi.goods.service.IGoodsBrandService; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.common.core.exception.ServiceException; +import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.common.core.utils.page.BeanUtils; +import com.ruoyi.common.core.utils.page.PageDTO; +import com.ruoyi.goods.controller.management.dto.GoodsBrandDTO; +import com.ruoyi.goods.controller.management.dto.GoodsBrandQuery; +import com.ruoyi.goods.controller.management.vo.GoodsBrandVO; +import com.ruoyi.goods.mapper.GoodsBrandMapper; +import com.ruoyi.goods.mapper.GoodsSkuMapper; +import com.ruoyi.goods.service.IGoodsBrandService; +import com.ruoyi.system.api.domain.GoodsBrand; +import com.ruoyi.system.api.domain.GoodsSku; +import java.util.List; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; /** @@ -15,6 +28,69 @@ * @since 2024-05-16 */ @Service +@RequiredArgsConstructor public class GoodsBrandServiceImpl extends ServiceImpl<GoodsBrandMapper, GoodsBrand> implements IGoodsBrandService { + private final GoodsSkuMapper goodsSkuMapper; + /** + * 获取商品品牌列表。 + * <p>此方法通过调用{@code list()}方法获取原始列表,并使用BeanUtils的{@code copyList}方法将其复制为{@code + * GoodsBrandVO}类型的列表后返回。</p> + * + * @return 返回一个{@code GoodsBrandVO}类型的列表,包含商品品牌信息。 + */ + @Override + public List<GoodsBrandVO> getGoodsBrandList() { + // 将原始列表转换为GoodsBrandVO类型的列表 + return BeanUtils.copyList(this.list(), GoodsBrandVO.class); + } + + /** + * 获取商品品牌的分页信息 + * + * @param query 包含查询条件和分页信息的查询对象 + * @return 返回商品品牌分页DTO,包含分页信息和品牌列表 + */ + @Override + public PageDTO<GoodsBrandVO> getGoodsBrandPage(GoodsBrandQuery query) { + // 根据查询条件进行品牌查询,并分页 + Page<GoodsBrand> page = this.lambdaQuery() + .like(StringUtils.isNotEmpty(query.getBrandName()), GoodsBrand::getBrandName, + query.getBrandName()) + .orderByDesc(GoodsBrand::getCreateTime) + .page(new Page<>(query.getPageCurr(), query.getPageSize())); + if (StringUtils.isEmpty(page.getRecords())) { + return PageDTO.empty(page.getTotal(), page.getPages()); + } + // 将查询结果转换为VO类的分页DTO + return PageDTO.of(page, GoodsBrandVO.class); + } + + /** + * 保存或更新商品品牌信息。 + * + * @param dto 商品品牌数据传输对象,包含商品品牌的信息。 如果dto中的id为空,则认为是新品牌,调用save方法保存; + * 如果id不为空,则认为是更新已有品牌,调用updateById方法更新。 + */ + @Override + public void saveGoodsBrand(GoodsBrandDTO dto) { + // 将DTO对象复制到实体对象中 + GoodsBrand goodsBrand = BeanUtils.copyBean(dto, GoodsBrand.class); + // 判断DTO中的ID是否为空,决定是保存还是更新操作 + if (StringUtils.isNull(dto.getId())) { + this.save(goodsBrand); // 保存新品牌 + } else { + this.updateById(goodsBrand); // 更新已有品牌 + } + } + + @Override + public void delete(Long id) { + Long count = goodsSkuMapper.selectCount( + Wrappers.lambdaQuery(GoodsSku.class).eq(GoodsSku::getBrandId, id)); + if (count > 0) { + throw new ServiceException("该品牌已有商品关联,不能删除"); + } + this.removeById(id); + } } -- Gitblit v1.7.1