<?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.moment.QwMomentPlanDataMapper">
    <resultMap type="com.gic.haoban.manage.service.entity.moment.TabQwMomentPlanData" id="result-map-tabHaobanQwMomentPlanData">
        <result column="data_id" javaType="long" jdbcType="BIGINT" property="dataId"/>
        <result column="plan_id" javaType="long" jdbcType="BIGINT" property="planId"/>
        <result column="wx_enterprise_id" javaType="String" jdbcType="CHAR" property="wxEnterpriseId"/>
        <result column="enterprise_id" javaType="String" jdbcType="CHAR" property="enterpriseId"/>
        <result column="staff_id" javaType="String" jdbcType="CHAR" property="staffId"/>
        <result column="clerk_id" javaType="String" jdbcType="CHAR" property="clerkId"/>
        <result column="store_id" javaType="String" jdbcType="CHAR" property="storeId"/>
        <result column="member_id" javaType="String" jdbcType="CHAR" property="memberId"/>
        <result column="create_time" javaType="java.util.Date" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" javaType="java.util.Date" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="delete_flag" javaType="int" jdbcType="INTEGER" property="deleteFlag"/>
        <result column="comment_time" javaType="java.util.Date" jdbcType="TIMESTAMP" property="commentTime"/>
        <result column="like_time" javaType="java.util.Date" jdbcType="TIMESTAMP" property="likeTime"/>
        <result column="comment_flag" javaType="int" jdbcType="INTEGER" property="commentFlag"/>
        <result column="like_flag" javaType="int" jdbcType="INTEGER" property="likeFlag"/>
    </resultMap>
    <sql id="Base_Column_List">
      data_id,
	  plan_id,
	  wx_enterprise_id,
	  enterprise_id,
	  staff_id,
	  clerk_id,
	  store_id,
	  member_id,
	  create_time,
	  update_time,
	  delete_flag,
	  comment_time,
	  like_time,
	  comment_flag,
	  like_flag
    </sql>

    <update id="delAll">
        update tab_haoban_qw_moment_plan_data set delete_flag = 1 where plan_id=#{planId} and clerk_id=#{clerkId} and delete_flag = 0
    </update>
    <!-- ===================== 新增 ======================== -->

    <select id="list" resultType="com.gic.haoban.manage.api.dto.moment.QwMomentPlanDataDTO"
            parameterType="com.gic.haoban.manage.api.qdto.moment.PlanDataListQDTO">
        select
        b.staff_name staffName ,
        a.data_id dataId,
        a.plan_id planId ,
        a.staff_id staffId ,
        a.clerk_id clerkId ,
        a.store_id storeId ,
        a.member_id memberId ,
        a.create_time createTime ,
        a.update_time updateTime ,
        a.comment_time commentTime ,
        a.like_time likeTime ,
        a.comment_flag commentFlag ,
        a.like_flag likeFlag ,
        a.clerk_code clerkCode ,
        a.clerk_name clerkName
        from tab_haoban_qw_moment_plan_data a left join tab_haoban_staff b on a.staff_id = b.staff_id where a.plan_id=#{planId} and a.delete_flag = 0
            <if test="null != staffNameLike">
                and b.staff_name  like #{staffNameLike}
            </if>
            <if test="null != clerkParamsLike">
                and (a.clerk_code like #{clerkParamsLike} or a.clerk_name like #{clerkParamsLike})
            </if>
            <if test="type==1">
                and a.like_flag = 1
                <if test="null != startTime">
                    and ( a.like_time >= #{startTime} and  a.like_time <![CDATA[ <= ]]> #{endTime} )
                </if>
                order by a.like_time desc
            </if>
            <if test="type==2">
                and a.comment_flag = 1
                <if test="null != startTime">
                    and ( a.comment_time >= #{startTime}  and  a.comment_time <![CDATA[ <= ]]> #{endTime} )
                </if>
                order by a.comment_time desc
            </if>

    </select>

    <update id="batchInsert">
        INSERT INTO tab_haoban_qw_moment_plan_data(
            data_id,
            plan_id,
            wx_enterprise_id,
            enterprise_id,
            staff_id,
            clerk_id,
            clerk_code ,
            clerk_name,
            store_id,
            member_id,
            comment_time,
            like_time,
            comment_flag,
            like_flag
        )VALUES

                <foreach collection="list" item="item" separator="," index="index">
                  (  #{item.dataId,jdbcType=BIGINT},
                    #{item.planId,jdbcType=BIGINT},
                    #{item.wxEnterpriseId,jdbcType=CHAR},
                    #{item.enterpriseId,jdbcType=CHAR},
                    #{item.staffId,jdbcType=CHAR},
                    #{item.clerkId,jdbcType=CHAR},
                    #{item.clerkCode},
                    #{item.clerkName},
                    #{item.storeId,jdbcType=CHAR},
                    #{item.memberId,jdbcType=CHAR},
                    #{item.commentTime,jdbcType=TIMESTAMP},
                    #{item.likeTime,jdbcType=TIMESTAMP},
                    #{item.commentFlag,jdbcType=INTEGER},
                    #{item.likeFlag,jdbcType=INTEGER} )
                </foreach>
    </update>

</mapper>