<?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.tmerclub.cloud.multishop.mapper.ShopTemplateMapper">
  <resultMap id="shopTemplateMap" type="com.tmerclub.cloud.multishop.model.ShopTemplate">
    <id column="template_id" property="templateId" />
    <result column="shop_id" property="shopId"/>
    <result column="name" property="name"/>
    <result column="content" property="content"/>
    <result column="image" property="image"/>
    <result column="type" property="type"/>
    <result column="remark" property="remark"/>
    <result column="create_time" property="createTime"/>
    <result column="update_time" property="updateTime"/>
  </resultMap>
  <sql id="Vo_Column_List">
    `template_id`,`shop_id`,`name`,`content`,`image`,`type`,`remark`,`create_time`,`update_time`
  </sql>
  <select id="list" resultMap="shopTemplateMap">
    select <include refid="Vo_Column_List"/>
    from shop_template
    where shop_id = #{shopTemplate.shopId} and type = #{shopTemplate.type}
    order by template_id desc
  </select>
  <select id="getByTemplateId" resultMap="shopTemplateMap">
    select <include refid="Vo_Column_List"/> from shop_template where template_id = #{templateId}
  </select>
  <insert id="save" useGeneratedKeys="true" keyProperty="shopTemplate.templateId">
    insert into shop_template (`shop_id`,`name`,`content`,`image`,`type`,`remark`)
    values (#{shopTemplate.shopId},#{shopTemplate.name},#{shopTemplate.content},#{shopTemplate.image},#{shopTemplate.type},#{shopTemplate.remark});
  </insert>
  <update id="update">
    update shop_template
    <set>
      <if test="shopTemplate.shopId != null">
        `shop_id` = #{shopTemplate.shopId},
      </if>
      <if test="shopTemplate.name != null">
        `name` = #{shopTemplate.name},
      </if>
      <if test="shopTemplate.content != null">
        `content` = #{shopTemplate.content},
      </if>
      <if test="shopTemplate.image != null">
        `image` = #{shopTemplate.image},
      </if>
      <if test="shopTemplate.type != null">
        `type` = #{shopTemplate.type},
      </if>
      <if test="shopTemplate.remark != null">
        `remark` = #{shopTemplate.remark},
      </if>
    </set>
    where template_id = #{shopTemplate.templateId}
  </update>
  <delete id="deleteById">
    delete from shop_template where template_id = #{templateId}
  </delete>

</mapper>
