<?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.butlerApp.dao.butler.ButlerUserDecorationNewDao">

    <select id="list" parameterType="com.api.model.butlerApp.ButlerUserDecorationNewSearch" 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
            and udn.tracker = #{id}
            <if test="userDecorationNewStatus != null">
                and udn.status = #{userDecorationNewStatus}
            </if>
        </where>
        order by udn.application_check_date desc
    </select>
    <select id="findStatusById" parameterType="java.lang.Integer" resultType="java.lang.Integer">
        select status from user_decoration_new where id = #{decorationNewId}
    </select>
    <select id="findCheckDetailById" parameterType="java.lang.Integer" resultType="com.api.vo.butlerApp.ButlerUserDecorationNewCheckVo">
        select udcn.*,su.actual_name as create_name
        from user_decoration_check_new as udcn,sys_user as su
        where udcn.create_id = su.id and udcn.decoration_new_id = 1
        order by udcn.create_date desc
    </select>

    <insert id="submitReport" parameterType="com.api.model.butlerApp.ButlerUserDecorationNewCheck">
        insert into user_decoration_check_new(
            decoration_new_id,
            detail,
            is_qualified,
            create_id,
            create_date
        )values (
            #{decorationNewId},
            #{detail},
            #{isQualified},
            #{createId},
            #{createDate}
        )
    </insert>


    <update id="updateLastCheckInfo" parameterType="com.api.model.app.AppUserDecorationNew">
        update user_decoration_new
        set status = #{status},
        <if test="actualEnd != null">
            actual_end = #{actualEnd},
        </if>
        is_qualified = #{isQualified}
        where id = #{id}
    </update>

</mapper>