<?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.api.manage.dao.system.UploadFileDao">
    <insert id="insertEstate" parameterType="com.api.model.basicArchives.CpmBuildingUnitEstate">
        insert into cpm_building_unit_estate(
            building_unit_id,
            room_number,
            status,
            type,
            construction_area,
            indoor_area,
            create_id,
            create_date,
            is_delete,
            device_number
        )values (
            #{buildingUnitId},
            #{roomNumber},
            #{status},
            #{type},
            #{constructionArea},
            #{indoorArea},
            #{createId},
            #{createDate},
            #{isDelete},
            #{deviceNumber}
        )
    </insert>

    <insert id="insertBuilding" parameterType="com.api.model.basicArchives.CpmBuilding">
        insert into
        <trim prefix="cpm_building(" suffix=")" suffixOverrides=",">
            no,
            name,
            code,
            <if test="coordinate != null and coordinate != ''">
                coordinate,
            </if>
            <if test="totalFloor != null">
                total_floor,
            </if>
            create_id,
            create_date
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            #{no},
            #{name},
            #{code},
            <if test="coordinate != null and coordinate != ''">
                #{coordinate},
            </if>
            <if test="totalFloor != null">
                #{totalFloor},
            </if>
            #{createId},
            #{createDate}
        </trim>
    </insert>

    <insert id="insertServiceBrowsing">
        insert into sys_service_browsing(
            name,
            content,
            create_id,
            create_date
        )values (
            #{name},
            #{content},
            #{createId},
            #{createDate}
        )
    </insert>

    <select id="findByUnitId" parameterType="java.lang.Integer" resultType="com.api.model.basicArchives.CpmBuildingUnit">
        select * from cpm_building_unit where id = #{buildingUnitId}
    </select>
    <select id="findByBuildingId" resultType="com.api.model.basicArchives.CpmBuilding">
        select * from cpm_building where id = #{buildingId}
    </select>

    <insert id="insertBuildingUnit" parameterType="com.api.model.basicArchives.CpmBuildingUnit">
        insert into cpm_building_unit(
            building_id,
            no,
            total_floor,
            is_elevator,
            create_id,
            create_date
        ) values (
            #{buildingId},
            #{no},
            #{totalFloor},
            #{isElevator},
            #{createId},
            #{createDate}
        )
    </insert>

    <insert id="insertKey" parameterType="com.api.model.operationManagement.SysKeyManagement">
        insert into sys_key(
            code,
            facility_name,
            num,
            corresponding_position,
            storage_location,
            administrator,
            tel,
            create_id,
            create_date
        )values (
            #{code},
            #{facilityName},
            #{num},
            #{correspondingPosition},
            #{storageLocation},
            #{administrator},
            #{tel},
            #{createId},
            #{createDate}
        )
    </insert>
    <insert id="insertGreenArea" parameterType="com.api.model.operationManagement.SysGreenArea">
        insert into sys_green_area(
            name,
            create_id,
            create_date
        )values (
            #{name},
            #{createId},
            #{createDate}
        )
    </insert>
    <insert id="insertDailyPayment" parameterType="com.api.model.chargeManagement.DailyPayment">
        insert into sys_daily_payment(
            building_unit_estate_id,
            charges_template_detail_id,
            begin_date,
            end_date,
            unit_price,
            type,
            num,
            cost_price,
            paid_price,
            total_price,
            payment_price,
            status,
            rate,
            payment_term,
            create_id,
            create_date,
            is_delete
        ) values (
            #{buildingUnitEstateId},
            #{chargesTemplateDetailId},
            #{beginDate},
            #{endDate},
            #{unitPrice},
            #{type},
            #{num},
            #{costPrice},
            #{paidPrice},
            #{totalPrice},
            #{paymentPrice},
            #{status},
            #{rate},
            #{paymentTerm},
            #{createId},
            #{createDate},
            #{isDelete}
        )
        <selectKey keyProperty="id" resultType="java.lang.Integer">
            select LAST_INSERT_ID() AS id
        </selectKey>
    </insert>
</mapper>