<?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.cool.store.mapper.closeup.CloseUpPlatformMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.closeup.CloseUpPlatformDO">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="apply_id" jdbcType="BIGINT" property="applyId" />
    <result column="apply_type" jdbcType="TINYINT" property="applyType" />
    <result column="code" jdbcType="VARCHAR" property="code" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="status" jdbcType="TINYINT" property="status" />
    <result column="type" jdbcType="TINYINT" property="type" />
    <result column="task_start_date" jdbcType="DATE" property="taskStartDate" />
    <result column="icon" jdbcType="VARCHAR" property="icon" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  
  <insert id="insertBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO zxjp_close_up_platform(apply_id, apply_type, code, name, status, type, task_start_date, icon)
    VALUES
    <foreach collection="list" item="item" separator=",">
      (#{item.applyId}, #{item.applyType}, #{item.code}, #{item.name}, #{item.status}, #{item.type}, #{item.taskStartDate}, #{item.icon})
    </foreach>
  </insert>

  <select id="selectTodoApplyIds" resultType="java.lang.Long">
    SELECT DISTINCT apply_id FROM zxjp_close_up_platform a
    <if test="storeKeyword != null and storeKeyword != ''">
      LEFT JOIN zxjp_close_up_apply_form b ON a.apply_id = b.id
      LEFT JOIN store_${enterpriseId} c ON b.store_id = c.store_id
    </if>
    WHERE a.status = 0 AND a.task_start_date &lt;= now()
    <if test="applyType != null">
      AND a.apply_type = #{applyType}
    </if>
    <if test="storeKeyword != null and storeKeyword != ''">
        AND (c.store_name LIKE CONCAT('%', #{storeKeyword}, '%') OR c.store_num LIKE CONCAT('%', #{storeKeyword}, '%'))
    </if>
    ORDER BY a.create_time DESC
  </select>
</mapper>