|
|
@@ -11,11 +11,13 @@ import com.ylx.massage.domain.TJs;
|
|
|
import com.ylx.massage.domain.dto.MomentAuditDTO;
|
|
|
import com.ylx.massage.domain.dto.MomentManageQueryDTO;
|
|
|
import com.ylx.massage.domain.dto.PublishMomentDTO;
|
|
|
+import com.ylx.massage.domain.dto.EditMomentDTO;
|
|
|
import com.ylx.massage.domain.vo.MomentDetailVO;
|
|
|
import com.ylx.massage.domain.vo.MomentListVO;
|
|
|
import com.ylx.massage.domain.vo.MomentManageVO;
|
|
|
import com.ylx.massage.domain.vo.MomentMediaVO;
|
|
|
import com.ylx.massage.domain.vo.MomentSimpleDetailVO;
|
|
|
+import com.ylx.massage.domain.vo.MyMomentVO;
|
|
|
import com.ylx.massage.mapper.MomentMediaMapper;
|
|
|
import com.ylx.massage.mapper.TechnicianMomentMapper;
|
|
|
import com.ylx.massage.mapper.TJsMapper;
|
|
|
@@ -289,7 +291,7 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
throw new ServiceException("发布动态信息不能为空");
|
|
|
}
|
|
|
if (openId == null || openId.trim().isEmpty()) {
|
|
|
- throw new ServiceException("技师信息不能为空");
|
|
|
+ throw new ServiceException("openId不能为空");
|
|
|
}
|
|
|
|
|
|
// 2. 根据openId查询技师信息
|
|
|
@@ -335,8 +337,8 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
moment.setVisibleRange(dto.getVisibleRange());
|
|
|
moment.setLatitude(dto.getLatitude());
|
|
|
moment.setLongitude(dto.getLongitude());
|
|
|
+ moment.setLocation(dto.getLocation());
|
|
|
moment.setAddress(dto.getAddress());
|
|
|
- moment.setCityCode(dto.getCityCode());
|
|
|
|
|
|
// 设置封面图
|
|
|
if (dto.getMediaType() == 1) {
|
|
|
@@ -345,8 +347,8 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
moment.setCoverUrl(dto.getImageUrls().get(0));
|
|
|
}
|
|
|
} else if (dto.getMediaType() == 2) {
|
|
|
- // 视频类型,使用视频封面
|
|
|
- moment.setCoverUrl(dto.getVideoCoverUrl());
|
|
|
+ // 视频类型,使用视频URL作为封面
|
|
|
+ moment.setCoverUrl(dto.getVideoUrl());
|
|
|
}
|
|
|
|
|
|
// 6. 设置审核状态和发布时间
|
|
|
@@ -355,8 +357,8 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
moment.setAuditStatus(0); // 草稿
|
|
|
moment.setPublishTime(null);
|
|
|
} else {
|
|
|
- // 立即发布,进入审核状态
|
|
|
- moment.setAuditStatus(1); // 审核中
|
|
|
+ // 立即发布,进入待审核状态
|
|
|
+ moment.setAuditStatus(1);
|
|
|
moment.setPublishTime(LocalDateTime.now());
|
|
|
}
|
|
|
|
|
|
@@ -405,6 +407,163 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
return momentId;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 编辑动态
|
|
|
+ *
|
|
|
+ * @param dto 编辑动态请求对象
|
|
|
+ * @param openId 技师OpenID
|
|
|
+ * @return Long 动态ID
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Long editMoment(EditMomentDTO dto, String openId) {
|
|
|
+ // 1. 参数校验
|
|
|
+ if (dto == null) {
|
|
|
+ throw new ServiceException("编辑动态信息不能为空");
|
|
|
+ }
|
|
|
+ if (openId == null || openId.trim().isEmpty()) {
|
|
|
+ throw new ServiceException("openId不能为空");
|
|
|
+ }
|
|
|
+ if (dto.getMomentId() == null) {
|
|
|
+ throw new ServiceException("动态ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 根据openId查询技师信息
|
|
|
+ LambdaQueryWrapper<TJs> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(TJs::getcOpenId, openId);
|
|
|
+ TJs technician = tJsMapper.selectOne(queryWrapper);
|
|
|
+ if (technician == null) {
|
|
|
+ throw new ServiceException("技师信息不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 查询动态信息
|
|
|
+ TechnicianMoment moment = momentMapper.selectById(dto.getMomentId());
|
|
|
+ if (moment == null) {
|
|
|
+ throw new ServiceException("动态不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 验证动态是否属于当前技师
|
|
|
+ if (!moment.getTechnicianId().equals(technician.getId())) {
|
|
|
+ throw new ServiceException("无权编辑此动态");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 验证动态状态是否允许编辑(只能编辑草稿和审核拒绝的动态)
|
|
|
+ if (moment.getAuditStatus() == null ||
|
|
|
+ (moment.getAuditStatus() != 0 && moment.getAuditStatus() != 3)) {
|
|
|
+ throw new ServiceException("只能编辑草稿或审核拒绝的动态");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 校验媒体类型和媒体文件
|
|
|
+ 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("媒体类型不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 7. 校验可见范围
|
|
|
+ if (dto.getVisibleRange() == null || dto.getVisibleRange() != 1) {
|
|
|
+ throw new ServiceException("可见范围只能选择公开");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 8. 更新动态对象
|
|
|
+ moment.setTitle(dto.getTitle());
|
|
|
+ moment.setContent(dto.getContent());
|
|
|
+ moment.setMediaType(dto.getMediaType());
|
|
|
+ moment.setVisibleRange(dto.getVisibleRange());
|
|
|
+ moment.setLongitude(dto.getLongitude());
|
|
|
+ moment.setLatitude(dto.getLatitude());
|
|
|
+ moment.setLocation(dto.getLocation());
|
|
|
+ moment.setAddress(dto.getAddress());
|
|
|
+
|
|
|
+ // 设置封面图
|
|
|
+ if (dto.getMediaType() == 1) {
|
|
|
+ // 图片类型,默认取第一张作为封面
|
|
|
+ if (dto.getImageUrls() != null && !dto.getImageUrls().isEmpty()) {
|
|
|
+ moment.setCoverUrl(dto.getImageUrls().get(0));
|
|
|
+ }
|
|
|
+ } else if (dto.getMediaType() == 2) {
|
|
|
+ // 视频类型,使用视频封面URL(如果提供了)或视频URL作为封面
|
|
|
+ if (dto.getVideoCoverUrl() != null && !dto.getVideoCoverUrl().trim().isEmpty()) {
|
|
|
+ moment.setCoverUrl(dto.getVideoCoverUrl());
|
|
|
+ } else {
|
|
|
+ moment.setCoverUrl(dto.getVideoUrl());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 9. 设置审核状态和发布时间
|
|
|
+ if (dto.getIsDraft() != null && dto.getIsDraft() == 1) {
|
|
|
+ // 保存草稿
|
|
|
+ moment.setAuditStatus(0); // 草稿
|
|
|
+ moment.setPublishTime(null);
|
|
|
+ moment.setRejectReason(null); // 清空拒绝原因
|
|
|
+ } else {
|
|
|
+ // 提交发布,进入待审核状态
|
|
|
+ moment.setAuditStatus(1);
|
|
|
+ if (moment.getPublishTime() == null) {
|
|
|
+ moment.setPublishTime(LocalDateTime.now());
|
|
|
+ }
|
|
|
+ moment.setRejectReason(null); // 清空拒绝原因
|
|
|
+ }
|
|
|
+ moment.setUpdateTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ // 10. 更新动态到数据库
|
|
|
+ int updateResult = momentMapper.updateById(moment);
|
|
|
+ if (updateResult <= 0) {
|
|
|
+ throw new ServiceException("编辑动态失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long momentId = moment.getId();
|
|
|
+
|
|
|
+ // 11. 删除旧的媒体信息
|
|
|
+ LambdaQueryWrapper<MomentMedia> mediaWrapper = new LambdaQueryWrapper<>();
|
|
|
+ mediaWrapper.eq(MomentMedia::getMomentId, momentId);
|
|
|
+ mediaMapper.delete(mediaWrapper);
|
|
|
+
|
|
|
+ // 12. 保存新的媒体信息到媒体表
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ log.info("编辑动态成功,动态ID:{},技师ID:{},是否草稿:{}", momentId, technician.getId(), dto.getIsDraft());
|
|
|
+ return momentId;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询草稿箱列表
|
|
|
*
|
|
|
@@ -454,6 +613,68 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
}).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询我的动态列表(已发布的动态:审核中+审核通过)
|
|
|
+ *
|
|
|
+ * @param openId 技师OpenID
|
|
|
+ * @param pageNum 页码
|
|
|
+ * @param pageSize 每页数量
|
|
|
+ * @return Page<MyMomentVO> 我的动态列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<MyMomentVO> getMyMoments(String openId, Integer pageNum, Integer pageSize) {
|
|
|
+ // 1. 参数校验
|
|
|
+ if (openId == null || openId.trim().isEmpty()) {
|
|
|
+ throw new ServiceException("openId不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 根据openId查询技师信息
|
|
|
+ LambdaQueryWrapper<TJs> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(TJs::getcOpenId, openId);
|
|
|
+ TJs technician = tJsMapper.selectOne(queryWrapper);
|
|
|
+ if (technician == null) {
|
|
|
+ throw new ServiceException("技师信息不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 查询该技师的已发布动态(待审核、审核通过)
|
|
|
+ Page<TechnicianMoment> page = new Page<>(pageNum, pageSize);
|
|
|
+ LambdaQueryWrapper<TechnicianMoment> momentWrapper = new LambdaQueryWrapper<>();
|
|
|
+ momentWrapper.eq(TechnicianMoment::getTechnicianId, technician.getId())
|
|
|
+ .in(TechnicianMoment::getAuditStatus, 1, 2) // 1-待审核, 2-审核通过
|
|
|
+ .eq(TechnicianMoment::getStatus, 1) // 正常状态
|
|
|
+ .orderByDesc(TechnicianMoment::getPublishTime);
|
|
|
+
|
|
|
+ Page<TechnicianMoment> momentPage = momentMapper.selectPage(page, momentWrapper);
|
|
|
+
|
|
|
+ // 4. 组装分页返回结果
|
|
|
+ Page<MyMomentVO> voPage = new Page<>(pageNum, pageSize);
|
|
|
+ voPage.setTotal(momentPage.getTotal());
|
|
|
+ voPage.setCurrent(momentPage.getCurrent());
|
|
|
+ voPage.setSize(momentPage.getSize());
|
|
|
+
|
|
|
+ List<TechnicianMoment> moments = momentPage.getRecords();
|
|
|
+ if (moments == null || moments.isEmpty()) {
|
|
|
+ voPage.setRecords(new ArrayList<>());
|
|
|
+ return voPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 组装VO列表
|
|
|
+ List<MyMomentVO> voList = moments.stream().map(moment -> {
|
|
|
+ MyMomentVO vo = new MyMomentVO();
|
|
|
+ vo.setId(moment.getId());
|
|
|
+ vo.setTitle(moment.getTitle());
|
|
|
+ vo.setAuditStatus(moment.getAuditStatus());
|
|
|
+ vo.setCoverUrl(moment.getCoverUrl());
|
|
|
+ vo.setPublishTime(moment.getPublishTime());
|
|
|
+ vo.setViewCount(moment.getViewCount());
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ voPage.setRecords(voList);
|
|
|
+ log.info("查询我的动态列表成功,技师ID:{},页码:{},每页数量:{},总记录数:{}", technician.getId(), pageNum, pageSize, voPage.getTotal());
|
|
|
+ return voPage;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询动态列表(管理后台)
|
|
|
*
|