OrderMapper.xml 10.5 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="shopBuyerId" column="shop_buyer_id" />
		<result property="marketId" column="market_id" />
		<result property="deliveryType" column="delivery_type" />
		<result property="orderStatus" column="order_status" />
		<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="deliveryAddress" column="delivery_address" />
		<result property="receiverName" column="receiver_name" />
		<result property="receiverPhoneNumber" column="receiver_phone_number" />
		<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="postage" column="postage" />
		<result property="versionNum" column="version_num" />
		<result property="delete" column="delete_flag" />
		<result property="statusInReason" column="status_in_reason" />
		<result property="buyerId" column="buyer_id" />
		<result property="buyerName" column="buyer_name" />
		<result property="buyerPhoneNumber" column="buyer_phone_number" />
		<result property="sellerId" column="seller_id" />
		<result property="sellerName" column="seller_name" />
		<result property="sellerPhoneNumber" column="seller_phone_number" />
		<result property="shopId" column="shop_id" />
		<result property="shopName" column="shop_name" />
		<result property="shopPhoneNumber" column="shop_phone_number" />
		<result property="shopAddress" column="shop_address" />
		<result property="tradeName" column="trade_name" />
		<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.seller_phone_number
		,t1.shop_buyer_id
		,t1.market_id
		,t1.delivery_type
		,t1.order_status
		,t1.pay_status
		,t1.buyer_memo
		,t1.pay_time
		,t1.delivery_time
		,t1.delivery_address
		,t1.receiver_phone_number
		,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.postage
		,t1.version_num
		,t1.status_in_reason
		,t1.shop_id
		,t1.shop_name
		,t1.shop_phone_number
		,t1.shop_address
		,t1.trade_name
	</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.shopBuyerId != null and param.shopBuyerId != ''">
				and t1.shop_buyer_id = #{param.shopBuyerId}
			</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.marketId != null and param.marketId != ''">
				and t1.market_id = #{param.marketId}
			</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.receiverPhoneNumber != null and param.receiverPhoneNumber != ''">
				and t1.receiver_phone_number = #{param.receiverPhoneNumber}
			</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 t1.trade_name like CONCAT('%',#{param.productName},'%')]]>
			</if>
			<if test="param.buyerDelete != null and param.buyerDelete == false">
				and t1.buyer_delete = 0
			</if>
			<if test="param.sellerDelete != null and param.sellerDelete == false">
				and t1.seller_delete = 0
			</if>
		</if>
	</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,
	                    buyer_name,
	                    buyer_phone_number,
	                    seller_id,
	                    seller_name,
	                    seller_phone_number,
	                    shop_id,
	                    shop_name,
	                    shop_address,
	                    shop_phone_number,
	                    shop_buyer_id,
	                    market_id,
	                    delivery_type,
	                    order_status,
	                    pay_status,
	                    buyer_memo,
	                    delivery_time,
	                    delivery_address,
	                    receiver_name,
	                    receiver_phone_number,
	                    pay_type,
	                    total_price,
	                    trade_name
			) VALUES(
						#{id},
						#{buyerId},
			        	#{buyerName},
			        	#{buyerPhoneNumber},
			        	#{sellerId},
			        	#{sellerName},
			        	#{sellerPhoneNumber},
			        	#{shopId},
			        	#{shopName},
			        	#{shopAddress},
			        	#{shopPhoneNumber},
			        	#{shopBuyerId},
			        	#{marketId},
			        	#{deliveryType},
			        	#{orderStatus},
			        	#{payStatus},
			        	#{buyerMemo},
			        	#{deliveryTime},
			        	#{deliveryAddress},
			        	#{receiverName},
			        	#{receiverPhoneNumber},
			        	#{payType},
			        	#{totalPrice},
			        	#{tradeName}
			)
		]]>
	</insert>

	<update id="update" parameterType="com.b2c.orders.domain.Order">
    <![CDATA[
            UPDATE t_order set
            	order_status=#{orderStatus},
            	pay_status=#{payStatus},
            	pay_type=#{payType},
            	buyer_memo=#{buyerMemo},
            	pay_time=#{payTime},
            	delivery_time=#{deliveryTime},
            	buyer_confirm_time=#{buyerConfirmTime},
            	seller_confirm_time=#{sellerConfirmTime},
            	real_total_price=#{realTotalPrice},
            	postage=#{postage},
            	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 t1
		<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="buyerRemove" parameterType="Long">
		UPDATE t_order SET
		buyer_delete = 1 WHERE id = #{orderId}
	</update>

	<update id="sellerRemove" parameterType="Long">
		UPDATE t_order SET
		seller_delete = 1 WHERE id = #{orderId}
	</update>


	<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>