if(o.payment_term IS NOT NULL ,CONCAT(o.payment_term,o.payment_term_unit),(SELECT e.element_text from ag_po_order_life_product_elements e where o.id = e.order_id and e.factor_code like 'f_pay_term' LIMIT 1)) paymentTermUnit,
if(o.cover_term IS NOT NULL ,CONCAT(o.cover_term,o.cover_term_type) ,(SELECT e.element_text from ag_po_order_life_product_elements e where o.id = e.order_id and e.factor_code like 'f_coverage_term' LIMIT 1)) coverTermType,
o.order_price orderPrice,
pra.name practitionerName,
dept.name insurerBranchDeptName,
sub.name subordinateSystemName,
f.practitioner_level practitionerLevel,
f.commission_amount commissionAmount,
f.commission_type commissionType,
f.referral_rate referralRate,
f.referral_amount referralAmount,
op.drop_option_name commissionPayoutStatus,
pb.payout_yearmonth monthPeriod
from ag_acl_customer_fortune f
LEFT JOIN ag_po_order o
LEFT JOIN ag_acl_insurer i ON i.id = o.insurer_id
LEFT JOIN ag_product p ON p.id = o.product_id
LEFT JOIN ag_product_plan pp ON pp.id = o.plan_id
ON o.id = f.order_id
LEFT JOIN ag_acl_practitioner pra
LEFT JOIN ag_acl_insurer_branch_dept dept ON pra.dept_id = dept.id
LEFT JOIN ag_acl_practitioner_subordinate_system sub ON sub.id = pra.subordinate_system_id
ON pra.customer_id = f.customer_id
LEFT JOIN ag_acl_customer_fortune_payout_batch pb ON pb.id = f.payout_batch_id
LEFT JOIN ag_md_drop_options op
LEFT JOIN ag_md_drop_master mas ON mas.id = op.drop_master_id
ON op.drop_option_code = f.commission_payout_status
where o.commission_check_status = 2
AND mas.drop_code like 'Commission_Payout_Status'
<iftest="item.insurerId != null">
AND i.id = #{item.insurerId,jdbcType=BIGINT}
</if>
<iftest="item.insurerBranchId != null">
and pra.insurer_branch_id = #{item.insurerBranchDeptId,jdbcType=BIGINT}
</if>
<iftest="item.insurerBranchDeptId != null">
and dept.id = #{item.insurerBranchDeptId,jdbcType=BIGINT}
</if>
<iftest="item.subordinateSystemId != null">
and sub.id = #{item.subordinateSystemId,jdbcType=BIGINT}
</if>
<iftest="item.practitionerId != null">
and pra.id = #{item.practitionerId,jdbcType=BIGINT}
</if>
<iftest="item.commissionPayoutStatus != null">
and f.commission_payout_status = #{item.commissionPayoutStatus,jdbcType=BIGINT}
</if>
<iftest="item.commissionPayoutYearmonth != null">
and date_format(f.commission_payout_at, '%Y-%m') = #{item.commissionPayoutYearmonth,jdbcType=VARCHAR}
</if>
<iftest="item.payoutYearmonth != null">
and pb.payout_yearmonth = #{item.payoutYearmonth,jdbcType=VARCHAR}