| | |
| | | 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.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.domain.SiteMenu; |
| | | import com.ruoyi.chargingPile.api.feignClient.PartnerClient; |
| | | 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.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import com.ruoyi.order.api.model.TEvaluationAutoReply; |
| | | import com.ruoyi.order.api.model.TOrderEvaluate; |
| | | import com.ruoyi.order.api.model.TOrderEvaluateTag; |
| | | import com.ruoyi.order.api.model.TVinChargingOrder; |
| | | import com.ruoyi.order.api.query.TOrderEvaluateQuery; |
| | | import com.ruoyi.order.api.vo.SiteDetailEvaluateVO; |
| | | import com.ruoyi.order.api.vo.TOrderEvaluateVO; |
| | |
| | | import com.ruoyi.order.mapper.TOrderEvaluateMapper; |
| | | import com.ruoyi.order.mapper.TOrderEvaluateTagMapper; |
| | | import com.ruoyi.order.service.TChargingOrderService; |
| | | import com.ruoyi.order.service.TEvaluationAutoReplyService; |
| | | import com.ruoyi.order.service.TOrderEvaluateService; |
| | | import com.ruoyi.order.service.TVinChargingOrderService; |
| | | import com.ruoyi.order.service.WxSubscribeMessageService; |
| | | import com.ruoyi.other.api.domain.TEvaluationTag; |
| | | import com.ruoyi.other.api.domain.TIntegralRule; |
| | | import com.ruoyi.other.api.domain.TVip; |
| | |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.ruoyi.system.api.feignClient.SysUserRoleClient; |
| | | import com.ruoyi.system.api.model.SysUserRoleVo; |
| | | import io.seata.spring.annotation.GlobalTransactional; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | |
| | | @Service |
| | | public class TOrderEvaluateServiceImpl extends ServiceImpl<TOrderEvaluateMapper, TOrderEvaluate> implements TOrderEvaluateService { |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(TOrderEvaluateServiceImpl.class); |
| | | |
| | | @Resource |
| | | private TEvaluationTagClient evaluationTagClient; |
| | | @Resource |
| | |
| | | |
| | | @Resource |
| | | private TChargingOrderService chargingOrderService; |
| | | |
| | | @Resource |
| | | private TVinChargingOrderService vinChargingOrderService; |
| | | |
| | | @Resource |
| | | private IntegralRuleClient integralRuleClient; |
| | |
| | | @Resource |
| | | private SysUserRoleClient sysUserRoleClient; |
| | | |
| | | @Resource |
| | | private TEvaluationAutoReplyService evaluationAutoReplyService; |
| | | |
| | | @Resource |
| | | private WxSubscribeMessageService wxSubscribeMessageService; |
| | | |
| | | |
| | | |
| | |
| | | @Override |
| | | public PageInfo<TOrderEvaluateVO> getTagList(TOrderEvaluateQuery query) { |
| | | PageInfo<TOrderEvaluateVO> pageInfo = new PageInfo<>(query.getPageCurr(),query.getPageSize()); |
| | | // 查询站点下的所有订单 |
| | | List<TChargingOrder> tChargingOrders = chargingOrderMapper.selectList(Wrappers.lambdaQuery(TChargingOrder.class) |
| | | .eq(TChargingOrder::getSiteId, query.getSiteId())); |
| | | if(CollectionUtils.isEmpty(tChargingOrders)){ |
| | | return new PageInfo<>(); |
| | | } |
| | | List<Long> orderIds = tChargingOrders.stream().map(TChargingOrder::getId).collect(Collectors.toList()); |
| | | query.setOrderIds(orderIds); |
| | | List<TOrderEvaluateVO> list = this.baseMapper.pageList(query,pageInfo); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | | // 查询用户信息 |
| | | List<TAppUser> appUsers = appUserClient.getUserByIds(list.stream().map(TOrderEvaluateVO::getAppUserId).collect(Collectors.toList())).getData(); |
| | | // 查询用户绑定车辆品牌 |
| | |
| | | tagList.add(evaluationTagVO); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Resource |
| | | private PartnerClient partnerClient; |
| | | /** |
| | | * 获取充电评价列表 |
| | | * @param pageList |
| | |
| | | |
| | | //校验合作商权限 |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | SysUser sysUser = sysUserClient.getSysUser(SecurityUtils.getUserId()).getData(); |
| | | Integer roleType = sysUser.getRoleType(); |
| | | Integer objectId = sysUser.getObjectId(); |
| | | if(null == pageList.getSiteId() || 0 == pageList.getSiteId()){ |
| | | SysUser sysUser = sysUserClient.getSysUser(SecurityUtils.getUserId()).getData(); |
| | | Integer roleType = sysUser.getRoleType(); |
| | | Integer objectId = sysUser.getObjectId(); |
| | | //合作商 |
| | | if(roleType == 2){ |
| | | Set<Integer> data = partnerService.authSite(objectId, "/data/site").getData(); |
| | | Set<Integer> data = partnerService.authSite(objectId, SiteMenu.CHARGE_EVALUATION.getValue()).getData(); |
| | | siteIds = new ArrayList<>(data); |
| | | }else{ |
| | | //非管理员需要根据角色和用户配置查询允许的站点数据 |
| | | if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){ |
| | | if(!SecurityUtils.isAdmin(tokenService.getLoginUser().getUserid())){ |
| | | List<Integer> data = userSiteClient.getSiteIds(sysUser.getUserId()).getData(); |
| | | List<SysUserRoleVo> data2 = sysUserRoleClient.getRoleByUserId(sysUser.getUserId()).getData(); |
| | | List<Integer> data1 = roleSiteClient.getSiteIds(data2.get(0).getRoleId()).getData(); |
| | |
| | | siteIds = data; |
| | | } |
| | | } |
| | | }else{ |
| | | siteIds.add(pageList.getSiteId()); |
| | | } |
| | | |
| | | List<GetOrderEvaluatePageListDTO> list = this.baseMapper.getPageList(pageList, evaluationTagIds, siteIds, pageInfo); |
| | | for (GetOrderEvaluatePageListDTO dto : list) { |
| | | TAppUser appUser = appUserClient.getUserById(dto.getAppUserId()).getData(); |
| | |
| | | List<String> collect = data.stream().map(TEvaluationTag::getName).collect(Collectors.toList()); |
| | | dto.setTags(collect); |
| | | } |
| | | dto.setAuthReply(roleType == 1 ? true : partnerService.authMenu(objectId, dto.getSiteId(), SiteMenu.CHARGE_EVALUATION_ANSWER.getValue())); |
| | | dto.setAuthDelete(roleType == 1 ? true : partnerService.authMenu(objectId, dto.getSiteId(), SiteMenu.CHARGE_EVALUATION_DEL.getValue())); |
| | | } |
| | | return pageInfo.setRecords(list); |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @GlobalTransactional(rollbackFor = Exception.class)//分布式事务 |
| | | public AjaxResult addOrderEvaluate(OrderEvaluateVo query) { |
| | | if (query.getMark() == null || query.getMark() < 1 || query.getMark() > 5) { |
| | | return AjaxResult.error("评分必须在1到5星之间"); |
| | | } |
| | | TOrderEvaluate orderEvaluate = this.getOne(new LambdaQueryWrapper<TOrderEvaluate>().eq(TOrderEvaluate::getOrderId, query.getOrderId()) |
| | | .eq(TOrderEvaluate::getOrderType, query.getOrderType()).eq(TOrderEvaluate::getDelFlag, 0)); |
| | | if(null != orderEvaluate){ |
| | |
| | | BeanUtils.copyProperties(query, orderEvaluate); |
| | | Long userid = tokenService.getLoginUserApplet().getUserId(); |
| | | orderEvaluate.setAppUserId(userid); |
| | | if(query.getOrderType() == 1){ |
| | | Integer orderType = query.getOrderType(); |
| | | if(null == orderType){ |
| | | return AjaxResult.error("订单类型不能为空"); |
| | | } |
| | | if(orderType == 1){ |
| | | TChargingOrder chargingOrder = chargingOrderService.getById(query.getOrderId()); |
| | | if(null == chargingOrder){ |
| | | return AjaxResult.error("订单不存在"); |
| | | } |
| | | orderEvaluate.setAppUserCarId(chargingOrder.getAppUserCarId()); |
| | | }else if(orderType == 5){ |
| | | //VIN码充电订单,仅允许评价本人订单 |
| | | TVinChargingOrder vinChargingOrder = vinChargingOrderService.getById(query.getOrderId()); |
| | | if(null == vinChargingOrder || !userid.equals(vinChargingOrder.getAppUserId())){ |
| | | return AjaxResult.error("订单不存在"); |
| | | } |
| | | orderEvaluate.setAppUserCarId(vinChargingOrder.getAppUserCarId()); |
| | | }else{ |
| | | return AjaxResult.error("订单类型不支持评价"); |
| | | } |
| | | TAppUser appUser = appUserClient.getUserById(userid).getData(); |
| | | |
| | |
| | | String content = orderEvaluate.getContent(); |
| | | if(StringUtils.isNotEmpty(content)){ |
| | | Boolean data = appUserClient.sensitiveWordDetection(content, appUser.getWxOpenid()).getData(); |
| | | if(data){ |
| | | if(Boolean.TRUE.equals(data)){ |
| | | return AjaxResult.error("评价包含违规内容,请重新评价!"); |
| | | } |
| | | } |
| | | orderEvaluate.setContent(content); |
| | | this.save(orderEvaluate); |
| | | applyAutoReply(orderEvaluate); |
| | | |
| | | List<Integer> tagIds = query.getTagIds(); |
| | | if(null != tagIds){ |
| | |
| | | appUser.setPoints(appUser.getPoints() + num1); |
| | | appUserClient.updateAppUser(appUser); |
| | | |
| | | TChargingOrder chargingOrder = chargingOrderService.getById(orderEvaluate.getOrderId()); |
| | | //积分变动明细 |
| | | TAppUserIntegralChange appUserIntegralChange = new TAppUserIntegralChange(); |
| | | appUserIntegralChange.setAppUserId(appUser.getId()); |
| | |
| | | appUserIntegralChange.setHistoricalIntegral(points); |
| | | appUserIntegralChange.setCurrentIntegral(points + num1); |
| | | appUserIntegralChange.setCreateTime(LocalDateTime.now()); |
| | | appUserIntegralChange.setOrderCode(chargingOrder.getCode()); |
| | | appUserIntegralChange.setOrderCode(getOrderCode(orderEvaluate.getOrderType(), orderEvaluate.getOrderId())); |
| | | appUserIntegralChange.setExtension(orderEvaluate.getOrderId().toString()); |
| | | appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange); |
| | | } |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 根据评价的订单类型获取对应的订单编号 |
| | | * @param orderType 订单类型(1=充电订单,5=VIN码充电订单) |
| | | * @param orderId 订单id |
| | | * @return 订单编号 |
| | | */ |
| | | private String getOrderCode(Integer orderType, Long orderId) { |
| | | if(Integer.valueOf(5).equals(orderType)){ |
| | | TVinChargingOrder vinChargingOrder = vinChargingOrderService.getById(orderId); |
| | | return null == vinChargingOrder ? null : vinChargingOrder.getCode(); |
| | | } |
| | | TChargingOrder chargingOrder = chargingOrderService.getById(orderId); |
| | | return null == chargingOrder ? null : chargingOrder.getCode(); |
| | | } |
| | | |
| | | private void applyAutoReply(TOrderEvaluate orderEvaluate) { |
| | | TEvaluationAutoReply rule = evaluationAutoReplyService.matchRule(orderEvaluate.getContent(), orderEvaluate.getMark()); |
| | | if (rule == null || StringUtils.isEmpty(rule.getReplyContent())) { |
| | | return; |
| | | } |
| | | orderEvaluate.setEvaluationResponse(rule.getReplyContent()); |
| | | orderEvaluate.setResponseTime(LocalDateTime.now()); |
| | | this.updateById(orderEvaluate); |
| | | sendAutoEvaluationReplyMessage(orderEvaluate); |
| | | } |
| | | |
| | | private void sendAutoEvaluationReplyMessage(TOrderEvaluate orderEvaluate) { |
| | | try { |
| | | if (orderEvaluate == null || !Integer.valueOf(1).equals(orderEvaluate.getOrderType())) { |
| | | return; |
| | | } |
| | | TChargingOrder order = chargingOrderService.getById(orderEvaluate.getOrderId()); |
| | | Site site = null; |
| | | if (order != null && order.getSiteId() != null) { |
| | | List<Site> sites = siteClient.getSiteByIds(Collections.singletonList(order.getSiteId())).getData(); |
| | | site = sites == null || sites.isEmpty() ? null : sites.get(0); |
| | | } |
| | | wxSubscribeMessageService.sendEvaluationReply(orderEvaluate, order, site); |
| | | } catch (Exception e) { |
| | | log.warn("评价自动回复订阅消息发送异常,evaluateId={}", orderEvaluate == null ? null : orderEvaluate.getId(), e); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public OrderEvaluateVo getOrderEvaluate(String orderId, Integer orderType) { |
| | | TOrderEvaluate orderEvaluate = this.getOne(new LambdaQueryWrapper<TOrderEvaluate>().eq(TOrderEvaluate::getOrderId, orderId).eq(TOrderEvaluate::getOrderType, orderType)); |
| | | if(null != orderEvaluate){ |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | if(!orderEvaluate.getAppUserId().equals(userId)){ |
| | | throw new RuntimeException("权限不足"); |
| | | } |
| | | OrderEvaluateVo orderEvaluateVo = new OrderEvaluateVo(); |
| | | BeanUtils.copyProperties(orderEvaluate, orderEvaluateVo); |
| | | List<TOrderEvaluateTag> tOrderEvaluateTags = orderEvaluateTagMapper.selectList(new LambdaQueryWrapper<TOrderEvaluateTag>().eq(TOrderEvaluateTag::getOrderEvaluateId, orderEvaluate.getId())); |