<?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.StockChangeReasonLangMapper">
  <resultMap id="stockChangeReasonLangMap" type="com.tmerclub.cloud.product.model.StockChangeReasonLang">
    <id column="stock_change_reason_id" property="stockChangeReasonId" />
    <result column="lang" property="lang"/>
    <result column="reason" property="reason"/>
    <result column="remark" property="remark"/>
  </resultMap>
  <sql id="Vo_Column_List">
    `stock_change_reason_id`,`lang`,`reason`,`remark`
  </sql>
  <select id="list" resultMap="stockChangeReasonLangMap">
    select <include refid="Vo_Column_List"/> from stock_change_reason_lang order by stock_change_reason_id desc
  </select>
  <select id="getByStockChangeReasonId" resultMap="stockChangeReasonLangMap">
    select <include refid="Vo_Column_List"/> from stock_change_reason_lang where stock_change_reason_id = #{stockChangeReasonId}
  </select>
    <select id="countReason" resultType="java.lang.Integer">
      select ifnull(count(1), 0)
      from stock_change_reason scr
      join stock_change_reason_lang scrl on scr.stock_change_reason_id = scrl.stock_change_reason_id
      <where>
        <if test="stockChangeReasonDTO.shopId != null">
          AND scr.shop_id = #{stockChangeReasonDTO.shopId}
        </if>
        <if test="stockChangeReasonDTO.reason != null">
          AND scrl.reason = #{stockChangeReasonDTO.reason}
        </if>
        <if test="stockChangeReasonDTO.type != null">
          AND scr.type = #{stockChangeReasonDTO.type}
        </if>
        <if test="stockChangeReasonDTO.stockChangeReasonId != null">
          AND scr.stock_change_reason_id != #{stockChangeReasonDTO.stockChangeReasonId}
        </if>
        AND scr.status > -1
      </where>
    </select>
    <insert id="save">
    insert into stock_change_reason_lang (`lang`,`reason`,`remark`, stock_change_reason_id)
    values (#{stockChangeReasonLang.lang},#{stockChangeReasonLang.reason},#{stockChangeReasonLang.remark}, #{stockChangeReasonLang.stockChangeReasonId}) ;
  </insert>
  <update id="update">
    update stock_change_reason_lang
    <set>
      <if test="stockChangeReasonLang.lang != null">
        `lang` = #{stockChangeReasonLang.lang},
      </if>
      <if test="stockChangeReasonLang.reason != null">
        `reason` = #{stockChangeReasonLang.reason},
      </if>
      <if test="stockChangeReasonLang.remark != null">
        `remark` = #{stockChangeReasonLang.remark},
      </if>
    </set>
    where stock_change_reason_id = #{stockChangeReasonLang.stockChangeReasonId}
  </update>
  <delete id="deleteById">
    delete from stock_change_reason_lang where stock_change_reason_id = #{stockChangeReasonId}
  </delete>

</mapper>
