(select `name` from auth_warehouse where code = ip.invCode) invName,
(select `name`
from auth_space
where code = ipd.invSpaceCode and invWarehouseCode = ip.invCode) invSpaceName,
bp.ggxh,
bp.cpmctymc productName,
bu.lowStockNum,
bu.overStockNum,
bu.recentDateTime,
bu.isDateBy
from inv_product ip
left join basic_udirel bu on ip.relIdFk = bu.id
left join basic_products bp on bu.uuid = bp.uuid
left join inv_product_detail ipd
on ip.relIdFk = ipd.relId and IFNULL(ip.batchNo, 'empty') = ifnull(ipd.batchNo, 'empty')
and ip.invCode = ipd.invCode
where ip.id = #{invId}
group by ip.id
SELECT
ip.relIdFk AS relId,
ip.deptCode,
ip.invCode,
ipd.invSpaceCode,
aw.name AS invName,
aspc.name AS invSpaceName,
bp.ggxh,
bp.cpmctymc AS productName,
bu.lowStockNum,
bu.overStockNum,
bu.recentDateTime,
bu.isDateBy
FROM inv_product AS ip
LEFT JOIN basic_udirel AS bu ON ip.relIdFk = bu.id
LEFT JOIN basic_products AS bp ON bu.uuid = bp.uuid
LEFT JOIN inv_product_detail AS ipd ON ip.relIdFk = ipd.relId AND IFNULL(ip.batchNo, 'empty') = IFNULL(ipd.batchNo, 'empty') AND ip.invCode = ipd.invCode
LEFT JOIN auth_warehouse AS aw ON aw.code = ip.invCode
LEFT JOIN auth_space AS aspc ON aspc.code = ipd.invSpaceCode AND aspc.invWarehouseCode = ip.invCode