<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fjhx.sale.mapper.contract.ContractProductBomMapper">
    <select id="getContractProductBomQuantitySum"
            resultType="com.fjhx.sale.entity.contract.vo.ContractProductBomVo">
        SELECT cpb.contract_id,
               cpb.material_id,
               sum(cpb.quantity * cp.quantity) AS quantity,
               cpb.*
        FROM contract_product_bom cpb
                 LEFT JOIN contract_product cp ON cpb.contract_product_id = cp.id
        WHERE cpb.contract_id = #{contractId}
        GROUP BY cpb.contract_id,
                 cpb.material_id
    </select>
</mapper>
