hejianhao
2026-08-20 8adff1576d322f1095d35dad5fd7bec17417f0e7
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
package com.tcm.training.admin.app.projectintroduction.service;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tcm.training.admin.live.entity.ProjectIntroduction;
import com.tcm.training.admin.live.mapper.ProjectIntroductionMapper;
import com.tcm.training.admin.live.vo.AppProjectIntroductionDetailVO;
import com.tcm.training.admin.live.vo.AppProjectIntroductionItemVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
 
@Service
public class AppProjectIntroductionService {
 
    private final ProjectIntroductionMapper projectIntroductionMapper;
 
    public AppProjectIntroductionService(ProjectIntroductionMapper projectIntroductionMapper) {
        this.projectIntroductionMapper = projectIntroductionMapper;
    }
 
    /**
     * 获取APP项目介绍列表(按类别筛选)
     */
    public List<AppProjectIntroductionItemVO> listByCategory(String category) {
        LambdaQueryWrapper<ProjectIntroduction> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProjectIntroduction::getStatus, 1)
                .eq(ProjectIntroduction::getDeleted, 0);
 
        if (category != null && !category.isEmpty()) {
            wrapper.eq(ProjectIntroduction::getCategory, category);
        }
 
        wrapper.orderByDesc(ProjectIntroduction::getCreatedAt);
 
        List<ProjectIntroduction> list = projectIntroductionMapper.selectList(wrapper);
 
        List<AppProjectIntroductionItemVO> result = new ArrayList<>();
        for (ProjectIntroduction item : list) {
            AppProjectIntroductionItemVO vo = new AppProjectIntroductionItemVO();
            vo.setId(item.getId());
            vo.setTitle(item.getTitle());
            vo.setCoverImg(item.getCoverImg());
            vo.setCategory(item.getCategory());
            vo.setContentType(item.getContentType());
            vo.setClickCount(item.getClickCount());
            result.add(vo);
        }
 
        return result;
    }
 
    /**
     * 获取APP项目介绍详情,并增加点击量
     */
    @Transactional
    public AppProjectIntroductionDetailVO getDetail(Long id) {
        ProjectIntroduction entity = projectIntroductionMapper.selectOne(
                new LambdaQueryWrapper<ProjectIntroduction>()
                        .eq(ProjectIntroduction::getId, id)
                        .eq(ProjectIntroduction::getStatus, 1)
                        .eq(ProjectIntroduction::getDeleted, 0)
        );
 
        if (entity == null) {
            return null;
        }
 
        // 增加点击量
        entity.setClickCount(entity.getClickCount() + 1);
        projectIntroductionMapper.updateById(entity);
 
        // 转换为VO
        AppProjectIntroductionDetailVO vo = new AppProjectIntroductionDetailVO();
        vo.setId(entity.getId());
        vo.setTitle(entity.getTitle());
        vo.setCoverImg(entity.getCoverImg());
        vo.setCategory(entity.getCategory());
        vo.setContentType(entity.getContentType());
        vo.setContent(entity.getContent());
        vo.setVideoUrl(entity.getVideoUrl());
        vo.setVideoFileName(entity.getVideoFileName());
        vo.setVideoDescription(entity.getVideoDescription());
        vo.setClickCount(entity.getClickCount());
 
        return vo;
    }
}