select thisTab.id, thisTab.system_no, thisTab.bill_name, thisTab.customer_name, thisTab.payee, thisTab.responsible_person, thisTab.responsible_leader, thisTab.settlement_method, thisTab.business_type, thisTab.promotion_requirement, thisTab.is_internal_settlement, thisTab.internal_settlement_unit, thisTab.document_count, thisTab.total_amount, thisTab.currency, thisTab.discount_amount, thisTab.received_amount, thisTab.pending_amount, thisTab.exchange_rate, thisTab.cny_amount, thisTab.period_type, thisTab.business_start_date, thisTab.business_end_date, thisTab.billing_start_date, thisTab.billing_end_date, thisTab.bill_generate_date, thisTab.bill_send_date, thisTab.bill_due_date, thisTab.due_in_30_days, thisTab.overdue_amount, thisTab.overdue_1_to_30_days, thisTab.overdue_31_to_60_days, thisTab.overdue_61_to_90_days, thisTab.overdue_91_to_180_days, thisTab.overdue_181_to_365_days, thisTab.overdue_over_1_year, thisTab.overdue_days, thisTab.settlement_category, thisTab.settlement_period, thisTab.nc_settlement_date, thisTab.nc_settlement_amount, thisTab.account_remark, thisTab.overdue_interest, thisTab.status, thisTab.audit_status, thisTab.source_system_id, thisTab.remark, thisTab.create_by, thisTab.create_time, thisTab.update_by, thisTab.update_time, thisTab.deleted from receivable_bill_management AS thisTab select count(0) from receivable_bill_management as thisTab and thisTab.system_no = #{systemNo} and thisTab.bill_name like concat('%', #{billName}, '%') and thisTab.customer_name like concat('%', #{customerName}, '%') and thisTab.payee like concat('%', #{payee}, '%') and thisTab.responsible_person like concat('%', #{responsiblePerson}, '%') and thisTab.responsible_leader like concat('%', #{responsibleLeader}, '%') and thisTab.settlement_method = #{settlementMethod} and thisTab.business_type = #{businessType} and thisTab.promotion_requirement like concat('%', #{promotionRequirement}, '%') and thisTab.is_internal_settlement = #{isInternalSettlement} and thisTab.internal_settlement_unit = #{internalSettlementUnit} and thisTab.document_count = #{documentCount} and thisTab.total_amount = #{totalAmount} and thisTab.currency = #{currency} and thisTab.discount_amount = #{discountAmount} and thisTab.received_amount = #{receivedAmount} and thisTab.pending_amount = #{pendingAmount} and thisTab.exchange_rate = #{exchangeRate} and thisTab.cny_amount = #{cnyAmount} and thisTab.period_type = #{periodType} and thisTab.business_start_date = #{businessStartDate} and thisTab.business_end_date = #{businessEndDate} and thisTab.billing_start_date = #{billingStartDate} and thisTab.billing_end_date = #{billingEndDate} and thisTab.bill_generate_date = #{billGenerateDate} and thisTab.bill_send_date = #{billSendDate} and thisTab.bill_due_date = #{billDueDate} and thisTab.settlement_category = #{settlementCategory} and thisTab.settlement_period = #{settlementPeriod} and thisTab.nc_settlement_date = #{ncSettlementDate} and thisTab.nc_settlement_amount = #{ncSettlementAmount} and thisTab.account_remark like concat('%', #{accountRemark}, '%') and thisTab.overdue_interest = #{overdueInterest} and thisTab.status in (0, 1) and thisTab.status = #{status} and thisTab.deleted = #{deleted} insert into receivable_bill_management system_no, bill_name, customer_name, payee, responsible_person, responsible_leader, settlement_method, business_type, promotion_requirement, is_internal_settlement, internal_settlement_unit, document_count, total_amount, currency, discount_amount, received_amount, pending_amount, exchange_rate, cny_amount, period_type, business_start_date, business_end_date, billing_start_date, billing_end_date, bill_generate_date, bill_send_date, bill_due_date, settlement_category, settlement_period, nc_settlement_date, nc_settlement_amount, account_remark, overdue_interest, status, audit_status, source_system_id, remark, create_by, create_time, update_by, update_time, deleted, #{systemNo}, #{billName}, #{customerName}, #{payee}, #{responsiblePerson}, #{responsibleLeader}, #{settlementMethod}, #{businessType}, #{promotionRequirement}, #{isInternalSettlement}, #{internalSettlementUnit}, #{documentCount}, #{totalAmount}, #{currency}, #{discountAmount}, #{receivedAmount}, #{pendingAmount}, #{exchangeRate}, #{cnyAmount}, #{periodType}, #{businessStartDate}, #{businessEndDate}, #{billingStartDate}, #{billingEndDate}, #{billGenerateDate}, #{billSendDate}, #{billDueDate}, #{settlementCategory}, #{settlementPeriod}, #{ncSettlementDate}, #{ncSettlementAmount}, #{accountRemark}, #{overdueInterest}, #{status}, #{auditStatus}, #{sourceSystemId}, #{remark}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{deleted}, insert into receivable_bill_management system_no,bill_name,customer_name,payee,responsible_person,responsible_leader,settlement_method,business_type,promotion_requirement,is_internal_settlement,internal_settlement_unit,document_count,total_amount,currency,discount_amount,received_amount,pending_amount,exchange_rate,cny_amount,period_type,business_start_date,business_end_date,billing_start_date,billing_end_date,bill_generate_date,bill_send_date,bill_due_date,settlement_category,settlement_period,nc_settlement_date,nc_settlement_amount,account_remark,overdue_interest,status,audit_status,source_system_id,remark,create_by,create_time,update_by,update_time,deleted, #{item.systemNo},#{item.billName},#{item.customerName},#{item.payee},#{item.responsiblePerson},#{item.responsibleLeader},#{item.settlementMethod},#{item.businessType},#{item.promotionRequirement},#{item.isInternalSettlement},#{item.internalSettlementUnit},#{item.documentCount},#{item.totalAmount},#{item.currency},#{item.discountAmount},#{item.receivedAmount},#{item.pendingAmount},#{item.exchangeRate},#{item.cnyAmount},#{item.periodType},#{item.businessStartDate},#{item.businessEndDate},#{item.billingStartDate},#{item.billingEndDate},#{item.billGenerateDate},#{item.billSendDate},#{item.billDueDate},#{item.settlementCategory},#{item.settlementPeriod},#{item.ncSettlementDate},#{item.ncSettlementAmount},#{item.accountRemark},#{item.overdueInterest},#{item.status},#{item.auditStatus},#{item.sourceSystemId},#{item.remark},#{item.createBy},#{item.createTime},#{item.updateBy},#{item.updateTime},#{item.deleted}, update receivable_bill_management system_no = #{systemNo}, bill_name = #{billName}, customer_name = #{customerName}, payee = #{payee}, responsible_person = #{responsiblePerson}, responsible_leader = #{responsibleLeader}, settlement_method = #{settlementMethod}, business_type = #{businessType}, promotion_requirement = #{promotionRequirement}, is_internal_settlement = #{isInternalSettlement}, internal_settlement_unit = #{internalSettlementUnit}, document_count = #{documentCount}, total_amount = #{totalAmount}, currency = #{currency}, discount_amount = #{discountAmount}, received_amount = #{receivedAmount}, pending_amount = #{pendingAmount}, exchange_rate = #{exchangeRate}, cny_amount = #{cnyAmount}, period_type = #{periodType}, business_start_date = #{businessStartDate}, business_end_date = #{businessEndDate}, billing_start_date = #{billingStartDate}, billing_end_date = #{billingEndDate}, bill_generate_date = #{billGenerateDate}, bill_send_date = #{billSendDate}, bill_due_date = #{billDueDate}, settlement_category = #{settlementCategory}, settlement_period = #{settlementPeriod}, nc_settlement_date = #{ncSettlementDate}, nc_settlement_amount = #{ncSettlementAmount}, account_remark = #{accountRemark}, overdue_interest = #{overdueInterest}, status = #{status}, audit_status = #{auditStatus}, source_system_id = #{sourceSystemId}, remark = #{remark}, create_by = #{createBy}, create_time = #{createTime}, update_by = #{updateBy}, update_time = #{updateTime}, deleted = #{deleted}, where id = #{id} update receivable_bill_management system_no = #{item.systemNo}, bill_name = #{item.billName}, customer_name = #{item.customerName}, payee = #{item.payee}, responsible_person = #{item.responsiblePerson}, responsible_leader = #{item.responsibleLeader}, settlement_method = #{item.settlementMethod}, business_type = #{item.businessType}, promotion_requirement = #{item.promotionRequirement}, is_internal_settlement = #{item.isInternalSettlement}, internal_settlement_unit = #{item.internalSettlementUnit}, document_count = #{item.documentCount}, total_amount = #{item.totalAmount}, currency = #{item.currency}, discount_amount = #{item.discountAmount}, received_amount = #{item.receivedAmount}, pending_amount = #{item.pendingAmount}, exchange_rate = #{item.exchangeRate}, cny_amount = #{item.cnyAmount}, period_type = #{item.periodType}, business_start_date = #{item.businessStartDate}, business_end_date = #{item.businessEndDate}, billing_start_date = #{item.billingStartDate}, billing_end_date = #{item.billingEndDate}, bill_generate_date = #{item.billGenerateDate}, bill_send_date = #{item.billSendDate}, bill_due_date = #{item.billDueDate}, settlement_category = #{item.settlementCategory}, settlement_period = #{item.settlementPeriod}, nc_settlement_date = #{item.ncSettlementDate}, nc_settlement_amount = #{item.ncSettlementAmount}, account_remark = #{item.accountRemark}, overdue_interest = #{item.overdueInterest}, status = #{item.status}, audit_status = #{item.auditStatus}, source_system_id = #{item.sourceSystemId}, remark = #{item.remark}, create_by = #{item.createBy}, create_time = #{item.createTime}, update_by = #{item.updateBy}, update_time = #{item.updateTime}, deleted = #{item.deleted}, where id = #{item.id} delete from receivable_bill_management where id = #{id} delete from receivable_bill_management where id in #{id} UPDATE receivable_bill_management SET due_in_30_days = CASE WHEN pending_amount > 0 AND bill_due_date IS NOT NULL AND bill_due_date > CURDATE() AND DATEDIFF(bill_due_date, CURDATE()) <= 30 THEN pending_amount ELSE due_in_30_days END, overdue_amount = CASE WHEN pending_amount > 0 AND bill_due_date IS NOT NULL AND bill_due_date <= CURDATE() THEN pending_amount ELSE overdue_amount END, overdue_1_to_30_days = CASE WHEN pending_amount > 0 AND bill_due_date IS NOT NULL AND bill_due_date <= CURDATE() AND DATEDIFF(CURDATE(), bill_due_date) BETWEEN 1 AND 30 THEN pending_amount ELSE overdue_1_to_30_days END, overdue_31_to_60_days = CASE WHEN pending_amount > 0 AND bill_due_date IS NOT NULL AND bill_due_date <= CURDATE() AND DATEDIFF(CURDATE(), bill_due_date) BETWEEN 31 AND 60 THEN pending_amount ELSE overdue_31_to_60_days END, overdue_61_to_90_days = CASE WHEN pending_amount > 0 AND bill_due_date IS NOT NULL AND bill_due_date <= CURDATE() AND DATEDIFF(CURDATE(), bill_due_date) BETWEEN 61 AND 90 THEN pending_amount ELSE overdue_61_to_90_days END, overdue_91_to_180_days = CASE WHEN pending_amount > 0 AND bill_due_date IS NOT NULL AND bill_due_date <= CURDATE() AND DATEDIFF(CURDATE(), bill_due_date) BETWEEN 91 AND 180 THEN pending_amount ELSE overdue_91_to_180_days END, overdue_181_to_365_days = CASE WHEN pending_amount > 0 AND bill_due_date IS NOT NULL AND bill_due_date <= CURDATE() AND DATEDIFF(CURDATE(), bill_due_date) BETWEEN 181 AND 365 THEN pending_amount ELSE overdue_181_to_365_days END, overdue_over_1_year = CASE WHEN pending_amount > 0 AND bill_due_date IS NOT NULL AND bill_due_date <= CURDATE() AND DATEDIFF(CURDATE(), bill_due_date) > 365 THEN pending_amount ELSE overdue_over_1_year END, overdue_days = CASE WHEN pending_amount > 0 AND bill_due_date IS NOT NULL AND bill_due_date <= CURDATE() THEN DATEDIFF(CURDATE(), bill_due_date) ELSE overdue_days END, update_time = NOW() WHERE pending_amount > 0