吉安感知网项目-后端
linwei
2026-04-02 e95775fca40b69671c259594742a2bce72a6afe3
opt: sql改造其他模块改造12
2 files modified
46 ■■■■ changed files
drone-service/drone-gd/src/main/java/org/sxkj/gd/orderdata/mapper/GdDataObjectionMapper.xml 12 ●●●● patch | view | raw | blame | history
drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/mapper/GdManageDeviceMapper.xml 34 ●●●● patch | view | raw | blame | history
drone-service/drone-gd/src/main/java/org/sxkj/gd/orderdata/mapper/GdDataObjectionMapper.xml
@@ -31,28 +31,26 @@
    <select id="selectGdDataObjectionPage" resultMap="gdDataObjectionResultMap">
        select
        obj.id,
        /* 建议显式列出 obj 的其他必要字段,或者确保 id 是主键 */
        obj.title,
        obj.objection_status,
        obj.create_dept,
        obj.apply_target_dept_id,
        obj.create_time,
        /* 必须显式查询排序字段,否则某些情况下分页插件生成的 COUNT 会报错 */
        obj.update_time,
        obj.is_deleted,
        /* 修改点1:修正 string_agg 语法,去掉 SEPARATOR */
        string_agg(da.attach_name::text, ',') as attach_names,
        bd.dept_name as create_dept_name
        from
        ja_gd_data_objection obj
        left join
        ja_gd_data_objection_attachment da
        /* 修改点2:双向转型对齐 */
        on obj.id::text = da.objection_id::text
        and da.is_deleted = 0
        left join
        blade_dept bd on bd.id::text = obj.create_dept::text
        <where>
            obj.is_deleted = 0
            /* 修改点3:da.is_deleted 已移至 ON 条件,此处删除以保证 LEFT JOIN 有效 */
            <if test="param2.title != null and param2.title != ''">
                and obj.title::text like concat('%',#{param2.title},'%')
            </if>
@@ -72,10 +70,12 @@
                )
            </if>
        </where>
        /* 修改点4:GROUP BY 必须包含 SELECT 中所有非聚合字段 */
        group by
        obj.id, obj.title, obj.objection_status, obj.create_dept,
        obj.apply_target_dept_id, obj.create_time, obj.is_deleted, bd.dept_name
        obj.apply_target_dept_id, obj.create_time,
        /* 只要 SELECT 里出现的非聚合字段,GROUP BY 必须加上 */
        obj.update_time,
        obj.is_deleted, bd.dept_name
    </select>
drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/mapper/GdManageDeviceMapper.xml
@@ -58,35 +58,37 @@
    <select id="selectGdManageDevice" resultType="org.sxkj.gd.workorder.vo.GdManageDeviceVO">
        select
            md.id,
            md.device_sn,
            md.device_name,
            md.nickname,
            md.device_payload,
            md.longitude,
            md.latitude,
            md.geom,
            d2.height as height
        md.id,
        md.device_sn,
        md.device_name,
        md.nickname,
        md.device_payload,
        md.longitude,
        md.latitude,
        md.geom,
        d2.height as height
        from
            ja_gd_manage_device md
        left join ja_gd_manage_device d2 on md.device_sn::VARCHAR = d2.device_sn::VARCHAR and d2.device_type = '0'
        ja_gd_manage_device md
        /* 修改点1:关联条件双向转型 text(规避之前的 bigint = varchar 错误) */
        left join ja_gd_manage_device d2 on md.device_sn::text = d2.device_sn::text and d2.device_type = '0'
        <where>
            <if test="deviceIds != null and deviceIds.size() > 0">
                and md.id in
                and md.id::text in
                <foreach item="item" collection="deviceIds" index="index" open="(" close=")" separator=",">
                    #{item}
                    #{item}::text
                </foreach>
            </if>
            <if test="devicePayload != null and devicePayload != ''">
                and md.device_payload like concat('%',#{devicePayload},'%')
            </if>
            <if test="geom != null and geom != ''">
                and ST_Intersects(md.geom, ST_GeomFromText(#{geom}))
                /* 修改点2:增加显式类型转换 ::text,并建议指定 SRID (如 4326) */
                and ST_Intersects(md.geom, ST_GeomFromText(#{geom}::text, 4326))
            </if>
            <if test="deviceType != null and deviceType != '' ">
                and md.device_type = #{deviceType}
                and md.device_type::text = #{deviceType}::text
            </if>
                and md.is_deleted = 0
            and md.is_deleted = 0
        </where>
    </select>