<?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.kmall.admin.dao.GoodsIssueDao">

    <resultMap type="com.kmall.admin.entity.GoodsIssueEntity" id="goodsIssueMap">
        <result property="id" column="id"/>
        <result property="question" column="question"/>
        <result property="answer" column="answer"/>
        <result property="merchSn" column="merch_sn"/>
        <result property="storeId" column="store_id"/>
        <result property="createrSn" column="creater_sn"/>
        <result property="createTime" column="create_time"/>
        <result property="moderSn" column="moder_sn"/>
        <result property="modTime" column="mod_time"/>
        <result property="tstm" column="tstm"/>
    </resultMap>

    <select id="queryObject" resultType="com.kmall.admin.entity.GoodsIssueEntity">
		select
			`id`,
			`question`,
			`answer`,
			`merch_sn`,
			`store_id`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`
		from mall_goods_issue
		where id = #{id}
	</select>

    <select id="queryList" resultType="com.kmall.admin.entity.GoodsIssueEntity">
        select
        f.id,
        f.question,
        f.answer,
        f.merch_sn,
        f.store_id,
        f.creater_sn,
        f.create_time,
        f.moder_sn,
        f.mod_time,
        f.tstm,
        s.store_name
        from mall_goods_issue f  left join mall_store s on f.store_id = s.id
        WHERE 1=1
        <if test="storeId != null and storeId != '' ">
            AND f.store_id = #{storeId}
        </if>
        <if test="merchSn != null and merchSn.trim() != '' ">
            AND f.merch_sn = #{merchSn}
        </if>
        <if test="question != null and question.trim() != ''">
            AND f.question LIKE concat('%',#{question},'%')
        </if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
            <otherwise>
                order by f.id desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="queryTotal" resultType="int">
        select count(*) from mall_goods_issue

        WHERE 1=1
        <if test="storeId != null and storeId != '' ">
            AND store_id = #{storeId}
        </if>
        <if test="merchSn != null and merchSn.trim() != '' ">
            AND merch_sn = #{merchSn}
        </if>
        <if test="question != null and question.trim() != ''">
            AND question LIKE concat('%',#{question},'%')
        </if>
    </select>

    <insert id="save" parameterType="com.kmall.admin.entity.GoodsIssueEntity" useGeneratedKeys="true" keyProperty="id">
		insert into mall_goods_issue(
			`question`,
			`answer`,
			`merch_sn`,
			`store_id`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`)
		values(
			#{question},
			#{answer},
			#{merchSn},
			#{storeId},
			#{createrSn},
			#{createTime},
			#{moderSn},
			#{modTime},
			#{tstm})
	</insert>

    <update id="update" parameterType="com.kmall.admin.entity.GoodsIssueEntity">
        update mall_goods_issue
        <set>
            <if test="question != null">`question` = #{question},</if>
            <if test="answer != null">`answer` = #{answer},</if>
            <if test="merchSn != null">`merch_sn` = #{merchSn}, </if>
            <if test="storeId != null">`store_id` = #{storeId}, </if>
            <if test="createrSn != null">`creater_sn` = #{createrSn}, </if>
            <if test="createTime != null">`create_time` = #{createTime}, </if>
            <if test="moderSn != null">`moder_sn` = #{moderSn}, </if>
            <if test="modTime != null">`mod_time` = #{modTime}, </if>
            <if test="tstm != null">`tstm` = #{tstm}</if>
        </set>
        where id = #{id}
    </update>

    <delete id="delete">
        delete from mall_goods_issue where id = #{value}
    </delete>

    <delete id="deleteBatch">
        delete from mall_goods_issue where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>