From 431bbf295ca207309f3c4ea90f88a5ed57e36d37 Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期五, 18 十月 2024 11:16:18 +0800
Subject: [PATCH] 18
---
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 100 insertions(+), 16 deletions(-)
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java
index e0f76a8..78d1c96 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java
@@ -2,6 +2,8 @@
import cn.hutool.db.DaoTemplate;
import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -17,6 +19,7 @@
import com.ruoyi.chargingPile.api.model.Site;
import com.ruoyi.chargingPile.api.vo.TAccountingStrategyVO;
import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.utils.HttpUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
@@ -37,8 +40,10 @@
import com.ruoyi.order.service.TOrderEvaluateService;
import com.ruoyi.other.api.domain.TEvaluationTag;
import com.ruoyi.other.api.domain.TIntegralRule;
+import com.ruoyi.other.api.domain.TVip;
import com.ruoyi.other.api.feignClient.IntegralRuleClient;
import com.ruoyi.other.api.feignClient.TEvaluationTagClient;
+import com.ruoyi.other.api.feignClient.VipClient;
import com.ruoyi.other.api.vo.TEvaluationTagVO;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.BeanUtils;
@@ -93,6 +98,9 @@
@Resource
private AppUserIntegralChangeClient appUserIntegralChangeClient;
+ @Resource
+ private VipClient vipClient;
+
@@ -110,17 +118,23 @@
@Override
public List<TEvaluationTagVO> getTagCount() {
// 查询标签列表
- R<List<TEvaluationTagVO>> r = evaluationTagClient.getTagList(null);
+ R<List<TEvaluationTagVO>> r = evaluationTagClient.getList();
List<TEvaluationTagVO> tagList = r.getData();
List<Integer> tagIds = tagList.stream().map(TEvaluationTagVO::getId).collect(Collectors.toList());
// 统计标签使用数量
List<TEvaluationTagVO> counts = orderEvaluateTagMapper.getCountByTagIds(tagIds);
+ List<Integer> ids = counts.stream().map(TEvaluationTagVO::getId).collect(Collectors.toList());
tagList.forEach(tag -> {
- counts.forEach(count -> {
- if (tag.getId().equals(count.getId())) {
- tag.setTagCount(count.getTagCount());
- }
- });
+ if(ids.contains(tag.getId())){
+ counts.forEach(count -> {
+ if (tag.getId().equals(count.getId())) {
+ tag.setTagCount(count.getTagCount());
+ }
+ });
+ }else{
+ tag.setTagCount(0);
+ }
+
});
tagList = tagList.stream().sorted(Comparator.comparing(TEvaluationTagVO::getTagCount).reversed()).collect(Collectors.toList());
// 统计有图,好评,中差评数量
@@ -176,10 +190,25 @@
siteDetailEvaluateVO.setOrderEvaluateVOS(tChargingOrders);
// 统计好评率
long goodCount = tChargingOrders.stream().filter(orderEvaluateVO -> orderEvaluateVO.getMark()>=4).count();
- BigDecimal reviewRate = new BigDecimal(goodCount).divide(new BigDecimal(tChargingOrders.size())).setScale(2, BigDecimal.ROUND_HALF_UP);
+ BigDecimal reviewRate = new BigDecimal(goodCount).divide(new BigDecimal(tChargingOrders.size()),2, BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP);
siteDetailEvaluateVO.setReviewRate(reviewRate);
siteDetailEvaluateVO.setEvaluateCount(tChargingOrders.size());
- siteDetailEvaluateVO.setOrderEvaluateVOS(tChargingOrders.stream().limit(3).collect(Collectors.toList()));
+ List<TOrderEvaluateVO> collect = tChargingOrders.stream().limit(3).collect(Collectors.toList());
+ // 查询评价下的标签
+ List<Long> orderIds = collect.stream().map(TOrderEvaluateVO::getId).collect(Collectors.toList());
+ if(!CollectionUtils.isEmpty(orderIds)){
+ List<TOrderEvaluateTag> tOrderEvaluateTags = orderEvaluateTagMapper.selectList(Wrappers.lambdaQuery(TOrderEvaluateTag.class)
+ .in(TOrderEvaluateTag::getOrderEvaluateId, orderIds));
+ for (TOrderEvaluateVO tOrderEvaluateVO : collect) {
+ List<TOrderEvaluateTag> tOrderEvaluateTagList = tOrderEvaluateTags.stream().filter(e -> e.getOrderEvaluateId().equals(tOrderEvaluateVO.getId())).collect(Collectors.toList());
+ if(!CollectionUtils.isEmpty(tOrderEvaluateTagList)){
+ List<Integer> tagIds = tOrderEvaluateTagList.stream().map(TOrderEvaluateTag::getEvaluationTagId).collect(Collectors.toList());
+ List<TEvaluationTag> data = evaluationTagClient.getListByIds(tagIds).getData();
+ tOrderEvaluateVO.setOrderEvaluateTags(data);
+ }
+ }
+ }
+ siteDetailEvaluateVO.setOrderEvaluateVOS(collect);
}
return siteDetailEvaluateVO;
}
@@ -216,16 +245,20 @@
List<GetOrderEvaluatePageListDTO> list = this.baseMapper.getPageList(pageList, evaluationTagIds, pageInfo);
for (GetOrderEvaluatePageListDTO dto : list) {
TAppUser appUser = appUserClient.getUserById(dto.getAppUserId()).getData();
- dto.setAvatar(appUser.getAvatar());
- String phone = appUser.getPhone();
- dto.setPhone(phone.substring(0, 3) + "****" + phone.substring(6));
+ if(null != appUser){
+ dto.setAvatar(appUser.getAvatar());
+ String phone = appUser.getPhone();
+ dto.setPhone(phone.substring(0, 3) + "****" + phone.substring(6));
+ }
Site site = siteClient.getSiteByIds(Arrays.asList(dto.getSiteId())).getData().get(0);
dto.setSiteName(site.getName());
List<TOrderEvaluateTag> tOrderEvaluateTags = orderEvaluateTagMapper.selectList(new LambdaQueryWrapper<TOrderEvaluateTag>().eq(TOrderEvaluateTag::getOrderEvaluateId, dto.getId()));
List<Integer> tagIds = tOrderEvaluateTags.stream().map(TOrderEvaluateTag::getEvaluationTagId).collect(Collectors.toList());
- List<TEvaluationTag> data = evaluationTagClient.getListByIds(tagIds).getData();
- List<String> collect = data.stream().map(TEvaluationTag::getName).collect(Collectors.toList());
- dto.setTags(collect);
+ if(tagIds.size() > 0){
+ List<TEvaluationTag> data = evaluationTagClient.getListByIds(tagIds).getData();
+ List<String> collect = data.stream().map(TEvaluationTag::getName).collect(Collectors.toList());
+ dto.setTags(collect);
+ }
}
return pageInfo.setRecords(list);
}
@@ -246,12 +279,45 @@
}
orderEvaluate = new TOrderEvaluate();
BeanUtils.copyProperties(query, orderEvaluate);
- Long userid = tokenService.getLoginUser().getUserid();
+ Long userid = tokenService.getLoginUserApplet().getUserId();
orderEvaluate.setAppUserId(userid);
if(query.getOrderType() == 1){
TChargingOrder chargingOrder = chargingOrderService.getById(query.getOrderId());
orderEvaluate.setAppUserCarId(chargingOrder.getAppUserCarId());
}
+ TAppUser appUser = appUserClient.getUserById(userid).getData();
+
+ //检测敏感词
+ String content = orderEvaluate.getContent();
+ if(StringUtils.isNotEmpty(content)){
+ String token = appUserClient.getWXToken().getData();
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("content", content);
+ jsonObject.put("version", 2);
+ jsonObject.put("scene", 2);
+ jsonObject.put("openid", appUser.getWxOpenid());
+ String post = HttpUtils.post("https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + token, jsonObject.toString());
+ JSONObject object = JSONObject.parseObject(post);
+ Integer errcode = object.getInteger("errcode");
+ if(0 != errcode){
+ throw new RuntimeException(object.getString("errmsg"));
+ }
+ JSONArray detail = object.getJSONArray("detail");
+ for (int i = 0; i < detail.size(); i++) {
+ JSONObject jsonObject1 = detail.getJSONObject(i);
+ Integer errcode1 = jsonObject1.getInteger("errcode");
+ if(0 == errcode1){
+ String suggest = jsonObject1.getString("suggest");
+ Integer label = jsonObject1.getInteger("label");
+ String keyword = jsonObject1.getString("keyword");
+ Integer prob = jsonObject1.getInteger("prob");
+ if(("risky".equals(suggest) || "review".equals(suggest)) && 100 != label && StringUtils.isNotEmpty(keyword) && 80 <= prob){
+ return AjaxResult.error("评价包含违规内容,请重新评价!");
+ }
+ }
+ }
+ }
+ orderEvaluate.setContent(content);
this.save(orderEvaluate);
List<Integer> tagIds = query.getTagIds();
@@ -269,7 +335,14 @@
//积分
Integer num1 = JSON.parseObject(credit).getInteger("num1");
if(null != num1 && 0 < num1){
- TAppUser appUser = appUserClient.getUserById(userid).getData();
+ if(null != appUser.getVipId()){
+ TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
+ Integer doubleIntegration = vip.getDoubleIntegration();
+ //双倍积分
+ if(1 == doubleIntegration){
+ num1 *= 2;
+ }
+ }
Integer points = appUser.getPoints();
appUser.setPoints(appUser.getPoints() + num1);
appUserClient.updateAppUser(appUser);
@@ -281,6 +354,7 @@
appUserIntegralChange.setHistoricalIntegral(points);
appUserIntegralChange.setCurrentIntegral(points + num1);
appUserIntegralChange.setCreateTime(LocalDateTime.now());
+ appUserIntegralChange.setOrderCode(orderEvaluate.getId().toString());
appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange);
}
}
@@ -309,4 +383,14 @@
}
return null;
}
+
+ @Override
+ public List<Map<String, Object>> goodTop(List<Integer> siteIds) {
+ return this.baseMapper.goodTop(siteIds);
+ }
+
+ @Override
+ public List<Map<String, Object>> badTop(List<Integer> siteIds) {
+ return this.baseMapper.badTop(siteIds);
+ }
}
--
Gitblit v1.7.1