<?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.common.dao.CusReqRecordDao">

    <resultMap type="com.kmall.common.entity.CusReqRecordEntity" id="cusReqRecordMap">
        <result property="id" column="id"/>
        <result property="orderNo" column="order_no"/>
        <result property="sessionID" column="session_id"/>
        <result property="serviceTime" column="service_time"/>
        <result property="status" column="status"/>
        <result property="message" column="message"/>
        <result property="createTime" column="create_time"/>
        <result property="modTime" column="mod_time"/>
    </resultMap>

	<select id="queryObject" resultType="com.kmall.common.entity.CusReqRecordEntity">
		select
			`id`,
			`order_no`,
			`session_id`,
			`service_time`,
			`status`,
			`create_time`,
			`mod_time`
		from cus_req_record
		where id = #{id}
	</select>

	<select id="queryList" resultType="com.kmall.common.entity.CusReqRecordEntity">
		select
    		`id`,
    		`order_no`,
    		`session_id`,
    		`service_time`,
    		`status`,
    		`create_time`,
    		`mod_time`
		from cus_req_record
		WHERE 1=1
		<if test="status != null and status != ''">
			AND status = #{status}
		</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 cus_req_record
		WHERE 1=1
		<if test="status != null and status != ''">
			AND status = #{status}
		</if>
	</select>
	 
	<insert id="save" parameterType="com.kmall.common.entity.CusReqRecordEntity" useGeneratedKeys="true" keyProperty="id">
		insert into cus_req_record(
			`order_no`,
			`session_id`,
			`service_time`,
			`status`,
			`create_time`,
			`mod_time`)
		values(
			#{orderNo},
			#{sessionID},
			#{serviceTime},
			#{status},
			#{createTime},
			#{modTime})
	</insert>
	 
	<update id="update" parameterType="com.kmall.common.entity.CusReqRecordEntity">
		update cus_req_record 
		<set>
			<if test="orderNo != null">`order_no` = #{orderNo}, </if>
			<if test="sessionID != null">`session_id` = #{sessionID}, </if>
			<if test="serviceTime != null">`service_time` = #{serviceTime}, </if>
			<if test="status != null">`status` = #{status}, </if>
			<if test="createTime != null">`create_time` = #{createTime}, </if>
			<if test="modTime != null">`mod_time` = #{modTime}</if>
		</set>
		where id = #{id}
	</update>
	
	<delete id="delete">
		delete from cus_req_record where id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from cus_req_record where id in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>