mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<?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.panzhihua.service_community.dao.ConvenientMerchantDAO">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.panzhihua.service_community.model.dos.ConvenientMerchantDO">
                <id column="id" property="id" />
                <id column="name" property="name" />
                <id column="community_id" property="communityId" />
                <id column="community_name" property="communityName" />
                <id column="logo" property="logo" />
                <id column="contacts" property="contacts" />
                <id column="id_card" property="idCard" />
                <id column="phone" property="phone" />
                <id column="address" property="address" />
                <id column="address" property="address" />
                <id column="detailed_address" property="detailedAddress" />
                <id column="lat" property="lat" />
                <id column="lon" property="lon" />
                <id column="begin_at" property="beginAt" />
                <id column="end_at" property="endAt" />
                <id column="period" property="period" />
                <id column="introduction" property="introduction" />
                <id column="business_status" property="businessStatus" />
                <id column="user_id" property="userId" />
                <id column="consultation_volume" property="consultationVolume" />
                <id column="view_num" property="viewNum" />
                <id column="is_del" property="isDel" />
                <id column="created_at" property="createdAt" />
                <id column="created_by" property="createdBy" />
                <id column="updated_at" property="updatedAt" />
                <id column="updated_by" property="updatedBy" />
                <id column="area_code" property="areaCode" />
                <id column="service_range" property="serviceRange" />
                <id column="mobile_phone" property="mobilePhone" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,`name`,community_id,community_name,logo,contacts,id_card,phone,address,lat,lon,begin_at,end_at,period,introduction,
        business_status,user_id,consultation_volume,is_del,created_at,created_by,updated_at,updated_by,area_code,service_range,mobile_phone,detailed_address
    </sql>
    <select id="pageMerchant" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO">
        SELECT ccm.*, su.account, su.status AS accountStatus, GROUP_CONCAT(ccss.service_name) AS serviceScope
        FROM  com_convenient_merchants ccm
        LEFT JOIN sys_user su ON ccm.user_id = su.user_id
        LEFT JOIN com_convenient_service_scope ccss ON ccm.id = ccss.merchant_id
        WHERE ccm.is_del = 0
        <if test="pageConvenientMerchantDTO.serviceId != null and pageConvenientMerchantDTO.serviceId != 0">
            AND ccss.service_category_id = #{pageConvenientMerchantDTO.serviceId}
        </if>
        <if test="pageConvenientMerchantDTO.accountStatus != null">
            AND su.status = #{pageConvenientMerchantDTO.accountStatus}
        </if>
        <if test="pageConvenientMerchantDTO.communityId != null and pageConvenientMerchantDTO.communityId != 0">
            AND ccm.community_id = ${pageConvenientMerchantDTO.communityId}
        </if>
        <if test="pageConvenientMerchantDTO.areaCode != null and pageConvenientMerchantDTO.areaCode != ''">
            AND ccm.area_code = ${pageConvenientMerchantDTO.areaCode}
        </if>
        <if test="pageConvenientMerchantDTO.businessStatus != null">
            AND ccm.business_status = #{pageConvenientMerchantDTO.businessStatus}
        </if>
        <if test="pageConvenientMerchantDTO.keyword != null and pageConvenientMerchantDTO.keyword != &quot;&quot;">
            AND (
                    ccm.name LIKE CONCAT('%', #{pageConvenientMerchantDTO.keyword}, '%')
                    OR ccm.address LIKE CONCAT('%', #{pageConvenientMerchantDTO.keyword}, '%')
                    OR ccm.phone LIKE CONCAT('%', #{pageConvenientMerchantDTO.keyword}, '%')
                )
        </if>
        GROUP BY ccm.id ORDER BY ccm.created_at DESC
    </select>
    <select id="selectMerchantById" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO">
        SELECT ccm.*, su.account, su.status AS accountStatus
        FROM  com_convenient_merchants ccm
        LEFT JOIN sys_user su ON ccm.user_id = su.user_id
        WHERE ccm.id = #{merchantId}
    </select>
 
    <select id="selectMerchantByUserId" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO">
        SELECT ccm.*, su.account, su.status AS accountStatus
        FROM  com_convenient_merchants ccm
        LEFT JOIN sys_user su ON ccm.user_id = su.user_id
        WHERE ccm.user_id = #{userId}
    </select>
 
    <select id="selectMerchantByName" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO">
        SELECT
            temp.id,
            temp.NAME,
            temp.introduction,
            temp.logo,
            temp.serviceScope,
        IF
            (
                SUM( temp.consultation_volume ) IS NULL,
                0,
            SUM( temp.consultation_volume )) AS monthConsultationVolume
        FROM
            (
            SELECT
                ccm.id,
                ccm.NAME,
                ccm.introduction,
                ccm.logo,
                cccs.consultation_volume,
                GROUP_CONCAT( ccss.service_name ) AS serviceScope
            FROM
                com_convenient_merchants ccm
                LEFT JOIN (
                SELECT
                    *
                FROM
                    com_convenient_consultation_statistics
                WHERE
                    statistic_date LIKE #{currentMon}) cccs ON ccm.id = cccs.merchant_id
                    LEFT JOIN com_convenient_service_scope ccss ON ccm.id = ccss.merchant_id
                WHERE
                    ( ccm.community_id = ${communityId} or ccm.community_id = 0)  AND ccm.business_status = 1 and ccm.is_del = 0 and ccm.`name` = '犇师傅维修中心' GROUP BY cccs.id
                    ) temp
                GROUP BY
                    temp.id
            ORDER BY
            SUM( temp.consultation_volume ) DESC
    </select>
    <select id="getPopularMerchants" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO">
        SELECT
            temp.id, temp.name, temp.introduction, temp.logo,
            temp.serviceScope, IF(SUM(cccs.consultation_volume) is null, 0, SUM(cccs.consultation_volume)) as monthConsultationVolume
        FROM (
            SELECT
                ccm.id, ccm.name, ccm.introduction, ccm.logo,
                GROUP_CONCAT(ccss.service_name) AS serviceScope
            FROM com_convenient_merchants ccm
            LEFT JOIN com_convenient_service_scope ccss ON ccm.id = ccss.merchant_id
            WHERE ccm.area_code=#{areaCode} and  ( ccm.community_id = ${communityId} or ccm.community_id = 0)
            AND ccm.business_status = 1 and ccm.is_del = 0 and ccm.`name` != '犇师傅维修中心'
            GROUP BY ccm.id
        ) temp
        LEFT JOIN (SELECT * FROM com_convenient_consultation_statistics WHERE statistic_date LIKE #{currentMon}) cccs ON temp.id = cccs.merchant_id
        GROUP BY temp.id ORDER BY SUM(cccs.consultation_volume) DESC
    </select>
    <select id="getClassifyMerchants" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO">
        SELECT
            temp.id, temp.name, temp.introduction, temp.logo,
            IF(SUM(temp.consultation_volume) is null,0,SUM(temp.consultation_volume)) as monthConsultationVolume
        FROM (
            SELECT
                ccm.id, ccm.name, ccm.introduction, ccm.logo, cccs.consultation_volume
            FROM com_convenient_merchants ccm
            LEFT JOIN (SELECT * FROM com_convenient_consultation_statistics WHERE statistic_date LIKE #{currentMon}) cccs ON ccm.id = cccs.merchant_id
            LEFT JOIN com_convenient_service_scope ccss ON ccm.id = ccss.merchant_id
            WHERE ccm.area_code=#{pageClassifyMerchantDTO.areaCode} and (ccm.community_id = ${pageClassifyMerchantDTO.communityId} or ccm.community_id = 0) and ccm.is_del = 0  AND ccm.business_status = 1 AND ccss.service_category_id = #{pageClassifyMerchantDTO.serviceId}
        ) temp GROUP BY temp.id ORDER BY SUM(temp.consultation_volume) DESC
    </select>
    <select id="getMerchantDetail" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO">
        SELECT
            temp.id, temp.name, temp.introduction, temp.logo, temp.phone, temp.begin_at, temp.end_at, temp.period,temp.detailed_address,
            temp.address, temp.lat, temp.lon, temp.serviceScope, IF(SUM(temp.consultation_volume) is null,0,SUM(temp.consultation_volume)) as monthConsultationVolume
        FROM (
            SELECT
                ccm.id, ccm.name, ccm.introduction, ccm.logo, ccm.phone, ccm.begin_at, ccm.end_at, ccm.period,ccm.detailed_address,
                ccm.address, ccm.lat, ccm.lon, cccs.consultation_volume,GROUP_CONCAT(ccss.service_name) AS serviceScope
            FROM com_convenient_merchants ccm
            LEFT JOIN (SELECT * FROM com_convenient_consultation_statistics WHERE statistic_date LIKE #{currentMon}) cccs ON ccm.id = cccs.merchant_id
            LEFT JOIN com_convenient_service_scope ccss ON ccm.id = ccss.merchant_id
            WHERE ccm.id = #{merchantId} GROUP BY cccs.id
        ) temp GROUP BY temp.id ORDER BY SUM(temp.consultation_volume) DESC
    </select>
    <select id="pageSearchMerchant" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO">
         SELECT
            temp.id, temp.name, temp.introduction, temp.logo,temp.detailed_address,
            temp.serviceScope, IF(SUM(temp.consultation_volume) is null,0,SUM(temp.consultation_volume)) as monthConsultationVolume
        FROM (
            SELECT
                ccm.id, ccm.name, ccm.introduction, ccm.logo,ccm.detailed_address,
                cccs.consultation_volume,GROUP_CONCAT(ccss.service_name) AS serviceScope
            FROM com_convenient_merchants ccm
            LEFT JOIN (SELECT * FROM com_convenient_consultation_statistics WHERE statistic_date LIKE #{currentMon}) cccs ON ccm.id = cccs.merchant_id
            LEFT JOIN com_convenient_service_scope ccss ON ccm.id = ccss.merchant_id
            WHERE (ccm.community_id = ${pageSearchDTO.communityId} or ccm.community_id = 0) AND ccm.business_status = 1 AND ccm.`name` LIKE CONCAT('%', #{pageSearchDTO.keyword}, '%')
                AND ccm.is_del = 0 GROUP BY cccs.id
        ) temp GROUP BY temp.id ORDER BY SUM(temp.consultation_volume) DESC
    </select>
    <select id="exportMerchantBySearch" resultType="com.panzhihua.common.model.vos.community.convenient.ExportMerchantVO">
        SELECT ccm.*, su.account, su.status AS accountStatus, GROUP_CONCAT(ccss.service_name) AS serviceScope,
            CONCAT(ccm.period,DATE_FORMAT(ccm.begin_at,'%T'),'~',DATE_FORMAT(ccm.end_at,'%T')) AS businessTime
        FROM  com_convenient_merchants ccm
        LEFT JOIN sys_user su ON ccm.user_id = su.user_id
        LEFT JOIN com_convenient_service_scope ccss ON ccm.id = ccss.merchant_id
        WHERE ccm.community_id = ${exportMerchantDTO.communityId} AND ccm.is_del = 0
        <if test="exportMerchantDTO.serviceId != null and exportMerchantDTO.serviceId != 0">
            AND ccss.service_category_id = #{exportMerchantDTO.serviceId}
        </if>
        <if test="exportMerchantDTO.accountStatus != null">
            AND su.status = #{exportMerchantDTO.accountStatus}
        </if>
        <if test="exportMerchantDTO.businessStatus != null">
            AND ccm.business_status = #{exportMerchantDTO.businessStatus}
        </if>
        <if test="exportMerchantDTO.keyword != null and exportMerchantDTO.keyword != &quot;&quot;">
            AND (
                    ccm.name LIKE CONCAT('%', #{exportMerchantDTO.keyword}, '%')
                    OR ccm.address LIKE CONCAT('%', #{exportMerchantDTO.keyword}, '%')
                    OR ccm.phone LIKE CONCAT('%', #{exportMerchantDTO.keyword}, '%')
                    OR ccm.detailed_address  LIKE CONCAT('%', #{exportMerchantDTO.keyword}, '%')
                )
        </if>
        GROUP BY ccm.id
    </select>
    <select id="exportMerchantByIds" resultType="com.panzhihua.common.model.vos.community.convenient.ExportMerchantVO">
        SELECT ccm.*, su.account, su.status AS accountStatus, GROUP_CONCAT(ccss.service_name) AS serviceScope,
        CONCAT(ccm.period,DATE_FORMAT(ccm.begin_at,'%T'),'~',DATE_FORMAT(ccm.end_at,'%T')) AS businessTime
        FROM  com_convenient_merchants ccm
        LEFT JOIN sys_user su ON ccm.user_id = su.user_id
        LEFT JOIN com_convenient_service_scope ccss ON ccm.id = ccss.merchant_id
        WHERE ccm.id IN
            <foreach collection="needExportIds" open="(" separator="," close=")" index="index" item="item">
                #{item}
            </foreach>
        GROUP BY ccm.id
    </select>
    <select id="selectMerchantListByCommunity"
            resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO">
        SELECT id, `name`, logo, lat, lon FROM com_convenient_merchants WHERE community_id = ${communityId} AND is_del = 0
    </select>
    <select id="getScreenPopularMerchants"
            resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO">
        SELECT * FROM (
        SELECT id, `name`, consultation_volume, view_num
        FROM com_convenient_merchants
        WHERE area_code=#{pagePopularMerchantDTO.areaCode} and  (community_id = ${pagePopularMerchantDTO.communityId} OR community_id = 0) AND is_del = 0 ORDER BY (consultation_volume + consultation_volume) DESC LIMIT 100
        ) temp
    </select>
    <select id="getIndexMerchantBaseData"
            resultType="com.panzhihua.common.model.vos.community.bigscreen.BigScreenMerchantStatisticsInfo">
        SELECT
        (SELECT 0) AS resourceTypeNum,
        (SELECT COUNT(id) FROM com_convenient_merchants WHERE (community_id = ${communityId} OR community_id = 0) AND is_del = 0) AS merchantNum,
        (SELECT SUM(t1.consultation_volume)
        FROM com_convenient_consultation_statistics t1
        LEFT JOIN com_convenient_merchants t2 ON t1.merchant_id = t2.id
        WHERE (t2.community_id = ${communityId} OR t2.community_id = 0)) AS serviceTimes
    </select>
    <select id="selectServiceTypeCircleData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT t1.`name` AS filed, COUNT(t3.id) AS num
        FROM com_convenient_service_categories t1
        LEFT JOIN com_convenient_service_scope t2 ON t1.id = t2.service_category_id
        LEFT JOIN com_convenient_merchants t3 ON t2.merchant_id = t3.id
        WHERE (t3.community_id = ${communityId} OR t3.community_id = 0) AND t3.is_del = 0 GROUP BY t1.id
    </select>
    <select id="getServiceTimesAddPolylineData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, SUM(num) AS num FROM (
        SELECT DATE_FORMAT( t1.statistic_date, '%Y-%m' ) AS filed, SUM(t1.consultation_volume) AS num
        FROM com_convenient_consultation_statistics t1
        LEFT JOIN com_convenient_merchants t2 ON t1.merchant_id = t2.id
        WHERE (t2.community_id = ${communityId} OR t2.community_id = 0) AND DATE_FORMAT( t1.statistic_date, '%Y-%m' ) &gt; DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') GROUP BY filed
                UNION ALL SELECT * FROM
                (
                    SELECT DATE_FORMAT(curdate(),'%Y-%m') AS filed, 0 AS num union
                    SELECT DATE_FORMAT(date_sub(curdate(), interval 1 month),'%Y-%m') AS filed, 0 AS num union
                    SELECT DATE_FORMAT(date_sub(curdate(), interval 2 month),'%Y-%m') AS filed, 0 AS num union
                    SELECT DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') AS filed, 0 AS num union
                    SELECT DATE_FORMAT(date_sub(curdate(), interval 4 month),'%Y-%m') AS filed, 0 AS num union
                    SELECT DATE_FORMAT(date_sub(curdate(), interval 5 month),'%Y-%m') AS filed, 0 AS num union
                    SELECT DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') AS filed, 0 AS num union
                    SELECT DATE_FORMAT(date_sub(curdate(), interval 7 month),'%Y-%m') AS filed, 0 AS num union
                    SELECT DATE_FORMAT(date_sub(curdate(), interval 8 month),'%Y-%m') AS filed, 0 AS num union
                    SELECT DATE_FORMAT(date_sub(curdate(), interval 9 month),'%Y-%m') AS filed, 0 AS num union
                    SELECT DATE_FORMAT(date_sub(curdate(), interval 10 month),'%Y-%m') AS filed, 0 AS num union
                    SELECT DATE_FORMAT(date_sub(curdate(), interval 11 month),'%Y-%m') AS filed, 0 AS num
                ) temT
        ) temp GROUP BY filed ORDER BY filed ASC
    </select>
    <select id="getServiceTimesTotalPolylineDate"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT IF(SUM(t1.consultation_volume) IS NULL,0,SUM(t1.consultation_volume)) AS num
        FROM com_convenient_consultation_statistics t1
        LEFT JOIN com_convenient_merchants t2 ON t1.merchant_id = t2.id
        WHERE (t2.community_id = ${communityId} OR t2.community_id = 0) AND DATE_FORMAT( t1.statistic_date, '%Y-%m' ) &lt;= #{date}
    </select>
    <select id="indexMerchantList"
            resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO">
        SELECT t1.id, t1.`name`, t1.logo, t1.introduction, GROUP_CONCAT(t2.`service_name`) serviceScope
        FROM com_convenient_merchants t1
        LEFT JOIN com_convenient_service_scope t2 ON t1.id = t2.merchant_id
        WHERE (t1.community_id = ${pageBaseDTO.communityId} OR t1.community_id = 0)
        <if test="pageBaseDTO.paramId != null">
            AND t2.service_category_id = #{pageBaseDTO.paramId}
        </if>
        GROUP BY t1.id ORDER BY t1.id DESC
    </select>
    <update id="deleteMerchantById">
        UPDATE com_convenient_merchants SET is_del = 1, updated_by = #{operator} WHERE id = #{merchantId}
    </update>
    <update id="batchUpdateMerchantConsultationNum">
        UPDATE `com_convenient_merchants` SET consultation_volume = CASE id
        <foreach collection="consultationVOList" item="item" index="index">
            WHEN #{item.merchantId} THEN #{item.totalConsultationNum}
        </foreach>
        END
        WHERE id = CASE id
        <foreach collection="consultationVOList" item="item" index="index">
            WHEN #{item.merchantId} THEN #{item.merchantId}
        </foreach>
        END
    </update>
    <update id="batchUpdateMerchantViewNum">
        UPDATE `com_convenient_merchants` SET view_num = CASE id
        <foreach collection="viewVOList" item="item" index="index">
            WHEN #{item.merchantId} THEN #{item.totalViewNum}
        </foreach>
        END
        WHERE id = CASE id
        <foreach collection="viewVOList" item="item" index="index">
            WHEN #{item.merchantId} THEN #{item.merchantId}
        </foreach>
        END
    </update>
    <update id="batchUpdateBusinessStatus">
        UPDATE `com_convenient_merchants` SET business_status = #{status}
        WHERE id IN
        <foreach collection="convenientMerchantDOList" open="(" separator="," close=")" item="item" index="index">
            #{item.id}
        </foreach>
    </update>
 
    <select id="getMerchantDetailByAccount" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO">
        SELECT
        ccm.id, ccm.name, ccm.introduction, ccm.logo, ccm.phone, ccm.begin_at, ccm.end_at, ccm.period,ccm.detailed_address,
        ccm.address, ccm.lat, ccm.lon,u.status account_status,u.account,ccm.business_status
        FROM com_convenient_merchants ccm LEFT JOIN sys_user u on ccm.user_id = u.user_id WHERE u.type = 5
        and u.account = #{account}
 
    </select>
</mapper>