a.material_detail_id, a.organization_id, a.organization_name, a.top_organization_id, a.unique_id,
a.picking_order_number, a.material_base_info_id, a.material_code, a.material_name, a.bar_code, a.SIZE, a.weight_limit,
a.volume_limit, a.quantity, a.picking_quantity, a.pack_id, a.pack_code, a.pack_name,
a.pack_detail_id, a.unit_code, a.unit_name, a.material_warehouse_control_id, a.serial_number_manage,
a.material_inventory_id, a.batch_number, a.container_id, a.container_code, a.container_type, a.container_type_name, a.material_status_code, a.material_status_name,
a.warehouse_id, a.warehouse_code, a.warehouse_name, a.storage_section_id, a.storage_code, a.storage_name,
a.storage_location_id, a.storage_location_code, a.storage_location_name, a.remark,
a.BATCH_REF_NO, a.SHEET_REF_NO, a.BOX_PALLET_NO, a.EXT_ATTR_1, a.EXT_ATTR_2,
a.PRODUCTION_DATE, a.EXPIRY_DATE, a.INVENTORY_DATE, a.EXT_ATTR_3, a.EXT_ATTR_4,
a.create_time, a.create_by, a.create_by_name, a.update_time, a.update_by, a.update_by_name, a.del_flag,
a.total_area, a.total_gross_weight, a.total_net_weight, a.total_volume, a.out_unique_id,
a.COPY_CODE_REFERENCE_IDS,
omd.in_order_number, omd.lot_no as lot_number
and a.organization_id = #{organizationId}
and a.organization_name like concat('%', #{organizationName}, '%')
and a.top_organization_id = #{topOrganizationId}
and a.unique_id = #{uniqueId}
and a.picking_order_number = #{pickingOrderNumber}
and a.material_base_info_id = #{materialBaseInfoId}
and a.material_code = #{materialCode}
and a.material_name like concat('%', #{materialName}, '%')
and a.bar_code = #{barCode}
and a.weight_limit = #{weightLimit}
and a.volume_limit = #{volumeLimit}
and a.quantity = #{quantity}
and a.picking_quantity = #{pickingQuantity}
and a.pack_id = #{packId}
and a.pack_code = #{packCode}
and a.pack_name like concat('%', #{packName}, '%')
and a.pack_detail_id = #{packDetailId}
and a.unit_code = #{unitCode}
and a.unit_name like concat('%', #{unitName}, '%')
and a.material_warehouse_control_id = #{materialWarehouseControlId}
and a.serial_number_manage = #{serialNumberManage}
and a.warehouse_id = #{warehouseId}
and a.warehouse_code = #{warehouseCode}
and a.warehouse_name like concat('%', #{warehouseName}, '%')
and a.storage_section_id = #{storageSectionId}
and a.storage_code = #{storageCode}
and a.storage_name like concat('%', #{storageName}, '%')
and a.storage_location_id = #{storageLocationId}
and a.storage_location_code = #{storageLocationCode}
and a.storage_location_name like concat('%', #{storageLocationName}, '%')
and a.create_by_name like concat('%', #{createByName}, '%')
and a.update_by_name like concat('%', #{updateByName}, '%')
and a.del_flag = #{delFlag}
and a.del_flag = 1
UPDATE picking_material_detail
WHEN #{item.uniqueId} THEN LEAST(picking_quantity + #{item.pickingQuantity}, quantity)
WHEN #{item.uniqueId} THEN COALESCE(#{item.totalNetWeight}, total_net_weight)
WHEN #{item.uniqueId} THEN COALESCE(#{item.totalGrossWeight}, total_gross_weight)
WHEN #{item.uniqueId} THEN COALESCE(#{item.totalVolume}, total_volume)
WHEN #{item.uniqueId} THEN COALESCE(#{item.totalArea}, total_area)
update_by = #{updateBy},
update_by_name = #{updateByName},
update_time = #{updateTime}
WHERE
unique_id IN
#{item.uniqueId}
UPDATE picking_material_detail SET total_net_weight = 0, total_gross_weight = 0, total_volume = 0, total_area = 0
WHERE out_unique_id = #{outUniqueId} AND del_flag = 1
UPDATE picking_material_detail pmd
INNER JOIN (SELECT unique_id FROM picking_material_detail WHERE out_unique_id = #{outUniqueId} AND del_flag = 1 ORDER BY unique_id LIMIT 1) first_row ON pmd.unique_id = first_row.unique_id
SET pmd.total_net_weight = #{totalNetWeight}, pmd.total_gross_weight = #{totalGrossWeight}, pmd.total_volume = #{totalVolume}, pmd.total_area = #{totalArea},
pmd.update_by = #{updateBy}, pmd.update_by_name = #{updateByName}, pmd.update_time = #{updateTime}
WHERE pmd.out_unique_id = #{outUniqueId} AND pmd.del_flag = 1