<?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 != """>
|
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 != """>
|
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' ) > 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' ) <= #{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>
|