<?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.product.mapper.StockChangeReasonStatusMapper">
  <resultMap id="stockChangeReasonStatusMap" type="com.tmerclub.cloud.product.model.StockChangeReasonStatus">
    <id column="stock_change_reason_status_id" property="stockChangeReasonStatusId" />
    <result column="stock_change_reason_id" property="stockChangeReasonId"/>
    <result column="status" property="status"/>
    <result column="shop_id" property="shopId"/>
  </resultMap>
  <sql id="Vo_Column_List">
    `stock_change_reason_status_id`,`stock_change_reason_id`,`status`,`shop_id`
  </sql>
  <select id="list" resultMap="stockChangeReasonStatusMap">
    select <include refid="Vo_Column_List"/> from stock_change_reason_status order by stock_change_reason_status_id desc
  </select>
  <select id="getByStockChangeReasonStatusId" resultMap="stockChangeReasonStatusMap">
    select <include refid="Vo_Column_List"/> from stock_change_reason_status where stock_change_reason_status_id = #{stockChangeReasonStatusId}
  </select>

  <select id="getStatusByShopIdAndReasonId"
            resultType="com.tmerclub.cloud.product.model.StockChangeReasonStatus">
    SELECT
      *
    FROM
      stock_change_reason_status
    WHERE
      shop_id = #{shopId}
      AND stock_change_reason_id = #{reasonId}
  </select>
    <insert id="save">
    insert into stock_change_reason_status (`stock_change_reason_id`,`status`,`shop_id`)
    values (#{stockChangeReasonStatus.stockChangeReasonId},#{stockChangeReasonStatus.status},#{stockChangeReasonStatus.shopId});
  </insert>
  <update id="update">
    update stock_change_reason_status
    <set>
      <if test="stockChangeReasonStatus.status != null">
        `status` = #{stockChangeReasonStatus.status},
      </if>
    </set>
    where stock_change_reason_status_id = #{stockChangeReasonStatus.stockChangeReasonStatusId} and `shop_id` = #{stockChangeReasonStatus.shopId}
  </update>
  <delete id="deleteById">
    delete from stock_change_reason_status where stock_change_reason_status_id = #{stockChangeReasonStatusId}
  </delete>

</mapper>
