<?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.system.AgreementWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.system.pojo.Agreement">
    <id column="agreement_code" property="agreementCode" />
    <result column="web_site" property="webSite" />
    <result column="title" property="title" />
    <result column="update_time" property="updateTime" />
    <result column="update_admin_id" property="updateAdminId" />
    <result column="update_admin_name" property="updateAdminName" />
    <result column="content" property="content" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="agreementCode != null">
        `agreement_code`,
      </if>
      <if test="webSite != null">
        `web_site`,
      </if>
      <if test="title != null">
        `title`,
      </if>
      <if test="updateTime != null">
        `update_time`,
      </if>
      <if test="updateAdminId != null">
        `update_admin_id`,
      </if>
      <if test="updateAdminName != null">
        `update_admin_name`,
      </if>
      <if test="content != null">
        `content`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `agreement_code` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.agreementCodeNotEquals != null">
          AND `agreement_code` != #{example.agreementCodeNotEquals}
        </if>
        <if test="example.agreementCodeIn != null">
          AND `agreement_code` in (${example.agreementCodeIn})
        </if>
        <if test="example.webSite != null">
          AND `web_site` = #{example.webSite}
        </if>
        <if test="example.title != null">
          AND `title` = #{example.title}
        </if>
        <if test="example.titleLike != null">
          AND `title` like concat('%',#{example.titleLike},'%')
        </if>
        <if test="example.updateTimeAfter != null">
          AND `update_time` <![CDATA[ >= ]]> #{example.updateTimeAfter}
        </if>
        <if test="example.updateTimeBefore != null">
          AND `update_time` <![CDATA[ <= ]]> #{example.updateTimeBefore}
        </if>
        <if test="example.updateAdminId != null">
          AND `update_admin_id` = #{example.updateAdminId}
        </if>
        <if test="example.updateAdminName != null">
          AND `update_admin_name` = #{example.updateAdminName}
        </if>
        <if test="example.updateAdminNameLike != null">
          AND `update_admin_name` like concat('%',#{example.updateAdminNameLike},'%')
        </if>
        <if test="example.content != null">
          AND `content` = #{example.content}
        </if>
        <if test="example.contentLike != null">
          AND `content` like concat('%',#{example.contentLike},'%')
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `agreement_code` 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.system.example.AgreementExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `sys_agreement`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `sys_agreement`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `sys_agreement`
    <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 `sys_agreement`
    <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 `sys_agreement`
    <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 `sys_agreement`
    <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 `sys_agreement`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `sys_agreement`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="agreement_code" keyProperty="agreementCode" parameterType="com.slodon.b2b2c.system.pojo.Agreement" useGeneratedKeys="true">
    INSERT INTO `sys_agreement`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="agreementCode != null">
        #{agreementCode},
      </if>
      <if test="webSite != null">
        #{webSite},
      </if>
      <if test="title != null">
        #{title},
      </if>
      <if test="updateTime != null">
        #{updateTime},
      </if>
      <if test="updateAdminId != null">
        #{updateAdminId},
      </if>
      <if test="updateAdminName != null">
        #{updateAdminName},
      </if>
      <if test="content != null">
        #{content},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `sys_agreement`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.webSite != null">
        `web_site` = #{record.webSite},
      </if>
      <if test="record.title != null">
        `title` = #{record.title},
      </if>
      <if test="record.updateTime != null">
        `update_time` = #{record.updateTime},
      </if>
      <if test="record.updateAdminId != null">
        `update_admin_id` = #{record.updateAdminId},
      </if>
      <if test="record.updateAdminName != null">
        `update_admin_name` = #{record.updateAdminName},
      </if>
      <if test="record.content != null">
        `content` = #{record.content},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `sys_agreement`
    <trim prefix="SET" suffixOverrides=",">
      <if test="webSite != null">
        `web_site` = #{webSite},
      </if>
      <if test="title != null">
        `title` = #{title},
      </if>
      <if test="updateTime != null">
        `update_time` = #{updateTime},
      </if>
      <if test="updateAdminId != null">
        `update_admin_id` = #{updateAdminId},
      </if>
      <if test="updateAdminName != null">
        `update_admin_name` = #{updateAdminName},
      </if>
      <if test="content != null">
        `content` = #{content},
      </if>
    </trim>
    WHERE `agreement_code` = #{agreementCode}
  </update>
</mapper>