| | |
| | | |
| | | <select id="selectFwDevicePage" resultMap="fwDeviceResultMap"> |
| | | select |
| | | * |
| | | * |
| | | from |
| | | ja_fw_device |
| | | ja_fw_device |
| | | <where> |
| | | is_deleted = 0 |
| | | is_deleted = 0 |
| | | <if test="param2.id != null and param2.id != ''"> |
| | | and id = #{param2.id} |
| | | and id::text = #{param2.id}::text |
| | | </if> |
| | | <if test="param2.deviceName != null and param2.deviceName != ''"> |
| | | and device_name like concat('%',#{param2.deviceName},'%') |
| | | </if> |
| | | <if test="param2.deviceType != null and param2.deviceType != ''"> |
| | | and device_type = #{param2.deviceType} |
| | | and device_type::text = #{param2.deviceType}::text |
| | | </if> |
| | | <if test="param2.deviceModel != null and param2.deviceModel != ''"> |
| | | and device_model = #{param2.deviceModel} |
| | | and device_model::text = #{param2.deviceModel}::text |
| | | </if> |
| | | <if test="param2.deviceSpecification != null and param2.deviceSpecification != ''"> |
| | | and device_specification = #{param2.deviceSpecification} |
| | | and device_specification::text = #{param2.deviceSpecification}::text |
| | | </if> |
| | | <if test="param2.effectiveRangeKmIsNotNull != null and param2.effectiveRangeKmIsNotNull == 1"> |
| | | and effective_range_km is not null |
| | |
| | | and (effective_range_km is null or effective_range_km = 0) |
| | | </if> |
| | | <if test="param2.manufacturer != null and param2.manufacturer != ''"> |
| | | and manufacturer = #{param2.manufacturer} |
| | | and manufacturer::text = #{param2.manufacturer}::text |
| | | </if> |
| | | <if test="param2.source != null and param2.source != ''"> |
| | | and source = #{param2.source} |
| | | and source::text = #{param2.source}::text |
| | | </if> |
| | | <if test="param2.belongDept != null and param2.belongDept != ''"> |
| | | and belong_dept = #{param2.belongDept} |
| | | and belong_dept::text = #{param2.belongDept}::text |
| | | </if> |
| | | <if test="param2.deviceStatusList != null and param2.deviceStatusList != ''"> |
| | | and status in |
| | | and status::text in |
| | | <foreach item="item" collection="param2.deviceStatusList" separator="," open="(" close=")" index=""> |
| | | #{item} |
| | | #{item}::text |
| | | </foreach> |
| | | </if> |
| | | <if test="param2.status != null"> |
| | | and status = #{param2.status} |
| | | and status::text = #{param2.status}::text |
| | | </if> |
| | | <if test="param2.isTrack != null and param2.isTrack == 1"> |
| | | and (SELECT COUNT(*) FROM ja_fw_device_track tmp WHERE ja_fw_device.id::VARCHAR = tmp.device_id::VARCHAR) > 0 |
| | | and (SELECT COUNT(*) FROM ja_fw_device_track tmp WHERE ja_fw_device.id::text = tmp.device_id::text) > 0 |
| | | </if> |
| | | <if test="param2.isTrack != null and param2.isTrack == 2"> |
| | | and (SELECT COUNT(*) FROM ja_fw_device_track tmp WHERE ja_fw_device.id::VARCHAR = tmp.device_id::VARCHAR) = 0 |
| | | and (SELECT COUNT(*) FROM ja_fw_device_track tmp WHERE ja_fw_device.id::text = tmp.device_id::text) = 0 |
| | | </if> |
| | | <if test="param2.deptList != null and param2.deptList.size > 0"> |
| | | and ( create_dept in |
| | | and ( create_dept::text in |
| | | <foreach collection="param2.deptList" item="deptId" open="(" separator="," close=")"> |
| | | #{deptId} |
| | | #{deptId}::text |
| | | </foreach> |
| | | <!-- 或者设备是共享给当前部门的 --> |
| | | <if test="param2.currentDeptId != null and param2.currentDeptId != '' "> |
| | | or id in ( |
| | | SELECT device_id FROM ja_fw_device_per_share |
| | | WHERE loan_to_dept_id = #{param2.currentDeptId} |
| | | or id::text in ( |
| | | SELECT device_id::text FROM ja_fw_device_per_share |
| | | WHERE loan_to_dept_id = #{param2.currentDeptId}::bigint |
| | | AND is_deleted = 0 |
| | | ) |
| | | </if> |
| | |
| | | </if> |
| | | </where> |
| | | order by |
| | | create_time desc |
| | | create_time desc |
| | | </select> |
| | | |
| | | <select id="selectFwDeviceList" resultMap="fwDeviceResultMap"> |
| | |
| | | and ( |
| | | <foreach collection="query.polygons" item="polygon" separator=" OR "> |
| | | public.st_contains( |
| | | public.st_srid(public.st_geomfromtext(#{polygon}), 4326), |
| | | /* 注意:Kingbase/PostGIS 坐标顺序通常是 (经度, 纬度) 即 (longitude, latitude) */ |
| | | /* 直接在构造时指定 4326 */ |
| | | public.st_geomfromtext(#{polygon}::text, 4326), |
| | | /* 将经纬度拼接为点,并指定坐标系 */ |
| | | public.st_geomfromtext(CONCAT('POINT(', longitude, ' ', latitude, ')'), 4326) |
| | | ) |
| | | </foreach> |
| | |
| | | CASE |
| | | WHEN ps.id IS NOT NULL THEN TRUE |
| | | ELSE FALSE |
| | | END AS isShared |
| | | END AS isShared |
| | | FROM |
| | | ja_fw_device d |
| | | LEFT JOIN ja_fw_device_per_share ps ON ps.device_id::VARCHAR = d.id::VARCHAR |
| | | AND ps.loan_to_dept_id = #{currentDeptId} |
| | | /* 修改点1:建议使用 ::text,且如果 id 本身是数字类型,能不转就不转以优化索引, |
| | | 这里保留转换逻辑但改为更通用的 text */ |
| | | LEFT JOIN ja_fw_device_per_share ps ON ps.device_id::text = d.id::text |
| | | /* 修改点2:核心修复!显式转换参数为 bigint,匹配数据库字段类型 */ |
| | | AND ps.loan_to_dept_id = #{currentDeptId}::bigint |
| | | AND ps.is_deleted = 0 |
| | | WHERE |
| | | d.is_deleted = 0 |
| | |
| | | d.final_outbound_area |
| | | </select> |
| | | |
| | | <!-- 批量更新设备启用状态 --> |
| | | <update id="batchUpdateIsEnabled"> |
| | | UPDATE ja_fw_device |
| | | SET is_enabled = #{isEnabled} |
| | | WHERE id IN |
| | | <foreach collection="deviceIds" item="id" open="(" separator="," close=")"> |
| | | #{id}::bigint |
| | | </foreach> |
| | | AND is_deleted = 0 |
| | | </update> |
| | | |
| | | </mapper> |