| | |
| | | package com.ruoyi.goods.service.impl; |
| | | |
| | | 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.goods.controller.mamagement.VO.GoodsSeriesVO; |
| | | import com.ruoyi.goods.domain.pojo.GoodsSeries; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.goods.controller.management.dto.GoodsSeriesDTO; |
| | | import com.ruoyi.goods.controller.management.dto.GoodsSeriesQuery; |
| | | import com.ruoyi.goods.controller.management.vo.GoodsSeriesVO; |
| | | import com.ruoyi.goods.mapper.GoodsSeriesMapper; |
| | | import com.ruoyi.goods.mapper.GoodsSkuMapper; |
| | | import com.ruoyi.goods.service.IGoodsSeriesService; |
| | | import com.ruoyi.system.api.domain.GoodsSeries; |
| | | import com.ruoyi.system.api.domain.GoodsSku; |
| | | import java.util.List; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | |
| | | * @since 2024-05-16 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class GoodsSeriesServiceImpl extends ServiceImpl<GoodsSeriesMapper, GoodsSeries> implements IGoodsSeriesService { |
| | | |
| | | private final GoodsSkuMapper goodsSkuMapper; |
| | | /** |
| | | * 获取商品系列列表的视图对象。 |
| | | * |
| | |
| | | return BeanUtils.copyList(this.list(), GoodsSeriesVO.class); |
| | | } |
| | | |
| | | /** |
| | | * 获取商品系列的分页信息 |
| | | * |
| | | * @param query 包含分页参数和查询条件的查询对象 |
| | | * @return 返回商品系列的分页数据传输对象(DTO),包含分页信息和商品系列列表 |
| | | */ |
| | | @Override |
| | | public PageDTO<GoodsSeriesVO> getGoodsSeriesPage(GoodsSeriesQuery query) { |
| | | Page<GoodsSeries> page = this.lambdaQuery() |
| | | .like(StringUtils.isNotEmpty(query.getSeriesName()), GoodsSeries::getSeriesName, |
| | | query.getSeriesName()) |
| | | .orderByDesc(GoodsSeries::getCreateTime) |
| | | .page(new Page<>(query.getPageCurr(), query.getPageSize())); |
| | | if (StringUtils.isEmpty(page.getRecords())) { |
| | | return PageDTO.empty(page.getTotal(), page.getPages()); |
| | | } |
| | | return PageDTO.of(page, GoodsSeriesVO.class); |
| | | } |
| | | |
| | | /** |
| | | * 保存或更新商品系列信息。 |
| | | * |
| | | * @param dto 商品系列数据传输对象,包含商品系列的详细信息。 如果商品系列ID为空,则视为新记录,进行保存; 如果商品系列ID不为空,则视为更新记录,进行更新。 |
| | | */ |
| | | @Override |
| | | public void saveGoodsSeries(GoodsSeriesDTO dto) { |
| | | GoodsSeries goodsSeries = BeanUtils.copyBean(dto, GoodsSeries.class); |
| | | if (StringUtils.isNull(goodsSeries.getId())) { |
| | | this.save(goodsSeries); |
| | | } else { |
| | | this.updateById(goodsSeries); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void delete(Long id) { |
| | | Long count = goodsSkuMapper.selectCount( |
| | | Wrappers.lambdaQuery(GoodsSku.class).eq(GoodsSku::getSeriesId, id)); |
| | | if (count > 0) { |
| | | throw new ServiceException("该分类已有商品关联,不能删除"); |
| | | } |
| | | this.removeById(id); |
| | | } |
| | | } |