|
@@ -56,7 +56,7 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
*
|
|
*
|
|
|
* @param pageNum 页码,默认1
|
|
* @param pageNum 页码,默认1
|
|
|
* @param pageSize 每页数量,默认10
|
|
* @param pageSize 每页数量,默认10
|
|
|
- * @return R<List<MomentListVO>> 动态列表
|
|
|
|
|
|
|
+ * @return R<List < MomentListVO>> 动态列表
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public List<MomentListVO> getRecommendedMoments(Integer pageNum, Integer pageSize) {
|
|
public List<MomentListVO> getRecommendedMoments(Integer pageNum, Integer pageSize) {
|
|
@@ -122,7 +122,7 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
* @param latitude 纬度
|
|
* @param latitude 纬度
|
|
|
* @param pageNum 页码,默认1
|
|
* @param pageNum 页码,默认1
|
|
|
* @param pageSize 每页数量,默认10
|
|
* @param pageSize 每页数量,默认10
|
|
|
- * @return R<List<MomentListVO>> 动态列表
|
|
|
|
|
|
|
+ * @return R<List < MomentListVO>> 动态列表
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public List<MomentListVO> getNearbyMoments(BigDecimal longitude, BigDecimal latitude, Integer pageNum, Integer pageSize) {
|
|
public List<MomentListVO> getNearbyMoments(BigDecimal longitude, BigDecimal latitude, Integer pageNum, Integer pageSize) {
|
|
@@ -257,7 +257,7 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
* @param lat2 纬度2(技师纬度)
|
|
* @param lat2 纬度2(技师纬度)
|
|
|
* @param lon2 经度2(技师经度)
|
|
* @param lon2 经度2(技师经度)
|
|
|
* @return double 距离(单位:km)
|
|
* @return double 距离(单位:km)
|
|
|
- *
|
|
|
|
|
|
|
+ * <p>
|
|
|
* 使用Haversine公式
|
|
* 使用Haversine公式
|
|
|
*/
|
|
*/
|
|
|
private double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
|
|
private double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
|
|
@@ -284,15 +284,7 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Long publishMoment(PublishMomentDTO dto, String openId) {
|
|
public Long publishMoment(PublishMomentDTO dto, String openId) {
|
|
|
- // 1. 参数校验
|
|
|
|
|
- if (dto == null) {
|
|
|
|
|
- throw new ServiceException("发布动态信息不能为空");
|
|
|
|
|
- }
|
|
|
|
|
- if (openId == null || openId.trim().isEmpty()) {
|
|
|
|
|
- throw new ServiceException("openId不能为空");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 2. 根据openId查询技师信息
|
|
|
|
|
|
|
+ // 根据openId查询技师信息
|
|
|
LambdaQueryWrapper<TJs> queryWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<TJs> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(TJs::getcOpenId, openId);
|
|
queryWrapper.eq(TJs::getcOpenId, openId);
|
|
|
TJs technician = tJsMapper.selectOne(queryWrapper);
|
|
TJs technician = tJsMapper.selectOne(queryWrapper);
|
|
@@ -300,33 +292,49 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
throw new ServiceException("技师信息不存在");
|
|
throw new ServiceException("技师信息不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 3. 校验媒体类型和媒体文件
|
|
|
|
|
- if (dto.getMediaType() == null) {
|
|
|
|
|
- throw new ServiceException("媒体类型不能为空");
|
|
|
|
|
- }
|
|
|
|
|
- if (dto.getMediaType() == 1) {
|
|
|
|
|
- // 图片类型
|
|
|
|
|
- if (dto.getImageUrls() == null || dto.getImageUrls().isEmpty()) {
|
|
|
|
|
- throw new ServiceException("图片不能为空");
|
|
|
|
|
|
|
+ //查询是否保存为草稿
|
|
|
|
|
+ Integer isDraft = dto.getIsDraft();
|
|
|
|
|
+ if (isDraft == 1) {
|
|
|
|
|
+ //只校验标题
|
|
|
|
|
+ if (dto.getTitle() == null || dto.getTitle().trim().isEmpty()) {
|
|
|
|
|
+ throw new ServiceException("动态标题不能为空");
|
|
|
}
|
|
}
|
|
|
- if (dto.getImageUrls().size() > 9) {
|
|
|
|
|
- throw new ServiceException("最多只能上传9张图片");
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 校验动态标题
|
|
|
|
|
+ if (dto.getTitle() == null || dto.getTitle().trim().isEmpty()) {
|
|
|
|
|
+ throw new ServiceException("动态标题不能为空");
|
|
|
}
|
|
}
|
|
|
- } else if (dto.getMediaType() == 2) {
|
|
|
|
|
- // 视频类型
|
|
|
|
|
- if (dto.getVideoUrl() == null || dto.getVideoUrl().trim().isEmpty()) {
|
|
|
|
|
- throw new ServiceException("视频不能为空");
|
|
|
|
|
|
|
+ // 校验动态内容
|
|
|
|
|
+ if (dto.getContent() == null || dto.getContent().trim().isEmpty()) {
|
|
|
|
|
+ throw new ServiceException("动态内容不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 校验媒体类型和媒体文件
|
|
|
|
|
+ if (dto.getMediaType() == null) {
|
|
|
|
|
+ throw new ServiceException("媒体类型不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getMediaType() == 1) {
|
|
|
|
|
+ // 图片类型
|
|
|
|
|
+ if (dto.getImageUrls() == null || dto.getImageUrls().isEmpty()) {
|
|
|
|
|
+ throw new ServiceException("图片不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getImageUrls().size() > 9) {
|
|
|
|
|
+ throw new ServiceException("最多只能上传9张图片");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (dto.getMediaType() == 2) {
|
|
|
|
|
+ // 视频类型
|
|
|
|
|
+ if (dto.getVideoUrl() == null || dto.getVideoUrl().trim().isEmpty()) {
|
|
|
|
|
+ throw new ServiceException("视频不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new ServiceException("媒体类型不正确");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 校验可见范围
|
|
|
|
|
+ if (dto.getVisibleRange() == null || dto.getVisibleRange() != 1) {
|
|
|
|
|
+ throw new ServiceException("可见范围只能选择公开");
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- throw new ServiceException("媒体类型不正确");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 4. 校验可见范围
|
|
|
|
|
- if (dto.getVisibleRange() == null || dto.getVisibleRange() != 1) {
|
|
|
|
|
- throw new ServiceException("可见范围只能选择公开");
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 5. 创建动态对象
|
|
|
|
|
|
|
+ // 创建动态对象
|
|
|
TechnicianMoment moment = new TechnicianMoment();
|
|
TechnicianMoment moment = new TechnicianMoment();
|
|
|
moment.setTechnicianId(technician.getId());
|
|
moment.setTechnicianId(technician.getId());
|
|
|
moment.setTitle(dto.getTitle());
|
|
moment.setTitle(dto.getTitle());
|
|
@@ -338,18 +346,20 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
moment.setLocation(dto.getLocation());
|
|
moment.setLocation(dto.getLocation());
|
|
|
moment.setAddress(dto.getAddress());
|
|
moment.setAddress(dto.getAddress());
|
|
|
|
|
|
|
|
- // 设置封面图
|
|
|
|
|
- if (dto.getMediaType() == 1) {
|
|
|
|
|
- // 图片类型,默认取第一张作为封面
|
|
|
|
|
- if (dto.getImageUrls() != null && !dto.getImageUrls().isEmpty()) {
|
|
|
|
|
- moment.setCoverUrl(dto.getImageUrls().get(0));
|
|
|
|
|
|
|
+ if(Objects.nonNull(dto.getMediaType())){
|
|
|
|
|
+ // 设置封面图
|
|
|
|
|
+ if (dto.getMediaType() == 1) {
|
|
|
|
|
+ // 图片类型,默认取第一张作为封面
|
|
|
|
|
+ if (dto.getImageUrls() != null && !dto.getImageUrls().isEmpty()) {
|
|
|
|
|
+ moment.setCoverUrl(dto.getImageUrls().get(0));
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (dto.getMediaType() == 2) {
|
|
|
|
|
+ // 视频类型,使用视频URL作为封面
|
|
|
|
|
+ moment.setCoverUrl(dto.getVideoUrl());
|
|
|
}
|
|
}
|
|
|
- } else if (dto.getMediaType() == 2) {
|
|
|
|
|
- // 视频类型,使用视频URL作为封面
|
|
|
|
|
- moment.setCoverUrl(dto.getVideoUrl());
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 6. 设置审核状态和发布时间
|
|
|
|
|
|
|
+ // 设置审核状态和发布时间
|
|
|
if (dto.getIsDraft() != null && dto.getIsDraft() == 1) {
|
|
if (dto.getIsDraft() != null && dto.getIsDraft() == 1) {
|
|
|
// 保存草稿
|
|
// 保存草稿
|
|
|
moment.setAuditStatus(0);
|
|
moment.setAuditStatus(0);
|
|
@@ -360,7 +370,7 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
moment.setPublishTime(LocalDateTime.now());
|
|
moment.setPublishTime(LocalDateTime.now());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 7. 设置初始状态
|
|
|
|
|
|
|
+ // 设置初始状态
|
|
|
moment.setStatus(1); // 正常
|
|
moment.setStatus(1); // 正常
|
|
|
moment.setViewCount(0);
|
|
moment.setViewCount(0);
|
|
|
moment.setCreateTime(LocalDateTime.now());
|
|
moment.setCreateTime(LocalDateTime.now());
|
|
@@ -375,31 +385,33 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
Long momentId = moment.getId();
|
|
Long momentId = moment.getId();
|
|
|
|
|
|
|
|
// 9. 保存媒体信息到媒体表
|
|
// 9. 保存媒体信息到媒体表
|
|
|
- if (dto.getMediaType() == 1) {
|
|
|
|
|
- // 保存图片
|
|
|
|
|
- if (dto.getImageUrls() != null && !dto.getImageUrls().isEmpty()) {
|
|
|
|
|
- for (int i = 0; i < dto.getImageUrls().size(); i++) {
|
|
|
|
|
- MomentMedia media = new MomentMedia();
|
|
|
|
|
- media.setMomentId(momentId);
|
|
|
|
|
- media.setMediaUrl(dto.getImageUrls().get(i));
|
|
|
|
|
- media.setMediaType(1); // 图片
|
|
|
|
|
- media.setSortOrder(i + 1);
|
|
|
|
|
- media.setCreateTime(LocalDateTime.now());
|
|
|
|
|
- //获取文件的格式
|
|
|
|
|
- String fileFormat = dto.getImageUrls().get(i).substring(dto.getImageUrls().get(i).lastIndexOf(".") + 1);
|
|
|
|
|
- media.setFileFormat(fileFormat);
|
|
|
|
|
- mediaMapper.insert(media);
|
|
|
|
|
|
|
+ if(Objects.nonNull(dto.getMediaType())){
|
|
|
|
|
+ if (dto.getMediaType() == 1) {
|
|
|
|
|
+ // 保存图片
|
|
|
|
|
+ if (dto.getImageUrls() != null && !dto.getImageUrls().isEmpty()) {
|
|
|
|
|
+ for (int i = 0; i < dto.getImageUrls().size(); i++) {
|
|
|
|
|
+ MomentMedia media = new MomentMedia();
|
|
|
|
|
+ media.setMomentId(momentId);
|
|
|
|
|
+ media.setMediaUrl(dto.getImageUrls().get(i));
|
|
|
|
|
+ media.setMediaType(1); // 图片
|
|
|
|
|
+ media.setSortOrder(i + 1);
|
|
|
|
|
+ media.setCreateTime(LocalDateTime.now());
|
|
|
|
|
+ //获取文件的格式
|
|
|
|
|
+ String fileFormat = dto.getImageUrls().get(i).substring(dto.getImageUrls().get(i).lastIndexOf(".") + 1);
|
|
|
|
|
+ media.setFileFormat(fileFormat);
|
|
|
|
|
+ mediaMapper.insert(media);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if (dto.getMediaType() == 2) {
|
|
|
|
|
+ // 保存视频
|
|
|
|
|
+ MomentMedia media = new MomentMedia();
|
|
|
|
|
+ media.setMomentId(momentId);
|
|
|
|
|
+ media.setMediaUrl(dto.getVideoUrl());
|
|
|
|
|
+ media.setMediaType(2); // 视频
|
|
|
|
|
+ media.setSortOrder(1);
|
|
|
|
|
+ media.setCreateTime(LocalDateTime.now());
|
|
|
|
|
+ mediaMapper.insert(media);
|
|
|
}
|
|
}
|
|
|
- } else if (dto.getMediaType() == 2) {
|
|
|
|
|
- // 保存视频
|
|
|
|
|
- MomentMedia media = new MomentMedia();
|
|
|
|
|
- media.setMomentId(momentId);
|
|
|
|
|
- media.setMediaUrl(dto.getVideoUrl());
|
|
|
|
|
- media.setMediaType(2); // 视频
|
|
|
|
|
- media.setSortOrder(1);
|
|
|
|
|
- media.setCreateTime(LocalDateTime.now());
|
|
|
|
|
- mediaMapper.insert(media);
|
|
|
|
|
}
|
|
}
|
|
|
log.info("发布动态成功,动态ID:{},技师ID:{},是否草稿:{}", momentId, technician.getId(), dto.getIsDraft());
|
|
log.info("发布动态成功,动态ID:{},技师ID:{},是否草稿:{}", momentId, technician.getId(), dto.getIsDraft());
|
|
|
return momentId;
|
|
return momentId;
|
|
@@ -447,7 +459,7 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
|
|
|
|
|
// 5. 验证动态状态是否允许编辑(只能编辑草稿和审核拒绝的动态)
|
|
// 5. 验证动态状态是否允许编辑(只能编辑草稿和审核拒绝的动态)
|
|
|
if (moment.getAuditStatus() == null ||
|
|
if (moment.getAuditStatus() == null ||
|
|
|
- (moment.getAuditStatus() != 0 && moment.getAuditStatus() != 3)) {
|
|
|
|
|
|
|
+ (moment.getAuditStatus() != 0 && moment.getAuditStatus() != 3)) {
|
|
|
throw new ServiceException("只能编辑草稿或审核拒绝的动态");
|
|
throw new ServiceException("只能编辑草稿或审核拒绝的动态");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -681,13 +693,13 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
|
|
+ /**
|
|
|
* 根据技师ID查询动态列表(已发布的动态:审核中+审核通过)
|
|
* 根据技师ID查询动态列表(已发布的动态:审核中+审核通过)
|
|
|
*
|
|
*
|
|
|
* @param technicianId 技师ID
|
|
* @param technicianId 技师ID
|
|
|
* @return List<MomentListVO> 动态列表
|
|
* @return List<MomentListVO> 动态列表
|
|
|
*/
|
|
*/
|
|
|
- @Override
|
|
|
|
|
|
|
+ @Override
|
|
|
public List<MomentListVO> getMomentsByTechnicianId(String technicianId) {
|
|
public List<MomentListVO> getMomentsByTechnicianId(String technicianId) {
|
|
|
// 1. 参数校验
|
|
// 1. 参数校验
|
|
|
if (technicianId == null || technicianId.trim().isEmpty()) {
|
|
if (technicianId == null || technicianId.trim().isEmpty()) {
|
|
@@ -735,11 +747,11 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
String technicianName = queryDTO.getTechnicianName();
|
|
String technicianName = queryDTO.getTechnicianName();
|
|
|
Integer auditStatus = queryDTO.getAuditStatus();
|
|
Integer auditStatus = queryDTO.getAuditStatus();
|
|
|
String startTime = queryDTO.getStartTime();
|
|
String startTime = queryDTO.getStartTime();
|
|
|
- if(StringUtils.isNotBlank(startTime)){
|
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(startTime)) {
|
|
|
startTime = startTime + " 00:00:00";
|
|
startTime = startTime + " 00:00:00";
|
|
|
}
|
|
}
|
|
|
String endTime = queryDTO.getEndTime();
|
|
String endTime = queryDTO.getEndTime();
|
|
|
- if(StringUtils.isNotBlank(endTime)){
|
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(endTime)) {
|
|
|
endTime = endTime + " 23:59:59";
|
|
endTime = endTime + " 23:59:59";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -761,10 +773,10 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
LambdaQueryWrapper<TJs> jsQueryWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<TJs> jsQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
jsQueryWrapper.like(TJs::getcNickName, technicianName);
|
|
jsQueryWrapper.like(TJs::getcNickName, technicianName);
|
|
|
List<TJs> technicians = tJsMapper.selectList(jsQueryWrapper);
|
|
List<TJs> technicians = tJsMapper.selectList(jsQueryWrapper);
|
|
|
- if(CollUtil.isNotEmpty(technicians)){
|
|
|
|
|
|
|
+ if (CollUtil.isNotEmpty(technicians)) {
|
|
|
// 构建查询条件,查询所有匹配的技师的动态
|
|
// 构建查询条件,查询所有匹配的技师的动态
|
|
|
queryWrapper.in(TechnicianMoment::getTechnicianId, technicians.stream().map(TJs::getId).collect(Collectors.toList()));
|
|
queryWrapper.in(TechnicianMoment::getTechnicianId, technicians.stream().map(TJs::getId).collect(Collectors.toList()));
|
|
|
- }else{
|
|
|
|
|
|
|
+ } else {
|
|
|
// 没有匹配的技师,查询空字符串列表
|
|
// 没有匹配的技师,查询空字符串列表
|
|
|
queryWrapper.in(TechnicianMoment::getTechnicianId, Collections.singleton(""));
|
|
queryWrapper.in(TechnicianMoment::getTechnicianId, Collections.singleton(""));
|
|
|
}
|
|
}
|