<?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"/>
    </resultMap>

    <select id="queryObject" resultType="com.kmall.admin.entity.GoodsIssueEntity">
		select
			`id`,
			`question`,
			`answer`
		from mall_goods_issue
		where id = #{id}
	</select>

    <select id="queryList" resultType="com.kmall.admin.entity.GoodsIssueEntity">
        select
        mall_goods_issue.id,
        mall_goods_issue.question,
        mall_goods_issue.answer
        from mall_goods_issue
        WHERE 1=1
        <if test="question != null and question.trim() != ''">
            AND mall_goods_issue.question LIKE concat('%',#{question},'%')
        </if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
            <otherwise>
                order by 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="question != null and question.trim() != ''">
            AND mall_goods_issue.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`)
		values(
			#{question},
			#{answer})
	</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>
        </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>