<?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.ruoyi.system.mapper.PropertyRepairMapper">
    
    <resultMap type="PropertyRepair" id="PropertyRepairResult">
        <result property="repairId"    column="repair_id"    />
        <result property="userId"    column="user_id"    />
        <result property="portalId"    column="portal_id"    />
        <result property="houseAddress"    column="house_address"    />
        <result property="repairTime"    column="repair_time"    />
        <result property="phoneNumber"    column="phone_number"    />
        <result property="repairTitle"    column="repair_title"    />
        <result property="maintenanceCategory"    column="maintenance_category"    />
        <result property="repairDetails"    column="repair_details"    />
        <result property="repairImages"    column="repair_images"    />
        <result property="repairStatus"    column="repair_status"    />
        <result property="staffName"    column="staff_name"    />
        <result property="staffId"    column="staff_id"    />
        <result property="staffPhone"    column="staff_phone"    />
        <result property="visitTime"    column="visit_time"    />
        <result property="visitPhoto"    column="visit_photo"    />
        <result property="completionTime"    column="completion_time"    />
        <result property="completionPhoto"    column="completion_photo"    />
        <result property="repairCompletionDetails"    column="repair_completion_details"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectPropertyRepairVo">
        select repair_id, portal_id, house_address, repair_time,user_id, phone_number, repair_title, maintenance_category, repair_details, repair_images, repair_status, staff_name, staff_id, staff_phone, visit_time, visit_photo, completion_time, completion_photo, repair_completion_details, create_by, create_time, update_by, update_time, remark from property_repair
    </sql>

    <select id="selectPropertyRepairList" parameterType="PropertyRepair" resultMap="PropertyRepairResult">
        <include refid="selectPropertyRepairVo"/>
        <where>  
            <if test="portalId != null "> and portal_id = #{portalId}</if>
            <if test="houseAddress != null  and houseAddress != ''"> and house_address = #{houseAddress}</if>
            <if test="repairTime != null "> and repair_time = #{repairTime}</if>
            <if test="phoneNumber != null  and phoneNumber != ''"> and phone_number = #{phoneNumber}</if>
            <if test="repairTitle != null  and repairTitle != ''"> and repair_title = #{repairTitle}</if>
            <if test="maintenanceCategory != null  and maintenanceCategory != ''"> and maintenance_category = #{maintenanceCategory}</if>
            <if test="repairDetails != null  and repairDetails != ''"> and repair_details = #{repairDetails}</if>
            <if test="repairImages != null  and repairImages != ''"> and repair_images = #{repairImages}</if>
            <if test="repairStatus != null  and repairStatus != ''"> and repair_status = #{repairStatus}</if>
            <if test="staffName != null  and staffName != ''"> and staff_name like concat('%', #{staffName}, '%')</if>
            <if test="staffId != null "> and staff_id = #{staffId}</if>
            <if test="staffPhone != null  and staffPhone != ''"> and staff_phone = #{staffPhone}</if>
            <if test="visitTime != null "> and visit_time = #{visitTime}</if>
            <if test="visitPhoto != null  and visitPhoto != ''"> and visit_photo = #{visitPhoto}</if>
            <if test="completionTime != null "> and completion_time = #{completionTime}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="completionPhoto != null  and completionPhoto != ''"> and completion_photo = #{completionPhoto}</if>
            <if test="repairCompletionDetails != null  and repairCompletionDetails != ''"> and repair_completion_details = #{repairCompletionDetails}</if>
        </where>
        order by create_time DESC
    </select>
    
    <select id="selectPropertyRepairByRepairId" parameterType="Long" resultMap="PropertyRepairResult">
        <include refid="selectPropertyRepairVo"/>
        where repair_id = #{repairId}
    </select>
    <select id="selectPropertyRepairListByTime" parameterType="PropertyRepair" resultMap="PropertyRepairResult">
        <include refid="selectPropertyRepairVo"/>
        where date_format(repair_time,'%Y%m%d') &gt;= date_format(#{starTime},'%Y%m%d')
              AND date_format(repair_time,'%Y%m%d') &lt;= date_format(#{endTime},'%Y%m%d')
    </select>

    <insert id="insertPropertyRepair" parameterType="PropertyRepair" useGeneratedKeys="true" keyProperty="repairId">
        insert into property_repair
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="portalId != null">portal_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="houseAddress != null and houseAddress != ''">house_address,</if>
            <if test="repairTime != null">repair_time,</if>
            <if test="phoneNumber != null">phone_number,</if>
            <if test="repairTitle != null">repair_title,</if>
            <if test="maintenanceCategory != null">maintenance_category,</if>
            <if test="repairDetails != null">repair_details,</if>
            <if test="repairImages != null">repair_images,</if>
            <if test="repairStatus != null">repair_status,</if>
            <if test="staffName != null">staff_name,</if>
            <if test="staffId != null">staff_id,</if>
            <if test="staffPhone != null">staff_phone,</if>
            <if test="visitTime != null">visit_time,</if>
            <if test="visitPhoto != null">visit_photo,</if>
            <if test="completionTime != null">completion_time,</if>
            <if test="completionPhoto != null">completion_photo,</if>
            <if test="repairCompletionDetails != null">repair_completion_details,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="portalId != null">#{portalId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="houseAddress != null and houseAddress != ''">#{houseAddress},</if>
            <if test="repairTime != null">#{repairTime},</if>
            <if test="phoneNumber != null">#{phoneNumber},</if>
            <if test="repairTitle != null">#{repairTitle},</if>
            <if test="maintenanceCategory != null">#{maintenanceCategory},</if>
            <if test="repairDetails != null">#{repairDetails},</if>
            <if test="repairImages != null">#{repairImages},</if>
            <if test="repairStatus != null">#{repairStatus},</if>
            <if test="staffName != null">#{staffName},</if>
            <if test="staffId != null">#{staffId},</if>
            <if test="staffPhone != null">#{staffPhone},</if>
            <if test="visitTime != null">#{visitTime},</if>
            <if test="visitPhoto != null">#{visitPhoto},</if>
            <if test="completionTime != null">#{completionTime},</if>
            <if test="completionPhoto != null">#{completionPhoto},</if>
            <if test="repairCompletionDetails != null">#{repairCompletionDetails},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updatePropertyRepair" parameterType="PropertyRepair">
        update property_repair
        <trim prefix="SET" suffixOverrides=",">
            <if test="portalId != null">portal_id = #{portalId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="houseAddress != null and houseAddress != ''">house_address = #{houseAddress},</if>
            <if test="repairTime != null">repair_time = #{repairTime},</if>
            <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
            <if test="repairTitle != null">repair_title = #{repairTitle},</if>
            <if test="maintenanceCategory != null">maintenance_category = #{maintenanceCategory},</if>
            <if test="repairDetails != null">repair_details = #{repairDetails},</if>
            <if test="repairImages != null">repair_images = #{repairImages},</if>
            <if test="repairStatus != null">repair_status = #{repairStatus},</if>
            <if test="staffName != null">staff_name = #{staffName},</if>
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="staffPhone != null">staff_phone = #{staffPhone},</if>
            <if test="visitTime != null">visit_time = #{visitTime},</if>
            <if test="visitPhoto != null">visit_photo = #{visitPhoto},</if>
            <if test="completionTime != null">completion_time = #{completionTime},</if>
            <if test="completionPhoto != null">completion_photo = #{completionPhoto},</if>
            <if test="repairCompletionDetails != null">repair_completion_details = #{repairCompletionDetails},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where repair_id = #{repairId}
    </update>

    <delete id="deletePropertyRepairByRepairId" parameterType="Long">
        delete from property_repair where repair_id = #{repairId}
    </delete>

    <delete id="deletePropertyRepairByRepairIds" parameterType="String">
        delete from property_repair where repair_id in 
        <foreach item="repairId" collection="array" open="(" separator="," close=")">
            #{repairId}
        </foreach>
    </delete>
</mapper>