platformx-business-finance-biz/src/main/resources/mapper/ContractMapper.xml
@@ -4,4 +4,100 @@
<mapper namespace="com.by4cloud.platformx.business.mapper.ContractMapper">
    <select id="pageByCredit" resultType="com.by4cloud.platformx.business.vo.ContractCreditSalesPageVo">
      SELECT
      id,
      contract_no,
      contract_name,
      party_a_id,
      party_a,
      party_b_id,
      party_b,
      amount,
      currency,
      contract_type,
      supply_attribute,
      contract_status,
      contract_attribute,
      sign_date,
      effective_date,
      delivery_cycle,
      expiration_date,
      attachment_url,
      remark,
      parent_id,
      approve_time,
      arrival_schedule_id,
      accept_schedule_id,
      erp_push_flag,
      billing_status,
      next_schedule_name,
      template_id,
      sales_model,
      paid_amount,
      create_by,
      update_by,
      create_time,
      update_time,
      del_flag,
      comp_id,
      (SELECT GROUP_CONCAT(DISTINCT t1.material_internal_name) from contract_subject_matter t1 WHERE t1.contract_id = t.id) productNames,
      IFNULL( t.billing_amout, 0 ) billing_amout,
      ( SELECT IFNULL( sum( unit_price * delivered_quantity ), 0 ) FROM contract_subject_matter t1 WHERE t1.contract_id = t.id ) outBoundAmount,
      ((
      SELECT
      IFNULL( sum( unit_price * delivered_quantity ), 0 )
      FROM
      contract_subject_matter t1
      WHERE
      t1.contract_id = t.id
      ) - IFNULL( t.billing_amout, 0 )) creditAmount
      FROM
      contract t
      WHERE
      (
      IFNULL( t.billing_amout, 0 )&lt;(
      SELECT
      IFNULL( sum( unit_price * delivered_quantity ), 0 )
      FROM
      contract_subject_matter t1
      WHERE
      t1.contract_id = t.id
      ))=1
      <if test="queryDTO.contractName !=null and queryDTO.contractName !=''">
         and t.contract_name LIKE CONCAT('%', #{queryDTO.contractName}, '%')
      </if>
      <if test="queryDTO.partyA !=null and queryDTO.partyA !=''">
         and t.party_a LIKE CONCAT('%', #{queryDTO.partyA}, '%')
      </if>
      <if test="queryDTO.productNames !=null and queryDTO.productNames !=''">
         and (SELECT GROUP_CONCAT(DISTINCT t1.material_internal_name) from contract_subject_matter t1 WHERE t1.contract_id = t.id) LIKE CONCAT('%', #{queryDTO.productNames}, '%')
      </if>
      <choose>
         <when test="queryDTO.sortFiled !=null and queryDTO.sortFiled !='' and queryDTO.sortFiled == 'sign_date'">
            order by ${queryDTO.sortFiled}
         </when>
         <when test="queryDTO.sortFiled !=null and queryDTO.sortFiled !='' and queryDTO.sortFiled == 'creditAmount'">
            order by ((
            SELECT
            IFNULL( sum( unit_price * delivered_quantity ), 0 )
            FROM
            contract_subject_matter t1
            WHERE
            t1.contract_id = t.id
            ) - IFNULL( t.billing_amout, 0 ))
         </when>
         <otherwise>
            order by t.create_time
         </otherwise>
      </choose>
      <choose>
         <when test="queryDTO.sortMethod !=null and queryDTO.sortMethod !=''">
            ${queryDTO.sortMethod}
         </when>
         <otherwise>
            desc
         </otherwise>
      </choose>
   </select>
</mapper>