<iftest="id != null and id != ''"> and roi.id = #{id}</if>
<iftest="orderId != null and orderId != ''"> and roi.order_id like concat('%', #{orderId}, '%')</if>
<iftest="materialId != null and materialId != ''"> and (roi.material_id like concat('%', #{materialId}, '%') or m.material_code like concat('%', #{materialId}, '%'))</if>
<iftest="batchCode != null and batchCode != ''"> and roi.batch_code = #{batchCode}</if>
<iftest="warehouseId != null and warehouseId != ''"> and roi.warehouse_id = #{warehouseId}</if>
<iftest="locationId != null and locationId != ''"> and roi.location_id = #{locationId}</if>
<iftest="ownerId != null and ownerId != ''"> and ro.owner_id = #{ownerId}</if>
<iftest="startDate != null and startDate != ''"> and date_format(ro.return_date,'%Y-%m-%d') >= #{startDate}</if>
<iftest="endDate != null and endDate != ''"> and date_format(ro.return_date,'%Y-%m-%d') <= #{endDate}</if>
<iftest="plannedQuantity != null "> and roi.planned_quantity = #{plannedQuantity}</if>
<iftest="actualQuantity != null "> and roi.actual_quantity = #{actualQuantity}</if>
<iftest="plannedPackages != null "> and roi.planned_packages = #{plannedPackages}</if>
<iftest="actualPackages != null "> and roi.actual_packages = #{actualPackages}</if>
<iftest="divisor != null "> and roi.divisor = #{divisor}</if>
<iftest="labelColor != null "> and roi.label_color = #{labelColor}</if>
<iftest="voucherNumber != null and voucherNumber != ''"> and roi.voucher_number = #{voucherNumber}</if>
<iftest="unitPrice != null "> and roi.unit_price = #{unitPrice}</if>
<iftest="totalAmount != null "> and roi.total_amount = #{totalAmount}</if>
<iftest="isUsed != null "> and roi.is_used = #{isUsed}</if>
<iftest="sortNo != null "> and roi.sort_no = #{sortNo}</if>
<iftest="createUserCode != null and createUserCode != ''"> and roi.create_user_code = #{createUserCode}</if>
<iftest="updateUserCode != null and updateUserCode != ''"> and roi.update_user_code = #{updateUserCode}</if>
</where>
order by ro.return_date desc, roi.sort_no, roi.create_time
from return_order_items roi left join materials m on roi.material_id = m.id left join warehouses w on roi.warehouse_id = w.id left join storage_locations sl on roi.location_id = sl.id