Files
nanguangszwlback/mhd_bms/src/main/resources/mapper/BillingStatementMapper.xml
T
2026-03-16 18:29:33 +08:00

262 lines
14 KiB
XML

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mhd.bms.domain.billingStatement.repository.mapper.BillingStatementMapper">
<select id="queryList" parameterType="com.mhd.bms.domain.billingStatement.repository.todo.BillingStatementDO"
resultType="com.mhd.bms.domain.billingStatement.repository.po.BillingStatementPO">
select
*
from billing_statement
where del_flag = 1
<include refid="common_where"/>
ORDER BY create_time DESC
</select>
<select id="queryPaymentOutList" resultType="com.mhd.bms.domain.billingStatement.repository.po.BillingStatementPO" parameterType="com.mhd.bms.domain.billingStatement.repository.todo.BillingStatementDO">
SELECT
billing_statement_id,
billing_flow,
top_organization_id,
organization_id,
organization_name,
settlement_customers_id,
settlement_customers_code,
settlement_entity,
account_expense_type,
belong_module_code,
belong_module,
billing_amount
FROM
billing_statement
WHERE
del_flag = 1
<include refid="common_where_two"></include>
</select>
<select id="queryCollectList"
resultType="com.mhd.bms.domain.billingStatement.repository.po.BillingStatementCollectPO">
select
SUM( IF(account_expense_type=1,billing_amount,0)) receivable,
SUM( IF(account_expense_type=2,billing_amount,0)) feesPayable,
WM_CONCAT(billing_state) AS billingStateCount,
settlement_entity,settlement_customers_code,SUM(billing_amount) bill_amount_sum,account_expense_type,COUNT(settlement_customers_code) count_fee,MIN(business_date) business_start_date ,MAX(business_date) business_end_date,MAX(organization_id) organization_id,organization_name,top_organization_id,billing_state,update_by_name,update_by,update_time,create_by_name,create_by,create_time
from billing_statement
where del_flag = 1
<include refid="collect_where"/>
group by settlement_customers_code
having 1
<include refid="having_collect"/>
</select>
<select id="queryDetails"
resultType="com.mhd.bms.domain.billingStatement.repository.po.BillingStatementPO">
select
*
from billing_statement
where del_flag = 1
<include refid="common_where_details"></include>
</select>
<sql id="common_where_details">
<if test="bdo.settlementCustomersCode != null and bdo.settlementCustomersCode != ''">
and settlement_customers_code = #{bdo.settlementCustomersCode}
</if>
<if test="bdo.billingState != null and bdo.billingState == 1">
and (billing_state = 1 or billing_state = 2)
</if>
<if test="bdo.billingState != null and bdo.billingState == 2">
and billing_state = 3
</if>
<if test="bdo.billingState == null or bdo.billingState == ''">
and billing_state <![CDATA[<]]> 4
</if>
</sql>
<select id="getDetailsByManageId" resultType="com.mhd.bms.domain.billingStatement.repository.po.BillingStatementPO" parameterType="java.lang.Long">
SELECT
a.*,
a.BILLING_AMOUNT AS billingAmount
FROM
billing_statement a
WHERE
a.del_flag = 1
AND a.bill_manage_id = #{billManageId}
GROUP BY
a.billing_statement_id
</select>
<sql id="common_where">
<if test="billingStatementDO.createTimeStart != null and billingStatementDO.createTimeStart != ''">
AND date_format(create_time,'%Y-%m-%d') <![CDATA[>=]]> #{billingStatementDO.createTimeStart}
</if>
<if test="billingStatementDO.createTimeEnd != null and billingStatementDO.createTimeEnd != ''">
AND date_format(create_time,'%Y-%m-%d') <![CDATA[<=]]> #{billingStatementDO.createTimeEnd}
</if>
<if test="billingStatementDO.createByName != null and billingStatementDO.createByName != ''">
AND create_by_name like concat('%', #{billingStatementDO.createByName}, '%')
</if>
<if test="billingStatementDO.organizationId != null">
AND organization_id = #{billingStatementDO.organizationId}
</if>
<if test="billingStatementDO.topOrganizationId != null and billingStatementDO.topOrganizationId != ''">
AND top_organization_id = #{billingStatementDO.topOrganizationId}
</if>
<if test="billingStatementDO.updateTimeStart != null and billingStatementDO.updateTimeStart != ''">
AND date_format(update_time,'%Y-%m-%d') <![CDATA[>=]]> #{billingStatementDO.updateTimeStart}
</if>
<if test="billingStatementDO.updateTimeEnd != null and billingStatementDO.updateTimeEnd != ''">
AND date_format(update_time,'%Y-%m-%d') <![CDATA[<=]]> #{billingStatementDO.updateTimeEnd}
</if>
<if test="billingStatementDO.updateByName != null and billingStatementDO.updateByName != ''">
AND update_by_name like concat('%', #{billingStatementDO.updateByName}, '%')
</if>
<if test="billingStatementDO.billingFlow != null and billingStatementDO.billingFlow != ''">
AND billing_flow like concat('%', #{billingStatementDO.billingFlow}, '%')
</if>
<if test="billingStatementDO.settlementEntity != null and billingStatementDO.settlementEntity != ''">
AND settlement_entity like concat('%', #{billingStatementDO.settlementEntity}, '%')
</if>
<if test="billingStatementDO.secondSubjectName != null and billingStatementDO.secondSubjectName != ''">
AND( first_subject_name like concat('%', #{billingStatementDO.secondSubjectName}, '%')
OR second_subject_name like concat('%', #{billingStatementDO.secondSubjectName}, '%') )
</if>
<if test="billingStatementDO.serviceItemsName != null and billingStatementDO.serviceItemsName != ''">
AND service_items_name like concat('%', #{billingStatementDO.serviceItemsName}, '%')
</if>
<if test="billingStatementDO.accountExpenseType != null">
AND account_expense_type = #{billingStatementDO.accountExpenseType}
</if>
<if test="billingStatementDO.settlementCustomersCode != null">
AND settlement_customers_code = #{billingStatementDO.settlementCustomersCode}
</if>
<if test="billingStatementDO.belongModuleCode != null">
AND belong_module_code = #{billingStatementDO.belongModuleCode}
</if>
<if test="billingStatementDO.cycleBeginTime != null and billingStatementDO.cycleEndTime != null">
AND date_format(cycle_end_time,'%Y-%m-%d') <![CDATA[<=]]> #{billingStatementDO.cycleEndTime}
AND date_format(cycle_begin_time,'%Y-%m-%d') <![CDATA[>=]]> #{billingStatementDO.cycleBeginTime}
</if>
<if test="billingStatementDO.billingState != null">
AND billing_state = #{billingStatementDO.billingState}
</if>
<if test="billingStatementDO.redFlushState != null">
AND red_flush_state = #{billingStatementDO.redFlushState}
</if>
<if test="billingStatementDO.belongModule != null and billingStatementDO.belongModule != ''">
AND belong_module like concat('%', #{billingStatementDO.belongModule}, '%')
</if>
<if test="billingStatementDO.documentType != null and billingStatementDO.documentType != ''">
AND document_type like concat('%', #{billingStatementDO.documentType}, '%')
</if>
<if test="billingStatementDO.originalBusinessNum != null and billingStatementDO.originalBusinessNum != ''">
AND original_business_num like concat('%', #{billingStatementDO.originalBusinessNum}, '%')
</if>
<if test="billingStatementDO.queryState != null and billingStatementDO.queryState == 1">
AND (billing_state = 1 OR billing_state = 2)
</if>
<if test="billingStatementDO.queryState != null and billingStatementDO.queryState == 2">
AND billing_state = 3
</if>
<if test="billingStatementDO.queryState != null and billingStatementDO.queryState == 3">
AND (billing_state = 4 OR billing_state = 5)
</if>
<if test="billingStatementDO.billingStatementIdSet != null">
AND billing_statement_id in
<foreach item="id" collection="billingStatementDO.billingStatementIdSet" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</sql>
<sql id="common_where_two">
<if test="billingStatementDO.billingState != null">
AND billing_state = #{billingStatementDO.billingState}
</if>
<if test="billingStatementDO.topOrganizationId != null">
AND top_organization_id = #{billingStatementDO.topOrganizationId}
</if>
<if test="billingStatementDO.organizationId != null">
AND organization_id = #{billingStatementDO.organizationId}
</if>
<if test="billingStatementDO.settlementCustomersCode != null and billingStatementDO.settlementCustomersCode != ''">
AND settlement_customers_code = #{billingStatementDO.settlementCustomersCode}
</if>
<if test="billingStatementDO.accountExpenseType != null">
AND account_expense_type = #{billingStatementDO.accountExpenseType}
</if>
<if test="billingStatementDO.belongModuleCode != null and billingStatementDO.belongModuleCode != ''">
AND belong_module_code = #{billingStatementDO.belongModuleCode}
</if>
<if test="billingStatementDO.documentTypeCode != null and billingStatementDO.documentTypeCode != ''">
AND document_type_code = #{billingStatementDO.documentTypeCode}
</if>
<if test="billingStatementDO.serviceItemsCode != null and billingStatementDO.serviceItemsCode != ''">
AND service_items_code = #{billingStatementDO.serviceItemsCode}
</if>
<if test="billingStatementDO.secondSubjectCode != null and billingStatementDO.secondSubjectCode != ''">
AND (first_subject_code = #{billingStatementDO.secondSubjectCode} OR second_subject_code = #{billingStatementDO.secondSubjectCode})
</if>
<if test="billingStatementDO.contractType != null">
AND contract_type = #{billingStatementDO.contractType}
</if>
<if test="billingStatementDO.projectCode != null and billingStatementDO.projectCode != ''">
AND project_code = #{billingStatementDO.projectCode}
</if>
<if test="billingStatementDO.businessDateStart != null and billingStatementDO.businessDateStart != ''">
AND date_format(business_date,'%Y-%m-%d') <![CDATA[>=]]> #{billingStatementDO.businessDateStart}
</if>
<if test="billingStatementDO.businessDateEnd != null and billingStatementDO.businessDateEnd != ''">
AND date_format(business_date,'%Y-%m-%d') <![CDATA[<=]]> #{billingStatementDO.businessDateEnd}
</if>
</sql>
<sql id="collect_where">
<if test="billingStatementCollectDO.settlementEntity != null and billingStatementCollectDO.settlementEntity != ''">
and settlement_entity like concat('%',#{billingStatementCollectDO.settlementEntity},'%')
</if>
<if test="billingStatementCollectDO.settlementCustomersCode != null and billingStatementCollectDO.settlementCustomersCode != ''">
and settlement_customers_code like concat('%',#{billingStatementCollectDO.settlementCustomersCode},'%')
</if>
<if test="billingStatementCollectDO.accountExpenseType != null ">
and account_expense_type = #{billingStatementCollectDO.accountExpenseType}
</if>
<if test="billingStatementCollectDO.billingState != null and billingStatementCollectDO.billingState == 1">
and (billing_state = 1 or billing_state = 2)
</if>
<if test="billingStatementCollectDO.billingState != null and billingStatementCollectDO.billingState == 2">
and billing_state = 3
</if>
<if test="billingStatementCollectDO.billingState == null or billingStatementCollectDO.billingState == ''">
and billing_state <![CDATA[<]]> 4
</if>
<if test="billingStatementCollectDO.organizationId != null">
and organization_id = #{billingStatementCollectDO.organizationId}
</if>
<if test="billingStatementCollectDO.topOrganizationId != null and billingStatementCollectDO.topOrganizationId != ''">
and top_organization_id = #{billingStatementCollectDO.topOrganizationId}
</if>
<if test="billingStatementCollectDO.organizationName != null and billingStatementCollectDO.organizationName != ''">
and organization_name = #{billingStatementCollectDO.organizationName}
</if>
</sql>
<sql id="having_collect">
<if test="billingStatementCollectDO.billAmountSum != null and billingStatementCollectDO.billAmountSum != ''">
and bill_amount_sum = #{billingStatementCollectDO.billAmountSum}
</if>
<if test="billingStatementCollectDO.countFee != null and billingStatementCollectDO.countFee != ''">
and count_fee = #{billingStatementCollectDO.countFee}
</if>
<if test="billingStatementCollectDO.businessStartDate != null">
and date_format(MIN(business_date),'%Y-%m-%d %H:%i:%s') <![CDATA[>=]]> #{billingStatementCollectDO.businessStartDate}
</if>
<if test="billingStatementCollectDO.businessEndDate != null">
and date_format(MAX(business_date),'%Y-%m-%d %H:%i:%s') <![CDATA[<=]]> #{billingStatementCollectDO.businessEndDate}
</if>
</sql>
</mapper>