| | |
| | | <select id="selectGdDataObjectionPage" resultMap="gdDataObjectionResultMap"> |
| | | select |
| | | obj.id, |
| | | /* 建议显式列出 obj 的其他必要字段,或者确保 id 是主键 */ |
| | | obj.title, |
| | | obj.objection_type, |
| | | obj.objection_status, |
| | | obj.create_dept, |
| | | obj.catalog_resource_name, |
| | | obj.submitter, |
| | | obj.submitter_contact, |
| | | obj.handle_unit, |
| | | obj.objection_desc, |
| | | obj.objection_basis, |
| | | obj.other_objection_detail, |
| | | obj.review_opinion, |
| | | obj.area_code, |
| | | obj.apply_target_dept_id, |
| | | obj.create_user, |
| | | obj.create_dept, |
| | | obj.create_time, |
| | | obj.update_user, |
| | | obj.update_time, |
| | | obj.status, |
| | | 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> |
| | |
| | | ) |
| | | </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> |
| | | |
| | | |
| | |
| | | </select> |
| | | |
| | | <select id="getDetail" resultType="org.sxkj.gd.orderdata.vo.GdDataObjectionVO"> |
| | | select |
| | | obj.*, |
| | | string_agg(da.attach_name SEPARATOR ',') as attach_names , |
| | | string_agg(da.attach_id SEPARATOR ',') as attach_ids |
| | | from |
| | | ja_gd_data_objection obj |
| | | left join |
| | | ja_gd_data_objection_attachment da on obj.id::VARCHAR = da.objection_id::VARCHAR |
| | | SELECT |
| | | obj.*, |
| | | string_agg(da.attach_name::text, ',') AS attach_names, |
| | | string_agg(da.attach_id::text, ',') AS attach_ids |
| | | FROM |
| | | ja_gd_data_objection obj |
| | | LEFT JOIN |
| | | ja_gd_data_objection_attachment da ON obj.id::text = da.objection_id::text |
| | | <where> |
| | | and da.is_deleted = 0 |
| | | <if test="id != null "> |
| | | and obj.id = #{id} |
| | | da.is_deleted = 0 |
| | | <if test="id != null"> |
| | | AND obj.id::text = #{id}::text |
| | | </if> |
| | | </where> |
| | | group by obj.id |
| | | GROUP BY |
| | | obj.id |
| | | </select> |
| | | |
| | | </mapper> |