2026-08-19 16:24:02 +08:00
|
|
|
package com.baiyue.lastleg.mapper;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
|
|
import com.baiyue.lastleg.entity.LastlegOrder;
|
|
|
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
|
|
import org.apache.ibatis.annotations.Select;
|
|
|
|
|
import org.apache.ibatis.annotations.Update;
|
|
|
|
|
|
2026-08-28 16:30:02 +08:00
|
|
|
import java.util.List;
|
|
|
|
|
|
2026-08-19 16:24:02 +08:00
|
|
|
@Mapper
|
|
|
|
|
public interface LastlegOrderMapper extends BaseMapper<LastlegOrder> {
|
2026-08-28 16:30:02 +08:00
|
|
|
record PalletMergeRelationRow(Long orderId, String relatedOrderNo, String mergeGroupNo) {}
|
|
|
|
|
|
|
|
|
|
@Select("<script>SELECT relation.order_id AS orderId, related.order_no AS relatedOrderNo, " +
|
|
|
|
|
"relation.merge_group_no AS mergeGroupNo FROM (" +
|
|
|
|
|
"SELECT customer_id,source_order_id AS order_id,target_order_id AS related_order_id,merge_group_no " +
|
|
|
|
|
"FROM ll_inbound_pallet_merge WHERE status='CONFIRMED' AND source_order_id IN " +
|
|
|
|
|
"<foreach collection='orderIds' item='id' open='(' separator=',' close=')'>#{id}</foreach> " +
|
|
|
|
|
"UNION ALL SELECT customer_id,target_order_id AS order_id,source_order_id AS related_order_id,merge_group_no " +
|
|
|
|
|
"FROM ll_inbound_pallet_merge WHERE status='CONFIRMED' AND target_order_id IN " +
|
|
|
|
|
"<foreach collection='orderIds' item='id' open='(' separator=',' close=')'>#{id}</foreach>) relation " +
|
|
|
|
|
"JOIN ll_order related ON related.id=relation.related_order_id AND related.customer_id=relation.customer_id " +
|
|
|
|
|
"ORDER BY relation.order_id,relation.merge_group_no,related.order_no</script>")
|
|
|
|
|
List<PalletMergeRelationRow> findPalletMergeRelations(@Param("orderIds") List<Long> orderIds);
|
|
|
|
|
|
2026-08-19 16:24:02 +08:00
|
|
|
@Select("SELECT * FROM ll_order WHERE customer_id=#{customerId} AND source_region=#{sourceRegion} " +
|
|
|
|
|
"AND source_inbound_id=#{sourceInboundId} LIMIT 1")
|
|
|
|
|
LastlegOrder findSource(@Param("customerId") String customerId,
|
|
|
|
|
@Param("sourceRegion") String sourceRegion,
|
|
|
|
|
@Param("sourceInboundId") String sourceInboundId);
|
|
|
|
|
|
|
|
|
|
@Select("SELECT COUNT(*) FROM ll_order WHERE customer_id=#{customerId} AND container_no=#{containerNo}")
|
|
|
|
|
long countContainer(@Param("customerId") String customerId, @Param("containerNo") String containerNo);
|
|
|
|
|
|
|
|
|
|
@Select("SELECT * FROM ll_order WHERE customer_id=#{customerId} AND id=#{id} FOR UPDATE")
|
|
|
|
|
LastlegOrder lockById(@Param("customerId") String customerId, @Param("id") Long id);
|
|
|
|
|
|
|
|
|
|
@Update("UPDATE ll_order SET picked_package_count=picked_package_count+#{packages},updated_at=NOW() " +
|
|
|
|
|
"WHERE customer_id=#{customerId} AND id=#{id} " +
|
|
|
|
|
"AND package_count-shipped_package_count-picked_package_count >= #{packages}")
|
|
|
|
|
int increasePicked(@Param("customerId") String customerId, @Param("id") Long id,
|
|
|
|
|
@Param("packages") long packages);
|
|
|
|
|
|
|
|
|
|
@Update("UPDATE ll_order SET current_status=CASE WHEN shipped_package_count+#{packages}=package_count " +
|
|
|
|
|
"THEN 'COMPLETED' ELSE 'PARTIALLY_SHIPPED' END," +
|
|
|
|
|
"picked_package_count=picked_package_count-#{packages}," +
|
|
|
|
|
"shipped_package_count=shipped_package_count+#{packages},outbound_order_no=#{outboundNo},updated_at=NOW() " +
|
|
|
|
|
"WHERE customer_id=#{customerId} AND id=#{id} AND picked_package_count >= #{packages} " +
|
|
|
|
|
"AND shipped_package_count+#{packages} <= package_count")
|
|
|
|
|
int transferPickedToShipped(@Param("customerId") String customerId, @Param("id") Long id,
|
|
|
|
|
@Param("packages") long packages, @Param("outboundNo") String outboundNo);
|
2026-08-24 21:46:19 +08:00
|
|
|
|
|
|
|
|
@Update("UPDATE ll_order SET overseas_warehouse_id=#{warehouseId},overseas_warehouse_name=#{warehouseName}," +
|
|
|
|
|
"updated_at=NOW(3) WHERE id=#{orderId} AND customer_id=#{customerId} " +
|
|
|
|
|
"AND (overseas_warehouse_id IS NULL OR overseas_warehouse_id=#{warehouseId})")
|
|
|
|
|
int claimReceivingWarehouse(@Param("customerId") String customerId, @Param("orderId") long orderId,
|
|
|
|
|
@Param("warehouseId") String warehouseId,
|
|
|
|
|
@Param("warehouseName") String warehouseName);
|
2026-08-28 14:20:48 +08:00
|
|
|
|
|
|
|
|
@Update("UPDATE ll_order SET pallet_merge_flag=#{flag},updated_at=#{updatedAt} " +
|
|
|
|
|
"WHERE customer_id=#{customerId} AND id=#{id}")
|
|
|
|
|
int updatePalletMergeFlag(@Param("customerId") String customerId, @Param("id") long id,
|
|
|
|
|
@Param("flag") String flag,
|
|
|
|
|
@Param("updatedAt") java.time.LocalDateTime updatedAt);
|
2026-08-19 16:24:02 +08:00
|
|
|
}
|