2026-10-15 16:55:57 +08:00
|
|
|
package com.baiyue.lastleg.appointmentplanning;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
|
|
|
import org.apache.ibatis.annotations.Options;
|
|
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
|
|
import org.apache.ibatis.annotations.Select;
|
|
|
|
|
|
|
|
|
|
@Mapper
|
|
|
|
|
public interface AppointmentCargoVerificationMapper extends BaseMapper<AppointmentCargoVerification> {
|
|
|
|
|
/** Same canonical source row used by allocation; flush pre-lock observations before re-reading. */
|
|
|
|
|
@Select("SELECT id FROM ll_order WHERE id=#{orderId} FOR UPDATE")
|
|
|
|
|
@Options(flushCache = Options.FlushCachePolicy.TRUE, useCache = false)
|
|
|
|
|
Long lockSourceOrder(@Param("orderId") Long orderId);
|
|
|
|
|
|
|
|
|
|
@Select("SELECT * FROM ll_appointment_cargo_verification WHERE customer_id=#{customerId} AND source_key=#{sourceKey} ORDER BY version DESC LIMIT 1")
|
|
|
|
|
AppointmentCargoVerification latest(@Param("customerId") String customerId,@Param("sourceKey") String sourceKey);
|
|
|
|
|
|
2026-10-15 19:10:57 +08:00
|
|
|
@Select("""
|
|
|
|
|
<script>
|
|
|
|
|
SELECT ranked.* FROM (
|
|
|
|
|
SELECT v.*,ROW_NUMBER() OVER(PARTITION BY customer_id,source_key ORDER BY version DESC) work_row
|
|
|
|
|
FROM ll_appointment_cargo_verification v WHERE
|
|
|
|
|
<foreach collection='refs' item='ref' separator=' OR '>(customer_id=#{ref.customerId} AND source_key=#{ref.sourceKey})</foreach>
|
|
|
|
|
) ranked WHERE work_row=1
|
|
|
|
|
</script>
|
|
|
|
|
""")
|
|
|
|
|
java.util.List<AppointmentCargoVerification> latestBatch(@Param("refs") java.util.List<AppointmentCoverageService.SourceRef> refs);
|
|
|
|
|
|
2026-10-15 16:55:57 +08:00
|
|
|
@Select("SELECT * FROM ll_appointment_cargo_verification WHERE customer_id=#{customerId} AND source_key=#{sourceKey} AND command_key=#{key}")
|
|
|
|
|
AppointmentCargoVerification command(@Param("customerId") String customerId,@Param("sourceKey") String sourceKey,@Param("key") String key);
|
|
|
|
|
|
|
|
|
|
record Allocation(long packages, long unknownItems) { }
|
|
|
|
|
@Select("""
|
|
|
|
|
SELECT COALESCE(SUM(package_count),0) AS packages,
|
|
|
|
|
COUNT(*)-COUNT(package_count) AS unknownItems
|
|
|
|
|
FROM ll_inbound_fba_appointment_item
|
|
|
|
|
WHERE customer_id=#{customerId} AND source_key=#{sourceKey} AND active=1
|
|
|
|
|
""")
|
|
|
|
|
Allocation allocated(@Param("customerId") String customerId,@Param("sourceKey") String sourceKey);
|
2026-10-15 19:10:57 +08:00
|
|
|
|
|
|
|
|
record SourceAllocation(String customerId,String sourceKey,long packages,long unknownItems) { }
|
|
|
|
|
@Select("""
|
|
|
|
|
<script>
|
|
|
|
|
SELECT customer_id,source_key,COALESCE(SUM(package_count),0) packages,COUNT(*)-COUNT(package_count) unknown_items
|
|
|
|
|
FROM ll_inbound_fba_appointment_item WHERE active=1 AND (
|
|
|
|
|
<foreach collection='refs' item='ref' separator=' OR '>(customer_id=#{ref.customerId} AND source_key=#{ref.sourceKey})</foreach>
|
|
|
|
|
) GROUP BY customer_id,source_key
|
|
|
|
|
</script>
|
|
|
|
|
""")
|
|
|
|
|
java.util.List<SourceAllocation> allocatedBatch(@Param("refs") java.util.List<AppointmentCoverageService.SourceRef> refs);
|
2026-10-15 16:55:57 +08:00
|
|
|
}
|