Administrator
yesterday 2fb72d56082e2ee19aa187707751dd0dacd34f4b
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package cc.mrbird.febs.ai.service.impl;
 
import cc.mrbird.febs.ai.entity.AiMemberRole;
import cc.mrbird.febs.ai.entity.AiProductCategory;
import cc.mrbird.febs.ai.enumerates.ProductCategoryLevelEnum;
import cc.mrbird.febs.ai.mapper.AiProductCategoryMapper;
import cc.mrbird.febs.ai.req.productCategory.ApiProductCategoryAllDto;
import cc.mrbird.febs.ai.req.productCategory.ApiProductCategoryHotDto;
import cc.mrbird.febs.ai.req.productCategory.ApiProductCategoryPageDto;
import cc.mrbird.febs.ai.res.productCategory.ApiProductCategoryVo;
import cc.mrbird.febs.ai.service.AiProductCategoryService;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.mall.vo.ApiActivityInfoVo;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * AI产品类别 Service实现类
 *
 * @author yourname
 * @date 2025-07-29
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class AiProductCategoryServiceImpl extends ServiceImpl<AiProductCategoryMapper, AiProductCategory> implements AiProductCategoryService {
 
    private final AiProductCategoryMapper aiProductCategoryMapper;
 
 
    @Override
    public List<AiProductCategory> getListByQuery(LambdaQueryWrapper<AiProductCategory> query) {
        return aiProductCategoryMapper.selectList(query);
    }
 
    @Override
    public Page<ApiProductCategoryVo> getPageListByQuery(Page<ApiProductCategoryVo> page , ApiProductCategoryPageDto dto) {
        return aiProductCategoryMapper.selectPageListByQuery(page,dto);
    }
 
    @Override
    public FebsResponse hot() {
 
        List<ApiProductCategoryVo> list = new ArrayList<>();
 
        LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class);
        query.eq(AiProductCategory::getLevel, ProductCategoryLevelEnum.LEVEL_TWO.getLevel());
        query.eq(AiProductCategory::getState, 1);
        query.eq(AiProductCategory::getHotState, 1);
        query.orderByAsc(AiProductCategory::getSort);
        List<AiProductCategory> listByQuery = this.getListByQuery(query);
        if (CollUtil.isNotEmpty(listByQuery)){
            for (AiProductCategory aiProductCategory : listByQuery){
                ApiProductCategoryVo apiProductCategoryVo = new ApiProductCategoryVo();
                apiProductCategoryVo.setId(aiProductCategory.getId());
                apiProductCategoryVo.setName(aiProductCategory.getName());
                apiProductCategoryVo.setBackImg(aiProductCategory.getBackImg());
                apiProductCategoryVo.setIconImg(aiProductCategory.getIconImg());
                list.add(apiProductCategoryVo);
            }
        }
        return new FebsResponse().success().data(list);
    }
 
    @Override
    public FebsResponse hotV1(ApiProductCategoryHotDto dto) {
 
        List<ApiProductCategoryVo> list = new ArrayList<>();
 
        LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class);
        if (StrUtil.isNotEmpty(dto.getCompanyId())){
            query.eq(AiProductCategory::getCompanyId, dto.getCompanyId());
        }else{
            query.isNull(AiProductCategory::getCompanyId);
        }
        query.eq(AiProductCategory::getLevel, ProductCategoryLevelEnum.LEVEL_TWO.getLevel());
        query.eq(AiProductCategory::getState, 1);
        query.eq(AiProductCategory::getHotState, 1);
        query.orderByAsc(AiProductCategory::getSort);
        List<AiProductCategory> listByQuery = this.getListByQuery(query);
        if (CollUtil.isNotEmpty(listByQuery)){
            for (AiProductCategory aiProductCategory : listByQuery){
                ApiProductCategoryVo apiProductCategoryVo = new ApiProductCategoryVo();
                apiProductCategoryVo.setId(aiProductCategory.getId());
                apiProductCategoryVo.setName(aiProductCategory.getName());
                apiProductCategoryVo.setBackImg(aiProductCategory.getBackImg());
                apiProductCategoryVo.setIconImg(aiProductCategory.getIconImg());
                list.add(apiProductCategoryVo);
            }
        }
        return new FebsResponse().success().data(list);
    }
 
    @Override
    public FebsResponse categoryList(ApiProductCategoryPageDto dto) {
        // 创建分页对象,传入当前页和每页大小
        Page<ApiProductCategoryVo> page = new Page<>(dto.getPageNow(), dto.getPageSize());
        Page<ApiProductCategoryVo> pageListByQuery = this.getPageListByQuery(page, dto);
        return new FebsResponse().success().data(pageListByQuery);
    }
 
    @Override
    public String getDefaultProductCategoryId() {
        LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class);
        query.eq(AiProductCategory::getState, 1);
        query.isNull(AiProductCategory::getCompanyId);
        query.eq(AiProductCategory::getHotState, 1);
        query.orderByAsc(AiProductCategory::getSort);
        query.last("limit 1");
        List<AiProductCategory> listByQuery = this.getListByQuery(query);
        if (CollUtil.isNotEmpty(listByQuery)){
            return listByQuery.get(0).getId();
        }
        return null;
    }
 
    @Override
    public FebsResponse allList(ApiProductCategoryAllDto dto) {
        List<ApiProductCategoryVo> list = new ArrayList<>();
        LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class);
        if (StrUtil.isNotEmpty(dto.getCompanyId())){
            query.eq(AiProductCategory::getCompanyId, dto.getCompanyId());
        }else{
            query.isNull(AiProductCategory::getCompanyId);
        }
        query.eq(AiProductCategory::getState, 1);
        query.eq(AiProductCategory::getLevel, ProductCategoryLevelEnum.LEVEL_ONE.getLevel());
        query.orderByAsc(AiProductCategory::getSort);
        List<AiProductCategory> listByQuery = this.getListByQuery(query);
        if (CollUtil.isNotEmpty(listByQuery)){
            for (AiProductCategory aiProductCategory : listByQuery){
                ApiProductCategoryVo apiProductCategoryVo = new ApiProductCategoryVo();
                apiProductCategoryVo.setId(aiProductCategory.getId());
                apiProductCategoryVo.setName(aiProductCategory.getName());
                apiProductCategoryVo.setBackImg(aiProductCategory.getBackImg());
                apiProductCategoryVo.setIconImg(aiProductCategory.getIconImg());
                list.add(apiProductCategoryVo);
            }
 
        }
        return new FebsResponse().success().data(list);
    }
}