<?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.StoreMapper">
  <select id="pageList" resultType="com.chushang.inspection.terminal.vo.StoreVO">
      SELECT s.store_id         AS storeId,
             s.store_no         AS storeNo,
             s.store_name       AS storeName,
             s.shop_name        AS shopName,
             s.special_num      AS specialNum,
             s.store_phone      AS storePhone,
             s.store_address    AS storeAddress,
             s.store_type       AS storeType,
             s.products         AS products,
             s.tip_tool         AS tipTool,
             s.register_time    AS registerTime,
             s.account_phone    AS accountPhone,
             s.account_manager  AS accountManager,
             s.register_address AS registerAddress,
             s.legal_name       AS legalName,
             s.create_by        AS createBy,
             s.create_time      AS createTime,
             s.dept_id          AS deptId,
             s.state     AS storeStatus,
             pt1.`name`         AS taskName,
             pt2.`name`         AS totalTaskName,
            (select COUNT(*) from st_terminal where s.del_state = 0 AND s.store_id = store_id) AS countTerminal
      FROM `st_store` s
               LEFT JOIN ta_polling_task pt1 ON s.task_id = pt1.id
               LEFT JOIN ta_polling_task pt2 ON s.lower_task_id = pt2.id
               LEFT JOIN st_terminal t ON s.store_id = t.store_id
      WHERE s.del_state = 0
      <if test="1 == 1">
          ${query.sqlParam.get('sqlWhere')}
      </if>
      <if test="1 == 1">
          ${query.sqlParam.get('dataScope')}
      </if>
      ORDER BY #{query.orderBy} #{query.isAsc}
  </select>
</mapper>
