OrderMapper.xml 7.77 KB
<?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.b2c.orders.dao.impl.OrderDaoBean">
	<resultMap id="OrderRM" type="com.b2c.orders.domain.Order">
		<id property="id" column="id" />
		<result property="buyerId" column="buyer_id" />
		<result property="buyerName" column="buyer_name" />
		<result property="sellerId" column="seller_id" />
		<result property="sellerName" column="seller_name" />
		<result property="deliveryType" column="delivery_type" />
		<result property="orderStatus" column="order_status"
			typeHandler="com.b2c.orders.dao.utils.OrderStatusTypeHandler" />
		<result property="payStatus" column="pay_status" />
		<result property="buyerMemo" column="buyer_memo" />
		<result property="payTime" column="pay_time" />
		<result property="deliveryTime" column="delivery_time" />
		<result property="buyerConfirmTime" column="buyer_confirm_time" />
		<result property="sellerConfirmTime" column="seller_confirm_time" />
		<result property="reservationTime" column="reservation_time" />
		<result property="submitTime" column="submit_time" />
		<result property="payType" column="pay_type" />
		<result property="totalPrice" column="total_price" />
		<result property="realTotalPrice" column="real_total_price" />
		<result property="versionNum" column="version_num" />
		<result property="delete" column="delete_flag" />
		<result property="statusInReason" column="status_in_reason" />
		<collection property="orderItems" column="id"
			select="com.b2c.orders.dao.impl.OrderItemDaoBean.findByOrderId" />
	</resultMap>

	<sql id="selectColumn">
		t1.id
		,t1.buyer_id
		,t1.buyer_name
		,t1.seller_id
		,t1.seller_name
		,t1.delivery_type
		,t1.order_status
		,t1.pay_status
		,t1.buyer_memo
		,t1.pay_time
		,t1.delivery_time
		,t1.reservation_time
		,t1.buyer_confirm_time
		,t1.seller_confirm_time
		,t1.submit_time
		,t1.pay_type
		,t1.total_price
		,t1.real_total_price
		,t1.version_num
		,t1.status_in_reason
	</sql>

	<sql id="selectCondition">
		<if test="param != null">
			<if test="param.id != null and param.id != ''">
				and t1.id = #{param.id}
			</if>
			<if test="param.buyerId != null and param.buyerId != ''">
				and t1.buyer_id = #{param.buyerId}
			</if>
			<if test="param.buyerName != null and param.buyerName != ''">
				and t1.buyer_name = #{param.buyerName}
			</if>
			<if test="param.sellerId != null and param.sellerId != ''">
				and t1.seller_id = #{param.sellerId}
			</if>
			<if test="param.sellerName != null and param.sellerName != ''">
				and t1.seller_name = #{param.sellerName}
			</if>
			<if test="param.deliveryType != null and param.deliveryType != ''">
				and t1.delivery_type = #{param.deliveryType}
			</if>
			<if test="param.orderStatus != null and param.orderStatus != ''">
				and t1.order_status = #{param.orderStatus}
			</if>
			<if test="param.payStatus != null and param.payStatus != ''">
				and t1.pay_status = #{param.payStatus}
			</if>
			<if test="param.buyerMemo != null and param.buyerMemo != ''">
				and t1.buyer_memo = #{param.buyerMemo}
			</if>
			<if test="param.payBeginTime != null and param.payBeginTime != ''">
				<![CDATA[and t1.pay_time >= #{param.payBeginTime}]]>
			</if>
			<if test="param.payEndTime != null and param.payEndTime != ''">
				<![CDATA[and t1.pay_time <= #{param.payEndTime}]]>
			</if>
			<if
				test="param.deliveryBeginTime != null and param.deliveryBeginTime != ''">
				<![CDATA[and t1.delivery_time >= #{param.deliveryBeginTime}]]>
			</if>
			<if test="param.deliveryEndTime != null and param.deliveryEndTime != ''">
				<![CDATA[and t1.delivery_time <= #{param.deliveryEndTime}]]>
			</if>
			<if
				test="param.buyerConfirmEndTime != null and param.buyerConfirmBeginTime != ''">
				<![CDATA[and t1.buyer_confirm_time >= #{param.buyerConfirmBeginTime}]]>
			</if>
			<if
				test="param.buyerConfirmEndTime != null and param.buyerConfirmEndTime != ''">
				<![CDATA[and t1.buyer_confirm_time <= #{param.buyerConfirmEndTime}]]>
			</if>
			<if
				test="param.sellerConfirmBeginTime != null and param.sellerConfirmBeginTime != ''">
				<![CDATA[and t1.seller_confirm_time >= #{param.sellerConfirmBeginTime}]]>
			</if>
			<if
				test="param.sellerConfirmEndTime != null and param.sellerConfirmEndTime != ''">
				<![CDATA[and t1.seller_confirm_time <= #{param.sellerConfirmEndTime}]]>
			</if>
			<if
				test="param.reservationBeginTime != null and param.reservationBeginTime != ''">
				<![CDATA[and t1.reservation_time >= #{param.reservationBeginTime}]]>
			</if>
			<if
				test="param.reservationEndTime != null and param.reservationEndTime != ''">
				<![CDATA[and t1.reservation_time <= #{param.reservationEndTime}]]>
			</if>
			<if test="param.submitBeginTime != null and param.submitBeginTime != ''">
				<![CDATA[and t1.submit_time >= #{param.submitBeginTime}]]>
			</if>
			<if test="param.submitEndTime != null and param.submitEndTime != ''">
				<![CDATA[and t1.submit_time <= #{param.submitEndTime}]]>
			</if>
			<if test="param.buyerMemo != null and param.buyerMemo != ''">
				and t1.pay_type = #{param.payType}
			</if>
			<if test="param.buyerMemo != null and param.buyerMemo != ''">
				and t1.total_price = #{param.totalPrice}
			</if>
			<if test="param.productName != null and param.productName != ''">
				<![CDATA[and t2.product_name like CONCAT('%',#{param.productName},'%')]]>
			</if>
		</if>
		and delete_flag = 0
	</sql>

	<sql id="joinOrderItem">
		<if test="param.productName != null and param.productName != ''">
			RIGHT JOIN t_order_item t2 ON t2.order_id = t1.id
		</if>
	</sql>

	<select id="getById" parameterType="Long" resultMap="OrderRM">
		SELECT
		<include refid="selectColumn" />
		FROM t_order t1
		WHERE delete_flag = 0 AND id = #{id}
	</select>

	<insert id="save" parameterType="com.b2c.orders.domain.Order">
		<![CDATA[
			INSERT INTO t_order(
	                    id,
	                    buyer_id,
	                    seller_id,
	                    delivery_type,
	                    order_status,
	                    pay_status,
	                    buyer_memo,
	                    delivery_time,
	                    pay_type,
	                    total_price
			) VALUES(
						#{id},
			        	#{buyerId},
			        	#{sellerId},
			        	#{deliveryType},
			        	#{orderStatus},
			        	#{payStatus},
			        	#{buyerMemo},
			        	#{deliveryTime},
			        	#{payType},
			        	#{totalPrice}
			)
		]]>
	</insert>

	<update id="update" parameterType="com.b2c.orders.domain.Order">
    <![CDATA[
            UPDATE t_order set
            	order_status=#{orderStatus},
            	pay_status=#{payStatus},
            	buyer_memo=#{buyerMemo},
            	pay_time=#{payTime},
            	delivery_time=#{deliveryTime},
            	buyer_confirm_time=#{buyerConfirmTime},
            	seller_confirm_time=#{sellerConfirmTime},
            	real_total_price=#{realTotalPrice},
            	status_in_reason=#{statusInReason}
            	version_num=version_num + 1
            where 1=1
            and version_num=#{versionNum} and id = #{id}
            ]]>
	</update>

	<select id="countByCondition" parameterType="Query" resultType="Integer">
		SELECT count(1) FROM t_order
		<include refid="joinOrderItem" />
		where 1=1
		<include refid="selectCondition" />
	</select>

	<select id="listByCondition" parameterType="Query" resultMap="OrderRM">
		SELECT
		<include refid="selectColumn" />
		FROM t_order t1
		<include refid="joinOrderItem" />
		where 1=1
		<include refid="selectCondition" />
		order by t1.id desc
		<![CDATA[
		limit #{startRow},#{pageSize}
		]]>
	</select>


	<update id="deleteById" parameterType="Long">
    <![CDATA[
        update t_order set delete_flag = 1,version_num=version_num + 1
        where 1 = 1
        and id = #{id} and version_num=#{versionNum}
    ]]>
	</update>

</mapper>