chengf
2026-01-27 b6184e2ddf3db37a94f7efb3b619bbc64642a292
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
290
291
292
293
294
295
296
297
298
299
<?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="ownerPropertySurveyServiceDaoImpl">
 
    <!-- 保存业主房屋产调记录信息 -->
    <insert id="saveOwnerPropertySurveyInfo" parameterType="Map">
        insert into owner_property_survey(
        id, owner_id, room_id, survey_warrant_apply_date, property_survey_date,
        name, extra_date, create_time, update_time
        ) values (
        #{id}, #{ownerId}, #{roomId},
        <if test="surveyWarrantApplyDate == null">''</if>
        <if test="surveyWarrantApplyDate != null">#{surveyWarrantApplyDate}</if>,
        <if test="propertySurveyDate == null">''</if>
        <if test="propertySurveyDate != null">#{propertySurveyDate}</if>,
        <if test="name == null">''</if>
        <if test="name != null">#{name}</if>,
        <if test="extraDate == null">''</if>
        <if test="extraDate != null">#{extraDate}</if>,
        <if test="createTime == null">CURRENT_TIMESTAMP</if>
        <if test="createTime != null">#{createTime}</if>,
        <if test="updateTime == null">CURRENT_TIMESTAMP</if>
        <if test="updateTime != null">#{updateTime}</if>
        )
    </insert>
 
    <!-- 批量插入业主房屋产调记录 -->
    <insert id="saveOwnerPropertySurveys" parameterType="Map">
        insert into owner_property_survey(
        id, owner_id, room_id, survey_warrant_apply_date, property_survey_date,
        name, extra_date, create_time, update_time
        ) values
        <foreach collection="ownerPropertySurveyPos" item="item" separator=",">
            ( #{item.id}, #{item.ownerId}, #{item.roomId},
            <if test="item.surveyWarrantApplyDate == null">''</if><if test="item.surveyWarrantApplyDate != null">#{item.surveyWarrantApplyDate}</if>,
            <if test="item.propertySurveyDate == null">''</if><if test="item.propertySurveyDate != null">#{item.propertySurveyDate}</if>,
            <if test="item.name == null">''</if><if test="item.name != null">#{item.name}</if>,
            <if test="item.extraDate == null">''</if><if test="item.extraDate != null">#{item.extraDate}</if>,
            <if test="item.createTime == null">CURRENT_TIMESTAMP</if><if test="item.createTime != null">#{item.createTime}</if>,
            <if test="item.updateTime == null">CURRENT_TIMESTAMP</if><if test="item.updateTime != null">#{item.updateTime}</if>)
        </foreach>
    </insert>
 
    <!-- 查询业主房屋产调记录信息(单条/多条) -->
    <select id="getOwnerPropertySurveyInfo" parameterType="Map" resultType="Map">
        select
        t.id,
        t.owner_id as ownerId,
        t.room_id as roomId,
        t.survey_warrant_apply_date as surveyWarrantApplyDate,
        t.property_survey_date as propertySurveyDate,
        t.name,
        t.extra_date as extraDate,
        t.create_time as createTime,
        t.update_time as updateTime
        from owner_property_survey t
        where 1 = 1
        <if test="id != null">
            and t.id = #{id}
        </if>
        <if test="ownerId != null and ownerId != ''">
            and t.owner_id = #{ownerId}
        </if>
        <if test="roomId != null and roomId != ''">
            and t.room_id = #{roomId}
        </if>
        <if test="surveyWarrantApplyDate != null and surveyWarrantApplyDate != ''">
            and t.survey_warrant_apply_date = #{surveyWarrantApplyDate}
        </if>
        <if test="propertySurveyDate != null and propertySurveyDate != ''">
            and t.property_survey_date = #{propertySurveyDate}
        </if>
        <if test="name != null and name != ''">
            and t.name = #{name}
        </if>
        <if test="extraDate != null and extraDate != ''">
            and t.extra_date = #{extraDate}
        </if>
        <!-- 时间范围查询 -->
        <if test="startSurveyWarrantApplyDate != null">
            and t.survey_warrant_apply_date >= #{startSurveyWarrantApplyDate}
        </if>
        <if test="endSurveyWarrantApplyDate != null">
            and t.survey_warrant_apply_date &lt;= #{endSurveyWarrantApplyDate}
        </if>
        <if test="startPropertySurveyDate != null">
            and t.property_survey_date >= #{startPropertySurveyDate}
        </if>
        <if test="endPropertySurveyDate != null">
            and t.property_survey_date &lt;= #{endPropertySurveyDate}
        </if>
        <if test="startCreateTime != null">
            and t.create_time >= #{startCreateTime}
        </if>
        <if test="endCreateTime != null">
            and t.create_time &lt;= #{endCreateTime}
        </if>
        order by t.id desc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
 
    <!-- 查询业主房屋产调记录数量 -->
    <select id="queryOwnerPropertySurveysCount" parameterType="Map" resultType="Map">
        select count(1) count
        from owner_property_survey t
        where 1 = 1
        <if test="id != null">
            and t.id = #{id}
        </if>
        <if test="ownerId != null and ownerId != ''">
            and t.owner_id = #{ownerId}
        </if>
        <if test="roomId != null and roomId != ''">
            and t.room_id = #{roomId}
        </if>
        <if test="surveyWarrantApplyDate != null and surveyWarrantApplyDate != ''">
            and t.survey_warrant_apply_date = #{surveyWarrantApplyDate}
        </if>
        <if test="propertySurveyDate != null and propertySurveyDate != ''">
            and t.property_survey_date = #{propertySurveyDate}
        </if>
        <if test="name != null and name != ''">
            and t.name = #{name}
        </if>
        <if test="extraDate != null and extraDate != ''">
            and t.extra_date = #{extraDate}
        </if>
        <!-- 时间范围查询 -->
        <if test="startSurveyWarrantApplyDate != null">
            and t.survey_warrant_apply_date >= #{startSurveyWarrantApplyDate}
        </if>
        <if test="endSurveyWarrantApplyDate != null">
            and t.survey_warrant_apply_date &lt;= #{endSurveyWarrantApplyDate}
        </if>
        <if test="startPropertySurveyDate != null">
            and t.property_survey_date >= #{startPropertySurveyDate}
        </if>
        <if test="endPropertySurveyDate != null">
            and t.property_survey_date &lt;= #{endPropertySurveyDate}
        </if>
        <if test="startCreateTime != null">
            and t.create_time >= #{startCreateTime}
        </if>
        <if test="endCreateTime != null">
            and t.create_time &lt;= #{endCreateTime}
        </if>
    </select>
 
    <!-- 修改业主房屋产调记录信息 -->
    <update id="updateOwnerPropertySurveyInfo" parameterType="Map">
        update owner_property_survey t set
        <if test="ownerId != null and ownerId != ''">
            t.owner_id = #{ownerId},
        </if>
        <if test="roomId != null and roomId != ''">
            t.room_id = #{roomId},
        </if>
        <if test="surveyWarrantApplyDate != null">
            t.survey_warrant_apply_date = #{surveyWarrantApplyDate},
        </if>
        <if test="propertySurveyDate != null">
            t.property_survey_date = #{propertySurveyDate},
        </if>
        <if test="name != null">
            t.name = #{name},
        </if>
        <if test="extraDate != null">
            t.extra_date = #{extraDate},
        </if>
        <if test="updateTime != null">
            t.update_time = #{updateTime},
        </if>
        t.update_time = CURRENT_TIMESTAMP
        where 1 = 1
        <if test="id != null">
            and t.id = #{id}
        </if>
        <if test="ownerId != null and ownerId != '' and roomId != null and roomId != ''">
            and t.owner_id = #{ownerId} and t.room_id = #{roomId}
        </if>
    </update>
 
    <!-- 删除业主房屋产调记录信息 -->
    <delete id="deleteOwnerPropertySurveyInfo" parameterType="Map">
        delete from owner_property_survey t
        where 1 = 1
        <if test="id != null">
            and t.id = #{id}
        </if>
        <if test="ownerId != null and ownerId != ''">
            and t.owner_id = #{ownerId}
        </if>
        <if test="roomId != null and roomId != ''">
            and t.room_id = #{roomId}
        </if>
        <if test="surveyWarrantApplyDate != null and surveyWarrantApplyDate != ''">
            and t.survey_warrant_apply_date = #{surveyWarrantApplyDate}
        </if>
        <if test="propertySurveyDate != null and propertySurveyDate != ''">
            and t.property_survey_date = #{propertySurveyDate}
        </if>
        <!-- 时间范围查询 -->
        <if test="startSurveyWarrantApplyDate != null">
            and t.survey_warrant_apply_date >= #{startSurveyWarrantApplyDate}
        </if>
        <if test="endSurveyWarrantApplyDate != null">
            and t.survey_warrant_apply_date &lt;= #{endSurveyWarrantApplyDate}
        </if>
    </delete>
 
    <!-- 查询业主房屋产调记录统计信息 -->
    <select id="queryOwnerPropertySurveyStatistics" parameterType="Map" resultType="Map">
        select
        count(1) as total_count,
        count(distinct t.owner_id) as distinct_owner_count,
        count(distinct t.room_id) as distinct_room_count,
        min(t.survey_warrant_apply_date) as earliest_survey_warrant_apply_date,
        max(t.survey_warrant_apply_date) as latest_survey_warrant_apply_date,
        min(t.property_survey_date) as earliest_property_survey_date,
        max(t.property_survey_date) as latest_property_survey_date
        from owner_property_survey t
        where 1 = 1
        <if test="ownerId != null and ownerId != ''">
            and t.owner_id = #{ownerId}
        </if>
        <if test="roomId != null and roomId != ''">
            and t.room_id = #{roomId}
        </if>
        <if test="startSurveyWarrantApplyDate != null">
            and t.survey_warrant_apply_date >= #{startSurveyWarrantApplyDate}
        </if>
        <if test="endSurveyWarrantApplyDate != null">
            and t.survey_warrant_apply_date &lt;= #{endSurveyWarrantApplyDate}
        </if>
        <if test="startPropertySurveyDate != null">
            and t.property_survey_date >= #{startPropertySurveyDate}
        </if>
        <if test="endPropertySurveyDate != null">
            and t.property_survey_date &lt;= #{endPropertySurveyDate}
        </if>
    </select>
 
    <!-- 按年月维度统计产调记录 -->
    <select id="queryOwnerPropertySurveyByMonth" parameterType="Map" resultType="Map">
        select
        date_format(str_to_date(t.property_survey_date, '%Y-%m-%d'), '%Y-%m') as month,
        count(1) as total_count,
        count(distinct t.owner_id) as owner_count,
        count(distinct t.room_id) as room_count
        from owner_property_survey t
        where 1 = 1
        and t.property_survey_date != ''
        <if test="startPropertySurveyDate != null">
            and t.property_survey_date >= #{startPropertySurveyDate}
        </if>
        <if test="endPropertySurveyDate != null">
            and t.property_survey_date &lt;= #{endPropertySurveyDate}
        </if>
        group by date_format(str_to_date(t.property_survey_date, '%Y-%m-%d'), '%Y-%m')
        order by month desc
    </select>
 
    <!-- 查询未完成产调的记录(产调日期为空) -->
    <select id="queryUnfinishedPropertySurveyRecords" parameterType="Map" resultType="Map">
        select
        t.id,
        t.owner_id as ownerId,
        t.room_id as roomId,
        t.survey_warrant_apply_date as surveyWarrantApplyDate,
        t.property_survey_date as propertySurveyDate,
        t.name,
        t.extra_date as extraDate,
        datediff(curdate(), str_to_date(t.survey_warrant_apply_date, '%Y-%m-%d')) as overdue_days
        from owner_property_survey t
        where 1 = 1
        and (t.property_survey_date = '' or t.property_survey_date is null)
        <if test="ownerId != null and ownerId != ''">
            and t.owner_id = #{ownerId}
        </if>
        <if test="roomId != null and roomId != ''">
            and t.room_id = #{roomId}
        </if>
        <if test="startSurveyWarrantApplyDate != null">
            and t.survey_warrant_apply_date >= #{startSurveyWarrantApplyDate}
        </if>
        <if test="endSurveyWarrantApplyDate != null">
            and t.survey_warrant_apply_date &lt;= #{endSurveyWarrantApplyDate}
        </if>
        order by overdue_days desc, t.survey_warrant_apply_date asc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
 
</mapper>