<iftest="orderId != null and orderId != ''"> and oi.order_id like concat('%', #{orderId}, '%')</if>
<iftest="materialId != null and materialId != ''"> and oi.material_id = #{materialId}</if>
<iftest="materialId != null and materialId != ''"> and m.sap_no like concat('%', #{materialId}, '%')or m.material_name like concat('%', #{materialId}, '%')</if>
<iftest="batchCode != null and batchCode != ''"> and oi.batch_code = #{batchCode}</if>
<iftest="startDate != null and startDate != ''"> and date_format(COALESCE(oi.shipped_at, o.inbound_date),'%Y-%m-%d') >= #{startDate}</if>
<iftest="endDate != null and endDate != ''"> and date_format(COALESCE(oi.shipped_at, o.inbound_date),'%Y-%m-%d') <= #{endDate}</if>
<iftest="warehouseId != null and warehouseId != ''"> and oi.warehouse_id = #{warehouseId}</if>
<iftest="locationId != null and locationId != ''"> and oi.location_id = #{locationId}</if>
<iftest="itemStatus != null "> and oi.item_status = #{itemStatus}</if>
<iftest="orderStatus != null "> and o.order_status = #{orderStatus}</if>
</where>
group by oi.material_id,
m.material_name,
...
...
@@ -357,7 +359,107 @@
o.order_id
order by sum(oi.unit_price * oi.actual_quantity) desc,m.sap_no, m.sort_no
</select>
<selectid="selectOutboundOrdersitmesExportList"
parameterType="OutboundOrdersSummaryVO"
resultMap="OutboundOrdersSummaryVOResult">
select
oi.material_id,
m.material_name,
m.sap_no,
m.ts_code,
m.hazard_id,
m.specification,
m.material_unit,
m.unit_weight,
sum(oi.planned_quantity) as planned_quantity,
sum(oi.actual_quantity) as actual_quantity,
oi.unit_price,
sum(oi.unit_price * oi.actual_quantity) as total_amount,
w.warehouses_name as warehouse_name,
oi.batch_code,
o.order_id as main_order_id,
sl.location_name,
-- 以下为VO中保留但无Excel注解的字段(保证关联完整性)
m.package_weight,
m.total_weight,
m.volume,
m.shelf_life_days,
m.storage_temperature,
m.special_requirements,
m.sort_no,
oi.warehouse_id,
oi.order_id as sub_order_id,
oi.location_id,
oi.item_status,
oi.remark
from outbound_order_items oi
left join outbound_orders o on oi.outbound_order_id = o.id
left join materials m on oi.material_id = m.id
left join warehouses w on oi.warehouse_id = w.id
left join storage_locations sl on oi.location_id = sl.id
<where>
oi.is_used = 1 and o.is_used = 1
-- 整合两个SQL的所有检索条件(去重且兼容)
<iftest="orderId != null and orderId != ''">
and oi.order_id like concat('%', #{orderId}, '%')
</if>
<iftest="materialId != null and materialId != ''">
and (m.sap_no like concat('%', #{materialId}, '%')
or m.material_name like concat('%', #{materialId}, '%')
or oi.material_id like concat('%', #{materialId}, '%'))
</if>
<iftest="batchCode != null and batchCode != ''">
and oi.batch_code = #{batchCode}
</if>
<iftest="startDate != null and startDate != ''">
and date_format(COALESCE(oi.shipped_at, o.inbound_date),'%Y-%m-%d') >= #{startDate}
</if>
<iftest="endDate != null and endDate != ''">
and date_format(COALESCE(oi.shipped_at, o.inbound_date),'%Y-%m-%d') <= #{endDate}
</if>
<iftest="warehouseId != null and warehouseId != ''">
and oi.warehouse_id = #{warehouseId}
</if>
<iftest="locationId != null and locationId != ''">
and oi.location_id = #{locationId}
</if>
<iftest="itemStatus != null ">
and oi.item_status = #{itemStatus}
</if>
<iftest="orderStatus != null ">
and o.order_status = #{orderStatus}
</if>
</where>
-- 分组字段整合:覆盖两个SQL的分组维度,保证汇总逻辑一致
group by oi.material_id,
m.material_name,
m.sap_no,
m.ts_code,
m.hazard_id,
m.specification,
m.material_unit,
m.unit_weight,
oi.unit_price,
w.warehouses_name,
oi.batch_code,
o.order_id,
sl.location_name,
m.package_weight,
m.total_weight,
m.volume,
m.shelf_life_days,
m.storage_temperature,
m.special_requirements,
m.sort_no,
oi.warehouse_id,
oi.order_id,
oi.location_id,
oi.item_status
-- 排序规则:优先按总金额降序,再按SAP编码、物料排序号
order by sum(oi.unit_price * oi.actual_quantity) desc,