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;
|
}
|
}
|