<?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.chushang.inspection.terminal.mapper.FiveStoreMapper">
  <resultMap id="BaseResultMap" type="com.chushang.inspection.terminal.po.FiveStore">
    <!--@mbg.generated-->
    <!--@Table st_five_store-->
    <id column="five_id" jdbcType="BIGINT" property="fiveId" />
    <result column="terminal_id" jdbcType="BIGINT" property="terminalId" />
    <result column="store_id" jdbcType="BIGINT" property="storeId" />
    <result column="dept_id" jdbcType="BIGINT" property="deptId" />
    <result column="first_level_branch" jdbcType="BIGINT" property="firstLevelBranch" />
    <result column="secondary_branches" jdbcType="BIGINT" property="secondaryBranches" />
    <result column="new_year" jdbcType="TINYINT" property="newYear" />
    <result column="new_month" jdbcType="TINYINT" property="newMonth" />
    <result column="new_day" jdbcType="TINYINT" property="newDay" />
    <result column="client_name" jdbcType="VARCHAR" property="clientName" />
    <result column="customer_id" jdbcType="TINYINT" property="customerId" />
    <result column="marketing_date" jdbcType="TIMESTAMP" property="marketingDate" />
    <result column="consumption_date" jdbcType="TIMESTAMP" property="consumptionDate" />
    <result column="marketer" jdbcType="VARCHAR" property="marketer" />
    <result column="version" jdbcType="BIGINT" property="version" />
    <result column="del_state" jdbcType="BOOLEAN" property="delState" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    five_id, terminal_id, store_id, dept_id, first_level_branch, secondary_branches,
    new_year, new_month,new_day, client_name, customer_id, marketing_date,
    consumption_date, marketer, version, del_state, create_by, create_time, update_by,
    update_time
  </sql>

  <select id="pageList" resultType="com.chushang.inspection.terminal.vo.FiveStoreVO">
      SELECT t.terminal_id         AS terminalId,
             fs.five_id            AS fiveId,
             fs.first_level_branch AS firstLevelBranch,
             fs.secondary_branches AS secondaryBranch,
             t.terminal_no         AS terminalNo,
             fs.store_id           AS storeId,
             t.store_no            AS storeNo,
             fs.new_year           AS logoOfNewlySignedMerchantsThatYear,
             fs.new_month          AS logoOfNewlySignedMerchantsOfTheMonth,
             fs.new_day            AS logoOfNewlySignedMerchantsOnTheDay,
             fs.client_name        AS clientName,
             fs.marketing_date     AS marketingDate,
             fs.consumption_date   AS consumptionDate,
             fs.marketer           AS marketer
      FROM st_terminal t
               LEFT JOIN st_five_store fs ON t.terminal_id = fs.terminal_id
      WHERE t.del_state = 0
      <if test="query.terminalNo != null and query.terminalNo != ''">
          AND t.terminal_no = #{query.terminalNo}
      </if>
      <if test="query.no != null and query.no != ''">
          AND t.store_no = #{query.no}
      </if>
      <if test="query.firstLevelBranch != null">
          AND fs.first_level_branch = #{query.firstLevelBranch}
      </if>
      <if test="query.secondaryBranches != null and query.secondaryBranches.size() > 0">
          AND fs.secondary_branches IN
          <foreach collection="query.secondaryBranches" item="item" index="index" open="(" close=")" separator=",">
              #{item}
          </foreach>
      </if>
      <if test="1 == 1">
          ${query.sqlParam.get('dataScpoe')}
      </if>
      ORDER BY t.${query.orderBy} ${query.isAsc}
  </select>
</mapper>
