101captain
2021-11-09 e7f03acfa5ee4ad4fd6d1ee9e9ae9a5655488f6d
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
<?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="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" />
    </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
    </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.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="getPopularMerchants" 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} AND ccm.business_status = 1 GROUP BY cccs.id
        ) temp GROUP BY temp.id ORDER BY SUM(temp.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.community_id = #{pageClassifyMerchantDTO.communityId} AND ccm.business_status = 1 AND ccss.service_category_id = #{pageClassifyMerchantDTO.serviceId}
                GROUP BY cccs.id
        ) 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.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.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.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 = #{pageSearchDTO.communityId} 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}, '%')
                )
        </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>
    <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>
</mapper>