|
|
@@ -1,14 +1,25 @@
|
|
|
package com.ylx.massage.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ylx.common.core.domain.model.WxLoginUser;
|
|
|
-import com.ylx.massage.domain.TCommentUser;
|
|
|
+import com.ylx.common.exception.ServiceException;
|
|
|
+import com.ylx.massage.domain.CommentUserAudit;
|
|
|
+import com.ylx.massage.mapper.TCommentUserAuditMapper;
|
|
|
+import com.ylx.order.domain.TCommentUser;
|
|
|
import com.ylx.massage.mapper.TCommentUserMapper;
|
|
|
import com.ylx.massage.service.TCommentUserService;
|
|
|
+import com.ylx.order.domain.dto.OrderCommentDTO;
|
|
|
+import com.ylx.order.enums.AuditStatusEnum;
|
|
|
+import com.ylx.order.service.TCommentPictureService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -21,6 +32,14 @@ import java.util.List;
|
|
|
@Service("tCommentUserService")
|
|
|
public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCommentUser> implements TCommentUserService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private TCommentUserMapper tCommentUserMapper;
|
|
|
+ @Resource
|
|
|
+ private TCommentUserAuditMapper tCommentUserAuditMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TCommentPictureService tCommentPictureService;
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean saveComment(TCommentUser comment, WxLoginUser wxLoginUser) {
|
|
|
return null;
|
|
|
@@ -30,4 +49,94 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
public List<TCommentUser> selectAll(TCommentUser tCommentUser) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void submitComment(OrderCommentDTO dto) {
|
|
|
+ // 1. 参数校验
|
|
|
+ validateComment(dto);
|
|
|
+
|
|
|
+ // 1. 获取并校验当前用户
|
|
|
+// WxLoginUser wxLoginUser = SecurityUtils.getWxLoginUser();
|
|
|
+// if (ObjectUtil.isNull(wxLoginUser)) {
|
|
|
+// throw new ServiceException("用户未登录");
|
|
|
+// }
|
|
|
+
|
|
|
+ // 2. 构建评论实体 TCommentUser
|
|
|
+ TCommentUser comment = new TCommentUser();
|
|
|
+ String userId = "2052914416724815873";
|
|
|
+ comment.setUserId(userId);
|
|
|
+ comment.setOrderId(dto.getOrderId());
|
|
|
+ comment.setMerchantId(Math.toIntExact(dto.getMerchantId()));
|
|
|
+ comment.setMerchantName(dto.getMerchantName());
|
|
|
+ comment.setText(dto.getText());
|
|
|
+ comment.setExperienceComment(dto.getExperienceComment());
|
|
|
+ comment.setPriceComment(dto.getPriceComment());
|
|
|
+ comment.setAttitudeComment(dto.getAttitudeComment());
|
|
|
+ comment.setGroomingComment(dto.getGroomingComment());
|
|
|
+ comment.setCommentTime(new Date());
|
|
|
+ comment.setCreateTime(new Date());
|
|
|
+ comment.setUpdateTime(new Date());
|
|
|
+ comment.setIsDelete(0);
|
|
|
+
|
|
|
+ // 4. 保存评论到 t_comment_user
|
|
|
+ int insertResult = tCommentUserMapper.insert(comment);
|
|
|
+ if (insertResult <= 0) {
|
|
|
+ throw new RuntimeException("评论入库失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 构建审核记录 CommentUserAudit
|
|
|
+ CommentUserAudit audit = new CommentUserAudit();
|
|
|
+ audit.setCommentId(comment.getId());
|
|
|
+ audit.setOrderId(dto.getOrderId());
|
|
|
+ audit.setText(dto.getText());
|
|
|
+ audit.setAuditStatus(AuditStatusEnum.PENDING.getCode());
|
|
|
+ audit.setAuditReason(null);
|
|
|
+ audit.setAuditorId(null);
|
|
|
+ audit.setAuditorName(null);
|
|
|
+ audit.setAuditTime(null);
|
|
|
+ audit.setCreateTime(new Date());
|
|
|
+ audit.setUpdateTime(new Date());
|
|
|
+ audit.setIsDelete(0);
|
|
|
+ audit.setIsPublished(0);
|
|
|
+
|
|
|
+ int auditResult = tCommentUserAuditMapper.insert(audit);
|
|
|
+ if (auditResult <= 0) {
|
|
|
+ throw new ServiceException("评论审核记录入库失败");
|
|
|
+ }
|
|
|
+ // 5. 保存评论图片(新增)
|
|
|
+ List<String> pictureUrls = dto.getCommentPictures();
|
|
|
+ if (CollectionUtils.isNotEmpty(pictureUrls)) {
|
|
|
+ tCommentPictureService.batchSavePictures(comment.getId(), pictureUrls);
|
|
|
+ }
|
|
|
+ log.info("评论入库成功,评论ID:{},订单号:{},用户ID:{}", comment.getId(), dto.getOrderId(), userId);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 校验评论参数
|
|
|
+ */
|
|
|
+ private void validateComment(OrderCommentDTO dto) {
|
|
|
+ if (dto == null) {
|
|
|
+ throw new IllegalArgumentException("评论信息不能为空");
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(dto.getOrderId())) {
|
|
|
+ throw new IllegalArgumentException("订单ID不能为空");
|
|
|
+ }
|
|
|
+ if (dto.getMerchantId() == null) {
|
|
|
+ throw new IllegalArgumentException("商户ID不能为空");
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(dto.getText())) {
|
|
|
+ throw new IllegalArgumentException("评论内容不能为空");
|
|
|
+ }
|
|
|
+ // 评分校验:1-5分
|
|
|
+ checkScore(dto.getExperienceComment(), "体验评价");
|
|
|
+ checkScore(dto.getPriceComment(), "价格评价");
|
|
|
+ checkScore(dto.getAttitudeComment(), "态度评价");
|
|
|
+ checkScore(dto.getGroomingComment(), "仪表仪容评价");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkScore(Integer score, String fieldName) {
|
|
|
+ if (score == null || score < 1 || score > 5) {
|
|
|
+ throw new IllegalArgumentException(fieldName + "必须在1~5分之间");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|