package com.xiaopeng.operation.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.xiaopeng.api.dto.account.UcUserInfo; import com.xiaopeng.api.feignClient.account.UserResourcesClient; import com.xiaopeng.api.model.operation.XpFeedbackType; import com.xiaopeng.api.model.operation.XpUserFeedback; import com.xiaopeng.common.core.web.page.PageInfo; import com.xiaopeng.evi.oss.service.AliOssService; import com.xiaopeng.operation.mapper.XpUserFeedbackMapper; import com.xiaopeng.operation.query.UserFeedBackQuery; import com.xiaopeng.operation.service.IXpFeedbackTypeService; import com.xiaopeng.operation.service.IXpUserFeedbackService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.xiaopeng.operation.vo.XpUserFeedbackVO; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import java.io.UnsupportedEncodingException; import java.util.*; import java.util.stream.Collectors; /** *

* 用户意见反馈表 服务实现类 *

* * @author mitao * @since 2026-02-03 */ @Service @RequiredArgsConstructor(onConstructor_ = @Lazy) public class XpUserFeedbackServiceImpl extends ServiceImpl implements IXpUserFeedbackService { private final UserResourcesClient userResourcesClient; private final IXpFeedbackTypeService xpFeedbackTypeService; private final AliOssService aliOssService; @Override public PageInfo getPageList(UserFeedBackQuery query) { Page page = lambdaQuery() .like(StringUtils.isNotBlank(query.getContent()), XpUserFeedback::getFeedbackContent, query.getContent()) .orderByDesc(XpUserFeedback::getCreateTime) .page(new Page<>(query.getPageNum(), query.getPageSize())); //转换为VO List xpUserFeedbackVOS = BeanUtil.copyToList(page.getRecords(), XpUserFeedbackVO.class); //获取小鹏用户信息 List xpUid = xpUserFeedbackVOS.stream().map(XpUserFeedback::getFeedbackUserId).distinct().collect(Collectors.toList()); if (CollUtil.isNotEmpty(xpUid)) { Map userInfoMap = userResourcesClient.getUserListByUids(xpUid, false); if (userInfoMap != null && !userInfoMap.isEmpty()) { for (XpUserFeedbackVO xpUserFeedbackVO : xpUserFeedbackVOS) { UcUserInfo userInfo = userInfoMap.get(xpUserFeedbackVO.getFeedbackUserId().toString()); if (Objects.nonNull(userInfo)) { xpUserFeedbackVO.setNickname(userInfo.getNickName()); xpUserFeedbackVO.setAvatar(userInfo.getHeadImg()); xpUserFeedbackVO.setPhone(userInfo.getMobile()); } } } } //收集意见反馈类型ID List feedbackTypeIds = xpUserFeedbackVOS.stream().map(XpUserFeedback::getFeedbackTypeId).distinct().collect(Collectors.toList()); Map feedbackTypeMap = CollUtil.isNotEmpty(feedbackTypeIds) ? xpFeedbackTypeService.listByIds(feedbackTypeIds).stream() .collect(Collectors.toMap(XpFeedbackType::getId, XpFeedbackType::getFeedbackType)) : Collections.emptyMap(); xpUserFeedbackVOS.forEach(item-> item.setFeedbackTypeName(feedbackTypeMap.get(item.getFeedbackTypeId()))); //封装分页信息 PageInfo pageInfo = new PageInfo<>(); pageInfo.setTotal(page.getTotal()); pageInfo.setSize(page.getSize()); pageInfo.setPages(page.getPages()); for (XpUserFeedbackVO xpUserFeedbackVO : xpUserFeedbackVOS) { String feedbackPictures = xpUserFeedbackVO.getFeedbackPictures(); if (StringUtils.isNotBlank(feedbackPictures)) { JSONArray jsonArray = JSONArray.parseArray(feedbackPictures); ArrayList list = new ArrayList<>(jsonArray.size()); for (Object o : jsonArray) { JSONObject jsonObject = JSONObject.parseObject(o.toString()); String downloadUrl = null; try { downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } list.add(downloadUrl); } xpUserFeedbackVO.setFeedbackPictures(String.join(",", list)); } } pageInfo.setRecords(xpUserFeedbackVOS); return pageInfo; } }