|
|
|
@ -3,8 +3,11 @@ package com.youlai.boot.mini.service.impl; |
|
|
|
import ch.hsr.geohash.GeoHash; |
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.lang.Assert; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.youlai.boot.common.constant.CommonConstants; |
|
|
|
import com.youlai.boot.common.exception.MsgException; |
|
|
|
@ -21,12 +24,20 @@ import com.youlai.boot.mini.mapper.MiniStrayAnimalNoteMediaMapper; |
|
|
|
import com.youlai.boot.mini.model.dto.DeleteStrayAnimalDTO; |
|
|
|
import com.youlai.boot.mini.model.dto.DeleteStrayAnimalNoteMediaDTO; |
|
|
|
import com.youlai.boot.mini.model.dto.EditVisibilityDTO; |
|
|
|
import com.youlai.boot.mini.model.dto.MapSearchDTO; |
|
|
|
import com.youlai.boot.mini.model.enums.AnimalNoteMediaTypeEnum; |
|
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimal; |
|
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimalNote; |
|
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimalNoteMedia; |
|
|
|
import com.youlai.boot.mini.model.form.StrayAnimalForm; |
|
|
|
import com.youlai.boot.mini.model.query.OwnStrayAnimalQuery; |
|
|
|
import com.youlai.boot.mini.model.vo.MiniStrayAnimalNoteMediaVO; |
|
|
|
import com.youlai.boot.mini.model.vo.StrayAnimalDetailsVO; |
|
|
|
import com.youlai.boot.mini.model.vo.StrayAnimalNearbyVO; |
|
|
|
import com.youlai.boot.mini.model.vo.StrayAnimalShortVO; |
|
|
|
import com.youlai.boot.mini.service.StrayAnimalService; |
|
|
|
import com.youlai.boot.system.mapper.UserMapper; |
|
|
|
import com.youlai.boot.system.model.entity.SysUser; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
@ -34,6 +45,7 @@ import org.apache.commons.io.FilenameUtils; |
|
|
|
import org.locationtech.jts.geom.Coordinate; |
|
|
|
import org.locationtech.jts.geom.GeometryFactory; |
|
|
|
import org.locationtech.jts.geom.Point; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
@ -51,14 +63,26 @@ import java.util.*; |
|
|
|
@Slf4j |
|
|
|
public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, MiniStrayAnimal> implements StrayAnimalService { |
|
|
|
|
|
|
|
@Value("${oss.aliyun.endpoint}") |
|
|
|
private String endpoint; |
|
|
|
|
|
|
|
@Value("${oss.aliyun.bucket-name}") |
|
|
|
private String bucketName; |
|
|
|
|
|
|
|
|
|
|
|
private final AliyunFileService aliyunFileService; |
|
|
|
|
|
|
|
private final MiniStrayAnimalNoteMapper miniStrayAnimalNoteMapper; |
|
|
|
private final MiniStrayAnimalNoteMediaMapper miniStrayAnimalNoteMediaMapper; |
|
|
|
private final MiniStrayAnimalMapper miniStrayAnimalMapper; |
|
|
|
private final UserMapper userMapper; |
|
|
|
|
|
|
|
private final MiniStrayAnimalConverter miniStrayAnimalConverter; |
|
|
|
|
|
|
|
public String getDefaultCatCoverHost() { |
|
|
|
return "https://" + bucketName + "." + endpoint; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@ -81,7 +105,6 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
|
} |
|
|
|
|
|
|
|
private void saveMediaFiles(MiniStrayAnimalNote note, List<MultipartFile> images, List<MultipartFile> videos, long currentTimestamp) { |
|
|
|
long sortOrder = currentTimestamp; |
|
|
|
// 处理图片
|
|
|
|
if (images != null) { |
|
|
|
for (MultipartFile image : images) { |
|
|
|
@ -101,7 +124,6 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
|
BufferedImage imageInfo = ImageIO.read(image.getInputStream()); |
|
|
|
miniStrayAnimalNoteMedia.setWidth(imageInfo.getWidth()); |
|
|
|
miniStrayAnimalNoteMedia.setHeight(imageInfo.getHeight()); |
|
|
|
miniStrayAnimalNoteMedia.setSortOrder(sortOrder++); |
|
|
|
miniStrayAnimalNoteMedia.setCreateTimestamp(currentTimestamp); |
|
|
|
miniStrayAnimalNoteMedia.setCreateTime(new Date(currentTimestamp)); |
|
|
|
miniStrayAnimalNoteMedia.setCreateBy(note.getMiniUserId()); |
|
|
|
@ -131,7 +153,6 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
|
miniStrayAnimalNoteMedia.setMediaType(AnimalNoteMediaTypeEnum.VIDEO.name().toLowerCase()); |
|
|
|
miniStrayAnimalNoteMedia.setSourceUrl(url); |
|
|
|
miniStrayAnimalNoteMedia.setStorageKey(objectName); |
|
|
|
miniStrayAnimalNoteMedia.setSortOrder(sortOrder++); |
|
|
|
miniStrayAnimalNoteMedia.setCreateTimestamp(currentTimestamp); |
|
|
|
miniStrayAnimalNoteMedia.setCreateTime(new Date(currentTimestamp)); |
|
|
|
miniStrayAnimalNoteMedia.setCreateBy(note.getMiniUserId()); |
|
|
|
@ -231,6 +252,7 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void updateStrayAnimal(String animalUuid, StrayAnimalForm formData) { |
|
|
|
// 校验动物是否存在
|
|
|
|
MiniStrayAnimal animal = getValidAnimal(animalUuid); |
|
|
|
@ -422,4 +444,107 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
|
miniStrayAnimalMapper.update(null, updateWrapper); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public IPage<StrayAnimalShortVO> getSelfCreatedPage(OwnStrayAnimalQuery queryParams) { |
|
|
|
queryParams.setMiniUserId(SecurityUtils.getUserId()); |
|
|
|
queryParams.setCreatorId(SecurityUtils.getUserId()); |
|
|
|
return getAnimalPage(queryParams); |
|
|
|
} |
|
|
|
|
|
|
|
private IPage<StrayAnimalShortVO> getAnimalPage(OwnStrayAnimalQuery queryParams) { |
|
|
|
// 参数构建
|
|
|
|
int pageNum = queryParams.getPageNum(); |
|
|
|
int pageSize = queryParams.getPageSize(); |
|
|
|
Page<StrayAnimalShortVO> page = new Page<>(pageNum, pageSize); |
|
|
|
|
|
|
|
IPage<StrayAnimalShortVO> result = this.miniStrayAnimalMapper.getAnimalPage(page, queryParams); |
|
|
|
if (result.getTotal() > 0) { |
|
|
|
result.getRecords().forEach(item -> { |
|
|
|
if (StrUtil.isBlank(item.getFirstImageUrl())) { |
|
|
|
switch (item.getAnimalType()) { |
|
|
|
case "cat": |
|
|
|
item.setFirstImageUrl(getDefaultCatCoverHost() + "/default_cat.png"); |
|
|
|
break; |
|
|
|
case "dog": |
|
|
|
item.setFirstImageUrl(getDefaultCatCoverHost() + "/default_dog.png"); |
|
|
|
break; |
|
|
|
default: |
|
|
|
item.setFirstImageUrl(getDefaultCatCoverHost() + "/default_other.png"); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
// 查询数据
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public StrayAnimalDetailsVO getDetails(String animalUuid, Long miniUserId) { |
|
|
|
// 校验动物是否存在
|
|
|
|
MiniStrayAnimal animal = getValidAnimal(animalUuid); |
|
|
|
|
|
|
|
StrayAnimalDetailsVO strayAnimalDetailsVO = miniStrayAnimalMapper.getStrayAnimalDetails(animalUuid, miniUserId); |
|
|
|
|
|
|
|
MiniStrayAnimalNote appStrayAnimalNote = miniStrayAnimalNoteMapper.selectOne(new LambdaQueryWrapper<MiniStrayAnimalNote>() |
|
|
|
.eq(MiniStrayAnimalNote::getStrayAnimalId, animal.getId())); |
|
|
|
if (appStrayAnimalNote != null) { |
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
param.put("noteId", appStrayAnimalNote.getId()); |
|
|
|
|
|
|
|
param.put("mediaType", AnimalNoteMediaTypeEnum.IMAGE.name().toLowerCase()); |
|
|
|
List<MiniStrayAnimalNoteMediaVO> images = miniStrayAnimalNoteMediaMapper.getMediaByNoteIdAndType(param); |
|
|
|
if (CollectionUtils.isNotEmpty(images)) { |
|
|
|
images.forEach(item -> { |
|
|
|
item.setNoteUuid(appStrayAnimalNote.getUuid()); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
param.put("mediaType", AnimalNoteMediaTypeEnum.VIDEO.name().toLowerCase()); |
|
|
|
List<MiniStrayAnimalNoteMediaVO> videos = miniStrayAnimalNoteMediaMapper.getMediaByNoteIdAndType(param); |
|
|
|
if (CollectionUtils.isNotEmpty(videos)) { |
|
|
|
videos.forEach(item -> { |
|
|
|
item.setNoteUuid(appStrayAnimalNote.getUuid()); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
strayAnimalDetailsVO.setImages(images); |
|
|
|
strayAnimalDetailsVO.setVideos(videos); |
|
|
|
} |
|
|
|
|
|
|
|
return strayAnimalDetailsVO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public IPage<StrayAnimalShortVO> getOthersCreatedPage(String authorUuid, OwnStrayAnimalQuery queryParams) { |
|
|
|
SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper<SysUser>() |
|
|
|
.eq(SysUser::getUuid, authorUuid) |
|
|
|
.eq(SysUser::getIsDeleted, 0)); |
|
|
|
if (sysUser == null) { |
|
|
|
throw new MsgException("用户不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
queryParams.setMiniUserId(SecurityUtils.getUserId()); |
|
|
|
queryParams.setCreatorId(sysUser.getId()); |
|
|
|
return getAnimalPage(queryParams); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<StrayAnimalNearbyVO> listByMapBounds(MapSearchDTO mapSearch) { |
|
|
|
if (mapSearch.getNorthEastLng() == null || mapSearch.getNorthEastLat() == null |
|
|
|
|| mapSearch.getSouthWestLng() == null || mapSearch.getSouthWestLat() == null) { |
|
|
|
throw new MsgException("地图边界参数未完整填写"); |
|
|
|
} |
|
|
|
|
|
|
|
double[] wgs84 = CoordinateTransformUtils.gcj02ToWgs84(mapSearch.getNorthEastLng(), mapSearch.getNorthEastLat()); |
|
|
|
mapSearch.setNorthEastLat(wgs84[1]); |
|
|
|
mapSearch.setNorthEastLng(wgs84[0]); |
|
|
|
|
|
|
|
double[] wgs842 = CoordinateTransformUtils.gcj02ToWgs84(mapSearch.getSouthWestLng(), mapSearch.getSouthWestLat()); |
|
|
|
mapSearch.setSouthWestLat(wgs842[1]); |
|
|
|
mapSearch.setSouthWestLng(wgs842[0]); |
|
|
|
|
|
|
|
return miniStrayAnimalMapper.listByMapBounds(mapSearch); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|