select if(count(1)=0,0,1) from sys_auth where auth_source=#{authSource} and auth_target=#{authTarget}
</select>
<selectid="findAuthId"resultType="String">
select id from sys_auth where auth_source=#{authSource} and auth_source_type=#{authSourceType} and auth_target=#{authTarget} and auth_target_type=#{authTargetType} limit 1
and ( v_auth_model.type ='spine' OR ( v_auth_model.create_by = #{createBy} AND v_auth_model.type = 'leaf'))
</if>
<iftest="pid !=null">
and v_auth_model.pid = #{pid}
</if>
<iftest="withExtend == null and id != null">
and v_auth_model.id = #{id}
</if>
<iftest="withExtend == 'parent' and id != null">
and FIND_IN_SET(v_auth_model.id,GET_V_AUTH_MODEL_WITH_PARENT(#{id},#{modelType}))
</if>
<iftest="withExtend == 'children' and id != null">
and FIND_IN_SET(v_auth_model.id,GET_V_AUTH_MODEL_WITH_CHILDREN(#{id},#{modelType}))
</if>
<iftest="name != null and name !='' and withExtend == 'parent'">
and FIND_IN_SET(v_auth_model.id,GET_V_AUTH_MODEL_WITH_PARENT ( (select GROUP_CONCAT(id) from v_auth_model where model_type = #{modelType} and `name` like CONCAT('%', #{name},'%')) ,#{modelType}))
</if>
<iftest="name != null and name =='' and withExtend == 'parent'">
and v_auth_model.pid = '0'
</if>
</where>
) auth
LEFT JOIN (
SELECT
count( 1 ) AS `children_count`,
`authTemp`.`pid` AS `pid`
FROM
( SELECT * FROM v_auth_model
<where>
model_type = #{modelType}
<iftest="createBy != null">
and ( v_auth_model.type ='spine' OR ( v_auth_model.create_by = #{createBy} AND v_auth_model.type = 'leaf'))
</if>
</where>
) authTemp
GROUP BY
authTemp.pid
) authCount ON
auth.id = authCount.pid
<where>
<iftest="createBy != null">
(chartcount.children_count>0 or chart.create_by = #{createBy})