<?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.yami.shop.distribution.comment.dao.DistributionLevelSetMapper">
  <resultMap id="BaseResultMap" type="com.yami.shop.distribution.comment.model.DistributionLevelSet">
    <id column="level_set_id" jdbcType="BIGINT" property="levelSetId" />
    <result column="shop_id" jdbcType="BIGINT" property="shopId" />
    <result column="level_set_conditions_switch_json" jdbcType="VARCHAR" property="levelSetConditionsSwitchJson" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="modifier" jdbcType="BIGINT" property="modifier" />
    <result column="award_switch" jdbcType="TINYINT" property="awardSwitch" />
    <result column="parent_award_switch" jdbcType="TINYINT" property="parentAwardSwitch" />
    <result column="award_proportion" jdbcType="TINYINT" property="awardProportion" />
    <result column="is_auto_auditing" jdbcType="TINYINT" property="isAutoAuditing" />
  </resultMap>

  <resultMap id="DistributionLevelSet_DistributionLevel_DistributionAward" type="com.yami.shop.distribution.comment.model.DistributionLevelSet">
    <id column="level_set_id" jdbcType="BIGINT" property="levelSetId" />
    <result column="shop_id" jdbcType="BIGINT" property="shopId" />
      <result column="level_set_conditions_switch_json" jdbcType="VARCHAR" property="levelSetConditionsSwitchJson" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="modifier" jdbcType="BIGINT" property="modifier" />
    <result column="award_switch" jdbcType="TINYINT" property="awardSwitch" />
    <result column="parent_award_switch" jdbcType="TINYINT" property="parentAwardSwitch" />
    <result column="award_proportion" jdbcType="TINYINT" property="awardProportion" />
      <result column="is_auto_auditing" jdbcType="TINYINT" property="isAutoAuditing" />
    <collection property="distributionLevels" ofType="com.yami.shop.distribution.comment.model.DistributionLevel">
      <id column="level_id" jdbcType="BIGINT" property="levelId" />
      <result column="name" jdbcType="VARCHAR" property="name" />
      <result column="condition_data" jdbcType="VARCHAR" property="conditionData" />
      <result column="level" jdbcType="INTEGER" property="level" />
      <result column="state" jdbcType="TINYINT" property="state" />
        <result column="award_number" jdbcType="DECIMAL" property="awardNumber" />
        <result column="parent_award_number" jdbcType="DECIMAL" property="parentAwardNumber" />
    </collection>
  </resultMap>

  <select id="getDistributionLevelSetAndLevelByShopId" resultMap="DistributionLevelSet_DistributionLevel_DistributionAward">
      select
      dls.level_set_id,
      dls.shop_id,
      dls.level_set_conditions_switch_json,
      dls.update_time,
      dls.modifier,
      dls.award_switch,
      dls.parent_award_switch,
      dls.award_proportion,
      dl.level_id,
      dl.NAME,
      dl.condition_data,
      dl.LEVEL,
      dl.state,
      dl.award_number,
      dl.parent_award_number
    FROM
    tz_distribution_level_set dls
    LEFT JOIN tz_distribution_level dl on dl.shop_id=dls.shop_id
    WHERE
    dls.shop_id = #{shopId}
    ORDER BY
    LEVEL
  </select>

</mapper>