jialh
1 天以前 dd6687b118561100e1677e88a9c2f5842a54c531
java110-db/src/main/resources/mapper/store/ContractServiceDaoImplMapper.xml
@@ -1,26 +1,144 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="contractServiceDaoImpl">
    <!-- 保存合同管理信息 add by wuxw 2018-07-03 -->
    <insert id="saveContractInfo" parameterType="Map">
        insert into contract(
        a_link,a_contacts,amount,contract_type,store_id,operator,signing_time,b_contacts,party_a,b_link,party_b,
        contract_id,obj_id,contract_name,start_time,end_time,state,contract_code,obj_type,operator_link,contract_parent_id,
        obj_name, obj_person_name, obj_person_id,start_user_id
        ) values (
        #{aLink},#{aContacts},#{amount},#{contractType},#{storeId},#{operator},#{signingTime},#{bContacts},#{partyA},#{bLink},#{partyB},
        #{contractId},#{objId},#{contractName},#{startTime},#{endTime},#{state},#{contractCode},#{objType},#{operatorLink},#{contractParentId},
        #{objName}, #{objPersonName}, #{objPersonId},#{startUserId}
        )
        insert into contract(a_link, a_contacts, amount, contract_type, store_id, operator, signing_time, b_contacts,
                             party_a, b_link, party_b,
                             contract_id, obj_id, contract_name, start_time, end_time, state, contract_code, obj_type,
                             operator_link, contract_parent_id,
                             obj_name, obj_person_name, obj_person_id, start_user_id,party_c,c_link,c_contacts
            ,a_partya_id,b_partya_id,c_partya_id,community_id,
                             property_company,contract_term,is_archived,contract_reminder_date,
                             signatory_address,contact_email,contact_wechat,remarks,has_supplement_agreement, community_name)
        values (#{aLink}, #{aContacts}, #{amount}, #{contractType}, #{storeId}, #{operator}, #{signingTime},
                #{bContacts}, #{partyA}, #{bLink}, #{partyB},
                #{contractId}, #{objId}, #{contractName}, #{startTime}, #{endTime}, #{state}, #{contractCode},
                #{objType}, #{operatorLink}, #{contractParentId},
                #{objName}, #{objPersonName}, #{objPersonId}, #{startUserId},#{partyC},#{cLink},#{cContacts}
                   ,#{aPartyaId},#{bPartyaId},#{cPartyaId},#{communityId},
                #{propertyCompany},#{contractTerm},#{isArchived},#{contractReminderDate},
                #{signatoryAddress},#{contactEmail},#{contactWechat},#{remarks},#{hasSupplementAgreement},#{communityName})
    </insert>
    <resultMap id="ContractDtoResultMap" type="com.java110.dto.contract.ContractDto">
        <!-- ===================== 1. ContractDto 主表字段 ===================== -->
        <id column="contract_id" property="contractId"/>
        <result column="a_link" property="aLink"/>
        <result column="a_contacts" property="aContacts"/>
        <result column="amount" property="amount"/>
        <result column="contract_type" property="contractType"/>
        <result column="status_cd" property="statusCd"/>
        <result column="store_id" property="storeId"/>
        <result column="operator" property="operator"/>
        <result column="signing_time" property="signingTime"/>
        <result column="b_contacts" property="bContacts"/>
        <result column="party_a" property="partyA"/>
        <result column="b_link" property="bLink"/>
        <result column="party_b" property="partyB"/>
        <result column="obj_id" property="objId"/>
        <result column="contract_name" property="contractName"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="state" property="state"/>
        <result column="contract_code" property="contractCode"/>
        <result column="obj_type" property="objType"/>
        <result column="operator_link" property="operatorLink"/>
        <result column="contractTypeName" property="contractTypeName"/>
        <result column="audit" property="audit"/>
        <result column="stateName" property="stateName"/>
        <result column="state_desc" property="stateDesc"/>
        <result column="contractParentId" property="contractParentId"/>
        <result column="parentContractCode" property="parentContractCode"/>
        <result column="parentContractName" property="parentContractName"/>
        <result column="objName" property="objName"/>
        <result column="objPersonName" property="objPersonName"/>
        <result column="objPersonId" property="objPersonId"/>
        <result column="startUserId" property="startUserId"/>
        <result column="createTime" property="createTime"/>
        <result column="partyC" property="partyC"/>
        <result column="cLink" property="cLink"/>
        <result column="cContacts" property="cContacts"/>
        <result column="aPartyaId" property="aPartyaId"/>
        <result column="bPartyaId" property="bPartyaId"/>
        <result column="cPartyaId" property="cPartyaId"/>
        <result column="communityName" property="communityName"/>
        <result column="propertyCompany" property="propertyCompany"/>
        <result column="contractTerm" property="contractTerm"/>
        <result column="isArchived" property="isArchived"/>
        <result column="contractReminderDate" property="contractReminderDate"/>
        <result column="signatoryAddress" property="signatoryAddress"/>
        <result column="contactEmail" property="contactEmail"/>
        <result column="contactWechat" property="contactWechat"/>
        <result column="remarks" property="remarks"/>
        <result column="has_supplement_agreement" property="hasSupplementAgreement"/>
    <!-- 查询合同管理信息 add by wuxw 2018-07-03 -->
    <select id="getContractInfo" parameterType="Map" resultType="Map">
        <!-- ===================== 2. 广告信息子对象(已生效) ===================== -->
        <association property="adContractInfo" javaType="com.java110.dto.contract.AdContractInfoDto">
            <id column="ad_id" property="id"/>
            <result column="ad_contract_id" property="contractId"/>
            <result column="ad_type" property="adType"/>
            <result column="sub_type" property="subType"/>
            <result column="cooperation_form" property="cooperationForm"/>
            <result column="building_elevator_count" property="buildingElevatorCount"/>
            <result column="online_quantity" property="onlineQuantity"/>
            <result column="facility_location" property="facilityLocation"/>
        </association>
        <!-- ===================== 3. 合同金额明细 ===================== -->
        <association property="contractAmountDetail" javaType="com.java110.dto.contract.ContractAmountDetailDto">
            <id column="detail_id" property="id"/>
            <result column="detail_contract_id" property="contractId"/>
            <result column="total_contract_amount" property="totalContractAmount"/>
            <result column="unit_price" property="unitPrice"/>
            <result column="annual_amount" property="annualAmount"/>
            <result column="total_amount" property="totalAmount"/>
            <result column="settlement_method" property="settlementMethod"/>
            <result column="settlement_amount" property="settlementAmount"/>
            <result column="fee_type" property="feeType"/>
            <result column="account_info" property="accountInfo"/>
            <result column="main_meter_no" property="mainMeterNo"/>
            <result column="sub_meter_no" property="subMeterNo"/>
            <result column="last_month_reading" property="lastMonthReading"/>
            <result column="current_month_reading" property="currentMonthReading"/>
            <result column="current_period_consumption" property="currentPeriodConsumption"/>
            <result column="electricity_unit_price" property="electricityUnitPrice"/>
            <result column="electricity_fee" property="electricityFee"/>
            <result column="deposit" property="deposit"/>
            <result column="settlement_cycle" property="settlementCycle"/>
            <result column="payment_remark" property="paymentRemark"/>
        </association>
        <!-- ===================== 4. 合同管理分成 ===================== -->
        <association property="contractManagementShare" javaType="com.java110.dto.contract.ContractManagementShareDto">
            <id column="share_id" property="id"/>
            <result column="share_contract_id" property="contractId"/>
            <result column="management_ratio" property="managementRatio"/>
            <result column="our_company_amount" property="ourCompanyAmount"/>
            <result column="our_committee_share" property="ourCommitteeShare"/>
            <result column="our_company_receivable" property="ourCompanyReceivable"/>
        </association>
        <!-- ===================== 5. 合同缴费状态 ===================== -->
        <association property="contractPaymentStatus" javaType="com.java110.dto.contract.ContractPaymentStatusDto">
            <id column="payment_id" property="id"/>
            <result column="payment_contract_id" property="contractId"/>
            <result column="payment_status" property="paymentStatus"/>
            <result column="receivable_amount" property="receivableAmount"/>
            <result column="received_amount" property="receivedAmount"/>
            <result column="unpaid_amount" property="unpaidAmount"/>
            <result column="special_discount" property="specialDiscount"/>
            <result column="collection_progress" property="collectionProgress"/>
            <result column="final_collection_deadline" property="finalCollectionDeadline"/>
            <result column="collection_reminder_status" property="collectionReminderStatus"/>
            <result column="remark" property="remark"/>
        </association>
    </resultMap>
    <select id="getContractInfo" resultMap="ContractDtoResultMap">
        select t.a_link,t.a_link aLink,t.a_contacts,t.a_contacts aContacts,t.amount,t.contract_type,t.contract_type
        contractType,t.status_cd,t.status_cd statusCd,t.store_id,t.store_id
        storeId,t.operator,t.signing_time,t.signing_time signingTime,t.b_contacts,t.b_contacts
@@ -30,16 +148,105 @@
        endTime,t.state,t.contract_code,t.contract_code contractCode,t.obj_type,t.obj_type
        objType,t.operator_link,t.operator_link operatorLink,ct.type_name contractTypeName,ct.audit,td.`name`
        stateName,t.state_desc stateDesc,t.contract_parent_id contractParentId,tt.contract_code parentContractCode,
        tt.contract_name parentContractName,t.obj_name objName, t.obj_person_name objPersonName, t.obj_person_id objPersonId,
        t.start_user_id startUserId,t.create_time createTime
        tt.contract_name parentContractName,t.obj_name objName, t.obj_person_name objPersonName, t.obj_person_id
        objPersonId,t.start_user_id startUserId,t.create_time createTime,t.party_c partyC,t.c_link cLink,t.c_contacts cContacts
        ,t.a_partya_id aPartyaId,t.b_partya_id bPartyaId,t.c_partya_id cPartyaId,s_community.`name` communityName,
        t.property_company propertyCompany,t.contract_term contractTerm,t.is_archived isArchived,
        t.contract_reminder_date contractReminderDate,t.signatory_address signatoryAddress,
        t.contact_email contactEmail,t.contact_wechat contactWechat,t.remarks remarks,
        t.has_supplement_agreement           has_supplement_agreement,
        -- 广告表字段
        ad.id                                ad_id,
        ad.contract_id                       ad_contract_id,
        ad.ad_type,
        ad.sub_type,
        ad.cooperation_form,
        ad.building_elevator_count,
        ad.online_quantity,
        ad.facility_location,
        -- 合同金额明细
        detail.id                            detail_id,
        detail.contract_id                   detail_contract_id,
        detail.total_contract_amount,
        detail.unit_price,
        detail.annual_amount,
        detail.total_amount,
        detail.settlement_method,
        detail.settlement_amount,
        detail.fee_type,
        detail.account_info,
        detail.main_meter_no,
        detail.sub_meter_no,
        detail.last_month_reading,
        detail.current_month_reading,
        detail.current_period_consumption,
        detail.electricity_unit_price,
        detail.electricity_fee,
        detail.deposit,
        detail.settlement_cycle,
        detail.payment_remark,
        -- 合同管理分成
        share.id                             share_id,
        share.contract_id                    share_contract_id,
        share.management_ratio,
        share.our_company_amount,
        share.our_committee_share,
        share.our_company_receivable,
        -- 合同缴费状态
        payment.id                           payment_id,
        payment.contract_id                  payment_contract_id,
        payment.payment_status,
        payment.receivable_amount,
        IFNULL(ccd.received_amount, 0)       received_amount,
        payment.unpaid_amount,
        payment.special_discount,
        payment.collection_progress,
        payment.final_collection_deadline,
        payment.collection_reminder_status,
        payment.remark
        from contract t
        LEFT JOIN contract_type ct on t.contract_type = ct.contract_type_id and ct.status_cd = '0' and ct.store_id =
        t.store_id
        LEFT JOIN contract_type ct on t.contract_type = ct.contract_type_id and ct.status_cd = '0' and ct.store_id = t.store_id
        LEFT JOIN t_dict td on td.status_cd = t.state and td.table_name = 'contract' and td.table_columns = 'state'
        left join contract tt on t.contract_parent_id = tt.contract_id and tt.status_cd = '0' and tt.store_id = t.store_id
        where 1 =1
        left join s_community on t.community_id = s_community.community_id
        LEFT JOIN (
        SELECT
        contract_id,
        IFNULL(SUM(collection_amount), 0) AS received_amount
        FROM contract_collection_detail
        GROUP BY contract_id
        ) ccd ON t.contract_id = ccd.contract_id
        -- 已有的广告表
        LEFT JOIN ad_contract_info ad on t.contract_id = ad.contract_id
        -- 新增 3 张子表关联
        LEFT JOIN contract_amount_detail detail on t.contract_id = detail.contract_id
        LEFT JOIN contract_management_share share on t.contract_id = share.contract_id
        LEFT JOIN contract_payment_status payment on t.contract_id = payment.contract_id
        where 1=1
        <if test="communityName != null and communityName != ''">
            and s_community.`name` like concat('%',#{communityName},'%')
        </if>
        <if test="communityId != null and communityId != ''">
            and t.community_id = #{communityId}
        </if>
        <if test="aLink !=null and aLink != ''">
            and t.a_link= #{aLink}
        </if>
        <if test="aPartyaId !=null and aPartyaId != ''">
            and t.a_partya_id= #{aPartyaId}
        </if>
        <if test="bPartyaId !=null and bPartyaId != ''">
            and t.b_partya_id= #{bPartyaId}
        </if>
        <if test="cPartyaId !=null and cPartyaId != ''">
            and t.c_partya_id= #{cPartyaId}
        </if>
        <if test="aContacts !=null and aContacts != ''">
            and t.a_contacts= #{aContacts}
@@ -75,7 +282,7 @@
            and t.party_b= #{partyB}
        </if>
        <if test="partyBLike !=null and partyBLike != ''">
            and t.party_b like  concat('%',#{partyBLike},'%')
            and t.party_b like concat('%',#{partyBLike},'%')
        </if>
        <if test="contractId !=null and contractId != ''">
            and t.contract_id= #{contractId}
@@ -96,7 +303,7 @@
            and t.contract_name= #{contractName}
        </if>
        <if test="contractNameLike !=null and contractNameLike != ''">
            and t.contract_name like  concat('%',#{contractNameLike},'%')
            and t.contract_name like concat('%',#{contractNameLike},'%')
        </if>
        <if test="startTime !=null">
            and t.start_time= #{startTime}
@@ -104,14 +311,23 @@
        <if test="endTime !=null ">
            and t.end_time &lt;= #{endTime}
        </if>
        <if test="queryStartTime !=null">
        <if test="queryStartTime !=null and queryStartTime != ''">
            and t.create_time &gt; #{queryStartTime}
        </if>
        <if test="queryEndTime !=null">
        <if test="queryEndTime !=null and queryEndTime != ''">
            and t.create_time &lt; #{queryEndTime}
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="partyC !=null and partyC != ''">
            and t.party_c= #{partyC}
        </if>
        <if test="cLink !=null and cLink != ''">
            and t.c_link= #{cLink}
        </if>
        <if test="cContacts !=null and cContacts != ''">
            and t.c_contacts= #{cContacts}
        </if>
        <if test="noStates !=null ">
            and t.state not in
@@ -123,7 +339,7 @@
            and t.contract_code= #{contractCode}
        </if>
        <if test="contractCodeLike !=null and contractCodeLike != ''">
            and t.contract_code like  concat('%',#{contractCodeLike},'%')
            and t.contract_code like concat('%',#{contractCodeLike},'%')
        </if>
        <if test="objType !=null and objType != ''">
            and t.obj_type= #{objType}
@@ -135,15 +351,29 @@
            and t.contract_parent_id= #{contractParentId}
        </if>
        <if test="parentContractCodeLike !=null and parentContractCodeLike != ''">
            and tt.contract_code like  concat('%',#{parentContractCodeLike},'%')
            and tt.contract_code like concat('%',#{parentContractCodeLike},'%')
        </if>
        <!-- 新增字段的查询条件 -->
        <if test="propertyCompany !=null and propertyCompany != ''">
            and t.property_company like concat('%',#{propertyCompany},'%')
        </if>
        <if test="contractTerm !=null and contractTerm != ''">
            and t.contract_term= #{contractTerm}
        </if>
        <if test="isArchived !=null and isArchived != ''">
            and t.is_archived= #{isArchived}
        </if>
        <if test="contractReminderDate !=null and contractReminderDate != ''">
            and t.contract_reminder_date= #{contractReminderDate}
        </if>
        <if test="hasSupplementAgreement !=null and hasSupplementAgreement != ''">
            and t.has_supplement_agreement= #{hasSupplementAgreement}
        </if>
        order by t.create_time desc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
    <!-- 修改合同管理信息 add by wuxw 2018-07-03 -->
    <update id="updateContractInfo" parameterType="Map">
@@ -151,90 +381,237 @@
        <if test="newBId != null and newBId != ''">
            ,t.b_id = #{newBId}
        </if>
        <if test="aLink !=null and aLink != ''">
        <if test="aLink != null and aLink != ''">
            , t.a_link= #{aLink}
        </if>
        <if test="aContacts !=null and aContacts != ''">
        <if test="aContacts != null and aContacts != ''">
            , t.a_contacts= #{aContacts}
        </if>
        <if test="amount !=null and amount != ''">
        <if test="amount != null and amount != ''">
            , t.amount= #{amount}
        </if>
        <if test="contractType !=null and contractType != ''">
        <if test="contractType != null and contractType != ''">
            , t.contract_type= #{contractType}
        </if>
        <if test="storeId !=null and storeId != ''">
        <if test="storeId != null and storeId != ''">
            , t.store_id= #{storeId}
        </if>
        <if test="operator !=null and operator != ''">
        <if test="operator != null and operator != ''">
            , t.operator= #{operator}
        </if>
        <if test="signingTime !=null and signingTime != ''">
        <if test="signingTime != null and signingTime != ''">
            , t.signing_time= #{signingTime}
        </if>
        <if test="bContacts !=null and bContacts != ''">
        <if test="bContacts != null and bContacts != ''">
            , t.b_contacts= #{bContacts}
        </if>
        <if test="partyA !=null and partyA != ''">
        <if test="partyA != null and partyA != ''">
            , t.party_a= #{partyA}
        </if>
        <if test="bLink !=null and bLink != ''">
        <if test="bLink != null and bLink != ''">
            , t.b_link= #{bLink}
        </if>
        <if test="partyB !=null and partyB != ''">
        <if test="partyB != null and partyB != ''">
            , t.party_b= #{partyB}
        </if>
        <if test="objId !=null and objId != ''">
        <if test="objId != null and objId != ''">
            , t.obj_id= #{objId}
        </if>
        <if test="objName !=null and objName != ''">
        <if test="objName != null and objName != ''">
            , t.obj_name= #{objName}
        </if>
        <if test="objPersonId !=null and objPersonId != ''">
        <if test="objPersonId != null and objPersonId != ''">
            , t.obj_person_id= #{objPersonId}
        </if>
        <if test="objPersonName !=null and objPersonName != ''">
        <if test="objPersonName != null and objPersonName != ''">
            , t.obj_person_name= #{objPersonName}
        </if>
        <if test="contractName !=null and contractName != ''">
        <if test="contractName != null and contractName != ''">
            , t.contract_name= #{contractName}
        </if>
        <if test="startTime !=null ">
        <!-- ========== 关键修复:时间字段必须判断空字符串 ========== -->
        <if test="startTime != null and startTime != ''">
            , t.start_time= #{startTime}
        </if>
        <if test="endTime !=null">
        <if test="endTime != null and endTime != ''">
            , t.end_time= #{endTime}
        </if>
        <if test="state !=null and state != ''">
        <if test="state != null and state != ''">
            , t.state= #{state}
        </if>
        <if test="stateDesc !=null and stateDesc != ''">
        <if test="stateDesc != null and stateDesc != ''">
            , t.state_desc= #{stateDesc}
        </if>
        <if test="contractCode !=null and contractCode != ''">
        <if test="contractCode != null and contractCode != ''">
            , t.contract_code= #{contractCode}
        </if>
        <if test="objType !=null and objType != ''">
        <if test="objType != null and objType != ''">
            , t.obj_type= #{objType}
        </if>
        <if test="operatorLink !=null and operatorLink != ''">
        <if test="operatorLink != null and operatorLink != ''">
            , t.operator_link= #{operatorLink}
        </if>
        where 1=1
        <if test="contractId !=null and contractId != ''">
            and t.contract_id= #{contractId}
        <if test="partyC != null and partyC != ''">
            , t.party_c= #{partyC}
        </if>
        <if test="cLink != null and cLink != ''">
            , t.c_link= #{cLink}
        </if>
        <if test="cContacts != null and cContacts != ''">
            , t.c_contacts= #{cContacts}
        </if>
        <if test="aPartyaId != null and aPartyaId != ''">
            , t.a_partya_id= #{aPartyaId}
        </if>
        <if test="bPartyaId != null and bPartyaId != ''">
            , t.b_partya_id= #{bPartyaId}
        </if>
        <if test="cPartyaId != null and cPartyaId != ''">
            , t.c_partya_id= #{cPartyaId}
        </if>
        <if test="communityId != null and communityId != ''">
            , t.community_id = #{communityId}
        </if>
        <if test="propertyCompany != null and propertyCompany != ''">
            , t.property_company= #{propertyCompany}
        </if>
        <if test="contractTerm != null and contractTerm != ''">
            , t.contract_term= #{contractTerm}
        </if>
        <if test="isArchived != null and isArchived != ''">
            , t.is_archived= #{isArchived}
        </if>
        <!-- ========== 关键修复 ========== -->
        <if test="contractReminderDate != null and contractReminderDate != ''">
            , t.contract_reminder_date= #{contractReminderDate}
        </if>
        <if test="signatoryAddress != null and signatoryAddress != ''">
            , t.signatory_address= #{signatoryAddress}
        </if>
        <if test="contactEmail != null and contactEmail != ''">
            , t.contact_email= #{contactEmail}
        </if>
        <if test="contactWechat != null and contactWechat != ''">
            , t.contact_wechat= #{contactWechat}
        </if>
        <if test="remarks != null and remarks != ''">
            , t.remarks= #{remarks}
        </if>
        <if test="hasSupplementAgreement != null and hasSupplementAgreement != ''">
            , t.has_supplement_agreement= #{hasSupplementAgreement}
        </if>
        where 1=1
        <if test="contractId != null and contractId != ''">
            and t.contract_id= #{contractId}
        </if>
    </update>
    <insert id="saveOrUpdateAdContractInfo">
        insert into ad_contract_info (id, contract_id, ad_type, sub_type, cooperation_form,
                                      building_elevator_count, online_quantity, facility_location)
        values (#{id}, #{contractId}, #{adType}, #{subType}, #{cooperationForm},
                #{buildingElevatorCount}, #{onlineQuantity}, #{facilityLocation})
            on duplicate key update
                                 ad_type = #{adType},
                                 sub_type = #{subType},
                                 cooperation_form = #{cooperationForm},
                                 building_elevator_count = #{buildingElevatorCount},
                                 online_quantity = #{onlineQuantity},
                                 facility_location = #{facilityLocation}
    </insert>
    <insert id="saveOrUpdateContractAmountDetail">
        insert into contract_amount_detail (id, contract_id, total_contract_amount, unit_price, annual_amount, total_amount,
                                            settlement_method, settlement_amount, fee_type, account_info, main_meter_no, sub_meter_no,
                                            last_month_reading, current_month_reading, current_period_consumption, electricity_unit_price,
                                            electricity_fee, deposit, settlement_cycle, payment_remark)
        values (#{id}, #{contractId}, #{totalContractAmount}, #{unitPrice}, #{annualAmount}, #{totalAmount},
                #{settlementMethod}, #{settlementAmount}, #{feeType}, #{accountInfo}, #{mainMeterNo}, #{subMeterNo},
                #{lastMonthReading}, #{currentMonthReading}, #{currentPeriodConsumption}, #{electricityUnitPrice},
                #{electricityFee}, #{deposit}, #{settlementCycle}, #{paymentRemark})
            on duplicate key update
                                 total_contract_amount = #{totalContractAmount},
                                 unit_price = #{unitPrice},
                                 annual_amount = #{annualAmount},
                                 total_amount = #{totalAmount},
                                 settlement_method = #{settlementMethod},
                                 settlement_amount = #{settlementAmount},
                                 fee_type = #{feeType},
                                 account_info = #{accountInfo},
                                 main_meter_no = #{mainMeterNo},
                                 sub_meter_no = #{subMeterNo},
                                 last_month_reading = #{lastMonthReading},
                                 current_month_reading = #{currentMonthReading},
                                 current_period_consumption = #{currentPeriodConsumption},
                                 electricity_unit_price = #{electricityUnitPrice},
                                 electricity_fee = #{electricityFee},
                                 deposit = #{deposit},
                                 settlement_cycle = #{settlementCycle},
                                 payment_remark = #{paymentRemark}
    </insert>
    <insert id="saveOrUpdateContractManagementShare">
        insert into contract_management_share (id, contract_id, management_ratio, our_company_amount, our_committee_share, our_company_receivable)
        values (#{id}, #{contractId}, #{managementRatio}, #{ourCompanyAmount}, #{ourCommitteeShare}, #{ourCompanyReceivable})
            on duplicate key update
                                 management_ratio = #{managementRatio},
                                 our_company_amount = #{ourCompanyAmount},
                                 our_committee_share = #{ourCommitteeShare},
                                 our_company_receivable = #{ourCompanyReceivable}
    </insert>
    <insert id="saveOrUpdateContractPaymentStatus">
        insert into contract_payment_status (id, contract_id, payment_status, receivable_amount, received_amount, unpaid_amount,
                                             special_discount, collection_progress, final_collection_deadline, collection_reminder_status, remark)
        values (#{id}, #{contractId}, #{paymentStatus}, #{receivableAmount}, #{receivedAmount}, #{unpaidAmount},
                #{specialDiscount}, #{collectionProgress}, #{finalCollectionDeadline}, #{collectionReminderStatus}, #{remark})
            on duplicate key update
                                 payment_status = #{paymentStatus},
                                 receivable_amount = #{receivableAmount},
                                 received_amount = #{receivedAmount},
                                 unpaid_amount = #{unpaidAmount},
                                 special_discount = #{specialDiscount},
                                 collection_progress = #{collectionProgress},
                                 final_collection_deadline = #{finalCollectionDeadline},
                                 collection_reminder_status = #{collectionReminderStatus},
                                 remark = #{remark}
    </insert>
    <!-- 查询合同管理数量 add by wuxw 2018-07-03 -->
    <select id="queryContractsCount" parameterType="Map" resultType="Map">
        select count(1) count
        from contract t
        left join contract tt on t.contract_parent_id = tt.contract_id and tt.status_cd = '0' and tt.store_id = t.store_id
        left join contract tt on t.contract_parent_id = tt.contract_id and tt.status_cd = '0' and tt.store_id =
        t.store_id
        where 1 =1
        <if test="communityId != null and communityId != ''">
            and t.community_id = #{communityId}
        </if>
        <if test="partyC !=null and partyC != ''">
            and t.party_c= #{partyC}
        </if>
        <if test="cLink !=null and cLink != ''">
            and t.c_link= #{cLink}
        </if>
        <if test="cContacts !=null and cContacts != ''">
            and t.c_contacts= #{cContacts}
        </if>
        <if test="aLink !=null and aLink != ''">
            and t.a_link= #{aLink}
        </if>
        <if test="aPartyaId !=null and aPartyaId != ''">
            and t.a_partya_id= #{aPartyaId}
        </if>
        <if test="bPartyaId !=null and bPartyaId != ''">
            and t.b_partya_id= #{bPartyaId}
        </if>
        <if test="cPartyaId !=null and cPartyaId != ''">
            and t.c_partya_id= #{cPartyaId}
        </if>
        <if test="aContacts !=null and aContacts != ''">
            and t.a_contacts= #{aContacts}
@@ -270,7 +647,7 @@
            and t.party_b= #{partyB}
        </if>
        <if test="partyBLike !=null and partyBLike != ''">
            and t.party_b like  concat('%',#{partyBLike},'%')
            and t.party_b like concat('%',#{partyBLike},'%')
        </if>
        <if test="contractId !=null and contractId != ''">
            and t.contract_id= #{contractId}
@@ -291,20 +668,18 @@
            and t.contract_name= #{contractName}
        </if>
        <if test="contractNameLike !=null and contractNameLike != ''">
            and t.contract_name like  concat('%',#{contractNameLike},'%')
            and t.contract_name like concat('%',#{contractNameLike},'%')
        </if>
        <if test="startTime !=null">
        <if test="startTime !=null and startTime != ''">
            and t.start_time= #{startTime}
        </if>
        <if test="endTime !=null ">
        <if test="endTime !=null and endTime != ''">
            and t.end_time &lt;= #{endTime}
        </if>
        <if test="queryStartTime !=null">
        <if test="queryStartTime !=null and queryStartTime != ''">
            and t.create_time &gt; #{queryStartTime}
        </if>
        <if test="queryEndTime !=null">
        <if test="queryEndTime !=null and queryEndTime != ''">
            and t.create_time &lt; #{queryEndTime}
        </if>
        <if test="state !=null and state != ''">
@@ -320,7 +695,7 @@
            and t.contract_code= #{contractCode}
        </if>
        <if test="contractCodeLike !=null and contractCodeLike != ''">
            and t.contract_code like  concat('%',#{contractCodeLike},'%')
            and t.contract_code like concat('%',#{contractCodeLike},'%')
        </if>
        <if test="objType !=null and objType != ''">
            and t.obj_type= #{objType}
@@ -332,21 +707,38 @@
            and t.contract_parent_id= #{contractParentId}
        </if>
        <if test="parentContractCodeLike !=null and parentContractCodeLike != ''">
            and tt.contract_code like  concat('%',#{parentContractCodeLike},'%')
            and tt.contract_code like concat('%',#{parentContractCodeLike},'%')
        </if>
        <!-- 新增字段的数量查询条件 -->
        <if test="propertyCompany !=null and propertyCompany != ''">
            and t.property_company like concat('%',#{propertyCompany},'%')
        </if>
        <if test="contractTerm !=null and contractTerm != ''">
            and t.contract_term= #{contractTerm}
        </if>
        <if test="isArchived !=null and isArchived != ''">
            and t.is_archived= #{isArchived}
        </if>
        <if test="contractReminderDate !=null and contractReminderDate != ''">
            and t.contract_reminder_date= #{contractReminderDate}
        </if>
        <if test="hasSupplementAgreement !=null and hasSupplementAgreement != ''">
            and t.has_supplement_agreement= #{hasSupplementAgreement}
        </if>
    </select>
    <select id="queryContractsByOwnerIds" parameterType="Map" resultType="Map">
        select t.obj_id ownerId,count(t.contract_id) contractCount
        from contract t
        where t.status_cd = '0'
        <if test="communityId != null and communityId != ''">
            and t.community_id = #{communityId}
        </if>
        and t.obj_id in
        <foreach collection="ownerIds" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
        group by t.obj_id
    </select>
</mapper>
</mapper>