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

    <resultMap type="TPreventivemaintenance" id="TPreventivemaintenanceResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="part"    column="part"    />
        <result property="itemtag"    column="itemtag"    />
        <result property="tagno"    column="tagno"    />
        <result property="maintcontents"    column="maintcontents"    />
        <result property="maintperiod"    column="maintperiod"    />
        <result property="responsibleby"    column="responsibleby"    />
        <result property="executor"    column="executor"    />
        <result property="confirmedby"    column="confirmedby"    />
        <result property="executionresult"    column="executionresult"    />
        <result property="quantity"    column="quantity"    />
        <result property="year"    column="year"    />
        <result property="jan"    column="jan"    />
        <result property="feb"    column="feb"    />
        <result property="mar"    column="mar"    />
        <result property="apr"    column="apr"    />
        <result property="may"    column="may"    />
        <result property="jun"    column="jun"    />
        <result property="jul"    column="jul"    />
        <result property="aug"    column="aug"    />
        <result property="sep"    column="sep"    />
        <result property="oct"    column="oct"    />
        <result property="nov"    column="nov"    />
        <result property="dec"    column="dec"    />
        <result property="item"    column="item"    />
        <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="selectTPreventivemaintenanceVo">
        select d.id, d.plant_code, d.part, d.itemtag, d.tagno, d.maintcontents, d.maintperiod, d.responsibleby, d.executor, d.confirmedby, d.executionresult, d.quantity, d.year, d.jan, d.feb, d.mar, d.apr, d.may, d.jun, d.jul, d.aug, d.sep, d.oct, d.nov, d.dec, d.item, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id ,s.dept_name from t_preventivemaintenance d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTPreventivemaintenanceList" parameterType="TPreventivemaintenance" resultMap="TPreventivemaintenanceResult">
        <include refid="selectTPreventivemaintenanceVo"/>
        <where>
            <if test="item != null  and item != ''"> and item = #{item}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>

    <select id="selectList" parameterType="TPreventivemaintenance" resultMap="TPreventivemaintenanceResult">
        <include refid="selectTPreventivemaintenanceVo"/>
        <where>
            <if test="year != null "> and year = #{year}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>

    <select id="selectTPreventivemaintenanceById" parameterType="Long" resultMap="TPreventivemaintenanceResult">
        <include refid="selectTPreventivemaintenanceVo"/>
        where id = #{id}
    </select>

    <insert id="insertTPreventivemaintenance" parameterType="TPreventivemaintenance">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_preventivemaintenance.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_preventivemaintenance
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="part != null">part,</if>
            <if test="itemtag != null">itemtag,</if>
            <if test="tagno != null">tagno,</if>
            <if test="maintcontents != null">maintcontents,</if>
            <if test="maintperiod != null">maintperiod,</if>
            <if test="responsibleby != null">responsibleby,</if>
            <if test="executor != null">executor,</if>
            <if test="confirmedby != null">confirmedby,</if>
            <if test="executionresult != null">executionresult,</if>
            <if test="quantity != null">quantity,</if>
            <if test="year != null">year,</if>
            <if test="jan != null">jan,</if>
            <if test="feb != null">feb,</if>
            <if test="mar != null">mar,</if>
            <if test="apr != null">apr,</if>
            <if test="may != null">may,</if>
            <if test="jun != null">jun,</if>
            <if test="jul != null">jul,</if>
            <if test="aug != null">aug,</if>
            <if test="sep != null">sep,</if>
            <if test="oct != null">oct,</if>
            <if test="nov != null">nov,</if>
            <if test="dec != null">dec,</if>
            <if test="item != null">item,</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="part != null">#{part},</if>
            <if test="itemtag != null">#{itemtag},</if>
            <if test="tagno != null">#{tagno},</if>
            <if test="maintcontents != null">#{maintcontents},</if>
            <if test="maintperiod != null">#{maintperiod},</if>
            <if test="responsibleby != null">#{responsibleby},</if>
            <if test="executor != null">#{executor},</if>
            <if test="confirmedby != null">#{confirmedby},</if>
            <if test="executionresult != null">#{executionresult},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="year != null">#{year},</if>
            <if test="jan != null">#{jan},</if>
            <if test="feb != null">#{feb},</if>
            <if test="mar != null">#{mar},</if>
            <if test="apr != null">#{apr},</if>
            <if test="may != null">#{may},</if>
            <if test="jun != null">#{jun},</if>
            <if test="jul != null">#{jul},</if>
            <if test="aug != null">#{aug},</if>
            <if test="sep != null">#{sep},</if>
            <if test="oct != null">#{oct},</if>
            <if test="nov != null">#{nov},</if>
            <if test="dec != null">#{dec},</if>
            <if test="item != null">#{item},</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="updateTPreventivemaintenance" parameterType="TPreventivemaintenance">
        update t_preventivemaintenance
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="part != null">part = #{part},</if>
            <if test="itemtag != null">itemtag = #{itemtag},</if>
            <if test="tagno != null">tagno = #{tagno},</if>
            <if test="maintcontents != null">maintcontents = #{maintcontents},</if>
            <if test="maintperiod != null">maintperiod = #{maintperiod},</if>
            <if test="responsibleby != null">responsibleby = #{responsibleby},</if>
            <if test="executor != null">executor = #{executor},</if>
            <if test="confirmedby != null">confirmedby = #{confirmedby},</if>
            <if test="executionresult != null">executionresult = #{executionresult},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="year != null">year = #{year},</if>
            <if test="jan != null">jan = #{jan},</if>
            <if test="feb != null">feb = #{feb},</if>
            <if test="mar != null">mar = #{mar},</if>
            <if test="apr != null">apr = #{apr},</if>
            <if test="may != null">may = #{may},</if>
            <if test="jun != null">jun = #{jun},</if>
            <if test="jul != null">jul = #{jul},</if>
            <if test="aug != null">aug = #{aug},</if>
            <if test="sep != null">sep = #{sep},</if>
            <if test="oct != null">oct = #{oct},</if>
            <if test="nov != null">nov = #{nov},</if>
            <if test="dec != null">dec = #{dec},</if>
            <if test="item != null">item = #{item},</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="deleteTPreventivemaintenanceById" parameterType="Long">
        update t_preventivemaintenance set del_flag = 2 where id = #{id}
    </update>

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

    <select id="selectPmStatusData" resultType="int">
        SELECT count(1) FROM t_preventivemaintenance d
        <where>
            and d.del_flag = 0
            <if test="month == 1">and jan = #{status}</if>
            <if test="month == 2">and feb = #{status}</if>
            <if test="month == 3">and mar = #{status}</if>
            <if test="month == 4">and apr = #{status}</if>
            <if test="month == 5">and may = #{status}</if>
            <if test="month == 6">and jun = #{status}</if>
            <if test="month == 7">and jul = #{status}</if>
            <if test="month == 8">and aug = #{status}</if>
            <if test="month == 9">and sep = #{status}</if>
            <if test="month == 10">and oct = #{status}</if>
            <if test="month == 11">and nov = #{status}</if>
            <if test="month == 12">and dec = #{status}</if>
            <if test="item != null  and item != ''"> and item = #{item}</if>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
</mapper>
