106 lines
3.1 KiB
XML
106 lines
3.1 KiB
XML
<?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.imyeyu.api.modules.gao.mapper.GaoCustomerMapper">
|
|
<select id="selectByIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomer">
|
|
SELECT
|
|
*
|
|
FROM `gao_customer`
|
|
WHERE
|
|
TRUE
|
|
<if test="idList != null and !idList.isEmpty()">
|
|
AND `id` IN
|
|
<foreach collection="idList" item="id" separator="," open="(" close=")">
|
|
#{id}
|
|
</foreach>
|
|
</if>
|
|
<if test="idList == null or idList.isEmpty()">
|
|
AND FALSE
|
|
</if>
|
|
AND `deleted_at` IS NULL
|
|
</select>
|
|
|
|
<sql id="queryWhere">
|
|
`c`.`deleted_at` IS NULL
|
|
<if test="storeId != null and storeId != ''">
|
|
AND `c`.`store_id` = #{storeId}
|
|
</if>
|
|
<if test="keyword != null and keyword != ''">
|
|
AND (
|
|
`c`.`code` LIKE CONCAT('%', #{keyword}, '%')
|
|
OR `c`.`name` LIKE CONCAT('%', #{keyword}, '%')
|
|
OR `c`.`telephone` LIKE CONCAT('%', #{keyword}, '%')
|
|
OR `c`.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%')
|
|
OR `c`.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%')
|
|
OR `c`.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%')
|
|
)
|
|
</if>
|
|
<if test="tagIdList != null and !tagIdList.isEmpty()">
|
|
<bind name="tagCount" value="tagIdList.size()"/>
|
|
AND `c`.`id` IN (
|
|
SELECT `ta`.`biz_id`
|
|
FROM `tag_apply` `ta`
|
|
WHERE
|
|
`ta`.`biz_type` = 'GAO_CUSTOMER'
|
|
AND `ta`.`tag_id` IN
|
|
<foreach collection="tagIdList" item="tagId" separator="," open="(" close=")">
|
|
#{tagId}
|
|
</foreach>
|
|
AND `ta`.`deleted_at` IS NULL
|
|
GROUP BY `ta`.`biz_id`
|
|
HAVING COUNT(DISTINCT `ta`.`tag_id`) = #{tagCount}
|
|
)
|
|
</if>
|
|
</sql>
|
|
|
|
<select id="countByQuery" resultType="long">
|
|
SELECT COUNT(1)
|
|
FROM `gao_customer` `c`
|
|
WHERE
|
|
<include refid="queryWhere"/>
|
|
</select>
|
|
|
|
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomer">
|
|
SELECT `c`.*
|
|
FROM `gao_customer` `c`
|
|
WHERE
|
|
<include refid="queryWhere"/>
|
|
ORDER BY `c`.`created_at` DESC, `c`.`id` DESC
|
|
LIMIT #{offset}, #{limit}
|
|
</select>
|
|
|
|
<select id="stateDailyNewCustomer" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView">
|
|
SELECT
|
|
CAST(DATE_FORMAT(FROM_UNIXTIME(`created_at` / 1000), '%Y%m%d') AS UNSIGNED) AS `dateValue`,
|
|
COUNT(1) AS `newCustomerCount`
|
|
FROM `gao_customer`
|
|
WHERE
|
|
`store_id` = #{storeId}
|
|
AND `created_at` >= #{beginCreatedAt}
|
|
AND `created_at` <= #{endCreatedAt}
|
|
AND `deleted_at` IS NULL
|
|
GROUP BY DATE_FORMAT(FROM_UNIXTIME(`created_at` / 1000), '%Y%m%d')
|
|
ORDER BY `dateValue` ASC
|
|
</select>
|
|
|
|
<select id="countCreatedBefore" resultType="java.lang.Long">
|
|
SELECT
|
|
COUNT(1)
|
|
FROM `gao_customer`
|
|
WHERE
|
|
`store_id` = #{storeId}
|
|
AND `created_at` < #{beginCreatedAt}
|
|
AND `deleted_at` IS NULL
|
|
</select>
|
|
|
|
<select id="stateGender" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView">
|
|
SELECT
|
|
IFNULL(CAST(`gender` AS CHAR), 'UNKNOWN') AS `genderCode`,
|
|
COUNT(1) AS `count`
|
|
FROM `gao_customer`
|
|
WHERE
|
|
`store_id` = #{storeId}
|
|
AND `deleted_at` IS NULL
|
|
GROUP BY IFNULL(CAST(`gender` AS CHAR), 'UNKNOWN')
|
|
</select>
|
|
</mapper>
|