|
|
@@ -3,20 +3,27 @@ package com.ylx.order.service.impl;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ylx.common.core.domain.model.WxLoginUser;
|
|
|
import com.ylx.common.exception.ServiceException;
|
|
|
+import com.ylx.common.utils.SecurityUtils;
|
|
|
+import com.ylx.massage.domain.MaTechnician;
|
|
|
+import com.ylx.massage.domain.vo.MaTechnicianAuditListVO;
|
|
|
+import com.ylx.massage.service.IMaTechnicianService;
|
|
|
import com.ylx.merchant.domain.dto.MerchantCommentDTO;
|
|
|
import com.ylx.merchant.domain.vo.MerchantCommentVO;
|
|
|
import com.ylx.order.domain.CommentUserAudit;
|
|
|
import com.ylx.massage.mapper.TCommentUserAuditMapper;
|
|
|
import com.ylx.order.domain.TCommentPicture;
|
|
|
import com.ylx.order.domain.TCommentUser;
|
|
|
+import com.ylx.order.domain.dto.MerchantMyCommentQueryDTO;
|
|
|
import com.ylx.order.mapper.TCommentUserMapper;
|
|
|
import com.ylx.order.service.TCommentUserService;
|
|
|
import com.ylx.order.domain.dto.OrderCommentDTO;
|
|
|
+import com.ylx.order.domain.vo.MerchantMyCommentVO;
|
|
|
import com.ylx.order.domain.vo.TCommentUserAuditStatusCountVO;
|
|
|
import com.ylx.order.enums.AuditStatusEnum;
|
|
|
import com.ylx.order.service.TCommentPictureService;
|
|
|
@@ -49,6 +56,9 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
@Resource
|
|
|
private TCommentPictureService tCommentPictureService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private IMaTechnicianService maTechnicianService;
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean saveComment(TCommentUser comment, WxLoginUser wxLoginUser) {
|
|
|
return null;
|
|
|
@@ -75,14 +85,14 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
validateComment(dto);
|
|
|
|
|
|
// 1. 获取并校验当前用户
|
|
|
-// WxLoginUser wxLoginUser = SecurityUtils.getWxLoginUser();
|
|
|
-// if (ObjectUtil.isNull(wxLoginUser)) {
|
|
|
-// throw new ServiceException("用户未登录");
|
|
|
-// }
|
|
|
+ WxLoginUser wxLoginUser = SecurityUtils.getWxLoginUser();
|
|
|
+ if (ObjectUtil.isNull(wxLoginUser)) {
|
|
|
+ throw new ServiceException("用户未登录");
|
|
|
+ }
|
|
|
|
|
|
// 2. 构建评论实体 TCommentUser
|
|
|
TCommentUser comment = new TCommentUser();
|
|
|
- String userId = "2052914416724815873";
|
|
|
+ String userId = wxLoginUser.getId();
|
|
|
comment.setUserId(userId);
|
|
|
comment.setOrderId(dto.getOrderId());
|
|
|
comment.setMerchantId(Math.toIntExact(dto.getMerchantId()));
|
|
|
@@ -95,7 +105,6 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
comment.setCommentTime(new Date());
|
|
|
comment.setCreateTime(new Date());
|
|
|
comment.setUpdateTime(new Date());
|
|
|
- comment.setIsDelete(0);
|
|
|
|
|
|
// 4. 保存评论到 t_comment_user
|
|
|
int insertResult = tCommentUserMapper.insert(comment);
|
|
|
@@ -136,7 +145,7 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
Page<MerchantCommentVO> page = new Page<>(dto.getCurrent(), dto.getSize());
|
|
|
// 1.查询评论和订单基础信息
|
|
|
page = this.baseMapper.getMerchantComment(page, dto);
|
|
|
- if(ObjectUtil.isNotNull(page) && CollUtil.isNotEmpty(page.getRecords())){
|
|
|
+ if (ObjectUtil.isNotNull(page) && CollUtil.isNotEmpty(page.getRecords())) {
|
|
|
List<MerchantCommentVO> records = page.getRecords();
|
|
|
|
|
|
// 2. 提取所有评论ID
|
|
|
@@ -164,6 +173,45 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Page<MerchantMyCommentVO> getMerchantMyCommentPage(MerchantMyCommentQueryDTO dto) {
|
|
|
+ Integer merchantId = getCurrentMerchantId();
|
|
|
+ MerchantMyCommentQueryDTO query = dto == null ? new MerchantMyCommentQueryDTO() : dto;
|
|
|
+ long current = query.getCurrent() <= 0 ? 1 : query.getCurrent();
|
|
|
+ long size = query.getSize() <= 0 ? 10 : query.getSize();
|
|
|
+ Page<MerchantMyCommentVO> page = new Page<>(current, size);
|
|
|
+
|
|
|
+ Page<MerchantMyCommentVO> result = tCommentUserMapper.selectMerchantMyCommentPage(page, merchantId);
|
|
|
+ if (ObjectUtil.isNull(result) || CollUtil.isEmpty(result.getRecords())) {
|
|
|
+ return result == null ? page : result;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<MerchantMyCommentVO> records = result.getRecords();
|
|
|
+ List<String> commentIds = records.stream()
|
|
|
+ .map(MerchantMyCommentVO::getId)
|
|
|
+ .filter(StrUtil::isNotBlank)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollUtil.isEmpty(commentIds)) {
|
|
|
+ records.forEach(record -> record.setPictures(Collections.emptyList()));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TCommentPicture> pictures = tCommentPictureService.selectByCommentIds(commentIds);
|
|
|
+ Map<String, List<String>> pictureMap = CollUtil.isEmpty(pictures)
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : pictures.stream()
|
|
|
+ .filter(picture -> StrUtil.isNotBlank(picture.getCommentId()) && StrUtil.isNotBlank(picture.getPictureUrl()))
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ TCommentPicture::getCommentId,
|
|
|
+ Collectors.mapping(TCommentPicture::getPictureUrl, Collectors.toList())
|
|
|
+ ));
|
|
|
+
|
|
|
+ for (MerchantMyCommentVO record : records) {
|
|
|
+ record.setPictures(pictureMap.getOrDefault(record.getId(), Collections.emptyList()));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 校验评论参数
|
|
|
*/
|
|
|
@@ -171,7 +219,7 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
if (dto == null) {
|
|
|
throw new IllegalArgumentException("评论信息不能为空");
|
|
|
}
|
|
|
- if (StrUtil.isBlank(dto.getOrderId())) {
|
|
|
+ if (ObjectUtil.isNull(dto.getOrderId())) {
|
|
|
throw new IllegalArgumentException("订单ID不能为空");
|
|
|
}
|
|
|
if (dto.getMerchantId() == null) {
|
|
|
@@ -200,4 +248,26 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
countVO.setRejectedCount(0L);
|
|
|
return countVO;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前登录商户ID
|
|
|
+ *
|
|
|
+ * @return Integer
|
|
|
+ */
|
|
|
+ private Integer getCurrentMerchantId() {
|
|
|
+ WxLoginUser wxLoginUser = SecurityUtils.getWxLoginUser();
|
|
|
+ if (ObjectUtil.isNull(wxLoginUser) || StrUtil.isBlank(wxLoginUser.getId())) {
|
|
|
+ throw new ServiceException("用户未登录");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据openID查询商户ID
|
|
|
+ String openid = wxLoginUser.getCOpenid();
|
|
|
+ LambdaQueryWrapper<MaTechnician> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(MaTechnician::getCOpenid, openid);
|
|
|
+ MaTechnician technician = maTechnicianService.getOne(queryWrapper);
|
|
|
+ if (ObjectUtil.isNull(technician)) {
|
|
|
+ throw new ServiceException("当前登录商户不存在");
|
|
|
+ }
|
|
|
+ return technician.getId();
|
|
|
+ }
|
|
|
}
|