213 lines
11 KiB
XML
213 lines
11 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.stdiet.custom.mapper.SysCustomerMapper">
|
|
|
|
<resultMap type="SysCustomer" id="SysCustomerResult">
|
|
<result property="id" column="id"/>
|
|
<result property="name" column="name"/>
|
|
<result property="phone" column="phone"/>
|
|
<result property="email" column="email"/>
|
|
<result property="address" column="address"/>
|
|
<result property="payDate" column="pay_date"/>
|
|
<result property="startDate" column="start_date"/>
|
|
<result property="fansTime" column="fans_time"/>
|
|
<result property="fansChannel" column="fans_channel"/>
|
|
<result property="purchaseNum" column="purchase_num"/>
|
|
<result property="payTotal" column="pay_total"/>
|
|
<result property="chargePerson" column="charge_person"/>
|
|
<result property="followStatus" column="follow_status"/>
|
|
<result property="createTime" column="create_time"/>
|
|
<result property="createBy" column="create_by"/>
|
|
<result property="updateTime" column="update_time"/>
|
|
<result property="updateBy" column="update_by"/>
|
|
<result property="channelId" column="channel_id"/>
|
|
|
|
<result property="mainDietitian" column="main_dietitian"/>
|
|
<result property="assistantDietitian" column="assistant_dietitian"/>
|
|
<result property="afterDietitian" column="after_dietitian"/>
|
|
<result property="salesman" column="salesman"/>
|
|
<result property="onSaleId" column="on_sale_id" />
|
|
|
|
<association property="dietitianName" column="{id=main_dietitian}" select="selectUserName"/>
|
|
<association property="assDietitianName" column="{id=assistant_dietitian}" select="selectUserName"/>
|
|
<association property="afterDietitianName" column="{id=after_dietitian}" select="selectUserName"/>
|
|
<association property="salesName" column="{id=salesman}" select="selectUserName"/>
|
|
</resultMap>
|
|
|
|
<select id="selectUserName" parameterType="java.util.Map" resultType="String">
|
|
select nick_name from sys_user where user_id = #{id}
|
|
</select>
|
|
|
|
<sql id="selectSysCustomerVo">
|
|
select id, name, phone, email, fans_time, fans_channel, address, pay_date, start_date, purchase_num, pay_total, main_dietitian, assistant_dietitian, after_dietitian, salesman, on_sale_id, charge_person, follow_status, create_time, create_by, update_time, update_by, channel_id from sys_customer
|
|
</sql>
|
|
|
|
<sql id="searchLoginUserId">
|
|
<if test="loginUserId != null">
|
|
and (
|
|
sc.main_dietitian = #{loginUserId} or sc.assistant_dietitian = #{loginUserId} or sc.after_dietitian = #{loginUserId} or sc.salesman = #{loginUserId}
|
|
or sc.on_sale_id = #{loginUserId}
|
|
)
|
|
</if>
|
|
</sql>
|
|
|
|
<select id="selectSysCustomerList" parameterType="SysCustomer" resultMap="SysCustomerResult">
|
|
select
|
|
sc.id, sc.name, sc.phone, sc.email, sc.fans_time, sc.fans_channel, sc.address, sc.pay_date, sc.start_date,
|
|
sc.purchase_num, sc.pay_total, sc.main_dietitian,
|
|
sc.assistant_dietitian, sc.after_dietitian, sc.on_sale_id, sc.salesman, sc.charge_person, sc.follow_status,
|
|
sc.create_time,sc.channel_id
|
|
from sys_customer sc
|
|
left join sys_customer_healthy as sch
|
|
on sch.customer_id = sc.id and sch.del_flag = 0
|
|
where sc.del_flag = 0
|
|
<if test="name != null and name != ''">
|
|
and (sc.name like concat('%', #{name}, '%') or sc.phone like concat('%', #{name}, '%'))
|
|
</if>
|
|
<if test="mainDietitian != null and mainDietitian != ''">and sc.main_dietitian = #{mainDietitian}</if>
|
|
<if test="mainDietitian == 0">and (isnull(sc.main_dietitian) or sc.main_dietitian=0)</if>
|
|
<if test="salesman != null and salesman != ''">and sc.salesman = #{salesman}</if>
|
|
<if test="salesman == 0">and (isnull(sc.salesman) or sc.salesman=0)</if>
|
|
<if test="onSaleId != null">and sc.on_sale_id = #{onSaleId}</if>
|
|
<if test="afterDietitian != null and afterDietitian != ''">and sc.after_dietitian = #{afterDietitian}</if>
|
|
<if test="afterDietitian == 0">and (isnull(sc.after_dietitian) or sc.after_dietitian=0)</if>
|
|
<if test="assistantDietitian != null and assistantDietitian != ''">and sc.assistant_dietitian =
|
|
#{assistantDietitian}
|
|
</if>
|
|
<if test="assistantDietitian == 0">and (isnull(sc.assistant_dietitian) or sc.assistant_dietitian=0)</if>
|
|
<if test="fansChannel != null ">and sc.fans_channel = #{fansChannel}</if>
|
|
<if test="channelId != null ">and sc.channel_id = #{channelId}</if>
|
|
<if test="channels != null">
|
|
and sc.channel_id in
|
|
<foreach collection="channels" item="cn" separator="," open="(" close=")">
|
|
#{cn}
|
|
</foreach>
|
|
</if>
|
|
<if test="signIdList != null">
|
|
and (
|
|
sch.other_physical_signs like concat('%', #{physicalSignsId}, '%')
|
|
<foreach collection="signIdList " item="signId" index="index" open=" OR (" close=")" separator=" OR ">
|
|
FIND_IN_SET(#{signId}, sch.physical_signs_id)
|
|
</foreach>
|
|
)
|
|
</if>
|
|
<include refid="searchLoginUserId">
|
|
<property name="loginUserId" value="#{loginUserId}"/>
|
|
</include>
|
|
order by sc.create_time desc
|
|
</select>
|
|
|
|
<select id="selectSysCustomerById" parameterType="Long" resultMap="SysCustomerResult">
|
|
<include refid="selectSysCustomerVo"/>
|
|
where id = #{id} and del_flag = 0
|
|
</select>
|
|
|
|
<insert id="insertSysCustomer" parameterType="SysCustomer" useGeneratedKeys="true" keyProperty="id">
|
|
insert into sys_customer
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
<if test="name != null">name,</if>
|
|
<if test="phone != null">phone,</if>
|
|
<if test="fansTime != null">fans_time,</if>
|
|
<if test="fansChannel != null">fans_channel,</if>
|
|
<if test="email != null">email,</if>
|
|
<if test="address != null">address,</if>
|
|
<if test="payDate != null">pay_date,</if>
|
|
<if test="startDate != null">start_date,</if>
|
|
<if test="purchaseNum != null">purchase_num,</if>
|
|
<if test="payTotal != null">pay_total,</if>
|
|
<if test="mainDietitian != null">main_dietitian,</if>
|
|
<if test="assistantDietitian != null">assistant_dietitian,</if>
|
|
<if test="afterDietitian != null">after_dietitian,</if>
|
|
<if test="salesman != null">salesman,</if>
|
|
<if test="onSaleId != null">on_sale_id,</if>
|
|
<if test="chargePerson != null">charge_person,</if>
|
|
<if test="followStatus != null">follow_status,</if>
|
|
<if test="createTime != null">create_time,</if>
|
|
<if test="createBy != null">create_by,</if>
|
|
<if test="updateTime != null">update_time,</if>
|
|
<if test="updateBy != null">update_by,</if>
|
|
<if test="channelId != null">channel_id,</if>
|
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
<if test="name != null">#{name},</if>
|
|
<if test="phone != null">#{phone},</if>
|
|
<if test="fansTime != null">#{fansTime},</if>
|
|
<if test="fansChannel != null">#{fansChannel},</if>
|
|
<if test="email != null">#{email},</if>
|
|
<if test="address != null">#{address},</if>
|
|
<if test="payDate != null">#{payDate},</if>
|
|
<if test="startDate != null">#{startDate},</if>
|
|
<if test="purchaseNum != null">#{purchaseNum},</if>
|
|
<if test="payTotal != null">#{payTotal},</if>
|
|
<if test="mainDietitian != null">#{mainDietitian},</if>
|
|
<if test="assistantDietitian != null">#{assistantDietitian},</if>
|
|
<if test="afterDietitian != null">#{afterDietitian},</if>
|
|
<if test="salesman != null">#{salesman},</if>
|
|
<if test="onSaleId != null">#{onSaleId},</if>
|
|
<if test="chargePerson != null">#{chargePerson},</if>
|
|
<if test="followStatus != null">#{followStatus},</if>
|
|
<if test="createTime != null">#{createTime},</if>
|
|
<if test="createBy != null">#{createBy},</if>
|
|
<if test="updateTime != null">#{updateTime},</if>
|
|
<if test="updateBy != null">#{updateBy},</if>
|
|
<if test="channelId != null">#{channelId},</if>
|
|
</trim>
|
|
</insert>
|
|
|
|
<update id="updateSysCustomer" parameterType="SysCustomer">
|
|
update sys_customer
|
|
<trim prefix="SET" suffixOverrides=",">
|
|
<if test="name != null">name = #{name},</if>
|
|
<if test="phone != null">phone = #{phone},</if>
|
|
<if test="fansTime != null">fans_time = #{fansTime},</if>
|
|
<if test="fansChannel != null">fans_channel = #{fansChannel},</if>
|
|
<if test="email != null">email = #{email},</if>
|
|
<if test="address != null">address = #{address},</if>
|
|
<if test="payDate != null">pay_date = #{payDate},</if>
|
|
<if test="startDate != null">start_date = #{startDate},</if>
|
|
<if test="purchaseNum != null">purchase_num = #{purchaseNum},</if>
|
|
<if test="payTotal != null">pay_total = #{payTotal},</if>
|
|
<if test="mainDietitian != null">main_dietitian = #{mainDietitian},</if>
|
|
<if test="assistantDietitian != null">assistant_dietitian = #{assistantDietitian},</if>
|
|
<if test="afterDietitian != null">after_dietitian = #{afterDietitian},</if>
|
|
<if test="salesman != null">salesman = #{salesman},</if>
|
|
<if test="onSaleId != null">on_sale_id = #{onSaleId},</if>
|
|
<if test="chargePerson != null">charge_person = #{chargePerson},</if>
|
|
<if test="followStatus != null">follow_status = #{followStatus},</if>
|
|
<if test="createTime != null">create_time = #{createTime},</if>
|
|
<if test="createBy != null">create_by = #{createBy},</if>
|
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
|
<if test="channelId != null">channel_id = #{channelId},</if>
|
|
</trim>
|
|
where id = #{id}
|
|
</update>
|
|
|
|
<update id="deleteSysCustomerById" parameterType="Long">
|
|
update sys_customer set del_flag = 1 where id = #{id}
|
|
</update>
|
|
|
|
<update id="deleteSysCustomerByIds" parameterType="String">
|
|
update sys_customer set del_flag = 1 where id in
|
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
|
#{id}
|
|
</foreach>
|
|
</update>
|
|
|
|
<!-- 根据手机号查询客户 -->
|
|
<select id="getCustomerByPhone" parameterType="String" resultMap="SysCustomerResult">
|
|
<include refid="selectSysCustomerVo"/>
|
|
where phone = #{phone} and del_flag = 0
|
|
</select>
|
|
|
|
<!-- 根据openId查询客户 -->
|
|
<select id="getCustomerByOpenId" parameterType="String" resultMap="SysCustomerResult">
|
|
select sc.id from sys_customer sc
|
|
left join sys_wx_user_info wu on wu.phone = sc.phone
|
|
where wu.openid = #{openid} and sc.del_flag = 0 order by sc.id desc limit 1
|
|
</select>
|
|
|
|
|
|
</mapper> |