yanghb
2025-02-18 031748e56f04bf939927fdc54f31df29660d9363
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
<?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.zzg.system.mapper.state.StateApplyRecordMapper">
    <select id="selectProjectWithApplyRecord" parameterType="com.zzg.system.domain.bo.StateApplyRecordPageBO"
            resultType="com.zzg.system.domain.vo.StateApplyRecordVO">
        SELECT A.project_name,
               A.id as projectId,
               b.*
        FROM state_project A
                 LEFT JOIN state_apply_record b ON A.id = b.project_id
        WHERE 1 = 1
          and b.id is not null
        <if test="stateApplyRecordPageBO.projectId != null">
            AND A.id = #{stateApplyRecordPageBO.projectId}
        </if>
        <if test="stateApplyRecordPageBO.applyStartTime != null
        and stateApplyRecordPageBO.applyEndTime != null">
            AND b.create_time BETWEEN #{stateApplyRecordPageBO.applyStartTime,jdbcType=DATE} AND
                #{stateApplyRecordPageBO.applyEndTime,jdbcType=DATE}
        </if>
        <if test="stateApplyRecordPageBO.applyStatus != null and stateApplyRecordPageBO.applyStatus != '' != null">
            AND b.apply_status = #{stateApplyRecordPageBO.applyStatus}
        </if>
        <if test="stateApplyRecordPageBO.applyUser != null and stateApplyRecordPageBO.applyUser != '' != null">
            AND b.apply_user LIKE CONCAT('%', #{stateApplyRecordPageBO.applyUser}, '%')
        </if>
        <if test="stateApplyRecordPageBO.applyDepartment != null and stateApplyRecordPageBO.applyDepartment != ''">
            AND b.apply_department LIKE CONCAT('%', #{stateApplyRecordPageBO.applyDepartment}, '%')
        </if>
        <if test="stateApplyRecordPageBO.projectName != null and stateApplyRecordPageBO.projectName != ''">
            AND a.project_name LIKE CONCAT('%', #{stateApplyRecordPageBO.projectName}, '%')
        </if>
        <if test="stateApplyRecordPageBO.applyType != null and stateApplyRecordPageBO.applyType != ''">
            AND b.apply_type = #{stateApplyRecordPageBO.applyType}
        </if>
        order by b.create_time desc
    </select>
 
    <select id="selectProjectAndHousehold"
            resultType="com.zzg.system.domain.vo.ApplyHouseholdOwnerVO">
        SELECT A.project_name,
               A.start_time,
               c.*
        FROM state_project A
                 LEFT JOIN state_household c ON A.ID = c.state_project_id
                 LEFT JOIN state_household_owner d ON c.ID = d.state_household_id
        WHERE 1 = 1
        <if test="projectId != null and projectId != ''">
            AND A.ID = #{projectId}
        </if>
        <if test="ownerType != null">
            AND c.owner_type = #{ownerType}
        </if>
        AND c.ID IS NOT NULL
    </select>
 
    <select id="selectApplyRecordWithOwnerDistinctPage"
            parameterType="com.zzg.system.domain.bo.GetApplyHouseholdOwnerBO"
            resultType="com.zzg.system.domain.bo.ApplyOwnerBO">
        SELECT DISTINCT on (t3.ID) t1.*,
                                   t2.person_id_card,
                                   t2.company_social_code,
                                   t2.company_agent,
                                   t2.owner_name,
                                   t2.owner_type,
                                   t2.id                    as stateHouseholdOwnerId,
                                   t4.record_no,
                                   t4.project_id,
                                   t5.start_time,
                                   t3.belonging_street_town as street,
                                   t3.id                    as stateHouseholdId
        FROM state_apply_record_item t1
                 LEFT JOIN state_household_owner t2 ON t1.state_household_owner = t2.id
                 LEFT JOIN state_household t3 ON t2.state_household_id = t3.id
                 LEFT JOIN state_apply_record t4 ON t1.apply_id = t4.id
                 LEFT JOIN state_project t5 ON t4.project_id = t5.id
        WHERE 1 = 1
        <!--        <if test="getApplyHouseholdOwnerBO.ownerType != null">-->
        <!--            AND t2.owner_type = #{getApplyHouseholdOwnerBO.ownerType}-->
        <!--        </if>-->
        <if test="getApplyHouseholdOwnerBO.applyType != null">
            AND t4.apply_type = #{getApplyHouseholdOwnerBO.applyType}
        </if>
        <if test="getApplyHouseholdOwnerBO.projectId != null and getApplyHouseholdOwnerBO.projectId != ''">
            AND t4.project_id = #{getApplyHouseholdOwnerBO.projectId}
        </if>
        <if test="getApplyHouseholdOwnerBO.applyId != null and getApplyHouseholdOwnerBO.applyId != ''">
            AND t4.id = #{getApplyHouseholdOwnerBO.applyId}
        </if>
        <if test="getApplyHouseholdOwnerBO.street != null and getApplyHouseholdOwnerBO.street != ''">
            AND t3.belonging_street_town LIKE CONCAT('%', #{getApplyHouseholdOwnerBO.street}, '%')
        </if>
        <!-- 使用 choose 来根据条件切换模糊查询的字段 -->
        <choose>
            <when test="getApplyHouseholdOwnerBO.ownerType == 1">
                <if test="getApplyHouseholdOwnerBO.ownerName != null and getApplyHouseholdOwnerBO.ownerName != ''">
                    AND t2.owner_name LIKE CONCAT('%', #{getApplyHouseholdOwnerBO.ownerName}, '%')
                </if>
            </when>
            <when test="getApplyHouseholdOwnerBO.ownerType == 2">
                <if test="getApplyHouseholdOwnerBO.ownerName != null and getApplyHouseholdOwnerBO.ownerName != ''">
                    AND t2.owner_name LIKE CONCAT('%', #{getApplyHouseholdOwnerBO.ownerName}, '%')
                </if>
            </when>
            <when test="getApplyHouseholdOwnerBO.ownerType == 0">
            </when>
            <otherwise>
                -- 默认情况不执行任何操作,防止空选择引起的语法错误
            </otherwise>
        </choose>
    </select>
    <select id="selectApplyRecordWithProject" parameterType="com.zzg.system.domain.bo.StateApplyRecordPageBO"
            resultType="com.zzg.system.domain.vo.StateApplyRecordVO">
        SELECT t1.*,
               t2.project_no,
               t2.project_name,
               t2.start_time,
               t2.street
        FROM state_apply_record t1
                 LEFT JOIN
             state_project t2 ON t1.project_id = t2.id
        WHERE 1 = 1
          AND t1.apply_status = 3
        <if test="stateApplyRecordPageInfoLevelBO.applyType != null">
            AND t1.apply_type = #{stateApplyRecordPageInfoLevelBO.applyType}
        </if>
        <!-- 动态判断 project_no -->
        <if test="stateApplyRecordPageInfoLevelBO.projectNo != null and stateApplyRecordPageInfoLevelBO.projectNo != ''">
            AND t2.project_no LIKE CONCAT('%', #{stateApplyRecordPageInfoLevelBO.projectNo}, '%')
        </if>
        <!-- 动态判断 project_name -->
        <if test="stateApplyRecordPageInfoLevelBO.projectName != null and stateApplyRecordPageInfoLevelBO.projectName != ''">
            AND t2.project_name LIKE CONCAT('%', #{stateApplyRecordPageInfoLevelBO.projectName}, '%')
        </if>
        <!-- 动态判断 street -->
        <if test="stateApplyRecordPageInfoLevelBO.street != null and stateApplyRecordPageInfoLevelBO.street != ''">
            AND t2.street LIKE CONCAT('%', #{stateApplyRecordPageInfoLevelBO.street}, '%')
        </if>
        <if test="stateApplyRecordPageInfoLevelBO.projectId != null and stateApplyRecordPageInfoLevelBO.projectId != ''">
            and t2.id = #{stateApplyRecordPageInfoLevelBO.projectId}
        </if>
    </select>
 
    <select id="countApplyRecordWithOwnerPage" parameterType="com.zzg.system.domain.bo.StateApplyRecordPageBO"
            resultType="java.lang.String">
        SELECT stateHouseholdId
        FROM (
        SELECT t1.*,
               t2.project_no,
               t2.project_name,
               t2.start_time,
               t2.street
        FROM state_apply_record t1
                 LEFT JOIN
             state_project t2 ON t1.project_id = t2.id
        WHERE 1 = 1
          AND t1.apply_status = 3
        <if test="stateApplyRecordPageInfoLevelBO.applyType != null">
            AND t1.apply_type = #{stateApplyRecordPageInfoLevelBO.applyType}
        </if>
        <!-- 动态判断 project_no -->
        <if test="stateApplyRecordPageInfoLevelBO.projectNo != null and stateApplyRecordPageInfoLevelBO.projectNo != ''">
            AND t2.project_no LIKE CONCAT('%', #{stateApplyRecordPageInfoLevelBO.projectNo}, '%')
        </if>
        <!-- 动态判断 project_name -->
        <if test="stateApplyRecordPageInfoLevelBO.projectName != null and stateApplyRecordPageInfoLevelBO.projectName != ''">
            AND t2.project_name LIKE CONCAT('%', #{stateApplyRecordPageInfoLevelBO.projectName}, '%')
        </if>
        <!-- 动态判断 street -->
        <if test="stateApplyRecordPageInfoLevelBO.street != null and stateApplyRecordPageInfoLevelBO.street != ''">
            AND t2.street LIKE CONCAT('%', #{stateApplyRecordPageInfoLevelBO.street}, '%')
        </if>
        <if test="stateApplyRecordPageInfoLevelBO.projectId != null and stateApplyRecordPageInfoLevelBO.projectId != ''">
            and t2.id = #{stateApplyRecordPageInfoLevelBO.projectId}
        </if>
        )  tmp_count
        GROUP BY stateHouseholdId
    </select>
 
    <select id="selectApplyRecordWithOwnerPage" resultType="com.zzg.system.domain.bo.ApplyOwnerBO">
        SELECT t1.*,
               t2.person_id_card,
               t2.company_social_code,
               t2.company_agent,
               t2.owner_name,
               t2.owner_type,
               t2.id                    as stateHouseholdOwnerId,
               t4.record_no,
               t4.project_id,
               t5.start_time,
               t3.belonging_street_town as street,
               t3.id                    as stateHouseholdId
        FROM state_apply_record_item t1
                 LEFT JOIN state_household_owner t2 ON t1.state_household_owner = t2.id
                 LEFT JOIN state_household t3 ON t2.state_household_id = t3.id
                 LEFT JOIN state_apply_record t4 ON t1.apply_id = t4.id
                 LEFT JOIN state_project t5 ON t4.project_id = t5.id
        WHERE 1 = 1
        <!--        <if test="getApplyHouseholdOwnerBO.ownerType != null">-->
        <!--            AND t2.owner_type = #{getApplyHouseholdOwnerBO.ownerType}-->
        <!--        </if>-->
        <if test="getApplyHouseholdOwnerBO.applyType != null">
            AND t4.apply_type = #{getApplyHouseholdOwnerBO.applyType}
        </if>
        <if test="getApplyHouseholdOwnerBO.projectId != null and getApplyHouseholdOwnerBO.projectId != ''">
            AND t4.project_id = #{getApplyHouseholdOwnerBO.projectId}
        </if>
        <if test="getApplyHouseholdOwnerBO.applyId != null and getApplyHouseholdOwnerBO.applyId != ''">
            AND t4.id = #{getApplyHouseholdOwnerBO.applyId}
        </if>
        <if test="getApplyHouseholdOwnerBO.street != null and getApplyHouseholdOwnerBO.street != ''">
            AND t3.belonging_street_town LIKE CONCAT('%', #{getApplyHouseholdOwnerBO.street}, '%')
        </if>
        <!-- 使用 choose 来根据条件切换模糊查询的字段 -->
        <choose>
            <when test="getApplyHouseholdOwnerBO.ownerType == 1">
                <if test="getApplyHouseholdOwnerBO.ownerName != null and getApplyHouseholdOwnerBO.ownerName != ''">
                    AND t2.owner_name LIKE CONCAT('%', #{getApplyHouseholdOwnerBO.ownerName}, '%')
                </if>
            </when>
            <when test="getApplyHouseholdOwnerBO.ownerType == 2">
                <if test="getApplyHouseholdOwnerBO.ownerName != null and getApplyHouseholdOwnerBO.ownerName != ''">
                    AND t2.owner_name LIKE CONCAT('%', #{getApplyHouseholdOwnerBO.ownerName}, '%')
                </if>
            </when>
            <when test="getApplyHouseholdOwnerBO.ownerType == 0">
            </when>
            <otherwise>
                -- 默认情况不执行任何操作,防止空选择引起的语法错误
            </otherwise>
        </choose>
 
        <if test="getApplyHouseholdOwnerBO.stateHouseIdList != null">
            AND t1.state_household_id in
            <foreach item="stateHouseId" collection="getApplyHouseholdOwnerBO.stateHouseIdList" open="(" separator=","
                     close=")">
                #{stateHouseId}
            </foreach>
        </if>
    </select>
</mapper>