wlzboy
2025-11-09 13a31edf7f569cdcf15d3c43a476a2c947f47fbf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.HospDataMapper">
    
    <resultMap type="HospData" id="HospDataResult">
        <result property="hospId" column="legacy_hosp_id" />
        <result property="hospName" column="hosp_name" />
        <result property="hospCityId" column="hosp_city_id" />
        <result property="hospShort" column="hosp_short" />
        <result property="hopsProvince" column="hops_province" />
        <result property="hopsCity" column="hops_city" />
        <result property="hopsArea" column="hops_area" />
        <result property="hospAddress" column="hosp_address" />
        <result property="hospTel" column="hosp_tel" />
        <result property="hospUnitId" column="hosp_unit_id" />
        <result property="hospState" column="hosp_state" />
        <result property="hospOaId" column="hosp_oa_id" />
        <result property="hospIntroducerId" column="hosp_introducer_id" />
        <result property="hospIntroducerDate" column="hosp_introducer_date" />
        <result property="hospLevel" column="hosp_level" />
    </resultMap>
 
    <select id="searchHospitals" resultMap="HospDataResult">
        SELECT legacy_hosp_id, hosp_name, hosp_city_id, hosp_short,
            hops_province, hops_city, hops_area, hosp_address, 
            hosp_tel, hosp_unit_id, hosp_state, hosp_oa_id, 
            hosp_introducer_id, hosp_introducer_date, hosp_level
        FROM tb_hosp_data
        WHERE status = '0'
        <!-- 有 keyword 就只用 keyword,不用 region -->
        <if test="keyword != null and keyword != ''">
        AND (
            hops_province LIKE CONCAT('%', #{keyword}, '%')
                OR hops_city LIKE CONCAT('%', #{keyword}, '%')
                OR hops_area LIKE CONCAT('%', #{keyword}, '%')
                OR hosp_address LIKE CONCAT('%', #{keyword}, '%')
                OR hosp_name LIKE CONCAT('%', #{keyword}, '%')
                OR hosp_short LIKE CONCAT('%', #{keyword}, '%')
        )
        </if>
        <!-- 没有 keyword 时才用 region -->
        <if test="(keyword == null or keyword == '') and (region != null and region != '')">
        AND (
            hops_province LIKE CONCAT('%', #{region}, '%')
                OR hops_city LIKE CONCAT('%', #{region}, '%')
                OR hops_area LIKE CONCAT('%', #{region}, '%')
                OR hosp_address LIKE CONCAT('%', #{region}, '%')
                OR hosp_name LIKE CONCAT('%', #{region}, '%')
                OR hosp_short LIKE CONCAT('%', #{region}, '%')
        )
        </if>
        AND (hosp_state IS NULL OR hosp_state = 1)
        ORDER BY 
            CASE WHEN hosp_name = '家中' THEN 0 ELSE 1 END,
            hosp_name
    </select>
    
    <select id="selectHospDataById" parameterType="Integer" resultMap="HospDataResult">
        SELECT 
            legacy_hosp_id, hosp_name, hosp_city_id, hosp_short, 
            hops_province, hops_city, hops_area, hosp_address, 
            hosp_tel, hosp_unit_id, hosp_state, hosp_oa_id, 
            hosp_introducer_id, hosp_introducer_date, hosp_level
        FROM tb_hosp_data
        WHERE legacy_hosp_id = #{hospId}
    </select>
    
 
    <select id="getHomeHospId" resultType="java.lang.Integer">
        select legacy_hosp_id from tb_hosp_data where hosp_name='家中'
    </select>
    
 
    <!-- 根据医院ID列表查询医院信息 -->
    <select id="selectHospDataByIds" resultMap="HospDataResult">
        SELECT 
            legacy_hosp_id, hosp_name, hosp_city_id, hosp_short, 
            hops_province, hops_city, hops_area, hosp_address, 
            hosp_tel, hosp_unit_id, hosp_state, hosp_oa_id, 
            hosp_introducer_id, hosp_introducer_date, hosp_level
        FROM tb_hosp_data
        WHERE legacy_hosp_id IN
        <foreach collection="hospIds" item="hospId" open="(" separator="," close=")">
            #{hospId}
        </foreach>
        <if test="region != null and region != ''">
        AND (
            hops_province LIKE CONCAT('%', #{region}, '%')
                OR hops_city LIKE CONCAT('%', #{region}, '%')
                OR hosp_short LIKE CONCAT('%', #{region}, '%')
                OR hops_area LIKE CONCAT('%', #{region}, '%')
                OR hosp_address LIKE CONCAT('%', #{region}, '%')
                OR hosp_name LIKE CONCAT('%', #{region}, '%')
        )
        </if>
        AND (hosp_state IS NULL OR hosp_state = 1)
        ORDER BY hosp_name
    </select>
    
    <!-- 根据部门区域配置查询医院(支持多级区域过滤) -->
    <select id="searchHospitalsByDeptRegion" resultMap="HospDataResult">
        SELECT DISTINCT
            h.legacy_hosp_id, h.hosp_name, h.hosp_city_id, h.hosp_short, 
            h.hops_province, h.hops_city, h.hops_area, h.hosp_address, 
            h.hosp_tel, h.hosp_unit_id, h.hosp_state, h.hosp_oa_id, 
            h.hosp_introducer_id, h.hosp_introducer_date, h.hosp_level
        FROM tb_hosp_data h
        WHERE (h.hosp_state IS NULL OR h.hosp_state = 1)
        AND h.status = '0'
        AND EXISTS (
            SELECT 1 FROM sys_dept_region r
            WHERE r.dept_id = #{deptId}
            AND r.status = '0'
            AND (
                -- 区域类型:地域范围匹配
                (r.region_type = 'AREA' AND (
                    -- 省份匹配(为空则跳过)
                    (r.province IS NULL OR r.province = '' OR h.hops_province LIKE CONCAT('%', r.province, '%'))
                    -- 城市匹配(为空则跳过)
                    AND (r.city IS NULL OR r.city = '' OR h.hops_city LIKE CONCAT('%', r.city, '%'))
                    -- 县/区匹配(为空则跳过)
                    AND (r.area IS NULL OR r.area = '' OR h.hops_area LIKE CONCAT('%', r.area, '%'))
                    -- 详细地址匹配(为空则跳过)
                    AND (r.address IS NULL OR r.address = '' OR h.hosp_address LIKE CONCAT('%', r.address, '%'))
                ))
                -- 区域类型:指定医院匹配
                OR (r.region_type = 'HOSPITAL' AND r.hospital_name IS NOT NULL AND r.hospital_name != '' AND (
                    h.hosp_name LIKE CONCAT('%', r.hospital_name, '%')
                    OR h.hosp_short LIKE CONCAT('%', r.hospital_name, '%')
                ))
            )
        )
        <!-- 关键词搜索 -->
        <if test="keyword != null and keyword != ''">
        AND (
            h.hops_province LIKE CONCAT('%', #{keyword}, '%')
            OR h.hops_city LIKE CONCAT('%', #{keyword}, '%')
            OR h.hops_area LIKE CONCAT('%', #{keyword}, '%')
            OR h.hosp_address LIKE CONCAT('%', #{keyword}, '%')
            OR h.hosp_name LIKE CONCAT('%', #{keyword}, '%')
            OR h.hosp_short LIKE CONCAT('%', #{keyword}, '%')
        )
        </if>
        ORDER BY 
            CASE WHEN h.hosp_name = '家中' THEN 0 ELSE 1 END,
            h.hosp_name
    </select>
</mapper>