|
@@ -1,12 +1,113 @@
|
|
|
package edu.travel.commodity.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import edu.travel.adapter.service.country.LanguageAdapter;
|
|
|
import edu.travel.commodity.entity.ShopOpinionType;
|
|
|
import edu.travel.commodity.mapper.ShopOpinionTypeMapper;
|
|
|
import edu.travel.commodity.service.ShopOpinionTypeService;
|
|
|
+import edu.travel.remote.dto.ShopOpinionTypeDto;
|
|
|
+import edu.travel.remote.vo.ShopOpinionTypeVo;
|
|
|
+import edu.travel.rpc.RPCBaseResponse;
|
|
|
+import edu.travel.service.SysServiceImpl;
|
|
|
+import edu.travel.vo.ShopLanguageVo;
|
|
|
+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 ShopOpinionTypeServiceImpl extends ServiceImpl<ShopOpinionTypeMapper, ShopOpinionType> implements ShopOpinionTypeService {
|
|
|
+public class ShopOpinionTypeServiceImpl extends SysServiceImpl<ShopOpinionTypeMapper, ShopOpinionType> implements ShopOpinionTypeService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ShopOpinionTypeMapper shopOpinionTypeMapper;
|
|
|
+ @Autowired
|
|
|
+ private LanguageAdapter languageAdapter;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页动态查询(联表)
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public RPCBaseResponse<IPage<ShopOpinionTypeVo>> getAllOpinionTypeLanguage(ShopOpinionTypeDto dto) {
|
|
|
+ // 创建分页对象
|
|
|
+ Page<ShopOpinionTypeVo> shopOpinionTypeVoPage = new Page<>(dto.getCurrentPage(), dto.getPageSize());
|
|
|
+
|
|
|
+ // 查询意见类型数据
|
|
|
+ List<ShopOpinionType> opinionTypes = shopOpinionTypeMapper.selectOpinionTypeWithLanguage(
|
|
|
+ dto.getTypeName(),
|
|
|
+ dto.getStatus(),
|
|
|
+ dto.getPageSize(),
|
|
|
+ (dto.getCurrentPage() - 1) * dto.getPageSize()
|
|
|
+ );
|
|
|
+
|
|
|
+ // 转换为 ShopOpinionTypeVo 列表
|
|
|
+ List<ShopOpinionTypeVo> opinionTypeList = opinionTypes.stream()
|
|
|
+ .map(this::convertToVo) // 确保这里的 convertToVo 方法返回 `ShopOpinionTypeVo`
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ int total = shopOpinionTypeMapper.countAll(dto.getTypeName(), dto.getStatus());
|
|
|
+
|
|
|
+ // 提取语言id
|
|
|
+ Set<String> languageIds = opinionTypeList.stream()
|
|
|
+ .map(ShopOpinionTypeVo::getLanguageId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 查询语言信息
|
|
|
+ Map<String, ShopOpinionTypeVo> shopOpinionTypeVoMap = fetchLanguageData(languageIds);
|
|
|
+
|
|
|
+ // 将语言信息放入对应的仓库列表中
|
|
|
+ for (ShopOpinionTypeVo opinionTypeVo : opinionTypeList) {
|
|
|
+ if (opinionTypeVo.getMap() == null) {
|
|
|
+ opinionTypeVo.setMap(new HashMap<>()); // 确保 map 被初始化
|
|
|
+ }
|
|
|
+ if (shopOpinionTypeVoMap.containsKey(opinionTypeVo.getLanguageId())) {
|
|
|
+ opinionTypeVo.getMap().put("language", shopOpinionTypeVoMap.get(opinionTypeVo.getLanguageId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 封装返回
|
|
|
+ IPage<ShopOpinionTypeVo> pageVoLink = new Page<>();
|
|
|
+ pageVoLink.setRecords(opinionTypeList);
|
|
|
+ pageVoLink.setTotal(total);
|
|
|
+ pageVoLink.setCurrent(dto.getCurrentPage());
|
|
|
+ pageVoLink.setSize(dto.getPageSize());
|
|
|
+
|
|
|
+ return new RPCBaseResponse<>(200, "SUCCESS", pageVoLink);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将 ShopOpinionType 转换为 ShopOpinionTypeVo 的方法
|
|
|
+ private ShopOpinionTypeVo convertToVo(ShopOpinionType opinionType) {
|
|
|
+ ShopOpinionTypeVo vo = new ShopOpinionTypeVo();
|
|
|
+ vo.setId(opinionType.getId());
|
|
|
+ vo.setTypeName(opinionType.getTypeName());
|
|
|
+ vo.setLanguageId(opinionType.getLanguageId());
|
|
|
+ // 设置其他字段,如果有的话
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
|
|
|
-}
|
|
|
+ // 查询语言数据的方法
|
|
|
+ private Map<String, ShopOpinionTypeVo> fetchLanguageData(Set<String> languageIds) {
|
|
|
+ // 这里是伪代码,您需要实现实际的语言数据查询逻辑
|
|
|
+ Map<String, ShopOpinionTypeVo> languageMap = new HashMap<>();
|
|
|
+ // 假设有一个适配器可以获取语言信息
|
|
|
+ for (String languageId : languageIds) {
|
|
|
+ ShopLanguageVo languageVo = languageAdapter.getFormId(languageId).getData();
|
|
|
+ if (languageVo != null) {
|
|
|
+ ShopOpinionTypeVo opinionTypeVo = new ShopOpinionTypeVo();
|
|
|
+ opinionTypeVo.setLanguageId(languageId);
|
|
|
+ opinionTypeVo.setMap(new HashMap<>()); // 初始化 map
|
|
|
+ opinionTypeVo.getMap().put("languageNameZh", languageVo.getLanguageNameZh());
|
|
|
+ opinionTypeVo.getMap().put("languageNameEn", languageVo.getLanguageNameEn());
|
|
|
+ opinionTypeVo.getMap().put("languageNameLocal", languageVo.getLanguageNameLocal());
|
|
|
+ languageMap.put(languageId, opinionTypeVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return languageMap;
|
|
|
+ }
|
|
|
+}
|