Przeglądaj źródła

根据附件名称查询,调整sql

chenendian 2 miesięcy temu
rodzic
commit
e2a6c06fb8

+ 2 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/ProjectController.java

@@ -179,6 +179,8 @@ public class ProjectController extends BaseController {
             Map<String, Object> projects = projectService.getListSearch(projectFilterVo);
             return R.ok(projects);
         } catch (Exception e) {
+            logger.error("异常发生:{}", e);
+            //e.printStackTrace();
             return R.fail(e.getMessage());
         }
     }

+ 16 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/domain/SerchProject.java

@@ -0,0 +1,16 @@
+package com.siwei.apply.domain;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 项目检索对象 t_project
+ *
+ * @author chened
+ * @date 2025-11-13
+ */
+@Data
+public class SerchProject extends Project {
+    private List<ProjectAttachmentInfo> attachmentInfoList;
+}

+ 49 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/handler/JsonTypeHandler.java

@@ -0,0 +1,49 @@
+package com.siwei.apply.handler;
+
+import com.alibaba.fastjson.JSON;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.MappedJdbcTypes;
+import org.apache.ibatis.type.MappedTypes;
+import org.postgresql.util.PGobject;
+
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+@MappedTypes({Object.class})
+@MappedJdbcTypes(JdbcType.OTHER)
+public class JsonTypeHandler extends BaseTypeHandler<Object> {
+    private static final PGobject jsonObject = new PGobject();
+    private static final String JSONB_STR = "jsonb";
+
+    @Override
+    public void setNonNullParameter(PreparedStatement ps, int i,
+                                    Object parameter, JdbcType jdbcType) throws SQLException {
+        jsonObject.setType(JSONB_STR);
+        jsonObject.setValue(JSON.toJSONString(parameter));
+        ps.setObject(i, jsonObject);
+    }
+
+    @Override
+    public Object getNullableResult(ResultSet rs, String columnName)
+            throws SQLException {
+        String value = rs.getString(columnName);
+        return value != null ? JSON.parse(value) : null;
+    }
+
+    @Override
+    public Object getNullableResult(ResultSet rs, int columnIndex)
+            throws SQLException {
+        String value = rs.getString(columnIndex);
+        return value != null ? JSON.parse(value) : null;
+    }
+
+    @Override
+    public Object getNullableResult(CallableStatement cs, int columnIndex)
+            throws SQLException {
+        String value = cs.getString(columnIndex);
+        return value != null ? JSON.parse(value) : null;
+    }
+}

+ 1 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/NodeAttachmentImpl.java

@@ -633,7 +633,7 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
         //这里使用异步方法
         CompletableFuture.supplyAsync(()->{
             try {
-                    logger.info("一部方法开始执行,projectId: {},nodeId: {},nodeAttachmentId: {}", paramProjectId,paramnodeId,nodeAttachmentId);
+                    logger.info("异步方法开始执行--start projectId: {},nodeId: {},nodeAttachmentId: {}", paramProjectId,paramnodeId,nodeAttachmentId);
                     String projectId = paramProjectId;
                     String nodeId = paramnodeId;
                     NodeAttachment nodeAttachment = this.getById(nodeAttachmentId);

+ 3 - 5
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/ProjectImpl.java

@@ -2,10 +2,7 @@ package com.siwei.apply.service.impl;
 
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
-import com.siwei.apply.domain.BaseId;
-import com.siwei.apply.domain.NodeAttachment;
-import com.siwei.apply.domain.Project;
-import com.siwei.apply.domain.ProjectWorkflow;
+import com.siwei.apply.domain.*;
 import com.siwei.apply.domain.res.*;
 import com.siwei.apply.domain.vo.NodeVo;
 import com.siwei.apply.domain.vo.ProjectFilterVo;
@@ -289,6 +286,7 @@ public class ProjectImpl implements ProjectService {
             List<String> keyWords = List.of(projectFilterVo.getKeyWord().trim().split("\\s+"));
             projectFilterVo.setKeyWords(keyWords);
         }
+        //todo 这里后期可以进行优化,把查询出的项目id写入redis中,分页时候可以取缓存
         List<Project> projects = projectMapper.getListSearch(projectFilterVo);
         Integer count = projectMapper.getSearchCount(projectFilterVo);
         //根据项目id查询所有流程id
@@ -323,7 +321,7 @@ public class ProjectImpl implements ProjectService {
         }
         Map<String, Object> map = new HashMap<>();
         map.put("projects", projects);
-         map.put("count", count);
+        map.put("count", count);
         map.put("attachmentCount", attachmentCount);
         map.put("graphicLayerCount", graphicLayerCount);
         return map;

+ 115 - 2
siwei-modules/siwei-apply/src/main/resources/mapper/ProjectMapper.xml

@@ -17,6 +17,12 @@
         <result column="second_plot_code" property="secondPlotCode"/>
     </resultMap>
 
+    <!-- 扩展映射:继承基础映射并添加特有字段 -->
+    <resultMap id="SearchProjectMap" type="com.siwei.apply.domain.SerchProject" extends="projectMap">
+        <result property="attachmentInfoList" column="attachmentInfoList" typeHandler="com.siwei.apply.handler.JsonTypeHandler"/>
+    </resultMap>
+
+
     <insert id="add" parameterType="com.siwei.apply.domain.Project">
         INSERT INTO t_project (id, name, code, company,
                                created_at, updated_at, project_type,first_plot_code,second_plot_code, creator_id)
@@ -150,7 +156,7 @@
         WHERE flow.node_id = #{nodeId}   LIMIT 1
     </select>
 
-    <select id="getListSearch" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultMap="projectMap">
+    <select id="getListSearchOld" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultMap="projectMap">
         SELECT *
         FROM t_project
         <where>
@@ -175,7 +181,8 @@
         LIMIT #{pageSize} offset #{offset}
     </select>
 
-    <select id="getSearchCount" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultType="int">
+
+    <select id="getSearchCountOld" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultType="int">
         SELECT COUNT(*)
         FROM t_project
         <where>
@@ -198,6 +205,112 @@
         </where>
     </select>
 
+    <select id="getListSearch" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo"  resultMap="SearchProjectMap">
+        SELECT
+            P."id" AS id,
+            P."name" AS  name,
+            P."code" AS code,
+            P."company" AS company,
+            P."created_at" AS createAt,
+            P."updated_at" AS updateAt,
+            P."project_type" AS projectType,
+            P."on_chain_num" AS onChainNum,
+            P."creator_id" AS creatorId,
+            COALESCE(
+                    jsonb_agg(jsonb_build_object('id', A.id,
+                                                'fileName', A.file_name,
+                                                'nodeId', A.node_id,
+                                                'filePath', A.file_path)),
+                    '[]'  -- 确保返回空数组而不是 null
+            ) AS attachmentInfoList
+        FROM
+            public.t_project P
+                LEFT JOIN
+            public.t_project_attachment_info A ON P.id = A.project_id
+            <if test="keyWords != null and keyWords.size() > 0">
+                AND regexp_like(A.file_name,
+                    REGEXP_REPLACE(
+                    <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
+                    , '[\r\n\s]+', '', 'g')
+                , 'i')
+            </if>
+        <where>
+            <if test="keyWords != null and keyWords.size() > 0">
+                regexp_like(P.name,
+                <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
+                , 'i')
+                OR
+                regexp_like(P.code,
+                <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
+                , 'i')
+                OR
+                regexp_like(P.company,
+                <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
+                , 'i')
+                OR
+                regexp_like(A.file_name,
+                <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
+                , 'i')
+            </if>
+            <if test="isOnchain != null and isOnchain">
+                AND on_chain_num > 0
+            </if>
+        </where>
+        GROUP BY
+            P.id, P.name, P.code, P.company, P.created_at, P.updated_at, P.project_type, P.on_chain_num, P.creator_id
+        ORDER BY
+            updated_at DESC
+            LIMIT #{pageSize} OFFSET #{offset}
+    </select>
+
+    <select id="getSearchCount" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultType="int">
+        SELECT COUNT(*)
+        FROM (
+        SELECT DISTINCT
+        P."id" AS id,
+        P."name" AS  name,
+        P."code" AS code,
+        P."company" AS company,
+        P."created_at" AS createAt,
+        P."updated_at" AS updateAt,
+        P."project_type" AS projectType,
+        P."on_chain_num" AS onChainNum,
+        P."creator_id" AS creatorId
+        FROM "public"."t_project" P
+        LEFT JOIN public.t_project_attachment_info A ON P.id = A.project_id
+        <if test="keyWords != null and keyWords.size() > 0">
+            AND regexp_like(A.file_name,
+            REGEXP_REPLACE(
+            <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
+            , '[\r\n\s]+', '', 'g')
+            , 'i')
+        </if>
+        <where>
+            <if test="keyWords != null and keyWords.size() > 0">
+                regexp_like(P.name,
+                <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
+                , 'i')
+                OR
+                regexp_like(P.code,
+                <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
+                , 'i')
+                OR
+                regexp_like(P.company,
+                <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
+                , 'i')
+                OR
+                regexp_like(A.file_name,
+                <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
+                , 'i')
+            </if>
+            <if test="isOnchain != null and isOnchain">
+                AND on_chain_num > 0
+            </if>
+        </where>
+        ) AS distinct_projects
+    </select>
+
+
     <delete id="deleteNodeByTable">
         DELETE FROM ${tableName}
         WHERE id = #{nodeId}