linwe
2024-08-09 8b7258c9427882bb1798f1502eaa35184c6e374e
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
<?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="org.springblade.modules.discuss.mapper.UserTopicsMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="userTopicsResultMap" type="org.springblade.modules.discuss.vo.UserTopicsVO">
        <result property="id" column="id"/>
        <result property="householdId" column="household_id"/>
        <result property="topicsId" column="topics_id"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="deleteFlag" column="delete_flag"/>
        <result property="publicDiscussId" column="public_discuss_id"/>
        <result property="selected" column="selected"/>
    </resultMap>
 
    <sql id="selectUserTopics">
        select
            id,
            household_id,
            topics_id,
            create_time,
            update_time,
            delete_flag,
            selected,
            public_discuss_id
        from
            jczz_user_topics
    </sql>
 
 
    <select id="selectUserTopicsPage" resultMap="userTopicsResultMap">
        SELECT
        jut.article_id,
        jut.delete_flag,
        jut.signature_path,
        jut.create_time,
        jut.household_id,
        bu.avatar,
        jh.name,
        jh.phone_number phone,
        jda.address_name,
        jda.aoi_name
        <if test="userTopics.articleId != null ">,
        group_concat(jt.option_content) optionContent  </if>
        FROM
        jczz_user_topics as jut
        LEFT JOIN jczz_household jh ON jh.id = jut.household_id and jh.is_deleted = 0
        LEFT JOIN jczz_doorplate_address jda ON jda.address_code = jh.house_code
        LEFT JOIN jczz_topics jt on jt.id = jut.topics_id
        LEFT JOIN blade_user bu ON jh.associated_user_id = bu.id AND bu.is_deleted = 0
        <where>
            <if test="userTopics.id != null ">and jut.id = #{userTopics.id}</if>
            <if test="userTopics.name != null and userTopics.name != ''">
                and bu.name like concat('%',#{userTopics.name},'%')
            </if>
            <if test="userTopics.phone != null and userTopics.phone != ''">
                and bu.phone like concat('%',#{userTopics.phone},'%')
            </if>
 
            <if test="userTopics.aoiCodeList != null and userTopics.aoiCodeList.size() > 0">
                and jda.aoi_code in
                <foreach collection="userTopics.aoiCodeList" item="code" open="(" close=")" separator=",">
                    #{code}
                </foreach>
            </if>
 
            <if test="userTopics.householdId != null ">and jut.household_id = #{userTopics.householdId}</if>
            <if test="userTopics.topicsId != null ">and jut.topics_id = #{userTopics.topicsId}</if>
            <if test="userTopics.createTime != null ">and jut.create_time = #{userTopics.createTime}</if>
            <if test="userTopics.updateTime != null ">and jut.update_time = #{userTopics.updateTime}</if>
            <if test="userTopics.deleteFlag != null ">and jut.delete_flag = #{userTopics.deleteFlag}</if>
            <if test="userTopics.articleId != null ">
                and jut.article_id = #{userTopics.articleId}
                and jut.delete_flag = 0
                GROUP BY jut.article_id, jut.signature_path,jut.create_time,jut.household_id,jut.delete_flag,
                bu.avatar,
                jh.name,
                jh.phone_number,
                jda.address_name,
                jda.aoi_name
            </if>
        </where>
    </select>
 
    <select id="selectUserTopicsList" parameterType="org.springblade.modules.discuss.dto.UserTopicsDTO"
            resultMap="userTopicsResultMap">
        <include refid="selectUserTopics"/>
        <where>
            <if test="id != null ">and id = #{id}</if>
            <if test="userId != null ">and user_id = #{userId}</if>
            <if test="topicsId != null ">and topics_id = #{topicsId}</if>
            <if test="createTime != null ">and create_time = #{createTime}</if>
            <if test="updateTime != null ">and update_time = #{updateTime}</if>
            <if test="deleteFlag != null ">and delete_flag = #{deleteFlag}</if>
            <if test="publicDiscussId != null ">and public_discuss_id = #{publicDiscussId}</if>
        </where>
    </select>
 
 
    <select id="exportUser" resultType="org.springblade.modules.discuss.excel.UserTopicsExcel">
        SELECT
        jut.article_id,
        jut.delete_flag,
        jut.signature_path,
        jut.create_time,
        jut.household_id,
        bu.avatar,
        jh.name,
        jh.phone_number phone,
        jda.address_name,
        jhs.area,
        jhs.remark,
        jda.address_code houseCode,
        jda.aoi_name
        <if test="articleId != null ">,
            group_concat(jt.option_content) optionContent  </if>
        FROM
        jczz_user_topics as jut
        LEFT JOIN jczz_household jh ON jh.id = jut.household_id and jh.is_deleted = 0
        LEFT JOIN jczz_doorplate_address jda ON jda.address_code = jh.house_code
        LEFT JOIN jczz_topics jt on jt.id = jut.topics_id
        LEFT JOIN blade_user bu ON jh.associated_user_id = bu.id AND bu.is_deleted = 0
        LEFT JOIN jczz_house jhs on jhs.house_code= jda.address_code
        <where>
            <if test="id != null ">and jut.id = #{id}</if>
            <if test="name != null and name != ''">
                and bu.name like concat('%',#{name},'%')
            </if>
            <if test="phone != null and phone != ''">
                and bu.phone like concat('%',#{phone},'%')
            </if>
 
            <if test="aoiCodeList != null and aoiCodeList.size() > 0">
                and jda.aoi_code in
                <foreach collection="aoiCodeList" item="code" open="(" close=")" separator=",">
                    #{code}
                </foreach>
            </if>
 
            <if test="householdId != null ">and jut.household_id = #{householdId}</if>
            <if test="topicsId != null ">and jut.topics_id = #{topicsId}</if>
            <if test="createTime != null ">and jut.create_time = #{createTime}</if>
            <if test="updateTime != null ">and jut.update_time = #{updateTime}</if>
            <if test="deleteFlag != null ">and jut.delete_flag = #{deleteFlag}</if>
            <if test="articleId != null ">
                and jut.article_id = #{articleId}
                and jut.delete_flag = 0
                GROUP BY jut.article_id, jut.signature_path,jut.create_time,jut.household_id,jut.delete_flag,
                bu.avatar,
                jh.name,
                jh.phone_number,
                jda.address_name,
                jhs.area,
                jhs.remark,
                jda.address_code,
                jda.aoi_name
            </if>
        </where>
 
    </select>
 
 
    <select id="getresult" resultMap="userTopicsResultMap">
 
        SELECT
            jts.option_content
        FROM
            jczz_user_topics jut
                LEFT JOIN jczz_topics jts ON jts.id = jut.topics_id
        WHERE
            jut.article_id = #{articleId}
          and jut.household_id=#{householdId}
          and jts.discuss_content=#{discussContent}
 
    </select>
 
    <select id="getresultTwo" resultType="org.springblade.modules.discuss.excel.UserTopicsExcel">
        SELECT
        jut.article_id,
        jut.delete_flag,
        jut.signature_path,
        jut.create_time,
        jut.household_id,
        bu.avatar,
        jh.name,
        jh.phone_number phone,
        jda.address_name,
        jhs.area,
        jhs.remark,
        jda.address_code houseCode,
        jda.aoi_name,
        jt.option_content,
        jhs.building,
        jhs.room,
        jhs.district_name
        FROM
        jczz_user_topics as jut
        LEFT JOIN jczz_household jh ON jh.id = jut.household_id
        LEFT JOIN jczz_doorplate_address jda ON jda.address_code = jh.house_code
        LEFT JOIN jczz_topics jt on jt.id = jut.topics_id
        LEFT JOIN blade_user bu ON jh.associated_user_id = bu.id AND bu.is_deleted = 0
        LEFT JOIN jczz_house jhs on jhs.house_code= jda.address_code
        <where>
            and jt.discuss_content != '议事规则'
            and jt.discuss_content != '管理规约'
            <if test="id != null ">and jut.id = #{id}</if>
            <if test="name != null and name != ''">
                and bu.name like concat('%',#{name},'%')
            </if>
            <if test="phone != null and phone != ''">
                and bu.phone like concat('%',#{phone},'%')
            </if>
 
            <if test="aoiCodeList != null and aoiCodeList.size() > 0">
                and jda.aoi_code in
                <foreach collection="aoiCodeList" item="code" open="(" close=")" separator=",">
                    #{code}
                </foreach>
            </if>
 
            <if test="householdId != null ">and jut.household_id = #{householdId}</if>
            <if test="topicsId != null ">and jut.topics_id = #{topicsId}</if>
            <if test="createTime != null ">and jut.create_time = #{createTime}</if>
            <if test="updateTime != null ">and jut.update_time = #{updateTime}</if>
            <if test="deleteFlag != null ">and jut.delete_flag = #{deleteFlag}</if>
            <if test="articleId != null ">
                and jut.article_id = #{articleId}
                and jut.delete_flag = 0
            </if>
        </where>
 
    </select>
    <select id="getHouseholdList" resultType="org.springblade.modules.discuss.excel.holdExcel">
        SELECT
        jh.id,
        jh.room,
        jh.building,
        jh.house_name,
        jh.district_name,
        jut.create_time,
        jh.area,
        (
        SELECT
        group_concat( jt.id ) AS optionContent
        FROM jczz_topics jt
        WHERE  jt.id = jut.topics_id
        and jut.house_code = jh.house_code
        AND jut.article_id = #{articleId}
        ) optionContent,
        (SELECT jhd.name from jczz_household jhd where  jhd.house_code = jh.house_code AND jhd.is_deleted = 0 and jhd.relationship = 1 limit 1 ) name,
        (SELECT jhd.phone_number from jczz_household jhd where  jhd.house_code = jh.house_code AND jhd.is_deleted = 0 and jhd.relationship = 1 limit 1 ) phone
        FROM
        jczz_house jh
        LEFT JOIN jczz_household jhd ON jhd.house_code = jh.house_code
        AND jh.is_deleted = 0 and jhd.relationship = 1
        LEFT JOIN jczz_user_topics jut on jut.household_id = jhd.id AND jut.article_id = #{articleId}
        <where>
            <if test="aoiCodeList != null and aoiCodeList.size() > 0">
                and jh.district_code in
                <foreach collection="aoiCodeList" item="code" open="(" close=")" separator=",">
                    #{code}
                </foreach>
            </if>
        </where>
        GROUP BY id
    </select>
 
    <select id="getUserTopicsTotal" resultType="java.util.Map">
        SELECT IFNULL(sum(a.area), 0) AS area,
               IFNULL(COUNT(1), 0)       number
        FROM (SELECT DISTINCT jut.house_code,
                              jh.area
              FROM jczz_user_topics jut
                       LEFT JOIN jczz_household jhd ON jhd.id = jut.household_id
                       LEFT JOIN jczz_house jh ON jh.house_code = jhd.house_code
                       LEFT JOIN jczz_topics jt ON jt.id = jut.topics_id
                  AND jt.delete_flag = 0
              WHERE jut.article_id = #{articleId}) a
 
    </select>
 
 
</mapper>