<?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.app.dao.butler.AppUserDecorationNewDao">

    <select id="list" parameterType="com.api.model.app.SearchAppUserDecorationNew" resultType="com.api.vo.butlerApp.ButlerUserDecorationNewVo">
        select concat(cb.no,'-',cbu.no,'-',cbue.room_number) as room_name,udn.*,
        ur.name as create_name,su.actual_name as tracker_name,su2.actual_name as reviewer_name
        from cpm_building_unit_estate as cbue,cpm_building_unit as cbu,
        cpm_building as cb,user_resident as ur,user_decoration_new as udn
        LEFT JOIN sys_user as su on udn.tracker = su.id
        LEFT JOIN sys_user as su2 on udn.reviewer = su2.id
        <where>
            udn.create_id = ur.id
            and udn.estate_id = cbue.id
            and cbue.building_unit_id = cbu.id
            and cbu.building_id = cb.id
            <if test="userDecorationNewStatus != null">
                and udn.status = #{userDecorationNewStatus}
            </if>
            and udn.create_id = #{id}
        </where>
        order by udn.create_date desc
    </select>

    <insert id="insert" parameterType="com.api.model.app.AppUserDecorationNew">
        insert into user_decoration_new(
            estate_id,
            status,
            construction_unit,
            director,
            director_tel,
            expected_begin,
            expected_end,
            create_id,
            create_date
        )values (
            #{estateId},
            #{status},
            #{constructionUnit},
            #{director},
            #{directorTel},
            #{expectedBegin},
            #{expectedEnd},
            #{createId},
            #{createDate}
        )
    </insert>


    <update id="applicationCompletion" parameterType="com.api.model.app.AppUserDecorationNew">
        update user_decoration_new
        set status = 5,
        application_check_date = #{applicationCheckDate}
        where id = #{id} and create_id = #{createId}
    </update>

</mapper>