<?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.gic.haoban.manage.service.dao.mapper.chat.GroupChatPlanLogMapper">
  <resultMap type="com.gic.haoban.manage.service.entity.chat.TabGroupChatPlanLog" id="result-map-tabHaobanGroupChatPlanLog">
      <result column="log_id"  property="logId"/>
      <result column="plan_id"  property="planId"/>
      <result column="wx_enterprise_id"  property="wxEnterpriseId"/>
      <result column="enterprise_id" property="enterpriseId"/>
      <result column="group_chat_id"  property="groupChatId"/>
      <result column="send_status"  property="sendStatus"/>
      <result column="own_log_id"  property="ownLogId"/>
      <result column="remark"  property="remark"/>
      <result column="send_time"  property="sendTime"/>
      <result column="create_time"  property="createTime"/>
      <result column="update_time"  property="updateTime"/>
      <result column="delete_flag" property="deleteFlag"/>
      <result column="staff_id" property="staffId"/>
  </resultMap>
  <sql id="Base_Column_List">
	  log_id,
	  plan_id,
	  wx_enterprise_id,
	  enterprise_id,
	  group_chat_id,
	  send_status,
	  own_log_id,
	  remark,
	  send_time,
	  delete_flag,
	  create_time,
	  update_time , staff_id
	  
  </sql>
  <!-- ===================== 新增 ======================== -->
  <insert id="batchInsert">
	  INSERT INTO tab_haoban_group_chat_plan_log(
		  log_id,
		  plan_id,
		  wx_enterprise_id,
		  enterprise_id,
		  group_chat_id,
		  send_status,
		  own_log_id,
		  remark,
		  send_time,
		  delete_flag,
		  create_time,
		  update_time , staff_id 
	  )VALUES
	  <foreach collection="list" item="item" separator=","  >
		  (
			  #{item.logId},
			  #{item.planId},
			  #{item.wxEnterpriseId},
			  #{item.enterpriseId} ,
			  #{item.groupChatId},
			  #{item.sendStatus},
			  #{item.ownLogId},
			  #{item.remark},
			  #{item.sendTime},
			  0,
			  now(),
			  now() ,
			  #{item.staffId}
		  )
	  </foreach>
  </insert>
  
  
  
  
  <select id="listPlanLog"  parameterType="com.gic.haoban.manage.api.dto.qdto.chat.GroupChatPlanSearchQDTO" resultType="com.gic.haoban.manage.api.dto.chat.GroupChatPlanLogDTO">
  	 SELECT	  b.clerk_id clerkId , 
              b.store_id storeId ,
	          d.name chatName , 
	          d.total_count chatTotalCount ,
              c.staff_name staffName , 
	          a.staff_id staffId ,
			  a.group_chat_id groupChatId,
			  a.send_status sendStatus,
			  a.send_time sendTime ,
			  a.create_time createTime ,
			  d.wx_chat_id wxChatId 
		  FROM tab_haoban_group_chat_plan_log a 
		  LEFT JOIN tab_haoban_group_chat_plan_owner_log b ON a.`own_log_id` = b.`owner_log_id` 
          LEFT JOIN tab_haoban_staff c      ON   a.`staff_id` = c.`staff_id` 
          LEFT JOIN tab_haoban_group_chat d ON   a.group_chat_id = d.group_chat_id
  	  where a.wx_enterprise_id = #{wxEnterpriseId} and a.plan_id = #{planId} 
  	  <if test="null != ownLogId">
  	  	and a.own_log_id = #{ownLogId}
  	  </if>
  	  <if test="null != searchParams and ''!=searchParams">
  	  	and c.staff_name like #{searchParams}
  	  </if>
  	  <if test="null !=chatName and '' !=chatName">
  	  	 and (d.name like #{chatName} or d.wx_chat_id like #{wxChatId}
  	  </if>
  	  <if test="null !=sendStatus">
  	  	<if test="sendStatus==30">
			and a.send_status in (0,3)
		</if>
		<if test="sendStatus != 30">
		   and a.send_status = #{sendStatus}
		</if>
  	  </if>

  	  <if test="null != startDate">
			and a.create_time <![CDATA[>=]]>	#{startDate} and a.create_time <![CDATA[<=]]> #{endDate}
	  </if>
  </select>
</mapper> 