<?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.SysPrinterDao">

    <resultMap type="com.kmall.admin.entity.SysPrinterEntity" id="sysPrinterMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="sn" column="sn"/>
        <result property="storeId" column="store_id"/>
    </resultMap>

	<select id="queryObject" resultType="com.kmall.admin.entity.SysPrinterEntity">
		select
			`id`,
			`name`,
			`sn`,
			`store_id`
		from sys_printer
		where id = #{id}
	</select>

	<select id="queryList" resultType="com.kmall.admin.entity.SysPrinterEntity">
		select
    		`id`,
    		`name`,
    		`sn`,
    		`store_id`
		from sys_printer
		WHERE 1=1
		<if test="storeId != null">
			AND store_id = #{storeId}
		</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 sys_printer
		WHERE 1=1
		<if test="storeId != null">
			AND store_id = #{storeId}
		</if>
	</select>
	 
	<insert id="save" parameterType="com.kmall.admin.entity.SysPrinterEntity" useGeneratedKeys="true" keyProperty="id">
		insert into sys_printer(
			`name`,
			`sn`,
			`store_id`)
		values(
			#{name},
			#{sn},
			#{storeId})
	</insert>
	 
	<update id="update" parameterType="com.kmall.admin.entity.SysPrinterEntity">
		update sys_printer 
		<set>
			<if test="name != null">`name` = #{name}, </if>
			<if test="sn != null">`sn` = #{sn}, </if>
			<if test="storeId != null">`store_id` = #{storeId}</if>
		</set>
		where id = #{id}
	</update>
	
	<delete id="delete">
		delete from sys_printer where id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from sys_printer where id in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>