<?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.AppArticleOutDao">
    <insert id="submit" parameterType="com.api.model.app.AppArticleOut">
        insert into user_article_out(
            building_unit_estate_id,
            name,
            weight,
            approach,
            <if test="movingCompanyTel != null and movingCompanyTel != ''">
                moving_company_tel,
            </if>
            expected_time,
            status,
            applicant_id,
            applicant_date,
            user_delete
        )values (
            #{buildingUnitEstateId},
            #{name},
            #{weight},
            #{approach},
            <if test="movingCompanyTel != null and movingCompanyTel != ''">
                #{movingCompanyTel},
            </if>
            #{expectedTime},
            #{status},
            #{applicantId},
            #{applicantDate},
            #{userDelete}
        )
        <selectKey keyProperty="id" resultType="java.lang.Integer">
            select LAST_INSERT_ID() AS id
        </selectKey>
    </insert>

    <select id="getMovingCompanyTel" resultType="com.api.vo.app.AppMovingCompanyVo">
        select * from sys_convenience_phone where type = 4
    </select>

    <select id="list" parameterType="java.lang.Integer" resultType="com.api.vo.app.AppArticleOutVo">
        select * from user_article_out where user_delete = 1 and applicant_id = #{id} order by applicant_date DESC
    </select>

    <update id="falseDelete" parameterType="com.api.model.app.UserIdAndArticleOutId">
        update user_article_out set user_delete = 0
        where id = #{articleOutId} and applicant_id = #{userId}
    </update>

    <select id="findQRCodeByIds" parameterType="com.api.model.app.UserIdAndArticleOutId" resultType="com.api.vo.app.AppArticleOutQRCodeVo">
        select uao.id,uao.applicant_id,uao.expected_time as effective_time,ur.name as applicant_name,concat(cb.no,"幢-",cbu.no,"单元-",cbue.room_number) as room_name
        from user_article_out as uao,user_resident as ur,cpm_building_unit_estate as cbue,cpm_building_unit as cbu,cpm_building as cb
        where uao.building_unit_estate_id = cbue.id and cbue.building_unit_id = cbu.id and cbu.building_id = cb.id and uao.applicant_id = ur.id and uao.id = #{articleOutId} and uao.applicant_id = #{userId}
    </select>
</mapper>