已知query是字符串createBy是字符串的list集合这样写sql对吗 select id=getByUserIdApp resultType=comredxunbpmcoreentityBpmTask parameterType=javautilMap select v from select t from BPM_TASK t left join bp
这段SQL语句的基本逻辑是正确的。它使用了两个子查询,分别使用了左连接和内连接。最后使用了多个条件判断和动态SQL语句。
但是,根据你的问题描述,query是一个字符串,而createBy是一个字符串的list集合。在SQL中,直接将list集合作为参数传入是不合法的。
如果createBy是一个字符串的list集合,你需要将其转换为合适的形式,例如将其转换为字符串,然后在SQL中进行匹配。
另外,根据你的SQL语句,createBy的匹配条件应该是v.CREATE_BY_ IN #{createBys},而不是v.CREATE_BY_ LIKE CONCAT('%', #{query}, '%') OR v.CREATE_BY_ IN #{createBys}。因为这样写会导致query和createBys之间的OR关系,可能会出现错误的结果。
综上所述,你可以将SQL语句修改如下:
<select id="getByUserIdApp" resultType="com.redxun.bpm.core.entity.BpmTask" parameterType="java.util.Map">
select v.* from (
select t.* from BPM_TASK t left join bpm_def d on t.def_id_= d.def_id_ where ASSIGNEE_=#{userId} and t.TENANT_ID_=#{tenantId} and t.STATUS_!='COMPLETED' and t.STATUS_!='LOCKED'
UNION
select t.* from bpm_task t left join bpm_def d on t.def_id_= d.def_id_ left join bpm_task_user u on
t.TASK_ID_=u.TASK_ID_
where t.ASSIGNEE_ is null AND t.STATUS_!='COMPLETED' and t.STATUS_!='LOCKED' and (u.USER_ID_=#{userId} and t.TENANT_ID_=#{tenantId}
<if test="@rx.Ognl@isNotEmpty(groupIds)">or u.GROUP_ID_ in
<foreach collection="groupIds" item="id" separator="," open="(" close=")">#{id}</foreach>
</if>
)
) v where 1=1
<if test="@rx.Ognl@isNotEmpty(w.whereSql)">
and ${w.whereSql}
</if>
<if test="query != null and query != ''">
AND (v.BUS_KEY_ LIKE CONCAT('%', #{query}, '%') OR v.SUBJECT_ LIKE CONCAT('%', #{query}, '%') OR v.CREATE_BY_ IN #{createBys})
</if>
<if test="@rx.Ognl@isNotEmpty(w.orderBySql)">
ORDER BY ${w.orderBySql}
</if>
</select>
``
原文地址: https://www.cveoy.top/t/topic/i1wD 著作权归作者所有。请勿转载和采集!