fix: 修复无交易记录自动结算并增加分时电量观测对比

复用 settleOrder 主路径纠正状态/锁/实时数据取值等问题,补充 mock 单测与 sys_job SQL;交易记录到达时按实时曲线估算尖峰平谷仅打日志对比,不参与结算。
This commit is contained in:
jsowell
2026-08-12 16:17:31 +08:00
parent 896908d692
commit 40c34fa49c
16 changed files with 1278 additions and 620 deletions

View File

@@ -3770,49 +3770,38 @@
</if>
</select>
<!-- 查询待自动结算的订单列表(无交易记录自动结算) -->
<!-- 查询待自动结算的订单列表(无交易记录自动结算)
说明:
1) order_status=2 待结算(不是 3 待补缴)
2) 启动时已有 transaction_code“无交易记录”指未完成结算不是流水号为空
3) 双依据预筛选:
- charge_end_time 已超过截止时间
- 或无 charge_end_time但 charge_start_time 已超过截止时间Java 再用实时数据时间兜底确认)
-->
<select id="selectPendingAutoSettleOrders" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM order_basic_info
WHERE del_flag = '0'
AND order_status = '3' -- 待结算
AND pay_status = '1' -- 已支付
AND (transaction_code IS NULL OR transaction_code = '') -- 无交易流水号
AND charge_end_time IS NOT NULL
AND charge_end_time <![CDATA[ < ]]> #{cutoffTime} -- 停止超过阈值时间
AND order_status = '2'
AND pay_status IN ('1', '2')
AND settlement_time IS NULL
AND transaction_code IS NOT NULL
AND transaction_code != ''
AND (
(charge_end_time IS NOT NULL AND charge_end_time <![CDATA[ <= ]]> #{cutoffTime})
OR (charge_end_time IS NULL AND charge_start_time IS NOT NULL AND charge_start_time <![CDATA[ <= ]]> #{cutoffTime})
)
<if test="stationIds != null and stationIds.size() > 0">
AND station_id IN
<foreach collection="stationIds" item="stationId" open="(" separator="," close=")">
#{stationId}
</foreach>
</if>
ORDER BY charge_end_time ASC
ORDER BY COALESCE(charge_end_time, charge_start_time) ASC
<if test="limit > 0">
LIMIT #{limit}
</if>
</select>
<!-- 使用乐观锁更新订单(用于自动结算) -->
<update id="updateOrderWithOptimisticLock">
UPDATE order_basic_info
SET order_status = #{order.orderStatus},
order_amount = #{order.orderAmount},
virtual_amount = #{order.virtualAmount},
settle_amount = #{order.settleAmount},
actual_received_amount = #{order.actualReceivedAmount},
reason = #{order.reason},
settlement_time = #{order.settlementTime},
refund_amount = #{order.refundAmount}
WHERE id = #{orderId}
AND order_status = #{expectedStatus}
<choose>
<when test="expectedSettlementTime == null">
AND settlement_time IS NULL
</when>
<otherwise>
AND settlement_time = #{expectedSettlementTime}
</otherwise>
</choose>
</update>
</mapper>