rentaiming
2024-06-13 fe2d5b14031edbe43238770fb1fc21e8a322b51a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.ruoyi.goods.service.impl;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.GoodsFlavorTypeDTO;
import com.ruoyi.goods.controller.management.dto.GoodsFlavorTypeQuery;
import com.ruoyi.goods.controller.management.vo.GoodsFlavorTypeVO;
import com.ruoyi.system.api.domain.GoodsFlavorType;
import com.ruoyi.goods.mapper.GoodsFlavorTypeMapper;
import com.ruoyi.goods.service.IGoodsFlavorTypeService;
import java.util.List;
import org.springframework.stereotype.Service;
 
/**
 * <p>
 * 香型表 服务实现类
 * </p>
 *
 * @author mitao
 * @since 2024-05-16
 */
@Service
public class GoodsFlavorTypeServiceImpl extends ServiceImpl<GoodsFlavorTypeMapper, GoodsFlavorType> implements IGoodsFlavorTypeService {
 
    /**
     * 获取商品口味类型的列表。
     * <p>此方法通过调用 {@code list()} 方法获取原始列表,并使用 {@code BeanUtils.copyList} 方法将每个元素转换为
     * {@code GoodsFlavorTypeVO} 类型,最终返回转换后的列表。</p>
     *
     * @return 返回一个 {@code List<GoodsFlavorTypeVO>},包含转换后的商品口味类型信息。
     */
    @Override
    public List<GoodsFlavorTypeVO> getGoodsFlavorTypeList() {
        return BeanUtils.copyList(this.list(), GoodsFlavorTypeVO.class);
    }
 
    /**
     * 获取商品口味类型分页数据
     *
     * @param query 查询条件,包含页码、页大小和口味类型名称等
     * @return 返回口味类型分页数据传输对象(PageDTO),其中包含了分页信息和转换后的口味类型视图对象(GoodsFlavorTypeVO)列表
     */
    @Override
    public PageDTO<GoodsFlavorTypeVO> getGoodsFlavorTypePage(GoodsFlavorTypeQuery query) {
        Page<GoodsFlavorType> page = this.lambdaQuery()
                .like(StringUtils.isNotEmpty(query.getFlavorTypeName()),
                        GoodsFlavorType::getFlavorTypeName, query.getFlavorTypeName())
                .page(new Page<>(query.getPageCurr(), query.getPageSize()));
        if (StringUtils.isEmpty(page.getRecords())) {
            return PageDTO.empty(page.getTotal(), page.getPages());
        }
        return PageDTO.of(page, GoodsFlavorTypeVO.class);
    }
 
    /**
     * 保存或更新商品口味类型信息。
     *
     * @param dto 商品口味类型数据传输对象,包含要保存或更新的信息。 如果dto中的id为空,则认为是新纪录,执行保存操作; 如果id不为空,则认为是更新现有纪录。
     */
    @Override
    public void saveGoodsFlavorType(GoodsFlavorTypeDTO dto) {
        GoodsFlavorType goodsFlavorType = BeanUtils.copyBean(dto, GoodsFlavorType.class);
        if (StringUtils.isNull(dto.getId())) {
            this.save(goodsFlavorType);
        } else {
            this.updateById(goodsFlavorType);
        }
    }
}