<?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.decoration.ShopDecorationAssignMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.decoration.ShopDecorationAssignDO">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="shop_id" jdbcType="BIGINT" property="shopId" />
    <result column="decoration_desc_status" jdbcType="TINYINT" property="decorationDescStatus" />
    <result column="decoration_team_id" jdbcType="BIGINT" property="decorationTeamId" />
    <result column="created_time" jdbcType="TIMESTAMP" property="createdTime" />
    <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime" />
  </resultMap>

  <select id="countByTeamId" resultType="java.lang.Integer">
    select count(1) from zxjp_shop_decoration_assign where decoration_team_id = #{teamId}
  </select>


  <select id="listByCondition" resultType="com.cool.store.dto.decoration.DecorationListDTO">
    SELECT
      zsda.id as id ,
      zsda.shop_id AS shopId,
      zsda.decoration_desc_status as decorationDescStatus,
      zsda.decoration_team_id as teamId,
      xsi.shop_name AS shopName,
      xsi.shop_code AS shopCode,
      xsi.region_id AS regionId,
      xsi.province AS province,
      xsi.city AS city,
      xsi.district AS district,
      xsi.detail_address AS detailAddress,
      xsi.store_type AS storeType,
      xsf.sign_type AS signType
    FROM zxjp_shop_decoration_assign zsda
    LEFT JOIN xfsg_shop_info xsi ON zsda.shop_id = xsi.id
    LEFT JOIN xfsg_sign_franchise xsf ON zsda.shop_id = xsf.shop_id
    <where>
      <if test="keyword != null and keyword != ''">
        AND (xsi.shop_name LIKE CONCAT('%', #{keyword}, '%') OR xsi.shop_code LIKE CONCAT('%', #{keyword}, '%'))
      </if>
      <if test="storeType != null">
        AND xsi.store_type = #{storeType}
      </if>
      <if test="signType != null">
        AND xsf.sign_type = #{signType}
      </if>
      <if test="regionId != null">
        AND xsi.region_id = #{regionId}
      </if>
      <if test="decorationDescStatus != null">
        AND zsda.decoration_desc_status = #{decorationDescStatus}
      </if>
      <if test="teamId != null">
        AND zsda.decoration_team_id = #{teamId}
      </if>
      <if test="wantShopAreaIds != null and wantShopAreaIds.size() > 0">
        and b.want_shop_area_id in
        <foreach collection="wantShopAreaIds" item="item" separator="," open="(" close=")">
          #{item}
        </foreach>
      </if>
    </where>
    order by decoration_desc_status asc , updated_time desc
  </select>





</mapper>