<?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.slodon.b2b2c.dao.write.promotion.CouponPackageWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.promotion.pojo.CouponPackage">
    <id column="package_id" property="packageId" />
    <result column="package_name" property="packageName" />
    <result column="description" property="description" />
    <result column="package_type" property="packageType" />
    <result column="received_num" property="receivedNum" />
    <result column="publish_num" property="publishNum" />
    <result column="publish_start_time" property="publishStartTime" />
    <result column="publish_end_time" property="publishEndTime" />
    <result column="state" property="state" />
    <result column="store_id" property="storeId" />
    <result column="store_name" property="storeName" />
    <result column="create_time" property="createTime" />
    <result column="create_user_id" property="createUserId" />
    <result column="create_user" property="createUser" />
    <result column="coupon_ids" property="couponIds" />
    <result column="theme_color" property="themeColor" />
    <result column="pc_act_diagram" property="pcActDiagram" />
    <result column="app_act_diagram" property="appActDiagram" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="packageName != null">
        `package_name`,
      </if>
      <if test="description != null">
        `description`,
      </if>
      <if test="packageType != null">
        `package_type`,
      </if>
      <if test="receivedNum != null">
        `received_num`,
      </if>
      <if test="publishNum != null">
        `publish_num`,
      </if>
      <if test="publishStartTime != null">
        `publish_start_time`,
      </if>
      <if test="publishEndTime != null">
        `publish_end_time`,
      </if>
      <if test="state != null">
        `state`,
      </if>
      <if test="storeId != null">
        `store_id`,
      </if>
      <if test="storeName != null">
        `store_name`,
      </if>
      <if test="createTime != null">
        `create_time`,
      </if>
      <if test="createUserId != null">
        `create_user_id`,
      </if>
      <if test="createUser != null">
        `create_user`,
      </if>
      <if test="couponIds != null">
        `coupon_ids`,
      </if>
      <if test="themeColor != null">
        `theme_color`,
      </if>
      <if test="pcActDiagram != null">
        `pc_act_diagram`,
      </if>
      <if test="appActDiagram != null">
        `app_act_diagram`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `package_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.packageIdNotEquals != null">
          AND `package_id` != #{example.packageIdNotEquals}
        </if>
        <if test="example.packageIdIn != null">
          AND `package_id` in (${example.packageIdIn})
        </if>
        <if test="example.packageName != null">
          AND `package_name` = #{example.packageName}
        </if>
        <if test="example.packageNameLike != null">
          AND `package_name` like concat('%',#{example.packageNameLike},'%')
        </if>
        <if test="example.description != null">
          AND `description` = #{example.description}
        </if>
        <if test="example.packageType != null">
          AND `package_type` = #{example.packageType}
        </if>
        <if test="example.receivedNum != null">
          AND `received_num` = #{example.receivedNum}
        </if>
        <if test="example.publishNum != null">
          AND `publish_num` = #{example.publishNum}
        </if>
        <if test="example.publishStartTimeAfter != null">
          AND `publish_start_time` <![CDATA[ >= ]]> #{example.publishStartTimeAfter}
        </if>
        <if test="example.publishStartTimeBefore != null">
          AND `publish_start_time` <![CDATA[ <= ]]> #{example.publishStartTimeBefore}
        </if>
        <if test="example.publishEndTimeAfter != null">
          AND `publish_end_time` <![CDATA[ >= ]]> #{example.publishEndTimeAfter}
        </if>
        <if test="example.publishEndTimeBefore != null">
          AND `publish_end_time` <![CDATA[ <= ]]> #{example.publishEndTimeBefore}
        </if>
        <if test="example.state != null">
          AND `state` = #{example.state}
        </if>
        <if test="example.storeId != null">
          AND `store_id` = #{example.storeId}
        </if>
        <if test="example.storeName != null">
          AND `store_name` = #{example.storeName}
        </if>
        <if test="example.storeNameLike != null">
          AND `store_name` like concat('%',#{example.storeNameLike},'%')
        </if>
        <if test="example.createTimeAfter != null">
          AND `create_time` <![CDATA[ >= ]]> #{example.createTimeAfter}
        </if>
        <if test="example.createTimeBefore != null">
          AND `create_time` <![CDATA[ <= ]]> #{example.createTimeBefore}
        </if>
        <if test="example.createUserId != null">
          AND `create_user_id` = #{example.createUserId}
        </if>
        <if test="example.createUser != null">
          AND `create_user` = #{example.createUser}
        </if>
        <if test="example.couponIds != null">
          AND `coupon_ids` = #{example.couponIds}
        </if>
        <if test="example.themeColor != null">
          AND `theme_color` = #{example.themeColor}
        </if>
        <if test="example.pcActDiagram != null">
          AND `pc_act_diagram` = #{example.pcActDiagram}
        </if>
        <if test="example.appActDiagram != null">
          AND `app_act_diagram` = #{example.appActDiagram}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `package_id` DESC
  </sql>
  <sql id="orderByOther">
    order by ${example.orderBy}
  </sql>
  <!--分组条件-->
  <sql id="groupBy">
    group by ${example.groupBy}
  </sql>
  <!--分页条件-->
  <sql id="limit">
    <if test="size != null and size &gt; 0">
      limit #{startRow},#{size}
    </if>
  </sql>
  <!--查询符合条件的记录数-->
  <select id="countByExample" parameterType="com.slodon.b2b2c.promotion.example.CouponPackageExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `promotion_coupon_package`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_coupon_package`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_coupon_package`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(所有字段)-->
  <select id="listPageByExample" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_coupon_package`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--查询符合条件的记录(指定字段)-->
  <select id="listFieldsByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `promotion_coupon_package`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(指定字段)-->
  <select id="listFieldsPageByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `promotion_coupon_package`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--根据条件删除记录，可多条删除-->
  <delete id="deleteByExample">
    DELETE FROM `promotion_coupon_package`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `promotion_coupon_package`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="package_id" keyProperty="packageId" parameterType="com.slodon.b2b2c.promotion.pojo.CouponPackage" useGeneratedKeys="true">
    INSERT INTO `promotion_coupon_package`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="packageName != null">
        #{packageName},
      </if>
      <if test="description != null">
        #{description},
      </if>
      <if test="packageType != null">
        #{packageType},
      </if>
      <if test="receivedNum != null">
        #{receivedNum},
      </if>
      <if test="publishNum != null">
        #{publishNum},
      </if>
      <if test="publishStartTime != null">
        #{publishStartTime},
      </if>
      <if test="publishEndTime != null">
        #{publishEndTime},
      </if>
      <if test="state != null">
        #{state},
      </if>
      <if test="storeId != null">
        #{storeId},
      </if>
      <if test="storeName != null">
        #{storeName},
      </if>
      <if test="createTime != null">
        #{createTime},
      </if>
      <if test="createUserId != null">
        #{createUserId},
      </if>
      <if test="createUser != null">
        #{createUser},
      </if>
      <if test="couponIds != null">
        #{couponIds},
      </if>
      <if test="themeColor != null">
        #{themeColor},
      </if>
      <if test="pcActDiagram != null">
        #{pcActDiagram},
      </if>
      <if test="appActDiagram != null">
        #{appActDiagram},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `promotion_coupon_package`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.packageName != null">
        `package_name` = #{record.packageName},
      </if>
      <if test="record.description != null">
        `description` = #{record.description},
      </if>
      <if test="record.packageType != null">
        `package_type` = #{record.packageType},
      </if>
      <if test="record.receivedNum != null">
        `received_num` = #{record.receivedNum},
      </if>
      <if test="record.publishNum != null">
        `publish_num` = #{record.publishNum},
      </if>
      <if test="record.publishStartTime != null">
        `publish_start_time` = #{record.publishStartTime},
      </if>
      <if test="record.publishEndTime != null">
        `publish_end_time` = #{record.publishEndTime},
      </if>
      <if test="record.state != null">
        `state` = #{record.state},
      </if>
      <if test="record.storeId != null">
        `store_id` = #{record.storeId},
      </if>
      <if test="record.storeName != null">
        `store_name` = #{record.storeName},
      </if>
      <if test="record.createTime != null">
        `create_time` = #{record.createTime},
      </if>
      <if test="record.createUserId != null">
        `create_user_id` = #{record.createUserId},
      </if>
      <if test="record.createUser != null">
        `create_user` = #{record.createUser},
      </if>
      <if test="record.couponIds != null">
        `coupon_ids` = #{record.couponIds},
      </if>
      <if test="record.themeColor != null">
        `theme_color` = #{record.themeColor},
      </if>
      <if test="record.pcActDiagram != null">
        `pc_act_diagram` = #{record.pcActDiagram},
      </if>
      <if test="record.appActDiagram != null">
        `app_act_diagram` = #{record.appActDiagram},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `promotion_coupon_package`
    <trim prefix="SET" suffixOverrides=",">
      <if test="packageName != null">
        `package_name` = #{packageName},
      </if>
      <if test="description != null">
        `description` = #{description},
      </if>
      <if test="packageType != null">
        `package_type` = #{packageType},
      </if>
      <if test="receivedNum != null">
        `received_num` = #{receivedNum},
      </if>
      <if test="publishNum != null">
        `publish_num` = #{publishNum},
      </if>
      <if test="publishStartTime != null">
        `publish_start_time` = #{publishStartTime},
      </if>
      <if test="publishEndTime != null">
        `publish_end_time` = #{publishEndTime},
      </if>
      <if test="state != null">
        `state` = #{state},
      </if>
      <if test="storeId != null">
        `store_id` = #{storeId},
      </if>
      <if test="storeName != null">
        `store_name` = #{storeName},
      </if>
      <if test="createTime != null">
        `create_time` = #{createTime},
      </if>
      <if test="createUserId != null">
        `create_user_id` = #{createUserId},
      </if>
      <if test="createUser != null">
        `create_user` = #{createUser},
      </if>
      <if test="couponIds != null">
        `coupon_ids` = #{couponIds},
      </if>
      <if test="themeColor != null">
        `theme_color` = #{themeColor},
      </if>
      <if test="pcActDiagram != null">
        `pc_act_diagram` = #{pcActDiagram},
      </if>
      <if test="appActDiagram != null">
        `app_act_diagram` = #{appActDiagram},
      </if>
    </trim>
    WHERE `package_id` = #{packageId}
  </update>
</mapper>