|
- <?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.iformall.mapper.WxCUserFromMapper">
- <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCUserFrom">
- <id column="id" jdbcType="BIGINT" property="id" />
- <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
- <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId"/>
- <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
-
- <result column="user_nick_name" jdbcType="VARCHAR" property="userNickName" />
- <result column="user_phone" jdbcType="VARCHAR" property="userPhone" />
-
- <result column="scene" jdbcType="VARCHAR" property="scene"/>
- <result column="scene_address" jdbcType="VARCHAR" property="sceneAddress"/>
-
- <result column="scene_address_desc" jdbcType="VARCHAR" property="sceneAddressDesc" />
-
- <result column="from_type" jdbcType="INTEGER" property="fromType" />
- <result column="from_id" jdbcType="BIGINT" property="fromId" />
-
- <result column="from_name" jdbcType="VARCHAR" property="fromName" />
-
- <result column="is_new_user" jdbcType="INTEGER" property="isNewUser" />
- <result column="share_user_type" jdbcType="INTEGER" property="shareUserType" />
- <result column="share_user" jdbcType="BIGINT" property="shareUser" />
-
- <result column="share_user_name" jdbcType="VARCHAR" property="shareUserName" />
-
- <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
-
- <result column="plat" jdbcType="INTEGER" property="plat" />
- </resultMap>
-
- <sql id="allColumns">
- wcuf.`id`,wcuf.`tenant_id`,wcuf.`parent_tenant_id`,wcuf.`c_user_id`,wcuf.`scene`,wcuf.`scene_address`,
- wcuf.`from_type`,wcuf.`from_id`,wcuf.`is_new_user`,wcuf.`share_user_type`,wcuf.`share_user`,wcuf.`create_date`,
- wcuf.`plat`
- </sql>
-
- <sql id="dynamicWhereConditions">
- where 1 = 1
- <if test=" null != id ">
- and wcuf.`id` = #{id}
- </if>
- <if test=" null != tenantId and '' != tenantId">
- and wcuf.`tenant_id` = #{tenantId}
- </if>
- <if test=" null != parentTenantId and '' != parentTenantId">
- and wcuf.`parent_tenant_id` = #{parentTenantId}
- </if>
- <if test=" null != cUserId ">
- and wcuf.`c_user_id` = #{cUserId}
- </if>
- <if test=" null != scene and '' != scene">
- and wcuf.`scene` = #{scene}
- </if>
- <if test=" null != sceneAddress and '' != sceneAddress">
- and wcuf.`scene_address` = #{sceneAddress}
- </if>
- <if test=" null != fromType ">
- and wcuf.`from_type` = #{fromType}
- </if>
- <if test=" null != fromId ">
- and wcuf.`from_id` = #{fromId}
- </if>
- <!--<if test=" null != isNewUser ">
- and wcuf.`is_new_user` = #{isNewUser}
- </if>-->
- <if test=" null != shareUserType ">
- and wcuf.`share_user_type` = #{shareUserType}
- </if>
- <if test=" null != shareUser ">
- and wcuf.`share_user` = #{shareUser}
- </if>
-
- <if test=" null != startDate ">
- and wcuf.`create_date` >= #{startDate}
- </if>
- <if test=" null != endDate">
- and wcuf.`create_date` <= #{endDate}
- </if>
- <if test=" null != plat">
- and wcuf.`plat` = #{plat}
- </if>
-
- <if test=" null != ids ">
- and wcuf.id in
- <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
- #{idItem}
- </foreach>
- </if>
-
- </sql>
-
- <select id="findList" parameterType="com.iformall.domain.po.WxCUserFrom" resultMap="BaseResultMap">
- select <include refid="allColumns" />
- ,wcu.nick_name user_nick_name
- ,wcu.phone user_phone
- ,wuc.description scene_address_desc
- from wx_c_user_from wcuf
- left join wx_c_user wcu on wcu.id = wcuf.c_user_id
- left join wx_user_channel wuc on wuc.scene_address = wcuf.scene_address
- <include refid="dynamicWhereConditions" />
- <if test=" null != isNewUser and isNewUser == 1">
- and wcuf.`is_new_user` = 1
- </if>
- <if test=" null != isNewUser and isNewUser == 0 ">
- and wcuf.c_user_id not in (select c_user_id from wx_c_user_from wcuf <include refid="dynamicWhereConditions" /> and wcuf.`is_new_user` = 1)
- </if>
- order by wcuf.`create_date` desc
- <if test=" null != begin ">
- limit #{begin}, #{limit}
- </if>
-
- <!-- select <include refid="allColumns" />-->
- <!-- ,(select nick_name from wx_c_user where id = wcuf.c_user_id ) user_nick_name-->
- <!-- ,(select description from wx_user_channel where scene_address = wcuf.scene_address ) scene_address_desc-->
- <!-- ,case when wcuf.from_type = 1 then (select nick_name from wx_c_user where id = wcuf.from_id)-->
- <!-- when wcuf.from_type = 2 then (select nick_name from wx_c_user_basic_info where id = wcuf.from_id)-->
- <!-- when wcuf.from_type = 3 then (select name from wx_merchant_b_user where id = wcuf.from_id)-->
- <!-- when wcuf.from_type = 4 then (select name from mall_user_info where id = wcuf.from_id)-->
- <!-- when wcuf.from_type = 5 then (select name from wx_merchant where id = wcuf.from_id)-->
- <!-- when wcuf.from_type = 6 then (select title from wx_coupon_channel where id = wcuf.from_id)-->
- <!-- when wcuf.from_type = 7 then (select title from wx_activity where id = wcuf.from_id)-->
- <!-- else '' end from_name-->
- <!-- ,case when wcuf.share_user_type = 1 then (select nick_name from wx_c_user where id = wcuf.share_user)-->
- <!-- when wcuf.share_user_type = 2 then (select nick_name from wx_c_user_basic_info where id = wcuf.share_user)-->
- <!-- when wcuf.share_user_type = 3 then (select name from wx_merchant_b_user where id = wcuf.share_user)-->
- <!-- when wcuf.share_user_type = 4 then (select name from mall_user_info where id = wcuf.share_user)-->
- <!-- else '' end share_user_name-->
- <!-- from wx_c_user_from wcuf-->
- <!-- <include refid="dynamicWhereConditions" />-->
- </select>
-
- <select id="visits" parameterType="com.iformall.domain.vo.WxCUserFromVo" resultType="com.iformall.domain.vo.WxCUserFromVo">
- select a.from_id fromId,a.from_type fromType,a.from_name fromName,a.from_phone fromPhone,IFNULL(a.visits,0) visits,IFNULL(b.reach_user,0) reachUser,IFNULL(c.new_user,0) newUser
- from (
- select wcuf.from_id,wcuf.from_type,
- <if test=" fromType == 2 ">wcubi.nick_name from_name,wcubi.phone from_phone,</if>
- <if test=" fromType == 5 ">wm.name from_name,wm.link_phone from_phone,</if>
- count(*) visits
- from wx_c_user_from wcuf
- <if test=" fromType == 2 ">left join wx_c_user_basic_info wcubi on wcuf.from_type = 2 and wcubi.id = wcuf.from_id</if>
- <if test=" fromType == 5 ">left join wx_merchant wm on wcuf.from_type = 5 and wm.id = wcuf.from_id</if>
- where wcuf.from_type = #{fromType}
- <if test=" null != tenantId and '' != tenantId">
- and wcuf.`tenant_id` = #{tenantId}
- </if>
- <if test=" null != parentTenantId and '' != parentTenantId">
- and wcuf.`parent_tenant_id` = #{parentTenantId}
- </if>
- <if test=" null != startDate ">
- and wcuf.`create_date` >= #{startDate}
- </if>
- <if test=" null != endDate">
- and wcuf.`create_date` <= #{endDate}
- </if>
- group by wcuf.from_id
- ) a
- left join (
- select wcuf.from_id,
- count(DISTINCT wcuf.c_user_id) reach_user
- from wx_c_user_from wcuf
- where wcuf.from_type = #{fromType}
- <if test=" null != tenantId and '' != tenantId">
- and wcuf.`tenant_id` = #{tenantId}
- </if>
- <if test=" null != parentTenantId and '' != parentTenantId">
- and wcuf.`parent_tenant_id` = #{parentTenantId}
- </if>
- <if test=" null != startDate ">
- and wcuf.`create_date` >= #{startDate}
- </if>
- <if test=" null != endDate">
- and wcuf.`create_date` <= #{endDate}
- </if>
- group by wcuf.from_id
- ) b on b.from_id = a.from_id
- left join (
- select wcuf.from_id,
- count(DISTINCT wcuf.c_user_id) new_user
- from wx_c_user_from wcuf
- where wcuf.from_type = #{fromType}
- and wcuf.is_new_user = 1
- <if test=" null != tenantId and '' != tenantId">
- and wcuf.`tenant_id` = #{tenantId}
- </if>
- <if test=" null != parentTenantId and '' != parentTenantId">
- and wcuf.`parent_tenant_id` = #{parentTenantId}
- </if>
- <if test=" null != startDate ">
- and wcuf.`create_date` >= #{startDate}
- </if>
- <if test=" null != endDate">
- and wcuf.`create_date` <= #{endDate}
- </if>
- group by wcuf.from_id
- ) c on c.from_id = a.from_id
- order by a.visits desc
- <if test=" null != begin ">
- limit #{begin}, #{limit}
- </if>
- </select>
-
- </mapper>
|