wlzboy
2025-11-01 82d6b98f5b6b88e223259547208ab59829ad723e
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?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.SysTaskEmergencyMapper">
    
    <resultMap type="SysTaskEmergency" id="SysTaskEmergencyResult">
        <result property="id"                      column="id"                      />
        <result property="taskId"                  column="task_id"                 />
        <result property="patientContact"          column="patient_contact"         />
        <result property="patientPhone"            column="patient_phone"           />
        <result property="patientName"             column="patient_name"            />
        <result property="patientGender"           column="patient_gender"          />
        <result property="patientIdCard"           column="patient_id_card"         />
        <result property="patientCondition"        column="patient_condition"       />
        <result property="hospitalOutName"         column="hospital_out_name"       />
        <result property="hospitalOutId"           column="hospital_out_id"         />
        <result property="hospitalOutDepartment"   column="hospital_out_department" />
        <result property="hospitalOutDepartmentId" column="hospital_out_department_id" />
        <result property="hospitalOutBedNumber"    column="hospital_out_bed_number" />
        <result property="hospitalOutAddress"      column="hospital_out_address"    />
        <result property="hospitalOutLongitude"    column="hospital_out_longitude"  />
        <result property="hospitalOutLatitude"     column="hospital_out_latitude"   />
        <result property="hospitalInName"          column="hospital_in_name"        />
        <result property="hospitalInId"            column="hospital_in_id"          />
        <result property="hospitalInDepartment"    column="hospital_in_department"  />
        <result property="hospitalInDepartmentId"  column="hospital_in_department_id" />
        <result property="hospitalInBedNumber"     column="hospital_in_bed_number"  />
        <result property="hospitalInAddress"       column="hospital_in_address"     />
        <result property="hospitalInLongitude"     column="hospital_in_longitude"   />
        <result property="hospitalInLatitude"      column="hospital_in_latitude"    />
        <result property="transferDistance"        column="transfer_distance"       />
        <result property="transferPrice"           column="transfer_price"          />
        <result property="passengerContact"        column="passenger_contact"       />
        <result property="passengerPhone"          column="passenger_phone"         />
        <result property="diseaseIds"              column="disease_ids"             />
        <result property="documentTypeId"          column="document_type_id"        />
        <result property="taskTypeId"              column="task_type_id"            />
        <result property="legacyServiceOrdId"      column="legacy_service_ord_id"   />
        <result property="legacyDispatchOrdId"     column="legacy_dispatch_ord_id"  />
        <result property="syncStatus"              column="sync_status"             />
        <result property="syncTime"                column="sync_time"               />
        <result property="syncErrorMsg"            column="sync_error_msg"          />
        <result property="dispatchSyncStatus"      column="dispatch_sync_status"    />
        <result property="dispatchSyncTime"        column="dispatch_sync_time"      />
        <result property="dispatchSyncErrorMsg"    column="dispatch_sync_error_msg" />
        <result property="createTime"              column="create_time"             />
        <result property="updateTime"              column="update_time"             />
        <result property="createBy"                column="create_by"               />
        <result property="updateBy"                column="update_by"               />
    </resultMap>
 
    <sql id="selectSysTaskEmergencyVo">
        select id, task_id, patient_contact, patient_phone, patient_name, patient_gender, 
               patient_id_card, patient_condition, hospital_out_name, hospital_out_id, hospital_out_department, 
               hospital_out_department_id, hospital_out_bed_number, hospital_out_address, hospital_out_longitude, 
               hospital_out_latitude, hospital_in_name, hospital_in_id, hospital_in_department, 
               hospital_in_department_id, hospital_in_bed_number, hospital_in_address, hospital_in_longitude, 
               hospital_in_latitude, transfer_distance, transfer_price, passenger_contact, 
               passenger_phone, disease_ids, document_type_id, task_type_id, legacy_service_ord_id, legacy_dispatch_ord_id, 
               sync_status, sync_time, sync_error_msg, dispatch_sync_status, dispatch_sync_time, dispatch_sync_error_msg,
               create_time, update_time, create_by, update_by
        from sys_task_emergency
    </sql>
 
    <select id="selectSysTaskEmergencyById" parameterType="Long" resultMap="SysTaskEmergencyResult">
        <include refid="selectSysTaskEmergencyVo"/>
        where id = #{id}
    </select>
 
    <select id="selectSysTaskEmergencyByTaskId" parameterType="Long" resultMap="SysTaskEmergencyResult">
        <include refid="selectSysTaskEmergencyVo"/>
        where task_id = #{taskId}
    </select>
 
    <insert id="insertSysTaskEmergency" parameterType="SysTaskEmergency" useGeneratedKeys="true" keyProperty="id">
        insert into sys_task_emergency
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="patientContact != null">patient_contact,</if>
            <if test="patientPhone != null">patient_phone,</if>
            <if test="patientName != null">patient_name,</if>
            <if test="patientGender != null">patient_gender,</if>
            <if test="patientIdCard != null">patient_id_card,</if>
            <if test="patientCondition != null">patient_condition,</if>
            <if test="hospitalOutName != null">hospital_out_name,</if>
            <if test="hospitalOutId != null">hospital_out_id,</if>
            <if test="hospitalOutDepartment != null">hospital_out_department,</if>
            <if test="hospitalOutDepartmentId != null">hospital_out_department_id,</if>
            <if test="hospitalOutBedNumber != null">hospital_out_bed_number,</if>
            <if test="hospitalOutAddress != null">hospital_out_address,</if>
            <if test="hospitalOutLongitude != null">hospital_out_longitude,</if>
            <if test="hospitalOutLatitude != null">hospital_out_latitude,</if>
            <if test="hospitalInName != null">hospital_in_name,</if>
            <if test="hospitalInId != null">hospital_in_id,</if>
            <if test="hospitalInDepartment != null">hospital_in_department,</if>
            <if test="hospitalInDepartmentId != null">hospital_in_department_id,</if>
            <if test="hospitalInBedNumber != null">hospital_in_bed_number,</if>
            <if test="hospitalInAddress != null">hospital_in_address,</if>
            <if test="hospitalInLongitude != null">hospital_in_longitude,</if>
            <if test="hospitalInLatitude != null">hospital_in_latitude,</if>
            <if test="transferDistance != null">transfer_distance,</if>
            <if test="transferPrice != null">transfer_price,</if>
            <if test="passengerContact != null">passenger_contact,</if>
            <if test="passengerPhone != null">passenger_phone,</if>
            <if test="diseaseIds != null">disease_ids,</if>
            <if test="documentTypeId != null">document_type_id,</if>
            <if test="taskTypeId != null">task_type_id,</if>
            <if test="legacyServiceOrdId != null">legacy_service_ord_id,</if>
            <if test="legacyDispatchOrdId != null">legacy_dispatch_ord_id,</if>
            <if test="syncStatus != null">sync_status,</if>
            <if test="syncTime != null">sync_time,</if>
            <if test="syncErrorMsg != null">sync_error_msg,</if>
            <if test="dispatchSyncStatus != null">dispatch_sync_status,</if>
            <if test="dispatchSyncTime != null">dispatch_sync_time,</if>
            <if test="dispatchSyncErrorMsg != null">dispatch_sync_error_msg,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="patientContact != null">#{patientContact},</if>
            <if test="patientPhone != null">#{patientPhone},</if>
            <if test="patientName != null">#{patientName},</if>
            <if test="patientGender != null">#{patientGender},</if>
            <if test="patientIdCard != null">#{patientIdCard},</if>
            <if test="patientCondition != null">#{patientCondition},</if>
            <if test="hospitalOutName != null">#{hospitalOutName},</if>
            <if test="hospitalOutId != null">#{hospitalOutId},</if>
            <if test="hospitalOutDepartment != null">#{hospitalOutDepartment},</if>
            <if test="hospitalOutDepartmentId != null">#{hospitalOutDepartmentId},</if>
            <if test="hospitalOutBedNumber != null">#{hospitalOutBedNumber},</if>
            <if test="hospitalOutAddress != null">#{hospitalOutAddress},</if>
            <if test="hospitalOutLongitude != null">#{hospitalOutLongitude},</if>
            <if test="hospitalOutLatitude != null">#{hospitalOutLatitude},</if>
            <if test="hospitalInName != null">#{hospitalInName},</if>
            <if test="hospitalInId != null">#{hospitalInId},</if>
            <if test="hospitalInDepartment != null">#{hospitalInDepartment},</if>
            <if test="hospitalInDepartmentId != null">#{hospitalInDepartmentId},</if>
            <if test="hospitalInBedNumber != null">#{hospitalInBedNumber},</if>
            <if test="hospitalInAddress != null">#{hospitalInAddress},</if>
            <if test="hospitalInLongitude != null">#{hospitalInLongitude},</if>
            <if test="hospitalInLatitude != null">#{hospitalInLatitude},</if>
            <if test="transferDistance != null">#{transferDistance},</if>
            <if test="transferPrice != null">#{transferPrice},</if>
            <if test="passengerContact != null">#{passengerContact},</if>
            <if test="passengerPhone != null">#{passengerPhone},</if>
            <if test="diseaseIds != null">#{diseaseIds},</if>
            <if test="documentTypeId != null">#{documentTypeId},</if>
            <if test="taskTypeId != null">#{taskTypeId},</if>
            <if test="legacyServiceOrdId != null">#{legacyServiceOrdId},</if>
            <if test="legacyDispatchOrdId != null">#{legacyDispatchOrdId},</if>
            <if test="syncStatus != null">#{syncStatus},</if>
            <if test="syncTime != null">#{syncTime},</if>
            <if test="syncErrorMsg != null">#{syncErrorMsg},</if>
            <if test="dispatchSyncStatus != null">#{dispatchSyncStatus},</if>
            <if test="dispatchSyncTime != null">#{dispatchSyncTime},</if>
            <if test="dispatchSyncErrorMsg != null">#{dispatchSyncErrorMsg},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>
 
    <update id="updateSysTaskEmergency" parameterType="SysTaskEmergency">
        update sys_task_emergency
        <trim prefix="SET" suffixOverrides=",">
            <if test="patientContact != null">patient_contact = #{patientContact},</if>
            <if test="patientPhone != null">patient_phone = #{patientPhone},</if>
            <if test="patientName != null">patient_name = #{patientName},</if>
            <if test="patientGender != null">patient_gender = #{patientGender},</if>
            <if test="patientIdCard != null">patient_id_card = #{patientIdCard},</if>
            <if test="patientCondition != null">patient_condition = #{patientCondition},</if>
            <if test="hospitalOutName != null">hospital_out_name = #{hospitalOutName},</if>
            <if test="hospitalOutId != null">hospital_out_id = #{hospitalOutId},</if>
            <if test="hospitalOutDepartment != null">hospital_out_department = #{hospitalOutDepartment},</if>
            <if test="hospitalOutDepartmentId != null">hospital_out_department_id = #{hospitalOutDepartmentId},</if>
            <if test="hospitalOutBedNumber != null">hospital_out_bed_number = #{hospitalOutBedNumber},</if>
            <if test="hospitalOutAddress != null">hospital_out_address = #{hospitalOutAddress},</if>
            <if test="hospitalOutLongitude != null">hospital_out_longitude = #{hospitalOutLongitude},</if>
            <if test="hospitalOutLatitude != null">hospital_out_latitude = #{hospitalOutLatitude},</if>
            <if test="hospitalInName != null">hospital_in_name = #{hospitalInName},</if>
            <if test="hospitalInId != null">hospital_in_id = #{hospitalInId},</if>
            <if test="hospitalInDepartment != null">hospital_in_department = #{hospitalInDepartment},</if>
            <if test="hospitalInDepartmentId != null">hospital_in_department_id = #{hospitalInDepartmentId},</if>
            <if test="hospitalInBedNumber != null">hospital_in_bed_number = #{hospitalInBedNumber},</if>
            <if test="hospitalInAddress != null">hospital_in_address = #{hospitalInAddress},</if>
            <if test="hospitalInLongitude != null">hospital_in_longitude = #{hospitalInLongitude},</if>
            <if test="hospitalInLatitude != null">hospital_in_latitude = #{hospitalInLatitude},</if>
            <if test="transferDistance != null">transfer_distance = #{transferDistance},</if>
            <if test="transferPrice != null">transfer_price = #{transferPrice},</if>
            <if test="passengerContact != null">passenger_contact = #{passengerContact},</if>
            <if test="passengerPhone != null">passenger_phone = #{passengerPhone},</if>
            <if test="diseaseIds != null">disease_ids = #{diseaseIds},</if>
            <if test="documentTypeId != null">document_type_id = #{documentTypeId},</if>
            <if test="taskTypeId != null">task_type_id = #{taskTypeId},</if>
            <if test="legacyServiceOrdId != null">legacy_service_ord_id = #{legacyServiceOrdId},</if>
            <if test="legacyDispatchOrdId != null">legacy_dispatch_ord_id = #{legacyDispatchOrdId},</if>
            <if test="syncStatus != null">sync_status = #{syncStatus},</if>
            <if test="syncTime != null">sync_time = #{syncTime},</if>
            <if test="syncErrorMsg != null">sync_error_msg = #{syncErrorMsg},</if>
            <if test="dispatchSyncStatus != null">dispatch_sync_status = #{dispatchSyncStatus},</if>
            <if test="dispatchSyncTime != null">dispatch_sync_time = #{dispatchSyncTime},</if>
            <if test="dispatchSyncErrorMsg != null">dispatch_sync_error_msg = #{dispatchSyncErrorMsg},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>
 
    <delete id="deleteSysTaskEmergencyById" parameterType="Long">
        delete from sys_task_emergency where id = #{id}
    </delete>
 
    <delete id="deleteSysTaskEmergencyByTaskId" parameterType="Long">
        delete from sys_task_emergency where task_id = #{taskId}
    </delete>
 
    <!-- 查询待同步的急救转运任务 -->
    <select id="selectPendingSyncTasks" resultMap="SysTaskEmergencyResult">
        <include refid="selectSysTaskEmergencyVo"/>
        where (sync_status = 0 or sync_status = 3)
          and task_id in (
              select task_id from sys_task 
              where task_type = 'EMERGENCY_TRANSFER'                
                and del_flag = '0'
          )
        order by id asc
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
        <if test="offset == null and limit != null">
            limit #{limit}
        </if>
        <if test="offset == null and limit == null">
            limit 100
        </if>
    </select>
    
    <!-- 查询待同步调度单的任务(已同步服务单但未同步调度单) -->
    <select id="selectPendingDispatchSyncTasks" resultMap="SysTaskEmergencyResult">
        <include refid="selectSysTaskEmergencyVo"/>
        where sync_status = 2 
          and legacy_service_ord_id is not null 
          and (dispatch_sync_status = 0 or dispatch_sync_status = 3 or dispatch_sync_status is null)
          and task_id in (
              select task_id from sys_task 
              where task_type = 'EMERGENCY_TRANSFER'
                and task_status not in ('COMPLETED', 'CANCELLED')  <!-- 过滤已完成/已取消的任务 -->
                and del_flag = '0'
          )
        order by id asc
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
        <if test="offset == null and limit != null">
            limit #{limit}
        </if>
        <if test="offset == null and limit == null">
            limit 100
        </if>
    </select>
    
    <!-- 查询已同步调度单且状态未完成的任务(用于状态同步) -->
    <select id="selectSyncedTasksForStatusUpdate" resultMap="SysTaskEmergencyResult">
        <include refid="selectSysTaskEmergencyVo"/>
        where dispatch_sync_status = 2 
          and legacy_dispatch_ord_id is not null
          and task_id in (
              select task_id from sys_task 
              where task_type = 'EMERGENCY_TRANSFER'
                and del_flag = '0'
          )
        order by id asc
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
        <if test="offset == null and limit != null">
            limit #{limit}
        </if>
        <if test="offset == null and limit == null">
            limit 200
        </if>
    </select>
 
</mapper>