<?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.asset.mapper.TbFaultReportMapper">
    
    <resultMap type="TbFaultReport" id="TbFaultReportResult">
        <result property="id"    column="id"    />
        <result property="assetBarCode"    column="asset_bar_code"    />
        <result property="userId"    column="user_id"    />
        <result property="reportDate"    column="report_date"    />
        <result property="faultPhenomenon"    column="fault_phenomenon"    />
        <result property="tel"    column="tel"    />
        <result property="processState"    column="process_state"    />
        <result property="processResult"    column="process_result"    />
    </resultMap>

    <sql id="selectTbFaultReportVo">
        select id, asset_bar_code, user_id, report_date, fault_phenomenon, tel, process_state, process_result from tb_fault_report
    </sql>

    <select id="selectTbFaultReportList" parameterType="TbFaultReport" resultMap="TbFaultReportResult">
        <include refid="selectTbFaultReportVo"/>
        <where>  
            <if test="assetBarCode != null  and assetBarCode != ''"> and asset_bar_code = #{assetBarCode}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="reportDate != null "> and report_date like concat('%', DATE_FORMAT(#{reportDate}, '%Y-%m-%d'), '%')</if>
            <if test="faultPhenomenon != null  and faultPhenomenon != ''"> and fault_phenomenon = #{faultPhenomenon}</if>
            <if test="processState != null "> and process_state = #{processState}</if>
        </where>
        order by process_state, report_date DESC
    </select>
    
    <select id="selectTbFaultReportById" parameterType="Long" resultMap="TbFaultReportResult">
        <include refid="selectTbFaultReportVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbFaultReport" parameterType="TbFaultReport" useGeneratedKeys="true" keyProperty="id">
        insert into tb_fault_report
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="assetBarCode != null and assetBarCode != ''">asset_bar_code,</if>
            <if test="userId != null">user_id,</if>
            <if test="reportDate != null">report_date,</if>
            <if test="faultPhenomenon != null and faultPhenomenon != ''">fault_phenomenon,</if>
            <if test="tel != null and tel != ''">tel,</if>
            <if test="processState != null">process_state,</if>
            <if test="processResult != null">process_result,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="assetBarCode != null and assetBarCode != ''">#{assetBarCode},</if>
            <if test="userId != null">#{userId},</if>
            <if test="reportDate != null">#{reportDate},</if>
            <if test="faultPhenomenon != null and faultPhenomenon != ''">#{faultPhenomenon},</if>
            <if test="tel != null and tel != ''">#{tel},</if>
            <if test="processState != null">#{processState},</if>
            <if test="processResult != null">#{processResult},</if>
         </trim>
    </insert>

    <update id="updateTbFaultReport" parameterType="TbFaultReport">
        update tb_fault_report
        <trim prefix="SET" suffixOverrides=",">
            <if test="assetBarCode != null and assetBarCode != ''">asset_bar_code = #{assetBarCode},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="reportDate != null">report_date = #{reportDate},</if>
            <if test="faultPhenomenon != null and faultPhenomenon != ''">fault_phenomenon = #{faultPhenomenon},</if>
            <if test="tel != null and tel != ''">tel = #{tel},</if>
            <if test="processState != null">process_state = #{processState},</if>
            <if test="processResult != null">process_result = #{processResult},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbFaultReportById" parameterType="Long">
        delete from tb_fault_report where id = #{id}
    </delete>

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