<?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.fjs.scenic.mapper.order.ErrorOrderMapper">
	<resultMap id="BaseResultMap" type="com.fjs.scenic.entity.order.ErrorOrder">
		<id column="id" jdbcType="INTEGER" property="id" />
		<result column="order_no" jdbcType="VARCHAR" property="orderNo" />
		<result column="manager_id" jdbcType="INTEGER" property="managerId" />
		<result column="order_id" jdbcType="INTEGER" property="orderId" />
		<result column="time" jdbcType="TIMESTAMP" property="time" />
		<result column="type" jdbcType="TINYINT" property="type" />
		<result column="description" jdbcType="VARCHAR" property="description" />
		<result column="price" jdbcType="INTEGER" property="price" />
		<result column="num" jdbcType="INTEGER" property="num" />
	</resultMap>
	<sql id="Base_Column_List">
		id, order_no, manager_id, order_id, time, type, description,price,num
	</sql>
	<insert id="insert" parameterType="com.fjs.scenic.entity.order.ErrorOrder">
		insert into error_order (id,
		order_no, manager_id,
		order_id, time, type,
		description,price,num)
		values
		(#{id,jdbcType=INTEGER}, #{orderNo,jdbcType=VARCHAR},
		#{managerId,jdbcType=INTEGER},
		#{orderId,jdbcType=INTEGER},
		#{time,jdbcType=TIMESTAMP}, #{type,jdbcType=TINYINT},
		#{description,jdbcType=VARCHAR},#{price,jdbcType=INTEGER},
		#{num,jdbcType=INTEGER})
	</insert>

	<update id="updateByPrimaryKeySelective" parameterType="com.fjs.scenic.entity.order.ErrorOrder">
		update error_order
		<set>
			<if test="orderNo != null">
				order_no = #{orderNo,jdbcType=VARCHAR},
			</if>
			<if test="managerId != null">
				manager_id = #{managerId,jdbcType=INTEGER},
			</if>
			<if test="orderId != null">
				order_id = #{orderId,jdbcType=INTEGER},
			</if>
			<if test="time != null">
				time = #{time,jdbcType=TIMESTAMP},
			</if>
			<if test="type != null">
				type = #{type,jdbcType=TINYINT},
			</if>
			<if test="description != null">
				description = #{description,jdbcType=VARCHAR},
			</if>
			<if test="price != null">
				price = #{price,jdbcType=INTEGER},
			</if>
			<if test="num != null">
				num = #{num,jdbcType=INTEGER},
			</if>
		</set>
		where id = #{id,jdbcType=INTEGER}
	</update>

	<delete id="delete" parameterType="com.fjs.scenic.entity.order.ErrorOrder">
		delete from error_order where 1=1
		<if test="id != null"> and id = #{id}</if>
		<if test="orderNo != null">
			and order_no = #{orderNo,jdbcType=VARCHAR}
		</if>
		<if test="managerId != null">
			and manager_id = #{managerId,jdbcType=INTEGER}
		</if>
		<if test="orderId != null">
			and order_id = #{orderId,jdbcType=INTEGER}
		</if>
		<if test="time != null">
			and time = #{time,jdbcType=TIMESTAMP}
		</if>
		<if test="type != null">
			and type = #{type,jdbcType=TINYINT}
		</if>
		<if test="description != null">
			and description = #{description,jdbcType=VARCHAR}
		</if>
	</delete>

	<select id="select" resultMap="BaseResultMap"
		parameterType="com.fjs.scenic.entity.order.ErrorOrder">
		SELECT e.*,o.order_no orderNum,o.order_name orderName,m.`name`
		managerName from error_order e LEFT JOIN orders o on e.order_id=o.id
		LEFT JOIN manage m on e.manager_id=m.id 
		where 1 = 1
		<if test="id != null"> and e.id = #{id}</if>
		<if test="orderNo != null">
			and e.order_no = #{orderNo,jdbcType=VARCHAR}
		</if>
		<if test="managerId != null">
			and e.manager_id = #{managerId,jdbcType=INTEGER}
		</if>
		<if test="orderId != null">
			and e.order_id = #{orderId,jdbcType=INTEGER}
		</if>
		<if test="time != null">
			and e.time = #{time,jdbcType=TIMESTAMP}
		</if>
		<if test="type != null">
			and e.type = #{type,jdbcType=TINYINT}
		</if>
		<if test="description != null">
			and e.description = #{description,jdbcType=VARCHAR}
		</if>
		 order by e.time desc
	</select>

	<select id="selectByParam" resultMap="BaseResultMap"
		parameterType="java.util.Map">
		select
		<if test="field != null and field != ''"> ${field}</if>
		<if test="field == null or field == ''"> * </if>
		from error_order
		<if test="param != null and param != ''">where ${param}</if>
	</select>

	<select id="selectByJoin" resultType="com.fjs.scenic.entity.order.ErrorOrder"
		parameterType="java.util.Map">
		select
		<if test="field != null and field != ''"> ${field}</if>
		<if test="field == null or field == ''"> e.*,o.order_no orderNum,o.order_name orderName,m.`name`
		managerName </if>
		 from error_order e LEFT JOIN orders o on e.order_id=o.id
		LEFT JOIN manage m on e.manager_id=m.id 
		<if test="param != null and param != ''"> ${param}</if>
	</select>

	<delete id="deleteByParam" parameterType="java.util.Map">
		delete from error_order
		<if test="param != null and param != ''">where ${param}</if>
	</delete>

	<update id="updateByParam" parameterType="java.util.Map">
		<if test="param != null and param !=''">update error_order set ${param}</if>
	</update>
	
	<select id="getErrorOrderByOption" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from error_order where order_no =  #{orderNo,jdbcType=VARCHAR}
	</select>

	<select id="getErrorOrderByOrderNo" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from error_order where order_no =  #{orderNo,jdbcType=VARCHAR}
	</select>
	
	<select id="getErrorOrderByNumlt3" resultMap="BaseResultMap">
	SELECT <include refid="Base_Column_List" /> FROM error_order WHERE num &lt; 3
	</select>
</mapper>