|
@@ -1,9 +1,8 @@
|
|
|
package edu.travel.commodity.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import edu.travel.adapter.service.country.CountryAdapter;
|
|
|
import edu.travel.commodity.entity.ShopOpinion;
|
|
|
import edu.travel.commodity.mapper.ShopOpinionMapper;
|
|
|
import edu.travel.commodity.service.ShopOpinionService;
|
|
@@ -11,27 +10,93 @@ import edu.travel.remote.dto.ShopOpinionDto;
|
|
|
import edu.travel.remote.vo.ShopOpinionVo;
|
|
|
import edu.travel.rpc.RPCBaseResponse;
|
|
|
import edu.travel.service.SysServiceImpl;
|
|
|
+import edu.travel.vo.BaseCountryServeVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
@Service
|
|
|
public class ShopOpinionServiceImpl extends SysServiceImpl<ShopOpinionMapper, ShopOpinion> implements ShopOpinionService {
|
|
|
+ @Autowired
|
|
|
+ private ShopOpinionMapper shopOpinionMapper;
|
|
|
+ @Autowired
|
|
|
+ private CountryAdapter countryAdapter;
|
|
|
+
|
|
|
@Override
|
|
|
- public RPCBaseResponse<List<ShopOpinion>> getAllFormPage(ShopOpinionDto dto) {
|
|
|
- // 创建 LambdaQueryWrapper 对象
|
|
|
- LambdaQueryWrapper<ShopOpinion> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- // 动态添加查询条件
|
|
|
- queryWrapper.eq(dto.getCountryId() != null,ShopOpinion::getCountryId, dto.getCountryId());
|
|
|
- queryWrapper.eq(dto.getTypeId() != null,ShopOpinion::getTypeId, dto.getTypeId());
|
|
|
- queryWrapper.eq(dto.getState() != null,ShopOpinion::getState, dto.getState());
|
|
|
- // 使用模糊查询
|
|
|
- queryWrapper.like(dto.getDescription() != null && !dto.getDescription().isEmpty(),ShopOpinion::getDescription, dto.getDescription());
|
|
|
- // 分页查询
|
|
|
- IPage<ShopOpinion> page = new Page<>(dto.getCurrentPage(), dto.getPageSize());
|
|
|
- // 使用自定义方法查询带联表的结果
|
|
|
- IPage<ShopOpinion> resultPage = super.getPageLink(queryWrapper,page);
|
|
|
- // 返回结果
|
|
|
- return new RPCBaseResponse<>(200, "SUCCESS", resultPage.getRecords());
|
|
|
+ public RPCBaseResponse<IPage<ShopOpinionVo>> getAllFormPage(ShopOpinionDto dto) {
|
|
|
+ // 创建分页对象
|
|
|
+ Page<ShopOpinionVo> shopOpinionPage = new Page<>(dto.getCurrentPage(), dto.getPageSize());
|
|
|
+
|
|
|
+ // 查询意见数据,确保返回类型正确
|
|
|
+ List<ShopOpinionVo> shopOpinions = shopOpinionMapper.selectOpinionsWithCountry(
|
|
|
+ dto.getDescription(),
|
|
|
+ dto.getState(),
|
|
|
+ dto.getCountryId(),
|
|
|
+ dto.getPageSize(),
|
|
|
+ (dto.getCurrentPage() - 1) * dto.getPageSize()
|
|
|
+ );
|
|
|
+
|
|
|
+ // 这里直接使用 shopOpinions,无需转换
|
|
|
+ List<ShopOpinionVo> shopOpinionVoList = shopOpinions; // 直接赋值
|
|
|
+
|
|
|
+ int total = shopOpinionMapper.countAll(dto.getDescription(), dto.getState(),null);
|
|
|
+
|
|
|
+ // 提取 countryID
|
|
|
+ Set<String> countryIds = shopOpinionVoList.stream()
|
|
|
+ .map(ShopOpinionVo::getCountryId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 查询国家信息
|
|
|
+ Map<String, ShopOpinionVo> countryMap = fetchCountryData(countryIds);
|
|
|
+
|
|
|
+ // 遍历并设置国家信息
|
|
|
+ for (ShopOpinionVo shopOpinionVo : shopOpinionVoList) {
|
|
|
+ if (shopOpinionVo.getMap() == null) {
|
|
|
+ shopOpinionVo.setMap(new HashMap<>());
|
|
|
+ }
|
|
|
+ if (countryMap.containsKey(shopOpinionVo.getCountryId())) {
|
|
|
+ shopOpinionVo.getMap().put("countryServe", countryMap.get(shopOpinionVo.getCountryId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 封装返回结果
|
|
|
+ IPage<ShopOpinionVo> pageVoLink = new Page<>();
|
|
|
+ pageVoLink.setRecords(shopOpinionVoList);
|
|
|
+ pageVoLink.setTotal(total);
|
|
|
+ pageVoLink.setCurrent(dto.getCurrentPage());
|
|
|
+ pageVoLink.setSize(dto.getPageSize());
|
|
|
+ return new RPCBaseResponse<>(200, "SUCCESS", pageVoLink);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保 convertToVo 方法处理正确
|
|
|
+ private ShopOpinionVo convertToVo(ShopOpinion shopOpinion) {
|
|
|
+ // 确保从 ShopOpinion 转换到 ShopOpinionVo 的逻辑是正确的
|
|
|
+ ShopOpinionVo vo = new ShopOpinionVo();
|
|
|
+ vo.setId(shopOpinion.getId());
|
|
|
+ vo.setCountryId(shopOpinion.getCountryId());
|
|
|
+ // 其他字段的设置...
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ //查询国家信息
|
|
|
+ private Map<String, ShopOpinionVo> fetchCountryData(Set<String> countryServeIds) {
|
|
|
+ Map<String, ShopOpinionVo> countryMap = new HashMap<>();
|
|
|
+ for(String countryServeId:countryServeIds){
|
|
|
+ BaseCountryServeVo countryServeVo= countryAdapter.getFormId(countryServeId).getData();
|
|
|
+ if (countryServeVo!=null){
|
|
|
+ ShopOpinionVo opinionVo=new ShopOpinionVo();
|
|
|
+ opinionVo.setCountryId(countryServeId);
|
|
|
+ opinionVo.setMap(new HashMap<>());
|
|
|
+ opinionVo.getMap().put("countryNameZh",countryServeVo.getCountryNameZh());
|
|
|
+ opinionVo.getMap().put("countryNameEn",countryServeVo.getCountryNameEn());
|
|
|
+ opinionVo.getMap().put("countryNameLocal",countryServeVo.getCountryNameLocal());
|
|
|
+ countryMap.put(countryServeId,opinionVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return countryMap;
|
|
|
}
|
|
|
}
|