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

    <resultMap type="com.kmall.admin.entity.SysCusUnitCodeEntity" id="sysCusUnitCodeMap">
        <result property="sn" column="sn"/>
        <result property="code" column="code"/>
        <result property="name" column="name"/>
        <result property="remark" column="remark"/>
        <result property="isValid" column="is_valid"/>
        <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.SysCusUnitCodeEntity">
		select
			`sn`,
			`code`,
			`name`,
			`remark`,
			`is_valid`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`
		from sys_cus_unit_code
		where sn = #{id}
	</select>

	<select id="queryObjectByName" resultType="com.kmall.admin.entity.SysCusUnitCodeEntity">
		select
		`sn`,
		`code`,
		`name`,
		`remark`,
		`is_valid`,
		`creater_sn`,
		`create_time`,
		`moder_sn`,
		`mod_time`,
		`tstm`
		from sys_cus_unit_code
		where `name` = #{unitName}
	</select>
	<select id="queryList" resultType="com.kmall.admin.entity.SysCusUnitCodeEntity">
		select
    		`sn`,
    		`code`,
    		`name`,
    		`remark`,
    		`is_valid`,
    		`creater_sn`,
    		`create_time`,
    		`moder_sn`,
    		`mod_time`,
    		`tstm`
		from sys_cus_unit_code
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by sn desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from sys_cus_unit_code
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
	</select>
	 
	<insert id="save" parameterType="com.kmall.admin.entity.SysCusUnitCodeEntity">
		insert into sys_cus_unit_code(
			`sn`,
			`code`,
			`name`,
			`remark`,
			`is_valid`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`)
		values(
			#{sn},
			#{code},
			#{name},
			#{remark},
			#{isValid},
			#{createrSn},
			#{createTime},
			#{moderSn},
			#{modTime},
			#{tstm})
	</insert>
	 
	<update id="update" parameterType="com.kmall.admin.entity.SysCusUnitCodeEntity">
		update sys_cus_unit_code 
		<set>
			<if test="code != null">`code` = #{code}, </if>
			<if test="name != null">`name` = #{name}, </if>
			<if test="remark != null">`remark` = #{remark}, </if>
			<if test="isValid != null">`is_valid` = #{isValid}, </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 sn = #{sn}
	</update>
	
	<delete id="delete">
		delete from sys_cus_unit_code where sn = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from sys_cus_unit_code where sn in 
		<foreach item="sn" collection="array" open="(" separator="," close=")">
			#{sn}
		</foreach>
	</delete>

</mapper>