소스 검색

问题处理

yzc 1 년 전
부모
커밋
355f4f58df
1개의 변경된 파일20개의 추가작업 그리고 16개의 파일을 삭제
  1. 20 16
      hx-sale/src/main/resources/mapper/contract/ContractMapper.xml

+ 20 - 16
hx-sale/src/main/resources/mapper/contract/ContractMapper.xml

@@ -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 &lt; 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 ) &lt; 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">