<?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.TBamListMapper">

    <resultMap type="TBamList" id="TBamListResult">
        <result property="id"    column="id"    />
        <result property="originalId"    column="original_id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="item"    column="item"    />
        <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="totalcost"    column="totalcost"    />
        <result property="responsible"    column="responsible"    />
        <result property="rcfa"    column="rcfa"    />
        <result property="treatment"    column="treatment"    />
        <result property="maintcostbi"    column="maintcostbi"    />
        <result property="prodlossbi"    column="prodlossbi"    />
        <result property="maintcostai"    column="maintcostai"    />
        <result property="prodlossai"    column="prodlossai"    />
        <result property="benefit"    column="benefit"    />
        <result property="investcost"    column="investcost"    />
        <result property="pro"    column="pro"    />
        <result property="plancompdate"    column="plancompdate"    />
        <result property="actcompdate"    column="actcompdate"    />
        <result property="status"    column="status"    />
        <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="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTBamListVo">
        select d.id, d.original_id, d.plant_code, d.item, d.priority, d.fl, d.description, d.discipline, d.failbrief, d.totalcost, d.responsible, d.rcfa, d.treatment, d.maintcostbi, d.prodlossbi, d.maintcostai, d.prodlossai, d.benefit, d.investcost, d.pro, d.plancompdate, d.actcompdate, d.status, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_bam_list d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTBamListList" parameterType="TBamList" resultMap="TBamListResult">
        <include refid="selectTBamListVo"/>
        <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="selectList" parameterType="TBamList" resultMap="TBamListResult">
        <include refid="selectTBamListVo"/>
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>

    <select id="selectTBamListById" parameterType="Long" resultMap="TBamListResult">
        <include refid="selectTBamListVo"/>
        where id = #{id}
    </select>

    <insert id="insertTBamList" parameterType="TBamList">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_bam_list.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_bam_list
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="originalId != null">original_id,</if>
            <if test="plantCode != null">plant_code,</if>
            <if test="item != null">item,</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="totalcost != null">totalcost,</if>
            <if test="responsible != null">responsible,</if>
            <if test="rcfa != null">rcfa,</if>
            <if test="treatment != null">treatment,</if>
            <if test="maintcostbi != null">maintcostbi,</if>
            <if test="prodlossbi != null">prodlossbi,</if>
            <if test="maintcostai != null">maintcostai,</if>
            <if test="prodlossai != null">prodlossai,</if>
            <if test="benefit != null">benefit,</if>
            <if test="investcost != null">investcost,</if>
            <if test="pro != null">pro,</if>
            <if test="plancompdate != null">plancompdate,</if>
            <if test="actcompdate != null">actcompdate,</if>
            <if test="status != null">status,</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="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="originalId != null">#{originalId},</if>
            <if test="plantCode != null">#{plantCode},</if>
            <if test="item != null">#{item},</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="totalcost != null">#{totalcost},</if>
            <if test="responsible != null">#{responsible},</if>
            <if test="rcfa != null">#{rcfa},</if>
            <if test="treatment != null">#{treatment},</if>
            <if test="maintcostbi != null">#{maintcostbi},</if>
            <if test="prodlossbi != null">#{prodlossbi},</if>
            <if test="maintcostai != null">#{maintcostai},</if>
            <if test="prodlossai != null">#{prodlossai},</if>
            <if test="benefit != null">#{benefit},</if>
            <if test="investcost != null">#{investcost},</if>
            <if test="pro != null">#{pro},</if>
            <if test="plancompdate != null">#{plancompdate},</if>
            <if test="actcompdate != null">#{actcompdate},</if>
            <if test="status != null">#{status},</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="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <insert id="insertTBamListFromOriginal" parameterType="TBamOriginal">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_bam_list.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_bam_list
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="originalId != null">original_id,</if>
            <if test="plantCode != null">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="totalcost != null">totalcost,</if>
            <if test="responsible != null">responsible,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="createrCode != null">creater_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="originalId != null">#{originalId},</if>
            <if test="plantCode != null">#{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="totalcost != null">#{totalcost},</if>
            <if test="responsible != null">#{responsible},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="createrCode != null">#{createrCode},</if>
        </trim>
    </insert>

    <update id="updateTBamList" parameterType="TBamList">
        update t_bam_list
        <trim prefix="SET" suffixOverrides=",">
            <if test="originalId != null">original_id = #{originalId},</if>
            <if test="plantCode != null">plant_code = #{plantCode},</if>
            <if test="item != null">item = #{item},</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="totalcost != null">totalcost = #{totalcost},</if>
            <if test="responsible != null">responsible = #{responsible},</if>
            <if test="rcfa != null">rcfa = #{rcfa},</if>
            <if test="treatment != null">treatment = #{treatment},</if>
            <if test="maintcostbi != null">maintcostbi = #{maintcostbi},</if>
            <if test="prodlossbi != null">prodlossbi = #{prodlossbi},</if>
            <if test="maintcostai != null">maintcostai = #{maintcostai},</if>
            <if test="prodlossai != null">prodlossai = #{prodlossai},</if>
            <if test="benefit != null">benefit = #{benefit},</if>
            <if test="investcost != null">investcost = #{investcost},</if>
            <if test="pro != null">pro = #{pro},</if>
            <if test="plancompdate != null">plancompdate = #{plancompdate},</if>
            <if test="actcompdate != null">actcompdate = #{actcompdate},</if>
            <if test="status != null">status = #{status},</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="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

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

    <update id="deleteTBamListByIds" parameterType="String">
        update t_bam_list 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_list 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_list d
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        GROUP BY discipline
        order by dataName
    </select>
</mapper>
