| | |
| | | dsm.*, |
| | | ds.scene_name as defense_scene_name |
| | | from ja_fw_defense_scene_manage dsm |
| | | left join ja_fw_defense_scene ds on ds.id = dsm.defense_scene_id::VARCHAR and ds.is_deleted = 0 |
| | | left join ja_fw_defense_scene ds on ds.id::VARCHAR = dsm.defense_scene_id::VARCHAR and ds.is_deleted = 0 |
| | | <where> |
| | | dsm.is_deleted = 0 |
| | | <if test="param2.name != null and param2.name != ''"> |
| | | and dsm.scene_name like concat('%', #{param2.name}, '%') |
| | | <if test="param2.sceneName != null and param2.sceneName != ''"> |
| | | and dsm.scene_name like concat('%', #{param2.sceneName}, '%') |
| | | </if> |
| | | <if test="param2.deptList != null and param2.deptList.size > 0"> |
| | | and dsm.create_dept in |
| | |
| | | dsm.*, |
| | | ds.scene_name as defense_scene_name |
| | | from ja_fw_defense_scene_manage dsm |
| | | left join ja_fw_defense_scene ds on ds.id = dsm.defense_scene_id::VARCHAR and ds.is_deleted = 0 |
| | | left join ja_fw_defense_scene ds on ds.id::VARCHAR = dsm.defense_scene_id::VARCHAR and ds.is_deleted = 0 |
| | | where dsm.is_deleted = 0 |
| | | and dsm.id = #{id} |
| | | </select> |
| | |
| | | else length(ds.area_divide_ids) - length(replace(ds.area_divide_ids, ',', '')) + 1 |
| | | end as area_count, |
| | | ( |
| | | select ifnull(sum( |
| | | case |
| | | when ad.device_ids is null or ad.device_ids = '' then 0 |
| | | else length(ad.device_ids) - length(replace(ad.device_ids, ',', '')) + 1 |
| | | end |
| | | ), 0) |
| | | SELECT COALESCE( |
| | | SUM( -- 这里已经删除了那两个反引号 `` |
| | | CASE |
| | | WHEN ad.device_ids IS NULL OR ad.device_ids = '' THEN 0 |
| | | ELSE length(ad.device_ids) - length(replace(ad.device_ids, ',', '')) + 1 |
| | | END |
| | | ), 0 |
| | | ) |
| | | from ja_fw_area_divide ad |
| | | where ad.is_deleted = 0 |
| | | and find_in_set(ad.id, ds.area_divide_ids) > 0 |
| | | and ad.id::VARCHAR = ANY(string_to_array(ds.area_divide_ids, ',')) |
| | | ) as device_count |
| | | from ja_fw_defense_scene_manage dsm |
| | | left join ja_fw_defense_scene ds on ds.id = dsm.defense_scene_id::VARCHAR and ds.is_deleted = 0 |
| | | left join ja_fw_defense_scene ds on ds.id::VARCHAR = dsm.defense_scene_id::VARCHAR and ds.is_deleted = 0 |
| | | <where> |
| | | dsm.is_deleted = 0 |
| | | <if test="time != null"> |
| | | and (dsm.effective_date_start is null or dsm.effective_date_start <= #{time}) |
| | | and (dsm.effective_date_end is null or dsm.effective_date_end >= #{time}) |
| | | and (dsm.effective_date_start is null or dsm.effective_date_start <= #{time}::timestamp) |
| | | and (dsm.effective_date_end is null or dsm.effective_date_end >= #{time}::timestamp) |
| | | </if> |
| | | </where> |
| | | </select> |
| | |
| | | </select> |
| | | |
| | | <select id="selectDeviceId" parameterType="java.lang.Long" resultType="java.lang.Long"> |
| | | <!-- 步骤1: 根据输入的ja_fw_defense_scene_manage.id获取对应的defense_scene_id --> |
| | | <!-- 步骤2: 通过defense_scene_id获取ja_fw_defense_scene中的area_divide_ids --> |
| | | <!-- 步骤3: 根据area_divide_ids获取所有ja_fw_area_divide记录的device_ids --> |
| | | <!-- 步骤4: 解析逗号分隔的device_ids并返回所有设备ID --> |
| | | SELECT DISTINCT CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(ad.device_ids, ',', numbers.n), ',', -1) AS UNSIGNED) AS device_id |
| | | FROM ( |
| | | SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 |
| | | UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10 |
| | | UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL SELECT 15 |
| | | ) numbers |
| | | INNER JOIN ( |
| | | SELECT |
| | | ad.device_ids |
| | | FROM ja_fw_defense_scene_manage dsm |
| | | LEFT JOIN ja_fw_defense_scene ds ON ds.id = dsm.defense_scene_id::VARCHAR AND ds.is_deleted = 0 |
| | | LEFT JOIN ja_fw_area_divide ad ON FIND_IN_SET(ad.id, ds.area_divide_ids) > 0 AND ad.is_deleted = 0 |
| | | WHERE dsm.id = #{id} |
| | | ) ad ON CHAR_LENGTH(ad.device_ids) - CHAR_LENGTH(REPLACE(ad.device_ids, ',', '')) >= numbers.n - 1 |
| | | WHERE ad.device_ids IS NOT NULL AND ad.device_ids != '' |
| | | /* Kingbase 适配说明: |
| | | 1. 使用 string_to_array + unnest 替代 SUBSTRING_INDEX,直接将逗号字符串转为行。 |
| | | 2. 去掉数字表 (numbers),Kingbase 内置函数自动处理拆分。 |
| | | 3. 所有的 ID 关联统一使用 ::text 强转,规避 bigint = varchar 错误。 |
| | | 4. replace(..., ' ', '') 用于防止字符串中包含空格导致转 bigint 失败。 |
| | | */ |
| | | SELECT DISTINCT |
| | | unnest(string_to_array(replace(ad.device_ids, ' ', ''), ','))::bigint AS device_id |
| | | FROM ja_fw_defense_scene_manage dsm |
| | | LEFT JOIN ja_fw_defense_scene ds |
| | | ON ds.id::text = dsm.defense_scene_id::text |
| | | AND ds.is_deleted = 0 |
| | | LEFT JOIN ja_fw_area_divide ad |
| | | ON ad.id::text = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')) |
| | | AND ad.is_deleted = 0 |
| | | WHERE |
| | | dsm.id::text = #{id}::text |
| | | AND ad.device_ids IS NOT NULL |
| | | AND ad.device_ids != '' |
| | | </select> |
| | | |
| | | <select id="selectFwDefenseSceneManageCockpitList" resultType="org.sxkj.fw.area.vo.FwDefenseSceneManageVO"> |
| | |
| | | dsm.*, |
| | | ds.scene_name as defense_scene_name |
| | | from ja_fw_defense_scene_manage dsm |
| | | left join ja_fw_defense_scene ds on ds.id = dsm.defense_scene_id::VARCHAR and ds.is_deleted = 0 |
| | | left join ja_fw_area_divide ad on FIND_IN_SET(ad.id, ds.area_divide_ids) > 0 and ad.is_deleted = 0 |
| | | left join ja_fw_defense_scene ds on ds.id::text = dsm.defense_scene_id::text and ds.is_deleted = 0 |
| | | left join ja_fw_area_divide ad on ad.id::text = ANY(string_to_array(replace(ds.area_divide_ids, ' ', ''), ',')) and ad.is_deleted = 0 |
| | | inner join ( |
| | | SELECT |
| | | d.id |
| | | FROM |
| | | ja_fw_device d |
| | | WHERE |
| | | d.is_deleted = 0 |
| | | AND d.is_enabled = 1 |
| | | AND d.final_outbound_area IS NOT NULL |
| | | SELECT |
| | | d.id |
| | | FROM |
| | | ja_fw_device d |
| | | WHERE |
| | | d.is_deleted = 0 |
| | | AND d.is_enabled = 1 |
| | | AND d.final_outbound_area IS NOT NULL |
| | | <if test="fwBaseInfo.regionCode != null and fwBaseInfo.regionCode != ''"> |
| | | and ( d.final_outbound_area_code like concat(#{fwBaseInfo.regionCode},'%') |
| | | <if test="fwBaseInfo.currentDeptId != null and fwBaseInfo.currentDeptId != '' "> |
| | | or d.id in ( |
| | | SELECT device_id FROM ja_fw_device_per_share |
| | | WHERE loan_to_dept_id = #{fwBaseInfo.currentDeptId} |
| | | AND is_deleted = 0 |
| | | ) |
| | | </if> |
| | | ) |
| | | </if> |
| | | GROUP BY |
| | | d.id |
| | | ) dd on find_in_set(dd.id, ad.device_ids) |
| | | or d.id in ( |
| | | SELECT device_id FROM ja_fw_device_per_share |
| | | WHERE |
| | | loan_to_dept_id = #{fwBaseInfo.currentDeptId}::bigint |
| | | AND is_deleted = 0 |
| | | ) |
| | | </if> |
| | | ) |
| | | </if> |
| | | GROUP BY |
| | | d.id |
| | | ) dd ON dd.id::text = ANY(string_to_array(replace(ad.device_ids, ' ', ''), ',')) |
| | | <where> |
| | | dsm.is_deleted = 0 |
| | | <if test="time != null"> |