100 lines
6.5 KiB
Java
100 lines
6.5 KiB
Java
package com.baiyue.firstleg.mapper;
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baiyue.firstleg.dto.ContainerDtos.Query;
|
|
import com.baiyue.firstleg.entity.ContainerBookingEntity;
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
import org.apache.ibatis.annotations.Param;
|
|
import org.apache.ibatis.annotations.Select;
|
|
import org.apache.ibatis.annotations.Update;
|
|
|
|
@Mapper
|
|
public interface ContainerBookingMapper extends BaseMapper<ContainerBookingEntity> {
|
|
@Select("""
|
|
<script>
|
|
SELECT b.*, p.id AS plan_id,
|
|
CASE WHEN p.id IS NULL THEN 'WAIT_LOADING'
|
|
WHEN p.plan_status != 'COMPLETED' AND NOT EXISTS (
|
|
SELECT 1 FROM fl_loading_plan_item active_item
|
|
WHERE active_item.loading_plan_id = p.id AND active_item.deleted = 0
|
|
) THEN 'WAIT_LOADING'
|
|
ELSE p.plan_status END AS plan_status
|
|
FROM fl_container_booking b LEFT JOIN fl_loading_plan p ON p.container_booking_id = b.id
|
|
WHERE (#{query.containerNo} IS NULL OR b.container_no = #{query.containerNo})
|
|
AND (#{query.cabinetNo} IS NULL OR b.cabinet_no = #{query.cabinetNo})
|
|
AND (#{query.billOfLadingNo} IS NULL OR b.bill_of_lading_no = #{query.billOfLadingNo})
|
|
AND (#{query.warehouseId} IS NULL OR b.warehouse_id = #{query.warehouseId})
|
|
AND (#{query.containerType} IS NULL OR b.container_type = #{query.containerType})
|
|
AND (#{query.shippingCompanyId} IS NULL OR b.shipping_company_id = #{query.shippingCompanyId})
|
|
AND (#{query.departurePortCode} IS NULL OR b.departure_port_code = #{query.departurePortCode})
|
|
AND (#{query.destinationPortCode} IS NULL OR b.destination_port_code = #{query.destinationPortCode})
|
|
AND (#{query.destinationWarehouseCode} IS NULL OR b.destination_warehouse_code = #{query.destinationWarehouseCode})
|
|
AND (#{query.status} IS NULL OR CASE WHEN p.id IS NULL THEN 'WAIT_LOADING'
|
|
WHEN p.plan_status != 'COMPLETED' AND NOT EXISTS (
|
|
SELECT 1 FROM fl_loading_plan_item active_item
|
|
WHERE active_item.loading_plan_id = p.id AND active_item.deleted = 0
|
|
) THEN 'WAIT_LOADING'
|
|
ELSE p.plan_status END = #{query.status})
|
|
AND (#{query.estimatedSailingFrom} IS NULL OR b.estimated_sailing_at >= #{query.estimatedSailingFrom})
|
|
AND (#{query.estimatedSailingTo} IS NULL OR b.estimated_sailing_at <= #{query.estimatedSailingTo})
|
|
AND (#{query.keyword} IS NULL OR b.container_no LIKE CONCAT('%', #{query.keyword}, '%')
|
|
OR b.cabinet_no LIKE CONCAT('%', #{query.keyword}, '%')
|
|
OR b.bill_of_lading_no LIKE CONCAT('%', #{query.keyword}, '%')
|
|
OR b.vessel_name LIKE CONCAT('%', #{query.keyword}, '%')
|
|
OR b.voyage_no LIKE CONCAT('%', #{query.keyword}, '%'))
|
|
ORDER BY b.updated_at DESC, b.id DESC
|
|
</script>
|
|
""")
|
|
Page<ContainerBookingEntity> selectBookingPage(Page<ContainerBookingEntity> page, @Param("query") Query query);
|
|
|
|
@Select("""
|
|
SELECT b.*, p.id AS plan_id,
|
|
CASE WHEN p.id IS NULL THEN 'WAIT_LOADING'
|
|
WHEN p.plan_status != 'COMPLETED' AND NOT EXISTS (
|
|
SELECT 1 FROM fl_loading_plan_item active_item
|
|
WHERE active_item.loading_plan_id = p.id AND active_item.deleted = 0
|
|
) THEN 'WAIT_LOADING'
|
|
ELSE p.plan_status END AS plan_status
|
|
FROM fl_container_booking b LEFT JOIN fl_loading_plan p ON p.container_booking_id = b.id
|
|
WHERE b.id = #{id}
|
|
""")
|
|
ContainerBookingEntity selectBooking(@Param("id") long id);
|
|
|
|
@Update("""
|
|
UPDATE fl_container_booking SET
|
|
container_no=#{value.containerNo}, cabinet_no=#{value.cabinetNo},
|
|
warehouse_id=#{value.warehouseId}, warehouse_name=#{value.warehouseName},
|
|
bill_of_lading_no=#{value.billOfLadingNo}, vessel_name=#{value.vesselName}, voyage_no=#{value.voyageNo},
|
|
container_type=#{value.containerType}, shipping_company_id=#{value.shippingCompanyId},
|
|
shipping_company_name=#{value.shippingCompanyName}, departure_port_code=#{value.departurePortCode},
|
|
departure_port_name=#{value.departurePortName}, destination_port_code=#{value.destinationPortCode},
|
|
destination_port_name=#{value.destinationPortName}, destination_warehouse_code=#{value.destinationWarehouseCode},
|
|
destination_warehouse_name=#{value.destinationWarehouseName}, capacity_cbm=#{value.capacityCbm},
|
|
max_weight_kg=#{value.maxWeightKg}, terminal_trucking_company=#{value.terminalTruckingCompany},
|
|
loading_at=#{value.loadingAt}, estimated_sailing_at=#{value.estimatedSailingAt},
|
|
actual_sailing_at=#{value.actualSailingAt}, estimated_port_arrival_at=#{value.estimatedPortArrivalAt},
|
|
actual_port_arrival_at=#{value.actualPortArrivalAt},
|
|
estimated_warehouse_arrival_at=#{value.estimatedWarehouseArrivalAt},
|
|
actual_warehouse_arrival_at=#{value.actualWarehouseArrivalAt}, updated_by=#{operatorId},
|
|
updated_by_name=#{operatorName}, updated_at=CURRENT_TIMESTAMP(3), version=version+1
|
|
WHERE id=#{value.id} AND version=#{expectedVersion}
|
|
AND NOT EXISTS (SELECT 1 FROM fl_loading_plan p
|
|
WHERE p.container_booking_id=fl_container_booking.id AND p.plan_status!='EDITING')
|
|
""")
|
|
int updateDraft(@Param("value") ContainerBookingEntity value, @Param("expectedVersion") int expectedVersion,
|
|
@Param("operatorId") long operatorId, @Param("operatorName") String operatorName);
|
|
|
|
@Update("""
|
|
UPDATE fl_container_booking SET container_no=#{containerNo}, voyage_no=#{voyageNo},
|
|
updated_by=#{operatorId}, updated_by_name=#{operatorName},
|
|
updated_at=CURRENT_TIMESTAMP(3), version=version+1
|
|
WHERE id=#{id} AND version=#{expectedVersion}
|
|
AND NOT EXISTS (SELECT 1 FROM fl_loading_plan p
|
|
WHERE p.container_booking_id=fl_container_booking.id AND p.plan_status='COMPLETED')
|
|
""")
|
|
int updateTransport(@Param("id") long id, @Param("containerNo") String containerNo,
|
|
@Param("voyageNo") String voyageNo, @Param("expectedVersion") int expectedVersion,
|
|
@Param("operatorId") long operatorId, @Param("operatorName") String operatorName);
|
|
}
|