case when (SELECT count(1) FROM tzs_user_equip t1 LEFT JOIN tzs_user_info t2 on t1.user_seq = t2.sequence_nbr where equip_id = ibjui."SEQUENCE_NBR") >0 THEN 1 ELSE 0 end isNotBind,
(SELECT GROUP_CONCAT(t2.name) from tzs_user_equip t1 LEFT JOIN tzs_user_info t2 on t1.user_seq = t2.sequence_nbr where equip_id = ibjui."SEQUENCE_NBR") "safety"
FROM
"idx_biz_jg_use_info" ibjui
LEFT JOIN idx_biz_jg_other_info ibjoi ON ibjui."RECORD" = ibjoi."RECORD"
LEFT JOIN idx_biz_jg_register_info ibjri ON ibjui."RECORD" = ibjri."RECORD"
LEFT JOIN amos_tzs_biz.tz_equipment_category tec ON ibjri."EQU_LIST" = tec.code
WHERE
"USE_UNIT_CREDIT_CODE" = #{companyCode}
AND "CLAIM_STATUS" = '已认领'
<iftest="type != '' and type != null and type == 'bind'">
AND ibjui."SEQUENCE_NBR" NOT IN (SELECT DISTINCT
equip_id
FROM
tzs_user_equip
WHERE
credit_code = #{companyCode}
AND user_seq = #{userSeq} UNION
( SELECT
equip_id
FROM
( SELECT COUNT ( equip_id ), equip_id FROM tzs_user_equip WHERE credit_code = #{companyCode} GROUP BY equip_id )
WHERE
COUNT =2 ))
</if>
<iftest="type != '' and type != null and type == 'untie'">
AND ibjui."SEQUENCE_NBR" IN (SELECT DISTINCT equip_id
FROM tzs_user_equip
WHERE credit_code = #{companyCode} AND user_seq = #{userSeq})
</if>
<iftest="dto.innerCode != '' and dto.innerCode != null">
and "USE_INNER_CODE" like concat('%',#{dto.innerCode},'%')
</if>
<iftest="dto.useOrgCode != '' and dto.useOrgCode != null">
and "USE_ORG_CODE" like concat('%',#{dto.useOrgCode},'%')
</if>
<iftest="dto.equipType != '' and dto.equipType != null">
and "EQU_LIST" = #{dto.equipType}
</if>
<iftest="dto.supervisorCode != '' and dto.supervisorCode != null">
and "SUPERVISORY_CODE" like concat('%',#{dto.supervisorCode},'%')
</if>
<iftest="dto.code96333 != '' and dto.code96333 != null">
and "CODE96333" like concat('%',#{dto.code96333},'%')
</if>
<iftest="dto.isNotBind != '' and dto.isNotBind != null and dto.isNotBind == 1">
AND ibjui."SEQUENCE_NBR" IN ( SELECT DISTINCT equip_id FROM tzs_user_equip WHERE credit_code = #{companyCode} )
</if>
<iftest="dto.isNotBind != '' and dto.isNotBind != null and dto.isNotBind == 0">
AND ibjui."SEQUENCE_NBR" NOT IN (SELECT DISTINCT equip_id FROM tzs_user_equip WHERE credit_code = #{companyCode} )