package com.shiep.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.shiep.dao.IUserDao;
import com.shiep.entity.*;
import com.shiep.mapper.*;
import com.shiep.service.IAnimalSearchService;
import com.shiep.vo.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class AnimalSearchServiceImpl implements IAnimalSearchService {
@Resource
private IAnimalSearchMapper animalSearchMapper;
@Resource
private IUserDao userDao;
@Resource
private ILocationDao locationDao;
@Resource
private IAnimalCategoryDetailsMapper animalCategoryDetailsMapper;
@Resource
private IPhotoAnimalSearchMapper photoAnimalSearchMapper;
@Resource
private ICountyMapper countyMapper;
@Resource
private IAnimalSearchCommentMapper animalSearchCommentMapper;
@Resource
private IUserMapper userMapper;
@Override
public boolean saveAnimalSearch(AnimalSearch animalSearch) {
if (animalSearch == null) {
return false;
}
return this.animalSearchMapper.insert(animalSearch) > 0;
}
@Override
public List<AnimalSearchVo> queryAll(
Long cityId, Integer categoryId, Long countyId, Integer searchAnimal) {
List<AnimalSearch> animalSearches = null;
// 1、)什么都不做 首先必须处理的是cityId 如果为null 查询所有adopt
if (cityId == null) {
QueryWrapper<AnimalSearch> qw = new QueryWrapper<>();
// 没有被删除 并且审核通过的
qw.lambda().eq(AnimalSearch::getDeleteStatus, 0).eq(AnimalSearch::getVerifyStatus, 1);
animalSearches = this.animalSearchMapper.selectList(qw);
List<AnimalSearchVo> animalSearchVos = this.getAnimalSearchVo(animalSearches);
return animalSearchVos;
}
// 2、) 选择地区后:其他都为null
if (cityId != null && (categoryId == null || categoryId == 0) && countyId == null && searchAnimal == null) {
// 首先根据cityId查询出所有的县区id
QueryWrapper<County> qwCounty = new QueryWrapper<>();
qwCounty.lambda().eq(County::getCityId, cityId);
List<County> counties = this.countyMapper.selectList(qwCounty);
List<Long> countyIds = counties.stream().map(County::getId).collect(Collectors.toList());
if (countyIds.isEmpty()) {
return new ArrayList<>();
}
// 查找
QueryWrapper<AnimalSearch> qw = new QueryWrapper<>();
qw.lambda().eq(AnimalSearch::getDeleteStatus, 0).eq(AnimalSearch::getVerifyStatus, 1)
.in(AnimalSearch::getCountyId, countyIds);
animalSearches = this.animalSearchMapper.selectList(qw);
List<AnimalSearchVo> AnimalSearchVos = this.getAnimalSearchVo(animalSearches);
return AnimalSearchVos;
}
// 3、) 选择了具体的县区
if (cityId != null && (categoryId == null || categoryId == 0) && countyId != null && searchAnimal == null) {
QueryWrapper<AnimalSearch> qw = new QueryWrapper<>();
// 没有被删除 并且审核通过的 h有具体县区
qw.lambda().eq(AnimalSearch::getDeleteStatus, 0).eq(AnimalSearch::getVerifyStatus, 1)
.eq(AnimalSearch::getCountyId, countyId);
animalSearches = this.animalSearchMapper.selectList(qw);
List<AnimalSearchVo> animalSearchVos = this.getAnimalSearchVo(animalSearches);
return animalSearchVos;
}
// 4、)选择了宠类
if (cityId != null && categoryId != null && countyId == null && searchAnimal == null) {
// 首先根据cityId查询出所有的县区id
QueryWrapper<County> qwCounty = new QueryWrapper<>();
qwCounty.lambda().eq(County::getCityId, cityId);
List<County> counties = this.countyMapper.selectList(qwCounty);
List<Long> countyIds = counties.stream().map(County::getId).collect(Collectors.toList());
if (countyIds.isEmpty()) {
return new ArrayList<>();
}
// 其次根据宠类ID选择出具体的宠类id
QueryWrapper<AnimalCategoryDetails> qwCategory = new QueryWrapper<>();
qwCategory.lambda().eq(AnimalCategoryDetails::getCategoryId, categoryId);
List<AnimalCategoryDetails> details = this.animalCategoryDetailsMapper.selectList(qwCategory);
List<Integer> detailsIds = details.stream().map(AnimalCategoryDetails::getId).collect(Collectors.toList());
// 查找
// 记住,mybatisPlus 在查询来的集合为null的前提下 不会组装in的SQL,所以,所有的in我们要自己判断一下
if (detailsIds.isEmpty()) {
return new ArrayList<>();
}
QueryWrapper<AnimalSearch> qw = new QueryWrapper<>();
qw.lambda().eq(AnimalSearch::getDeleteStatus, 0).eq(AnimalSearch::getVerifyStatus, 1)
.in(AnimalSearch::getCountyId, countyIds).in(AnimalSearch::getCategoryId, detailsIds);
animalSearches = this.animalSearchMapper.selectList(qw);
List<AnimalSearchVo> animalSearchVos = this.getAnimalSearchVo(animalSearches);
return animalSearchVos;
}
// 5、)选择了搜索类型 --宠物、主人
if (cityId != null && (categoryId == null || categoryId == 0) && countyId == null && searchAnimal != null) {
// 首先根据cityId查询出所有的县区id
QueryWrapper<County> qwCounty = new QueryWrapper<>();
qwCounty.lambda().eq(County::getCityId, cityId);
List<County> counties = this.countyMapper.selectList(qwCounty);
List<Long> countyIds = counties.stream().map(County::getId).collect(Collectors.toList());
if (countyIds.isEmpty()) {
return new ArrayList<>();
}
// 查找
QueryWrapper<AnimalSearch> qw = new QueryWrapper<>();
qw.lambda().eq(AnimalSearch::getDeleteStatus, 0).eq(AnimalSearch::getVerifyStatus, 1)
.in(AnimalSearch::getCountyId, countyIds).eq(AnimalSearch::getSearchAnimal, searchAnimal);
animalSearches = this.animalSearchMapper.selectList(qw);
List<AnimalSearchVo> animalSearchVos = this.getAnimalSearchVo(animalSearches);
return animalSearchVos;
}
// 6、)选了具体的县区+宠类
if (cityId != null && categoryId != null && countyId != null && searchAnimal == null) {
// 先根据宠类ID选择出具体的宠类id
QueryWrapper<AnimalCategoryDetails> qwCategory = new QueryWrapper<>();
qwCategory.lambda().eq(AnimalCategoryDetails::getCategoryId, categoryId);
List<AnimalCategoryDetails> details = this.animalCategoryDetailsMapper.selectList(qwCategory);
List<Integer> detailsIds = details.stream().map(AnimalCategoryDetails::getId).collect(Collectors.toList());
if (detailsIds.isEmpty()) {
return new ArrayList<>();
}
QueryWrapper<AnimalSearch> qw = new QueryWrapper<>();
// 没有被删除 并且审核通过的 h有具体县区 + 宠类
qw.lambda().eq(AnimalSearch::getDeleteStatus, 0).eq(AnimalSearch::getVerifyStatus, 1)
.eq(AnimalSearch::getCountyId, countyId).in(AnimalSearch::getCategoryId, detailsIds);
animalSearches = this.animalSearchMapper.selectList(qw);
List<AnimalSearchVo> animal
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 基于Vue.js+Element UI+Axios+SpringBoot+Redis+Nginx的流浪动物救助帖子发布、回复、评论系统源码(前台门户系统和后台管理系统).zip
资源推荐
资源详情
资源评论
收起资源包目录
基于Vue.js+ElementUI+SpringBoot流浪动物救助帖子发布、回复、评论系统源码(前台门户和后台管理).zip (1019个子文件)
AnimalSearchServiceImpl.class 23KB
AnimalAdoptServiceImpl.class 19KB
UserServiceImpl.class 13KB
AnimalAdoptController.class 12KB
AnimalSearchController.class 11KB
ReportServiceImpl.class 11KB
RedisUtil.class 11KB
INewServiceImpl.class 11KB
AnimalSearch.class 10KB
AnimalAdopt.class 9KB
UserController.class 9KB
ConfigManager.class 7KB
User.class 7KB
UploadFileController.class 6KB
NewsController.class 6KB
CookieUtilsOld.class 6KB
ReporCommentServiceImpl.class 6KB
Report.class 6KB
JwtConfig.class 6KB
UEditorController.class 6KB
ReportController.class 6KB
CookieUtils.class 6KB
StorageManager.class 5KB
News.class 5KB
IReportMapper.class 5KB
ImageHunter.class 5KB
BinaryUploader.class 5KB
AuthController.class 5KB
AnimalSearchComment.class 5KB
AnimalAdoptComment.class 5KB
ResultMessage.class 5KB
ActionEnter.class 4KB
AnimalAdoptVo.class 4KB
AnimalSearchVo.class 4KB
ProvinceAndCityServiceImpl.class 4KB
ReportComment.class 4KB
PhotoAnimalReport.class 4KB
PathFormat.class 4KB
LoginController.class 4KB
JsonUtils.class 4KB
FileManager.class 4KB
MultiState.class 4KB
AuthServiceImpl.class 4KB
IAnimalAdoptMapper.class 3KB
AnimalCategoryDetailsServiceImpl.class 3KB
BaseState.class 3KB
PhotoAnimalSearch.class 3KB
ProvinceAndCityController.class 3KB
PhotoAnimalAdopt.class 3KB
RedisConfig.class 3KB
Base64Uploader.class 3KB
ReportVo.class 3KB
UserDaoImpl.class 3KB
TokenInterceptor.class 3KB
NumberUtils.class 3KB
AnimalCategoryDetails.class 3KB
MailServiceImpl.class 3KB
City.class 3KB
County.class 3KB
AnimalCategoryController.class 3KB
NewsVo.class 2KB
IAnimalSearchService.class 2KB
IAnimalAdoptService.class 2KB
TokenController.class 2KB
Location.class 2KB
AdminCategory.class 2KB
AnimalCategory.class 2KB
AnimalStatus.class 2KB
NewsType.class 2KB
Province.class 2KB
ReportType.class 2KB
AnimalSearchCommentVo.class 2KB
AnimalAdoptCommentVo.class 2KB
ReportCommentVo.class 2KB
IUserService.class 2KB
Category.class 2KB
Uploader.class 2KB
MailController.class 2KB
SACorsConfiguration.class 2KB
AppInfo.class 2KB
SpringUtil.class 1KB
CodecUtils.class 1KB
UploadPhototServiceImpl.class 1KB
CrosConfig.class 1KB
UserInfo.class 1KB
AppInfo$1.class 1KB
WebConfig.class 1KB
ObjectUtils.class 1KB
ILocationDao.class 1KB
IUserMapper.class 1KB
PermissionHandler.class 1KB
FileUtil.class 1KB
ActionMap.class 1KB
FileType.class 1KB
INewsService.class 1KB
ActionState.class 1KB
Encoder.class 1KB
IAnimalCategoryDetailsMapper.class 1KB
AnimalCategoryServiceImpl.class 916B
ActionMap$1.class 902B
共 1019 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
土豆片片
- 粉丝: 1713
- 资源: 5641
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功