Files
gofly-platform-services/zlt-business/order-center/src/main/resources/mapper/OrderMapper.xml
T

111 lines
4.7 KiB
XML

<?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.central.order.mapper.OrderMapper">
<select id="findList" resultType="com.central.order.model.Order">
SELECT o.*, t.tourism_name as tourismName
FROM orders o
LEFT JOIN tourisms t ON o.tourism_id = t.id
<where>
<!-- 业务筛选条件 -->
<if test="p.orderNo != null and p.orderNo != ''">
AND o.order_no = #{p.orderNo}
</if>
<if test="p.orderStatus != null">
AND o.order_status = #{p.orderStatus}
</if>
<if test="p.payType != null">
AND o.pay_type = #{p.payType}
</if>
<if test="p.tourismId != null">
AND o.tourism_id = #{p.tourismId}
</if>
<if test="p.deviceSn != null and p.deviceSn != ''">
AND o.device_sn LIKE CONCAT('%', #{p.deviceSn}, '%')
</if>
<!-- 兼容 dashboard 透传的 qrcodeId 与现有 codeId 参数名 -->
<if test="p.codeId != null and p.codeId != ''">
AND o.code_id LIKE CONCAT('%', #{p.codeId}, '%')
</if>
<if test="p.qrcodeId != null and p.qrcodeId != ''">
AND o.code_id LIKE CONCAT('%', #{p.qrcodeId}, '%')
</if>
<if test="p.userId != null and p.userId != ''">
AND o.user_id LIKE CONCAT('%', #{p.userId}, '%')
</if>
<if test="p.mobile != null and p.mobile != ''">
AND o.mobile LIKE CONCAT('%', #{p.mobile}, '%')
</if>
<!-- 时间范围(与仪表盘统计口径一致) -->
<if test="p.startTime != null and p.startTime != ''">
AND o.create_time &gt;= #{p.startTime}
</if>
<if test="p.endTime != null and p.endTime != ''">
AND o.create_time &lt;= #{p.endTime}
</if>
<!-- 景区集合过滤(由租户+子孙→景区ID集合的去重结果提供) -->
<if test="p.tourismIds != null and p.tourismIds.size > 0">
AND o.tourism_id IN
<foreach collection="p.tourismIds" item="tid" open="(" separator="," close=")">#{tid}</foreach>
</if>
</where>
ORDER BY o.create_time DESC
</select>
<!-- 动态获取参数采用备参 -->
<select id="findListByUser" resultType="com.central.order.model.Order">
select id,order_no,tourism_id,device_sn,workspace_id,code_id,user_id,order_amount,order_status,create_time,update_time from orders t WHERE t.user_id = #{param2.userId}
and t.is_del = 0
<if test="param2.orderStatusList != null and param2.orderStatusList.size() > 0">
and t.order_status in
<foreach collection="param2.orderStatusList" item="status" open="(" separator="," close=")">
#{status}
</foreach>
</if>
ORDER BY id DESC
</select>
<!-- 根据订单状态查询订单列表 -->
<select id="getOrdersByStatus" resultMap="OrderResultMap">
SELECT * FROM orders WHERE order_status = #{status} ORDER BY id DESC
</select>
<!-- 新增订单 -->
<insert id="insertOrder" keyProperty="order_id" useGeneratedKeys="true">
INSERT INTO orders (user_id, order_amount, order_status)
VALUES (#{userId}, #{orderAmount}, #{orderStatus})
</insert>
<!-- 根据订单编号查询订单信息 -->
<resultMap id="OrderResultMap" type="com.central.order.model.Order"></resultMap>
<select id="getOrderById" resultMap="OrderResultMap">
SELECT * FROM orders WHERE id = #{orderId}
</select>
<!-- 更新订单状态 -->
<update id="updateOrderStatus">
UPDATE orders
SET order_status = #{newStatus}
WHERE id = #{orderId}
</update>
<!-- 查询所有处于排队状态的订单 -->
<select id="getOrdersInQueue" resultType="com.central.order.model.Order">
SELECT * FROM orders WHERE order_status = 1 order by id asc
</select>
<!-- 根据店铺编号和创建时间(当天)查询订单数量 -->
<select id="findByShopIdAndCreateTimeGreaterThanEqualAndCreateTimeLessThanEqual" resultMap="OrderResultMap">
SELECT * FROM orders
WHERE tourism_id = #{tourismId}
AND create_time >= #{startDate}
AND create_time &lt;= #{endDate}
</select>
<!-- 根据订单编号查询订单信息 -->
<select id="getOrderByNumber" resultMap="OrderResultMap">
SELECT * FROM orders WHERE order_no = #{orderNumber}
</select>
</mapper>