zjk
2026-09-29 54dcf0a82e7490fa58b1c056d5c0b9cb739c2931
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
package com.tcm.training.admin.app.live.service;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tcm.training.admin.app.live.vo.AppLiveExpertVO;
import com.tcm.training.admin.live.entity.Expert;
import com.tcm.training.admin.live.mapper.ExpertMapper;
import org.springframework.stereotype.Service;
 
/**
 * APP 养生直播专家服务。
 */
@Service
public class AppLiveExpertService {
 
    private static final int EXPERT_STATUS_ENABLED = 1;
 
    private final ExpertMapper expertMapper;
 
    /**
     * 注入专家查询能力。
     */
    public AppLiveExpertService(ExpertMapper expertMapper) {
        this.expertMapper = expertMapper;
    }
 
    /**
     * 获取 APP 专家详情,仅允许读取已启用专家。
     */
    public AppLiveExpertVO detail(Long expertId) {
        Expert expert = expertMapper.selectOne(new LambdaQueryWrapper<Expert>()
                .eq(Expert::getId, expertId)
                .eq(Expert::getDeleted, 0)
                .eq(Expert::getStatus, EXPERT_STATUS_ENABLED)
                .last("limit 1"));
        if (expert == null) {
            throw new IllegalArgumentException("授课专家不存在");
        }
        return toExpertVO(expert);
    }
 
    /**
     * 将专家实体转换为 APP 专家响应。
     */
    public AppLiveExpertVO toExpertVO(Expert expert) {
        if (expert == null) {
            return null;
        }
        AppLiveExpertVO expertVO = new AppLiveExpertVO();
        expertVO.setId(expert.getId());
        expertVO.setName(expert.getName());
        expertVO.setAvatar(expert.getAvatar());
        expertVO.setSpecialty(expert.getSpecialty());
        expertVO.setIntro(expert.getIntro());
        return expertVO;
    }
}