<?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.project.reliability.mapper.TBamOriginalMapper">

    <resultMap type="TBamOriginal" id="TBamOriginalResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="priority"    column="priority"    />
        <result property="fl"    column="fl"    />
        <result property="description"    column="description"    />
        <result property="discipline"    column="discipline"    />
        <result property="failbrief"    column="failbrief"    />
        <result property="primstudy"    column="primstudy"    />
        <result property="maintcost"    column="maintcost"    />
        <result property="frequency"    column="frequency"    />
        <result property="loss"    column="loss"    />
        <result property="totalcost"    column="totalcost"    />
        <result property="phase"    column="phase"    />
        <result property="responsible"    column="responsible"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTBamOriginalVo">
        select d.id, d.plant_code, d.priority, d.fl, d.description, d.discipline, d.failbrief, d.primstudy, d.maintcost, d.frequency, d.loss, d.totalcost, d.phase, d.responsible, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id ,s.dept_name from t_bam_original d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTBamOriginalList" parameterType="TBamOriginal" resultMap="TBamOriginalResult">
        <include refid="selectTBamOriginalVo"/>
        <where>
            <if test="fl != null  and fl != ''"> and fl like concat(concat('%', #{fl}), '%')</if>
            <if test="description != null  and description != ''"> and description like concat(concat('%', #{description}), '%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>

    <select id="selectTBamOriginalById" parameterType="Long" resultMap="TBamOriginalResult">
        <include refid="selectTBamOriginalVo"/>
        where id = #{id}
    </select>

    <insert id="insertTBamOriginal" parameterType="TBamOriginal">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_bam_original.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_bam_original
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="priority != null">priority,</if>
            <if test="fl != null">fl,</if>
            <if test="description != null">description,</if>
            <if test="discipline != null">discipline,</if>
            <if test="failbrief != null">failbrief,</if>
            <if test="primstudy != null">primstudy,</if>
            <if test="maintcost != null">maintcost,</if>
            <if test="frequency != null">frequency,</if>
            <if test="loss != null">loss,</if>
            <if test="totalcost != null">totalcost,</if>
            <if test="phase != null">phase,</if>
            <if test="responsible != null">responsible,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="priority != null">#{priority},</if>
            <if test="fl != null">#{fl},</if>
            <if test="description != null">#{description},</if>
            <if test="discipline != null">#{discipline},</if>
            <if test="failbrief != null">#{failbrief},</if>
            <if test="primstudy != null">#{primstudy},</if>
            <if test="maintcost != null">#{maintcost},</if>
            <if test="frequency != null">#{frequency},</if>
            <if test="loss != null">#{loss},</if>
            <if test="totalcost != null">#{totalcost},</if>
            <if test="phase != null">#{phase},</if>
            <if test="responsible != null">#{responsible},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTBamOriginal" parameterType="TBamOriginal">
        update t_bam_original
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="priority != null">priority = #{priority},</if>
            <if test="fl != null">fl = #{fl},</if>
            <if test="description != null">description = #{description},</if>
            <if test="discipline != null">discipline = #{discipline},</if>
            <if test="failbrief != null">failbrief = #{failbrief},</if>
            <if test="primstudy != null">primstudy = #{primstudy},</if>
            <if test="maintcost != null">maintcost = #{maintcost},</if>
            <if test="frequency != null">frequency = #{frequency},</if>
            <if test="loss != null">loss = #{loss},</if>
            <if test="totalcost != null">totalcost = #{totalcost},</if>
            <if test="phase != null">phase = #{phase},</if>
            <if test="responsible != null">responsible = #{responsible},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTBamOriginalById" parameterType="Long">
        update t_bam_original set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTBamOriginalByIds" parameterType="String">
        update t_bam_original set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <select id="selectPriorityData" resultType="com.ruoyi.project.common.domain.DataEntity">
        SELECT count(1) as dataNum,d.priority as dataName FROM t_bam_original d
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        GROUP BY priority
        order by dataName
    </select>
    <select id="selectDisciplineData" resultType="com.ruoyi.project.common.domain.DataEntity">
        SELECT count(1) as dataNum,d.discipline as dataName FROM t_bam_original d
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        GROUP BY discipline
        order by dataName
    </select>

</mapper>
