|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -23,6 +24,7 @@ import com.ylx.order.domain.dto.MerchantMyCommentQueryDTO;
|
|
|
import com.ylx.order.mapper.TCommentUserMapper;
|
|
import com.ylx.order.mapper.TCommentUserMapper;
|
|
|
import com.ylx.order.service.TCommentUserService;
|
|
import com.ylx.order.service.TCommentUserService;
|
|
|
import com.ylx.order.domain.dto.OrderCommentDTO;
|
|
import com.ylx.order.domain.dto.OrderCommentDTO;
|
|
|
|
|
+import com.ylx.order.domain.vo.MerchantCompositeScoreVO;
|
|
|
import com.ylx.order.domain.vo.MerchantMyCommentVO;
|
|
import com.ylx.order.domain.vo.MerchantMyCommentVO;
|
|
|
import com.ylx.order.domain.vo.TCommentUserAuditStatusCountVO;
|
|
import com.ylx.order.domain.vo.TCommentUserAuditStatusCountVO;
|
|
|
import com.ylx.order.enums.AuditStatusEnum;
|
|
import com.ylx.order.enums.AuditStatusEnum;
|
|
@@ -32,6 +34,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -94,6 +98,7 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
TCommentUser comment = new TCommentUser();
|
|
TCommentUser comment = new TCommentUser();
|
|
|
String userId = wxLoginUser.getId();
|
|
String userId = wxLoginUser.getId();
|
|
|
comment.setUserId(userId);
|
|
comment.setUserId(userId);
|
|
|
|
|
+ comment.setNickName(wxLoginUser.getNickName());
|
|
|
comment.setOrderId(dto.getOrderId());
|
|
comment.setOrderId(dto.getOrderId());
|
|
|
comment.setMerchantId(Math.toIntExact(dto.getMerchantId()));
|
|
comment.setMerchantId(Math.toIntExact(dto.getMerchantId()));
|
|
|
comment.setMerchantName(dto.getMerchantName());
|
|
comment.setMerchantName(dto.getMerchantName());
|
|
@@ -176,14 +181,13 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
@Override
|
|
@Override
|
|
|
public Page<MerchantMyCommentVO> getMerchantMyCommentPage(MerchantMyCommentQueryDTO dto) {
|
|
public Page<MerchantMyCommentVO> getMerchantMyCommentPage(MerchantMyCommentQueryDTO dto) {
|
|
|
Integer merchantId = getCurrentMerchantId();
|
|
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();
|
|
|
|
|
|
|
+ long current = dto.getCurrent();
|
|
|
|
|
+ long size = dto.getSize();
|
|
|
Page<MerchantMyCommentVO> page = new Page<>(current, size);
|
|
Page<MerchantMyCommentVO> page = new Page<>(current, size);
|
|
|
|
|
|
|
|
Page<MerchantMyCommentVO> result = tCommentUserMapper.selectMerchantMyCommentPage(page, merchantId);
|
|
Page<MerchantMyCommentVO> result = tCommentUserMapper.selectMerchantMyCommentPage(page, merchantId);
|
|
|
if (ObjectUtil.isNull(result) || CollUtil.isEmpty(result.getRecords())) {
|
|
if (ObjectUtil.isNull(result) || CollUtil.isEmpty(result.getRecords())) {
|
|
|
- return result == null ? page : result;
|
|
|
|
|
|
|
+ return page;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
List<MerchantMyCommentVO> records = result.getRecords();
|
|
List<MerchantMyCommentVO> records = result.getRecords();
|
|
@@ -191,10 +195,6 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
.map(MerchantMyCommentVO::getId)
|
|
.map(MerchantMyCommentVO::getId)
|
|
|
.filter(StrUtil::isNotBlank)
|
|
.filter(StrUtil::isNotBlank)
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
- if (CollUtil.isEmpty(commentIds)) {
|
|
|
|
|
- records.forEach(record -> record.setPictures(Collections.emptyList()));
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
List<TCommentPicture> pictures = tCommentPictureService.selectByCommentIds(commentIds);
|
|
List<TCommentPicture> pictures = tCommentPictureService.selectByCommentIds(commentIds);
|
|
|
Map<String, List<String>> pictureMap = CollUtil.isEmpty(pictures)
|
|
Map<String, List<String>> pictureMap = CollUtil.isEmpty(pictures)
|
|
@@ -208,7 +208,48 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
|
|
|
|
|
for (MerchantMyCommentVO record : records) {
|
|
for (MerchantMyCommentVO record : records) {
|
|
|
record.setPictures(pictureMap.getOrDefault(record.getId(), Collections.emptyList()));
|
|
record.setPictures(pictureMap.getOrDefault(record.getId(), Collections.emptyList()));
|
|
|
|
|
+ //根据评价ID更新综合评分
|
|
|
|
|
+ LambdaUpdateWrapper<TCommentUser> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ updateWrapper.set(TCommentUser::getScore, record.getScore());
|
|
|
|
|
+ updateWrapper.eq(TCommentUser::getId, record.getId());
|
|
|
|
|
+ tCommentUserMapper.update(null, updateWrapper);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public MerchantCompositeScoreVO getMerchantCompositeScore() {
|
|
|
|
|
+ return getMerchantCompositeScoreByMerchantId(getCurrentMerchantId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询商户的综合评分
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param merchantId
|
|
|
|
|
+ * @return MerchantCompositeScoreVO
|
|
|
|
|
+ */
|
|
|
|
|
+ MerchantCompositeScoreVO getMerchantCompositeScoreByMerchantId(Integer merchantId) {
|
|
|
|
|
+ if (ObjectUtil.isNull(merchantId) || merchantId <= 0) {
|
|
|
|
|
+ throw new ServiceException("商户ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ MerchantCompositeScoreVO statistic = tCommentUserMapper.selectMerchantScoreStatistics(merchantId);
|
|
|
|
|
+ BigDecimal scoreSum = ObjectUtil.isNull(statistic) || ObjectUtil.isNull(statistic.getScoreSum())
|
|
|
|
|
+ ? BigDecimal.ZERO
|
|
|
|
|
+ : statistic.getScoreSum();
|
|
|
|
|
+ Long orderCount = ObjectUtil.isNull(statistic) || ObjectUtil.isNull(statistic.getOrderCount())
|
|
|
|
|
+ ? 0L
|
|
|
|
|
+ : statistic.getOrderCount();
|
|
|
|
|
+
|
|
|
|
|
+ MerchantCompositeScoreVO result = new MerchantCompositeScoreVO();
|
|
|
|
|
+ result.setMerchantId(merchantId);
|
|
|
|
|
+ result.setScoreSum(scoreSum);
|
|
|
|
|
+ result.setOrderCount(orderCount);
|
|
|
|
|
+ if (orderCount <= 0) {
|
|
|
|
|
+ result.setComprehensiveScore(BigDecimal.ZERO.setScale(1));
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
+ result.setComprehensiveScore(scoreSum.divide(BigDecimal.valueOf(orderCount), 1, RoundingMode.HALF_UP));
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|