package com.linghu.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.linghu.mapper.KeywordMapper; import com.linghu.mapper.ReferenceMapper; import com.linghu.model.common.ResponseResult; import com.linghu.model.entity.Keyword; import com.linghu.model.entity.Type; import com.linghu.service.TypeService; import com.linghu.mapper.TypeMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; /** * @author xy * @description 针对表【type】的数据库操作Service实现 * @createDate 2025-07-04 20:10:31 */ @Service public class TypeServiceImpl extends ServiceImpl implements TypeService { @Resource private TypeMapper typeMapper; @Autowired private KeywordMapper keywordMapper; @Override public Type getTypeByName(String typeName) { // 查询 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Type::getType_name, typeName); return typeMapper.selectOne(queryWrapper); } @Override public ResponseResult addType(Type type) { boolean success = this.save(type); if (success) { return ResponseResult.success(type); } return ResponseResult.error("添加类型失败"); } @Override public ResponseResult batchDeleteTypes(List typeIds) { if (typeIds.isEmpty()) { return ResponseResult.error("请选择要删除的类型"); } List types = typeIds.stream().map(id -> { Type type = new Type(); type.setType_id(id); return type; }).collect(Collectors.toList()); boolean success = this.updateBatchById(types); if (success) { return ResponseResult.success(); } return ResponseResult.error("批量删除类型失败"); } @Override public ResponseResult> pageList(Integer keywordId, Integer questionId, Integer isNow) { List typeIds=new ArrayList<>(); Keyword keyword=new Keyword(); //先查找当前关键词下,所有的回答 的 所有的平台名称 if (keywordId != null) { keyword = keywordMapper.selectById(keywordId); } typeIds= keywordMapper.getTypeIds(keywordId, questionId, isNow,keyword); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); if (!typeIds.isEmpty()) { queryWrapper.in(Type::getType_id, typeIds); }else { if (keywordId != null) { return ResponseResult.success(new ArrayList<>()); }else { List list = this.list(queryWrapper); return ResponseResult.success(list); } } List list = this.list(queryWrapper); return ResponseResult.success(list); } }