<?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.ruixuan.salesLeads.mapper.SaleClueCallResultMapper">


	<!-- 保存通话记录 -->
	<insert id="addSaleCallResult">
		replace into sale_clue_call_result(
		`organization_id`,
		`organization_name`,
		`user_id`,
		`user_name`,
		`customer_id`,
		`customer_name`,
		`customer_phone`,
		`customer_company_name`,
		`label_type`,
		`started_at`,
		`duration`,
		`recordUrl`,
		`survey_id`,
		`survey_name`,
		`group_id`,
		`group_name`,
		`job_id`,
		`focus`,
		`content`,
		`create_time`
	)
		values
			(
			#{organizationId},
			#{organizationName},
			#{userId},
			#{userName},
			#{customerId},
			#{customerName},
			#{customerPhone},
			#{customerCompanyName},
			#{labelType},
			#{startedAt},
			#{duration},
			#{recordUrl},
			#{surveyId},
			#{surveyName},
			#{groupId},
			#{groupName},
			#{jobId},
			#{focus},
			#{content},
			NOW()
			)


	</insert>


<!-- 查询 通话记录-->
	<select id="getSaleClueCallResultList" resultType="com.ruixuan.salesLeads.pojo.SaleClueCallResultPojo">
		SELECT
			r.id,
			r.organization_id,
			r.organization_name,
			r.user_id,
			r.user_name,
			r.customer_id,
			r.customer_name,
			r.customer_phone,
			r.customer_company_name,
			r.label_type,
			r.started_at,
			r.duration,
			r.recordUrl,
			r.survey_id,
			r.survey_name,
			r.group_id,
			r.group_name,
			r.job_id,
			r.focus,
			r.content,
			r.create_time ,
			c.seller_id,
			c.seller_name,
			(SELECT name from sys_industry_info i where i.id = c.industry_id) industryName,
			(SELECT u.nick_name FROM sys_user u WHERE u.user_id = c.sale_id ) saleName,
			c.`state`
		FROM `ruixuan`.`sale_clue_call_result` r
		LEFT JOIN sale_clue_info c on c.telephone = r.customer_phone

		<where>
			<if test="createTime !=null and createTime != ''">
				and DATE_FORMAT(r.create_time,'%Y-%m-%d') = #{createTime}
			</if>
			<if test="state !=null and state != ''">
				and c.state = #{state}
			</if>
		</where>
		ORDER BY r.create_time DESC



	</select>



</mapper> 