|
@@ -160,26 +160,30 @@
|
|
|
|
|
|
<select id="getNoPackContractByCustomerId" resultType="com.fjhx.sale.entity.contract.vo.ContractVo">
|
|
|
SELECT
|
|
|
- *
|
|
|
- FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
t1.*,
|
|
|
t2.quantity AS cpQuantity,
|
|
|
- ( SELECT IFNULL( SUM( pd.pack_quantity * pdd.quantity ), 0 ) FROM pack_detail_product pdd LEFT JOIN pack_detail
|
|
|
- pd ON pdd.pack_detail_id = pd.id WHERE pdd.contract_product_id = t2.id ) AS sumPackQuantity
|
|
|
+ IFNULL( sp.sumPackQuantity, 0 ) sumPackQuantity
|
|
|
FROM
|
|
|
contract t1
|
|
|
- LEFT JOIN contract_product t2 ON t1.id = t2.contract_id
|
|
|
- <where>
|
|
|
- <if test="customerId neq null and customerId neq '' ">
|
|
|
- buy_corporation_id = #{customerId}
|
|
|
- </if>
|
|
|
- </where>
|
|
|
- ) t1
|
|
|
- WHERE t1.sumPackQuantity < t1.cpQuantity
|
|
|
- AND t1.`status`=30
|
|
|
- GROUP BY t1.id
|
|
|
+ JOIN contract_product t2 ON t1.id = t2.contract_id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pdd.contract_product_id,
|
|
|
+ IFNULL( SUM( pd.pack_quantity * pdd.quantity ), 0 ) AS sumPackQuantity
|
|
|
+ FROM
|
|
|
+ pack_detail_product pdd
|
|
|
+ JOIN pack_detail pd ON pdd.pack_detail_id = pd.id
|
|
|
+ GROUP BY
|
|
|
+ pdd.contract_product_id
|
|
|
+ ) sp ON sp.contract_product_id = t2.id
|
|
|
+ WHERE
|
|
|
+ t1.`status` = 30
|
|
|
+ AND IFNULL( sp.sumPackQuantity, 0 ) < t2.quantity
|
|
|
+ <if test="customerId neq null and customerId neq '' ">
|
|
|
+ and buy_corporation_id = #{customerId}
|
|
|
+ </if>
|
|
|
+ GROUP BY
|
|
|
+ t1.id
|
|
|
</select>
|
|
|
|
|
|
<select id="getSalesTotal" resultType="com.fjhx.sale.entity.contract.vo.ContractVo">
|