|
|
@ -3,18 +3,24 @@ package com.youlai.boot.mini.service.impl; |
|
|
import ch.hsr.geohash.GeoHash; |
|
|
import ch.hsr.geohash.GeoHash; |
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import cn.hutool.core.lang.Assert; |
|
|
import cn.hutool.core.lang.Assert; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.youlai.boot.common.constant.CommonConstants; |
|
|
import com.youlai.boot.common.constant.CommonConstants; |
|
|
|
|
|
import com.youlai.boot.common.exception.MsgException; |
|
|
import com.youlai.boot.common.util.CoordinateTransformUtils; |
|
|
import com.youlai.boot.common.util.CoordinateTransformUtils; |
|
|
import com.youlai.boot.common.util.FileUtils; |
|
|
import com.youlai.boot.common.util.FileUtils; |
|
|
import com.youlai.boot.common.util.JavaVCUtils; |
|
|
import com.youlai.boot.common.util.JavaVCUtils; |
|
|
import com.youlai.boot.common.util.RandomNumberUtils; |
|
|
import com.youlai.boot.common.util.RandomNumberUtils; |
|
|
import com.youlai.boot.file.service.FileService; |
|
|
import com.youlai.boot.file.service.impl.AliyunFileService; |
|
|
import com.youlai.boot.framework.security.util.SecurityUtils; |
|
|
import com.youlai.boot.framework.security.util.SecurityUtils; |
|
|
import com.youlai.boot.mini.converter.MiniStrayAnimalConverter; |
|
|
import com.youlai.boot.mini.converter.MiniStrayAnimalConverter; |
|
|
import com.youlai.boot.mini.mapper.MiniStrayAnimalMapper; |
|
|
import com.youlai.boot.mini.mapper.MiniStrayAnimalMapper; |
|
|
import com.youlai.boot.mini.mapper.MiniStrayAnimalNoteMapper; |
|
|
import com.youlai.boot.mini.mapper.MiniStrayAnimalNoteMapper; |
|
|
import com.youlai.boot.mini.mapper.MiniStrayAnimalNoteMediaMapper; |
|
|
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.enums.AnimalNoteMediaTypeEnum; |
|
|
import com.youlai.boot.mini.model.enums.AnimalNoteMediaTypeEnum; |
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimal; |
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimal; |
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimalNote; |
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimalNote; |
|
|
@ -23,6 +29,7 @@ import com.youlai.boot.mini.model.form.StrayAnimalForm; |
|
|
import com.youlai.boot.mini.service.StrayAnimalService; |
|
|
import com.youlai.boot.mini.service.StrayAnimalService; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.io.FilenameUtils; |
|
|
import org.apache.commons.io.FilenameUtils; |
|
|
import org.locationtech.jts.geom.Coordinate; |
|
|
import org.locationtech.jts.geom.Coordinate; |
|
|
import org.locationtech.jts.geom.GeometryFactory; |
|
|
import org.locationtech.jts.geom.GeometryFactory; |
|
|
@ -34,9 +41,7 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
import javax.imageio.ImageIO; |
|
|
import javax.imageio.ImageIO; |
|
|
import java.awt.image.BufferedImage; |
|
|
import java.awt.image.BufferedImage; |
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
import java.util.Date; |
|
|
import java.util.*; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 流浪动物业务实现类 |
|
|
* 流浪动物业务实现类 |
|
|
@ -46,7 +51,7 @@ import java.util.UUID; |
|
|
@Slf4j |
|
|
@Slf4j |
|
|
public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, MiniStrayAnimal> implements StrayAnimalService { |
|
|
public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, MiniStrayAnimal> implements StrayAnimalService { |
|
|
|
|
|
|
|
|
private final FileService fileService; |
|
|
private final AliyunFileService aliyunFileService; |
|
|
|
|
|
|
|
|
private final MiniStrayAnimalNoteMapper miniStrayAnimalNoteMapper; |
|
|
private final MiniStrayAnimalNoteMapper miniStrayAnimalNoteMapper; |
|
|
private final MiniStrayAnimalNoteMediaMapper miniStrayAnimalNoteMediaMapper; |
|
|
private final MiniStrayAnimalNoteMediaMapper miniStrayAnimalNoteMediaMapper; |
|
|
@ -59,7 +64,7 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public String saveStrayAnimal(StrayAnimalForm formData, List<MultipartFile> images, List<MultipartFile> videos) { |
|
|
public String saveStrayAnimal(StrayAnimalForm formData, List<MultipartFile> images, List<MultipartFile> videos) { |
|
|
// 1. 参数校验
|
|
|
// 1. 参数校验
|
|
|
validateInput(formData, images, videos); |
|
|
validateInput(images, videos); |
|
|
|
|
|
|
|
|
// 2. 保存流浪动物基本信息
|
|
|
// 2. 保存流浪动物基本信息
|
|
|
MiniStrayAnimal miniStrayAnimal = saveAnimalInfo(formData); |
|
|
MiniStrayAnimal miniStrayAnimal = saveAnimalInfo(formData); |
|
|
@ -68,23 +73,25 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
MiniStrayAnimalNote note = saveNoteInfo(formData, miniStrayAnimal); |
|
|
MiniStrayAnimalNote note = saveNoteInfo(formData, miniStrayAnimal); |
|
|
|
|
|
|
|
|
// 4. 处理并保存媒体文件
|
|
|
// 4. 处理并保存媒体文件
|
|
|
saveMediaFiles(note, images, videos); |
|
|
saveMediaFiles(note, images, videos, miniStrayAnimal.getCreateTimestamp()); |
|
|
|
|
|
|
|
|
|
|
|
// 5. 提交审核
|
|
|
|
|
|
|
|
|
return miniStrayAnimal.getUuid(); |
|
|
return miniStrayAnimal.getUuid(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void saveMediaFiles(MiniStrayAnimalNote note, List<MultipartFile> images, List<MultipartFile> videos) { |
|
|
private void saveMediaFiles(MiniStrayAnimalNote note, List<MultipartFile> images, List<MultipartFile> videos, long currentTimestamp) { |
|
|
int sortOrder = 0; |
|
|
long sortOrder = currentTimestamp; |
|
|
// 处理图片
|
|
|
// 处理图片
|
|
|
if (images != null) { |
|
|
if (images != null) { |
|
|
for (MultipartFile image : images) { |
|
|
for (MultipartFile image : images) { |
|
|
try { |
|
|
try { |
|
|
String objectName = "animal_note/" |
|
|
String objectName = "animal_note/" |
|
|
+ note.getId() + "/" |
|
|
+ note.getId() + "/" |
|
|
+ note.getCreateTimestamp() + RandomNumberUtils.createRandomLowerLetterAndNumber(8) |
|
|
+ currentTimestamp + RandomNumberUtils.createRandomLowerLetterAndNumber(8) |
|
|
+ "." |
|
|
+ "." |
|
|
+ FilenameUtils.getExtension(image.getOriginalFilename()); |
|
|
+ FilenameUtils.getExtension(image.getOriginalFilename()); |
|
|
String url = fileService.uploadFile(objectName, image.getInputStream()); |
|
|
String url = aliyunFileService.uploadFile(objectName, image.getInputStream()); |
|
|
MiniStrayAnimalNoteMedia miniStrayAnimalNoteMedia = new MiniStrayAnimalNoteMedia(); |
|
|
MiniStrayAnimalNoteMedia miniStrayAnimalNoteMedia = new MiniStrayAnimalNoteMedia(); |
|
|
miniStrayAnimalNoteMedia.setUuid(UUID.randomUUID().toString()); |
|
|
miniStrayAnimalNoteMedia.setUuid(UUID.randomUUID().toString()); |
|
|
miniStrayAnimalNoteMedia.setNoteId(note.getId()); |
|
|
miniStrayAnimalNoteMedia.setNoteId(note.getId()); |
|
|
@ -95,8 +102,8 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
miniStrayAnimalNoteMedia.setWidth(imageInfo.getWidth()); |
|
|
miniStrayAnimalNoteMedia.setWidth(imageInfo.getWidth()); |
|
|
miniStrayAnimalNoteMedia.setHeight(imageInfo.getHeight()); |
|
|
miniStrayAnimalNoteMedia.setHeight(imageInfo.getHeight()); |
|
|
miniStrayAnimalNoteMedia.setSortOrder(sortOrder++); |
|
|
miniStrayAnimalNoteMedia.setSortOrder(sortOrder++); |
|
|
miniStrayAnimalNoteMedia.setCreateTimestamp(note.getCreateTimestamp()); |
|
|
miniStrayAnimalNoteMedia.setCreateTimestamp(currentTimestamp); |
|
|
miniStrayAnimalNoteMedia.setCreateTime(new Date(miniStrayAnimalNoteMedia.getCreateTimestamp())); |
|
|
miniStrayAnimalNoteMedia.setCreateTime(new Date(currentTimestamp)); |
|
|
miniStrayAnimalNoteMedia.setCreateBy(note.getMiniUserId()); |
|
|
miniStrayAnimalNoteMedia.setCreateBy(note.getMiniUserId()); |
|
|
|
|
|
|
|
|
int result = miniStrayAnimalNoteMediaMapper.insert(miniStrayAnimalNoteMedia); |
|
|
int result = miniStrayAnimalNoteMediaMapper.insert(miniStrayAnimalNoteMedia); |
|
|
@ -111,13 +118,13 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
String tmpPath = System.getProperty("user.dir") + "/tmp"; |
|
|
String tmpPath = System.getProperty("user.dir") + "/tmp"; |
|
|
for (MultipartFile video : videos) { |
|
|
for (MultipartFile video : videos) { |
|
|
try { |
|
|
try { |
|
|
String fileName = note.getCreateTimestamp() + RandomNumberUtils.createRandomLowerLetterAndNumber(8); |
|
|
String fileName = currentTimestamp + RandomNumberUtils.createRandomLowerLetterAndNumber(8); |
|
|
String objectName = "animal_note/" |
|
|
String objectName = "animal_note/" |
|
|
+ note.getId() + "/" |
|
|
+ note.getId() + "/" |
|
|
+ fileName |
|
|
+ fileName |
|
|
+ "." |
|
|
+ "." |
|
|
+ FilenameUtils.getExtension(video.getOriginalFilename()); |
|
|
+ FilenameUtils.getExtension(video.getOriginalFilename()); |
|
|
String url = fileService.uploadFile(objectName, video.getInputStream()); |
|
|
String url = aliyunFileService.uploadFile(objectName, video.getInputStream()); |
|
|
MiniStrayAnimalNoteMedia miniStrayAnimalNoteMedia = new MiniStrayAnimalNoteMedia(); |
|
|
MiniStrayAnimalNoteMedia miniStrayAnimalNoteMedia = new MiniStrayAnimalNoteMedia(); |
|
|
miniStrayAnimalNoteMedia.setUuid(UUID.randomUUID().toString()); |
|
|
miniStrayAnimalNoteMedia.setUuid(UUID.randomUUID().toString()); |
|
|
miniStrayAnimalNoteMedia.setNoteId(note.getId()); |
|
|
miniStrayAnimalNoteMedia.setNoteId(note.getId()); |
|
|
@ -125,8 +132,8 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
miniStrayAnimalNoteMedia.setSourceUrl(url); |
|
|
miniStrayAnimalNoteMedia.setSourceUrl(url); |
|
|
miniStrayAnimalNoteMedia.setStorageKey(objectName); |
|
|
miniStrayAnimalNoteMedia.setStorageKey(objectName); |
|
|
miniStrayAnimalNoteMedia.setSortOrder(sortOrder++); |
|
|
miniStrayAnimalNoteMedia.setSortOrder(sortOrder++); |
|
|
miniStrayAnimalNoteMedia.setCreateTimestamp(note.getCreateTimestamp()); |
|
|
miniStrayAnimalNoteMedia.setCreateTimestamp(currentTimestamp); |
|
|
miniStrayAnimalNoteMedia.setCreateTime(new Date(miniStrayAnimalNoteMedia.getCreateTimestamp())); |
|
|
miniStrayAnimalNoteMedia.setCreateTime(new Date(currentTimestamp)); |
|
|
miniStrayAnimalNoteMedia.setCreateBy(note.getMiniUserId()); |
|
|
miniStrayAnimalNoteMedia.setCreateBy(note.getMiniUserId()); |
|
|
//时长
|
|
|
//时长
|
|
|
FileUtils.saveFile(video, tmpPath, fileName); |
|
|
FileUtils.saveFile(video, tmpPath, fileName); |
|
|
@ -135,12 +142,12 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
miniStrayAnimalNoteMedia.setDuration((int) Math.ceil(duration)); |
|
|
miniStrayAnimalNoteMedia.setDuration((int) Math.ceil(duration)); |
|
|
//缩略图
|
|
|
//缩略图
|
|
|
BufferedImage thumbnail = JavaVCUtils.getVideoThumbnail(videoPath, 1); |
|
|
BufferedImage thumbnail = JavaVCUtils.getVideoThumbnail(videoPath, 1); |
|
|
String thumbnailFileName = note.getCreateTimestamp() + RandomNumberUtils.createRandomLowerLetterAndNumber(8); |
|
|
String thumbnailFileName = currentTimestamp + RandomNumberUtils.createRandomLowerLetterAndNumber(8); |
|
|
String thumbnailObjectName = "animal_note/" |
|
|
String thumbnailObjectName = "animal_note/" |
|
|
+ note.getId() + "/" |
|
|
+ note.getId() + "/" |
|
|
+ thumbnailFileName |
|
|
+ thumbnailFileName |
|
|
+ ".png"; |
|
|
+ ".png"; |
|
|
String thumbnailUrl = fileService.uploadFile(thumbnailObjectName, |
|
|
String thumbnailUrl = aliyunFileService.uploadFile(thumbnailObjectName, |
|
|
FileUtils.bufferedImageToInputStream(thumbnail, "png")); |
|
|
FileUtils.bufferedImageToInputStream(thumbnail, "png")); |
|
|
miniStrayAnimalNoteMedia.setThumbnailUrl(thumbnailUrl); |
|
|
miniStrayAnimalNoteMedia.setThumbnailUrl(thumbnailUrl); |
|
|
|
|
|
|
|
|
@ -174,22 +181,13 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
private MiniStrayAnimal saveAnimalInfo(StrayAnimalForm formData) { |
|
|
private MiniStrayAnimal saveAnimalInfo(StrayAnimalForm formData) { |
|
|
|
|
|
|
|
|
long currentTimeUnix = System.currentTimeMillis(); |
|
|
long currentTimeUnix = System.currentTimeMillis(); |
|
|
MiniStrayAnimal entity = new MiniStrayAnimal(); |
|
|
MiniStrayAnimal entity = miniStrayAnimalConverter.toEntity(formData); |
|
|
|
|
|
|
|
|
entity.setMiniUserId(SecurityUtils.getUserId()); |
|
|
entity.setMiniUserId(SecurityUtils.getUserId()); |
|
|
entity.setUuid(UUID.randomUUID().toString()); |
|
|
entity.setUuid(UUID.randomUUID().toString()); |
|
|
entity.setAnimalType(formData.getAnimalType().toLowerCase()); |
|
|
|
|
|
entity.setColor(formData.getColor()); |
|
|
|
|
|
if (formData.getSize() != null) { |
|
|
|
|
|
entity.setSize(formData.getSize().toLowerCase()); |
|
|
|
|
|
} |
|
|
|
|
|
entity.setStatus(formData.getStatus().toLowerCase()); |
|
|
|
|
|
entity.setCreateTimestamp(currentTimeUnix); |
|
|
entity.setCreateTimestamp(currentTimeUnix); |
|
|
entity.setCreateTime(new Date(currentTimeUnix)); |
|
|
entity.setCreateTime(new Date(currentTimeUnix)); |
|
|
entity.setCreateBy(SecurityUtils.getUserId()); |
|
|
entity.setCreateBy(SecurityUtils.getUserId()); |
|
|
entity.setProvince(formData.getProvince()); |
|
|
|
|
|
entity.setCity(formData.getCity()); |
|
|
|
|
|
entity.setDistrict(formData.getDistrict()); |
|
|
|
|
|
entity.setAddress(formData.getAddress()); |
|
|
|
|
|
|
|
|
|
|
|
handleLngLat(entity, formData.getLng(), formData.getLat()); |
|
|
handleLngLat(entity, formData.getLng(), formData.getLat()); |
|
|
|
|
|
|
|
|
@ -211,17 +209,217 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M |
|
|
entity.setWgs84Geohash( GeoHash.withCharacterPrecision(wgs84[1], wgs84[0], CommonConstants.GEOHASH_LEVEL).toBase32()); |
|
|
entity.setWgs84Geohash( GeoHash.withCharacterPrecision(wgs84[1], wgs84[0], CommonConstants.GEOHASH_LEVEL).toBase32()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void validateInput(StrayAnimalForm formData, List<MultipartFile> images, List<MultipartFile> videos) { |
|
|
private void validateInput(List<MultipartFile> images, List<MultipartFile> videos) { |
|
|
// 验证必填图片
|
|
|
// 验证必填图片
|
|
|
Assert.notEmpty(images, "需要上传图片"); |
|
|
if (images == null || images.isEmpty()) { |
|
|
|
|
|
throw new MsgException("需要上传图片"); |
|
|
|
|
|
} |
|
|
// 验证图片数量
|
|
|
// 验证图片数量
|
|
|
Assert.isTrue( |
|
|
if (images.size() > CommonConstants.STRAY_ANIMAL_IMAGE_NUM_LIMIT) { |
|
|
images.size() <= CommonConstants.STRAY_ANIMAL_IMAGE_NUM_LIMIT, |
|
|
throw new MsgException( |
|
|
"最多只能上传" + CommonConstants.STRAY_ANIMAL_IMAGE_NUM_LIMIT + "张图片"); |
|
|
"最多只能上传" + CommonConstants.STRAY_ANIMAL_IMAGE_NUM_LIMIT + "张图片" |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 验证视频数量
|
|
|
// 验证视频数量
|
|
|
Assert.isTrue( |
|
|
if (!CollUtil.isEmpty(videos) && videos.size() > CommonConstants.STRAY_ANIMAL_VIDEO_NUM_LIMIT) { |
|
|
CollUtil.isEmpty(videos) || videos.size() <= CommonConstants.STRAY_ANIMAL_VIDEO_NUM_LIMIT, |
|
|
throw new MsgException( |
|
|
"最多只能上传" + CommonConstants.STRAY_ANIMAL_VIDEO_NUM_LIMIT + "个视频"); |
|
|
"最多只能上传" + CommonConstants.STRAY_ANIMAL_VIDEO_NUM_LIMIT + "个视频" |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void updateStrayAnimal(String animalUuid, StrayAnimalForm formData) { |
|
|
|
|
|
// 校验动物是否存在
|
|
|
|
|
|
MiniStrayAnimal animal = getValidAnimal(animalUuid); |
|
|
|
|
|
|
|
|
|
|
|
// 校验审核状态
|
|
|
|
|
|
checkNotAuditing(animal); |
|
|
|
|
|
|
|
|
|
|
|
long currentTimestamp = System.currentTimeMillis(); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 更新流浪动物基本信息
|
|
|
|
|
|
updateAnimalInfo(animal.getId(), formData, currentTimestamp); |
|
|
|
|
|
// 3. 更新笔记信息`
|
|
|
|
|
|
updateNoteInfo(animal.getId(), formData, currentTimestamp); |
|
|
|
|
|
// 4. 提交审核
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private MiniStrayAnimal getValidAnimal(String animalUuid) { |
|
|
|
|
|
MiniStrayAnimal animal = miniStrayAnimalMapper.selectOne( |
|
|
|
|
|
new LambdaQueryWrapper<MiniStrayAnimal>() |
|
|
|
|
|
.eq(MiniStrayAnimal::getUuid, animalUuid) |
|
|
|
|
|
.eq(MiniStrayAnimal::getDeleted, 0) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (animal == null) { |
|
|
|
|
|
throw new MsgException("动物不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return animal; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void checkNotAuditing(MiniStrayAnimal animal) { |
|
|
|
|
|
if (1 == animal.getAuditStatus()) { |
|
|
|
|
|
throw new MsgException("审核中无法更改"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void updateNoteInfo(Long animalId, StrayAnimalForm formData, long currentTimestamp) { |
|
|
|
|
|
//处理笔记
|
|
|
|
|
|
MiniStrayAnimalNote miniStrayAnimalNote = miniStrayAnimalNoteMapper.selectOne(new LambdaQueryWrapper<MiniStrayAnimalNote>() |
|
|
|
|
|
.eq(MiniStrayAnimalNote::getStrayAnimalId, animalId)); |
|
|
|
|
|
if (null != miniStrayAnimalNote){ |
|
|
|
|
|
LambdaUpdateWrapper<MiniStrayAnimalNote> updateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
updateWrapper.eq(MiniStrayAnimalNote::getId, miniStrayAnimalNote.getId()) |
|
|
|
|
|
.set(MiniStrayAnimalNote::getTitle, formData.getTitle()) |
|
|
|
|
|
.set(MiniStrayAnimalNote::getContent, formData.getContent()) |
|
|
|
|
|
.set(MiniStrayAnimalNote::getVisibility, formData.getVisibility()) |
|
|
|
|
|
.set(MiniStrayAnimalNote::getUpdateTimestamp, currentTimestamp) |
|
|
|
|
|
.set(MiniStrayAnimalNote::getUpdateBy, SecurityUtils.getUserId()) |
|
|
|
|
|
.set(MiniStrayAnimalNote::getUpdateTime, new Date(currentTimestamp)); |
|
|
|
|
|
|
|
|
|
|
|
miniStrayAnimalNoteMapper.update(null, updateWrapper); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void updateAnimalInfo(Long animalId, StrayAnimalForm formData, long currentTimestamp) { |
|
|
|
|
|
MiniStrayAnimal miniStrayAnimal = miniStrayAnimalConverter.toEntity(formData); |
|
|
|
|
|
|
|
|
|
|
|
miniStrayAnimal.setId(animalId); |
|
|
|
|
|
miniStrayAnimal.setUpdateTimestamp(currentTimestamp); |
|
|
|
|
|
miniStrayAnimal.setUpdateTime(new Date(currentTimestamp)); |
|
|
|
|
|
miniStrayAnimal.setUpdateBy(SecurityUtils.getUserId()); |
|
|
|
|
|
handleLngLat(miniStrayAnimal, formData.getLng(), formData.getLat()); |
|
|
|
|
|
|
|
|
|
|
|
miniStrayAnimalMapper.updateStrayAnimal(miniStrayAnimal); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void deleteMediaSource(DeleteStrayAnimalNoteMediaDTO deleteStrayAnimalNoteMediaDTO) { |
|
|
|
|
|
List<String> noteMediaUuidList = deleteStrayAnimalNoteMediaDTO.getNoteMediaUuidList(); |
|
|
|
|
|
|
|
|
|
|
|
MiniStrayAnimalNote note = miniStrayAnimalNoteMapper.selectOne(new LambdaQueryWrapper<MiniStrayAnimalNote>() |
|
|
|
|
|
.eq(MiniStrayAnimalNote::getUuid, deleteStrayAnimalNoteMediaDTO.getNoteUuid())); |
|
|
|
|
|
if (note == null) { |
|
|
|
|
|
throw new MsgException("笔记不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<MiniStrayAnimalNoteMedia> queryWrapper = |
|
|
|
|
|
new LambdaQueryWrapper<MiniStrayAnimalNoteMedia>() |
|
|
|
|
|
.in(MiniStrayAnimalNoteMedia::getUuid, noteMediaUuidList) |
|
|
|
|
|
.eq(MiniStrayAnimalNoteMedia::getNoteId, note.getId()) |
|
|
|
|
|
.eq(MiniStrayAnimalNoteMedia::getDeleted, 0); |
|
|
|
|
|
|
|
|
|
|
|
List<MiniStrayAnimalNoteMedia> mediaList = |
|
|
|
|
|
miniStrayAnimalNoteMediaMapper.selectList(queryWrapper); |
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(mediaList)) { |
|
|
|
|
|
|
|
|
|
|
|
// 删除源文件
|
|
|
|
|
|
List<String> storageKeyList = mediaList.stream() |
|
|
|
|
|
.map(MiniStrayAnimalNoteMedia::getStorageKey) |
|
|
|
|
|
.toList(); |
|
|
|
|
|
aliyunFileService.deleteMultiFile(storageKeyList); |
|
|
|
|
|
|
|
|
|
|
|
long currentTimestamp = System.currentTimeMillis(); |
|
|
|
|
|
|
|
|
|
|
|
// 逻辑删除
|
|
|
|
|
|
miniStrayAnimalNoteMediaMapper.update( |
|
|
|
|
|
null, |
|
|
|
|
|
new LambdaUpdateWrapper<MiniStrayAnimalNoteMedia>() |
|
|
|
|
|
.in(MiniStrayAnimalNoteMedia::getUuid, noteMediaUuidList) |
|
|
|
|
|
.eq(MiniStrayAnimalNoteMedia::getNoteId, note.getId()) |
|
|
|
|
|
.set(MiniStrayAnimalNoteMedia::getDeleted, 1) |
|
|
|
|
|
.set(MiniStrayAnimalNoteMedia::getUpdateTimestamp, currentTimestamp) |
|
|
|
|
|
.set(MiniStrayAnimalNoteMedia::getUpdateTime, new Date(currentTimestamp)) |
|
|
|
|
|
.set(MiniStrayAnimalNoteMedia::getUpdateBy, SecurityUtils.getUserId()) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private MiniStrayAnimalNote getValidNote(String noteUuid) { |
|
|
|
|
|
MiniStrayAnimalNote note = miniStrayAnimalNoteMapper.selectOne( |
|
|
|
|
|
new LambdaQueryWrapper<MiniStrayAnimalNote>() |
|
|
|
|
|
.eq(MiniStrayAnimalNote::getUuid, noteUuid) |
|
|
|
|
|
.eq(MiniStrayAnimalNote::getDeleted, 0) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (note == null) { |
|
|
|
|
|
throw new MsgException("笔记不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return note; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void saveMediaSource(String noteUuid, List<MultipartFile> images, List<MultipartFile> videos) { |
|
|
|
|
|
if ((images == null || images.isEmpty()) && (videos == null || videos.isEmpty())) { |
|
|
|
|
|
throw new MsgException("需要上传媒体资源"); |
|
|
|
|
|
} |
|
|
|
|
|
// 获取笔记
|
|
|
|
|
|
MiniStrayAnimalNote note = getValidNote(noteUuid); |
|
|
|
|
|
|
|
|
|
|
|
Long animalId = note.getStrayAnimalId(); |
|
|
|
|
|
MiniStrayAnimal miniStrayAnimal = miniStrayAnimalMapper.selectById(animalId); |
|
|
|
|
|
if (miniStrayAnimal == null) { |
|
|
|
|
|
throw new MsgException("动物信息不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
if (1 == miniStrayAnimal.getAuditStatus()){ |
|
|
|
|
|
throw new MsgException("审核中"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//校验数量有没有超出
|
|
|
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
|
|
param.put("noteId", note.getId()); |
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(images)){ |
|
|
|
|
|
param.put("mediaType", AnimalNoteMediaTypeEnum.IMAGE.name().toLowerCase()); |
|
|
|
|
|
int imagesExist = miniStrayAnimalNoteMediaMapper.getMediaCountByNoteIdAndType(param); |
|
|
|
|
|
if (imagesExist+images.size() > CommonConstants.STRAY_ANIMAL_IMAGE_NUM_LIMIT) { |
|
|
|
|
|
throw new MsgException("图片总数不能超过" + CommonConstants.STRAY_ANIMAL_IMAGE_NUM_LIMIT + "张"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (CollectionUtils.isNotEmpty(videos)){ |
|
|
|
|
|
param.put("mediaType", AnimalNoteMediaTypeEnum.VIDEO.name().toLowerCase()); |
|
|
|
|
|
int videosExist = miniStrayAnimalNoteMediaMapper.getMediaCountByNoteIdAndType(param); |
|
|
|
|
|
if(videosExist+videos.size() > CommonConstants.STRAY_ANIMAL_VIDEO_NUM_LIMIT){ |
|
|
|
|
|
throw new MsgException("视频总数不能超过" + CommonConstants.STRAY_ANIMAL_VIDEO_NUM_LIMIT + "个"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
saveMediaFiles(note, images, videos, System.currentTimeMillis()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void updateVisibility(String animalUuid, EditVisibilityDTO editVisibilityDTO) { |
|
|
|
|
|
// 校验动物是否存在
|
|
|
|
|
|
MiniStrayAnimal animal = getValidAnimal(animalUuid); |
|
|
|
|
|
|
|
|
|
|
|
MiniStrayAnimalNote miniStrayAnimalNote = miniStrayAnimalNoteMapper.selectOne(new LambdaQueryWrapper<MiniStrayAnimalNote>() |
|
|
|
|
|
.eq(MiniStrayAnimalNote::getStrayAnimalId, animal.getId()) |
|
|
|
|
|
.eq(MiniStrayAnimalNote::getDeleted, 0)); |
|
|
|
|
|
if (null != miniStrayAnimalNote) { |
|
|
|
|
|
LambdaUpdateWrapper<MiniStrayAnimalNote> updateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
updateWrapper.eq(MiniStrayAnimalNote::getId, miniStrayAnimalNote.getId()) |
|
|
|
|
|
.set(MiniStrayAnimalNote::getVisibility, editVisibilityDTO.getVisibility()); |
|
|
|
|
|
|
|
|
|
|
|
miniStrayAnimalNoteMapper.update(null, updateWrapper); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void delete(DeleteStrayAnimalDTO deleteStrayAnimalDTO) { |
|
|
|
|
|
LambdaUpdateWrapper<MiniStrayAnimal> updateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
updateWrapper.in(MiniStrayAnimal::getUuid, deleteStrayAnimalDTO.getAnimalUuidList()) |
|
|
|
|
|
.set(MiniStrayAnimal::getDeleted, 1); |
|
|
|
|
|
|
|
|
|
|
|
miniStrayAnimalMapper.update(null, updateWrapper); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|