<?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.ShopRenovationMapper">
  <resultMap id="shopRenovationMap" type="com.tmerclub.cloud.multishop.model.ShopRenovation">
    <id column="renovation_id" property="renovationId" />
    <result column="shop_id" property="shopId"/>
    <result column="name" property="name"/>
    <result column="content" property="content"/>
    <result column="home_status" property="homeStatus"/>
    <result column="renovation_type" property="renovationType"/>
    <result column="create_time" property="createTime"/>
    <result column="update_time" property="updateTime"/>
  </resultMap>
  <sql id="Vo_Column_List">
    `renovation_id`,`shop_id`,`name`,`content`,`home_status`,`renovation_type`,`create_time`,`update_time`
  </sql>
  <select id="list" resultMap="shopRenovationMap">
    select <include refid="Vo_Column_List"/>
    from shop_renovation
    where shop_id = #{shopRenovation.shopId}
    <if test="shopRenovation.renovationType != null">
      and renovation_type = #{shopRenovation.renovationType}
    </if>
    <if test="shopRenovation.homeStatus != null">
      and home_status = #{shopRenovation.homeStatus}
    </if>
    <if test="shopRenovation.name != null and shopRenovation.name != ''">
      AND name like CONCAT( '%', #{shopRenovation.name}, '%')
    </if>
    order by home_status desc, create_time desc
  </select>
  <select id="getByRenovationId" resultMap="shopRenovationMap">
    select <include refid="Vo_Column_List"/> from shop_renovation where renovation_id = #{renovationId}
  </select>
  <select id="getByShopIdAndRenovationType" resultMap="shopRenovationMap">
    select <include refid="Vo_Column_List"/>
    from shop_renovation
    where shop_id = #{shopId} and renovation_type = #{renovationType} and home_status = 1
  </select>
  <insert id="save" useGeneratedKeys="true" keyProperty="shopRenovation.renovationId">
    insert into shop_renovation (`shop_id`,`name`,`content`,`home_status`,`renovation_type`)
    values (#{shopRenovation.shopId},#{shopRenovation.name},#{shopRenovation.content},#{shopRenovation.homeStatus},#{shopRenovation.renovationType});
  </insert>
  <update id="update">
    update shop_renovation
    <set>
      <if test="shopRenovation.shopId != null">
        `shop_id` = #{shopRenovation.shopId},
      </if>
      <if test="shopRenovation.name != null">
        `name` = #{shopRenovation.name},
      </if>
      <if test="shopRenovation.content != null">
        `content` = #{shopRenovation.content},
      </if>
      <if test="shopRenovation.homeStatus != null">
        `home_status` = #{shopRenovation.homeStatus},
      </if>
      <if test="shopRenovation.renovationType != null">
        `renovation_type` = #{shopRenovation.renovationType},
      </if>
    </set>
    where renovation_id = #{shopRenovation.renovationId}
  </update>
  <delete id="deleteById">
    delete from shop_renovation where renovation_id = #{renovationId}
  </delete>
  <update id="updateHomeStatus">
    update shop_renovation
    set `home_status` = 0
    where renovation_type = #{renovationType} and shop_id = #{shopId} and home_status = 1
  </update>
</mapper>
