Browse Source

意见表动态分页查询完成。

Sakana 1 week ago
parent
commit
00c1b8d634

+ 5 - 1
edu-travel-remote/edu-travel-remote-commodity/src/main/java/edu/travel/remote/dto/ShopOpinionDto.java

@@ -26,7 +26,7 @@ public class ShopOpinionDto extends PagePO {
     /**
      * 国家id
      */
-    private Long countryId;
+    private String countryId;
 
     /**
      * 意见类型id
@@ -52,4 +52,8 @@ public class ShopOpinionDto extends PagePO {
      */
     @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
     private Date updateTime;
+    /**
+     * 项目标识
+     */
+    private String project;
 }

+ 7 - 8
edu-travel-remote/edu-travel-remote-commodity/src/main/java/edu/travel/remote/vo/ShopOpinionVo.java

@@ -1,13 +1,9 @@
 package edu.travel.remote.vo;
 
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
 import edu.travel.entity.BaseEntity;
-import lombok.AllArgsConstructor;
 import lombok.Data;
-import lombok.NoArgsConstructor;
+
+import java.util.Map;
 
 /**
  * 意见表
@@ -22,7 +18,7 @@ public class ShopOpinionVo extends BaseEntity {
     /**
      * 国家id
      */
-    private Long countryId;
+    private String countryId;
 
     /**
      * 意见类型id
@@ -38,6 +34,9 @@ public class ShopOpinionVo extends BaseEntity {
      * 意见处理,默认0,0未处理,1已处理
      */
     private Integer state;
-
+/**
+ * map
+ */
+    private Map<String, Object> map;
 
 }

+ 3 - 0
edu-travel-remote/edu-travel-remote-country/src/main/java/edu/travel/remote/BaseCountryServeRemoteController.java

@@ -6,6 +6,7 @@ import edu.travel.rpc.RPCBaseResponse;
 import edu.travel.vo.BaseCountryServeVo;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import java.util.List;
 @FeignClient(path = "/baseCountryServe",name = "country-dev")
@@ -13,4 +14,6 @@ public interface BaseCountryServeRemoteController extends RemoteBaseController<B
     //服务国家树
     @GetMapping("/getCountryServeTree")
     public RPCBaseResponse<List<BaseCountryServeVo>> getCountryServeTree();
+    @GetMapping("/getFormId")
+    public RPCBaseResponse<BaseCountryServeVo> getFormId(@RequestParam("id")String id);
 }

+ 1 - 5
edu-travel-remote/edu-travel-remote-country/src/main/java/edu/travel/remote/ShopLanguageRemoteController.java

@@ -7,8 +7,6 @@ import edu.travel.rpc.RPCBaseResponse;
 import edu.travel.vo.ShopLanguageVo;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import java.util.List;
@@ -20,8 +18,6 @@ public interface ShopLanguageRemoteController extends RemoteBaseController<ShopL
     @GetMapping("/getLanguagePage")
     public RPCBaseResponse<IPage<ShopLanguageVo>> getLanguagePage(ShopLanguageDto shopLanguageDto);
     @GetMapping("/getFormId")
-    public RPCBaseResponse<ShopLanguageVo> getFormId(@RequestParam(
-            "id"
-    ) String id);
+    public RPCBaseResponse<ShopLanguageVo> getFormId(@RequestParam("id") String id);
 
 }

+ 1 - 1
edu-travel-service/edu-travel-service-commodity/src/main/java/edu/travel/commodity/entity/ShopOpinion.java

@@ -33,7 +33,7 @@ public class ShopOpinion extends BaseEntity {
      * 国家id
      */
     @TableField(value = "country_id")
-    private Long countryId;
+    private String countryId;
 
     /**
      * 意见类型id

+ 19 - 12
edu-travel-service/edu-travel-service-commodity/src/main/java/edu/travel/commodity/mapper/ShopOpinionMapper.java

@@ -4,19 +4,26 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import edu.travel.commodity.entity.ShopOpinion;
+import edu.travel.remote.vo.ShopOpinionVo;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
+import java.util.List;
+
 public interface ShopOpinionMapper extends BaseMapper<ShopOpinion> {
-    @Select({
-            "<script>",
-            "SELECT so.*, sot.type_name, sot.type_description ",
-            "FROM shop_opinion so ",
-            "LEFT JOIN shop_opinion_type sot ON so.type_id = sot.id ",
-            "<where>",
-            "${ew.sqlSegment}",
-            "</where>",
-            "</script>"
-    })
-    IPage<ShopOpinion> selectOpinionsWithType(IPage<ShopOpinion> page, @Param("ew") LambdaQueryWrapper<ShopOpinion> queryWrapper);
-}
+    // 查询带有国家信息的意见列表,确保不包含 project 参数
+    // 确保返回类型是 ShopOpinionVo
+    List<ShopOpinionVo> selectOpinionsWithCountry(
+            @Param("description") String description,
+            @Param("state") Integer state,
+            @Param("countryId") String countryId,
+            @Param("pageSize") Integer pageSize,
+            @Param("offset") Integer offset
+    );
+
+    int countAll(
+            @Param("description") String description,
+            @Param("state") Integer state,
+            @Param("countryId") String countryId
+    );
+}

+ 1 - 1
edu-travel-service/edu-travel-service-commodity/src/main/java/edu/travel/commodity/service/ShopOpinionService.java

@@ -12,5 +12,5 @@ import java.util.List;
 public interface ShopOpinionService extends IService<ShopOpinion>{
 
 //分页连表
-    RPCBaseResponse<List<ShopOpinion>> getAllFormPage(ShopOpinionDto dto);
+    RPCBaseResponse<IPage<ShopOpinionVo>> getAllFormPage(ShopOpinionDto dto);
 }

+ 82 - 17
edu-travel-service/edu-travel-service-commodity/src/main/java/edu/travel/commodity/service/impl/ShopOpinionServiceImpl.java

@@ -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;
     }
 }

+ 1 - 1
edu-travel-service/edu-travel-service-commodity/src/main/java/edu/travel/commodity/web/ShopOpinionController.java

@@ -32,7 +32,7 @@ public class ShopOpinionController extends BaseController<ShopOpinion> implement
      * 分页查询(连表)
      */
     @GetMapping("/getAllFormPage")
-    public RPCBaseResponse<List<ShopOpinion>> getAllFormPage(ShopOpinionDto dto) {
+    public RPCBaseResponse<IPage<ShopOpinionVo>> getAllFormPage(ShopOpinionDto dto) {
         return shopOpinionService.getAllFormPage(dto);
      }
     /**

+ 40 - 2
edu-travel-service/edu-travel-service-commodity/src/main/resources/mapper/ShopOpinionMapper.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="edu.travel.commodity.mapper.ShopOpinionMapper">
+
   <resultMap id="BaseResultMap" type="edu.travel.commodity.entity.ShopOpinion">
     <!--@mbg.generated-->
     <!--@Table shop_opinion-->
@@ -16,9 +17,46 @@
     <result column="delete_flag" jdbcType="INTEGER" property="deleteFlag" />
     <result column="project" jdbcType="VARCHAR" property="project" />
   </resultMap>
+
   <sql id="Base_Column_List">
     <!--@mbg.generated-->
-    id, country_id, type_id, description, create_user_id, update_user_id, create_time, 
+    id, country_id, type_id, description, create_user_id, update_user_id, create_time,
     update_time, `state`, delete_flag, project
   </sql>
-</mapper>
+
+  <select id="countAll" resultType="int">
+    SELECT COUNT(*)
+    FROM shop_opinion so
+    <where>
+      <if test="countryId != null and countryId != ''">
+        AND so.country_id = #{countryId}
+      </if>
+      <if test="state != null">
+        AND so.state = #{state}
+      </if>
+      <if test="description != null and description != ''">
+        AND so.description LIKE CONCAT('%', #{description}, '%')
+      </if>
+    </where>
+  </select>
+
+  <select id="selectOpinionsWithCountry" resultType="edu.travel.remote.vo.ShopOpinionVo">
+    SELECT so.id, so.country_id AS countryId, so.type_id AS typeId, so.description, so.state
+    FROM shop_opinion so
+    <where>
+      <if test="description != null and description != ''">
+        AND so.description LIKE CONCAT('%', #{description}, '%')
+      </if>
+      <if test="countryId != null">
+        AND so.country_id = #{countryId}
+      </if>
+      <if test="state != null">
+        AND so.state = #{state}
+      </if>
+    </where>
+    LIMIT #{offset}, #{pageSize}
+  </select>
+
+
+
+</mapper>