| | |
| | | package com.ruoyi.order.service.impl; |
| | | |
| | | 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; |
| | | import com.ruoyi.account.api.feignClient.AppUserCarClient; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.feignClient.AppUserIntegralChangeClient; |
| | | import com.ruoyi.account.api.model.TAppUser; |
| | | import com.ruoyi.account.api.model.TAppUserCar; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.model.TAppUser; |
| | | import com.ruoyi.account.api.model.TAppUserIntegralChange; |
| | | import com.ruoyi.chargingPile.api.feignClient.SiteClient; |
| | | 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; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import com.ruoyi.order.api.model.TOrderEvaluate; |
| | | import com.ruoyi.order.api.model.TOrderEvaluateTag; |
| | |
| | | import com.ruoyi.order.api.vo.TOrderEvaluateVO; |
| | | import com.ruoyi.order.dto.GetOrderEvaluatePageList; |
| | | import com.ruoyi.order.dto.GetOrderEvaluatePageListDTO; |
| | | import com.ruoyi.order.dto.OrderEvaluateVo; |
| | | import com.ruoyi.order.mapper.TChargingOrderMapper; |
| | | import com.ruoyi.order.mapper.TOrderEvaluateMapper; |
| | | import com.ruoyi.order.mapper.TOrderEvaluateTagMapper; |
| | | import com.ruoyi.order.service.TChargingOrderService; |
| | | 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; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Arrays; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | |
| | | private TEvaluationTagClient evaluationTagClient; |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | @Autowired |
| | | @Resource |
| | | private AppUserCarClient appUserCarClient; |
| | | @Autowired |
| | | @Resource |
| | | private TOrderEvaluateTagMapper orderEvaluateTagMapper; |
| | | @Resource |
| | | private TChargingOrderMapper chargingOrderMapper; |
| | |
| | | @Resource |
| | | private SiteClient siteClient; |
| | | |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | @Resource |
| | | private TChargingOrderService chargingOrderService; |
| | | |
| | | @Resource |
| | | private IntegralRuleClient integralRuleClient; |
| | | |
| | | @Resource |
| | | private AppUserIntegralChangeClient appUserIntegralChangeClient; |
| | | |
| | | @Resource |
| | | private VipClient vipClient; |
| | | |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | |
| | | |
| | | @Resource |
| | | private TOrderEvaluateMapper orderEvaluateMapper; |
| | | @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()); |
| | | // 统计有图,好评,中差评数量 |
| | |
| | | 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<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); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 评价订单 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | @GlobalTransactional(rollbackFor = Exception.class)//分布式事务 |
| | | public AjaxResult addOrderEvaluate(OrderEvaluateVo query) { |
| | | TOrderEvaluate orderEvaluate = this.getOne(new LambdaQueryWrapper<TOrderEvaluate>().eq(TOrderEvaluate::getOrderId, query.getOrderId()) |
| | | .eq(TOrderEvaluate::getOrderType, query.getOrderType()).eq(TOrderEvaluate::getDelFlag, 0)); |
| | | if(null != orderEvaluate){ |
| | | return AjaxResult.error("不能重复评价"); |
| | | } |
| | | orderEvaluate = new TOrderEvaluate(); |
| | | BeanUtils.copyProperties(query, orderEvaluate); |
| | | 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(); |
| | | for (Integer tagId : tagIds) { |
| | | TOrderEvaluateTag orderEvaluateTag = new TOrderEvaluateTag(); |
| | | orderEvaluateTag.setOrderEvaluateId(orderEvaluate.getId()); |
| | | orderEvaluateTag.setEvaluationTagId(tagId); |
| | | orderEvaluateTagMapper.insert(orderEvaluateTag); |
| | | } |
| | | |
| | | //判断发放积分 文字+图片+5星好评 |
| | | if(StringUtils.isNotEmpty(query.getContent()) && StringUtils.isNotEmpty(query.getImgUrl()) && 5 == query.getMark()){ |
| | | TIntegralRule data = integralRuleClient.getSet().getData(); |
| | | String credit = data.getCredit(); |
| | | //积分 |
| | | Integer num1 = JSON.parseObject(credit).getInteger("num1"); |
| | | if(null != num1 && 0 < num1){ |
| | | 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); |
| | | |
| | | //积分变动明细 |
| | | TAppUserIntegralChange appUserIntegralChange = new TAppUserIntegralChange(); |
| | | appUserIntegralChange.setAppUserId(appUser.getId()); |
| | | appUserIntegralChange.setChangeType(3); |
| | | appUserIntegralChange.setHistoricalIntegral(points); |
| | | appUserIntegralChange.setCurrentIntegral(points + num1); |
| | | appUserIntegralChange.setCreateTime(LocalDateTime.now()); |
| | | appUserIntegralChange.setOrderCode(orderEvaluate.getId().toString()); |
| | | appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange); |
| | | } |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取订单评价 |
| | | * @param orderId 订单id |
| | | * @param orderType 订单类型 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public OrderEvaluateVo getOrderEvaluate(Integer orderId, Integer orderType) { |
| | | TOrderEvaluate orderEvaluate = this.getOne(new LambdaQueryWrapper<TOrderEvaluate>().eq(TOrderEvaluate::getOrderId, orderId).eq(TOrderEvaluate::getOrderType, orderType)); |
| | | if(null != orderEvaluate){ |
| | | OrderEvaluateVo orderEvaluateVo = new OrderEvaluateVo(); |
| | | BeanUtils.copyProperties(orderEvaluate, orderEvaluateVo); |
| | | List<TOrderEvaluateTag> tOrderEvaluateTags = orderEvaluateTagMapper.selectList(new LambdaQueryWrapper<TOrderEvaluateTag>().eq(TOrderEvaluateTag::getOrderEvaluateId, orderEvaluate.getId())); |
| | | List<Integer> tagId = tOrderEvaluateTags.stream().map(TOrderEvaluateTag::getEvaluationTagId).collect(Collectors.toList()); |
| | | List<TEvaluationTag> data = evaluationTagClient.getListByIds(tagId).getData(); |
| | | List<String> collect = data.stream().map(TEvaluationTag::getName).collect(Collectors.toList()); |
| | | orderEvaluateVo.setTagName(collect); |
| | | return orderEvaluateVo; |
| | | } |
| | | 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); |
| | | } |
| | | } |