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

    <resultMap type="TKkxglcs" id="TKkxglcsResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="area"    column="area"    />
        <result property="problem"    column="problem"    />
        <result property="loss"    column="loss"    />
        <result property="measures"    column="measures"    />
        <result property="category"    column="category"    />
        <result property="urgency"    column="urgency"    />
        <result property="saving"    column="saving"    />
        <result property="startdate"    column="startdate"    />
        <result property="closedate"    column="closedate"    />
        <result property="status"    column="status"    />
        <result property="imid"    column="imid"    />
        <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="selectTKkxglcsVo">
        select d.id, d.plant_code, d.area, d.problem, d.loss, d.measures, d.category, d.urgency, d.saving, d.startdate, d.closedate, d.status, d.imid, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id ,s.dept_name from t_kkxglcs d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTKkxglcsList" parameterType="TKkxglcs" resultMap="TKkxglcsResult">
        <include refid="selectTKkxglcsVo"/>
        <where>
            <if test="area != null  and area != ''"> and area = #{area}</if>
            <if test="category != null  and category != ''"> and category = #{category}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>

    <select id="selectTKkxglcsById" parameterType="Long" resultMap="TKkxglcsResult">
        <include refid="selectTKkxglcsVo"/>
        where id = #{id}
    </select>

    <insert id="insertTKkxglcs" parameterType="TKkxglcs">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_kkxglcs.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_kkxglcs
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="area != null">area,</if>
            <if test="problem != null">problem,</if>
            <if test="loss != null">loss,</if>
            <if test="measures != null">measures,</if>
            <if test="category != null">category,</if>
            <if test="urgency != null">urgency,</if>
            <if test="saving != null">saving,</if>
            <if test="startdate != null">startdate,</if>
            <if test="closedate != null">closedate,</if>
            <if test="status != null">status,</if>
            <if test="imid != null">imid,</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="area != null">#{area},</if>
            <if test="problem != null">#{problem},</if>
            <if test="loss != null">#{loss},</if>
            <if test="measures != null">#{measures},</if>
            <if test="category != null">#{category},</if>
            <if test="urgency != null">#{urgency},</if>
            <if test="saving != null">#{saving},</if>
            <if test="startdate != null">#{startdate},</if>
            <if test="closedate != null">#{closedate},</if>
            <if test="status != null">#{status},</if>
            <if test="imid != null">#{imid},</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="updateTKkxglcs" parameterType="TKkxglcs">
        update t_kkxglcs
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="area != null">area = #{area},</if>
            <if test="problem != null">problem = #{problem},</if>
            <if test="loss != null">loss = #{loss},</if>
            <if test="measures != null">measures = #{measures},</if>
            <if test="category != null">category = #{category},</if>
            <if test="urgency != null">urgency = #{urgency},</if>
            <if test="saving != null">saving = #{saving},</if>
            <if test="startdate != null">startdate = #{startdate},</if>
            <if test="closedate != null">closedate = #{closedate},</if>
            <if test="status != null">status = #{status},</if>
            <if test="imid != null">imid = #{imid},</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="deleteTKkxglcsById" parameterType="Long">
        update t_kkxglcs set del_flag = 2 where id = #{id}
    </update>

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

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

</mapper>
