<?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.sems.mapper.TReportMonthMapper">
    
    <resultMap type="TReportMonth" id="TReportMonthResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="approveStatus"    column="approve_status"    />
        <result property="checkMonth"    column="check_month"    />
        <result property="rqUnit"    column="rq_unit"    />
        <result property="rqSelf"    column="rq_self"    />
        <result property="rqSafe"    column="rq_safe"    />
        <result property="rqProtect"    column="rq_protect"    />
        <result property="rqControl"    column="rq_control"    />
        <result property="rqIns"    column="rq_ins"    />
        <result property="rqOut"    column="rq_out"    />
        <result property="rqOther"    column="rq_other"    />
        <result property="gdUnit"    column="gd_unit"    />
        <result property="gdSelf"    column="gd_self"    />
        <result property="gdSafe"    column="gd_safe"    />
        <result property="gdControl"    column="gd_control"    />
        <result property="gdIns"    column="gd_ins"    />
        <result property="gdOut"    column="gd_out"    />
        <result property="gdOther"    column="gd_other"    />
        <result property="glPressure"    column="gl_pressure"    />
        <result property="glSafe"    column="gl_safe"    />
        <result property="glIns"    column="gl_ins"    />
        <result property="glBurn"    column="gl_burn"    />
        <result property="glCer"    column="gl_cer"    />
        <result property="glWater"    column="gl_water"    />
        <result property="glOther"    column="gl_other"    />
        <result property="approveTime"    column="approve_time"    />
        <result property="buildDate"    column="build_date"    />
        <result property="approveId"    column="approve_id"    />
        <result property="rqRemark"    column="rq_remark"    />
        <result property="gdRemark"    column="gd_remark"    />
        <result property="glRemark"    column="gl_remark"    />
        <result property="glUnit"    column="gl_unit"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptId"    column="dept_id"    />
        <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="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTReportMonthVo">
        select d.id, d.plant_code, d.approve_status, d.check_month, d.rq_unit, d.rq_self, d.rq_safe, d.rq_protect, d.rq_control, d.rq_ins, d.rq_out, d.rq_other, d.gd_unit, d.gd_self, d.gd_safe, d.gd_control, d.gd_ins, d.gd_out, d.gd_other, d.gl_pressure, d.gl_safe, d.gl_ins, d.gl_burn, d.gl_cer, d.gl_water, d.gl_other, d.approve_time, d.build_date, d.approve_id, d.rq_remark, d.gd_remark, d.gl_remark, d.gl_unit, d.remarks, d.dept_id, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate ,s.dept_name from t_report_month d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTReportMonthList" parameterType="TReportMonth" resultMap="TReportMonthResult">
        <include refid="selectTReportMonthVo"/>
        <where>
            <if test="plantCode != null  and plantCode != ''"> and plant_code like concat(concat('%', #{plantCode}), '%')</if>
            <if test="approveStatus != null  and approveStatus != '' or approveStatus== 0"> and approve_status = #{approveStatus}</if>
            <if test="checkMonth != null"> and check_month = #{checkMonth}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTReportMonthById" parameterType="Long" resultMap="TReportMonthResult">
        <include refid="selectTReportMonthVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTReportMonth" parameterType="TReportMonth">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_report_month.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_report_month
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null">plant_code,</if>
            <if test="approveStatus != null">approve_status,</if>
            <if test="checkMonth != null">check_month,</if>
            <if test="rqUnit != null">rq_unit,</if>
            <if test="rqSelf != null">rq_self,</if>
            <if test="rqSafe != null">rq_safe,</if>
            <if test="rqProtect != null">rq_protect,</if>
            <if test="rqControl != null">rq_control,</if>
            <if test="rqIns != null">rq_ins,</if>
            <if test="rqOut != null">rq_out,</if>
            <if test="rqOther != null">rq_other,</if>
            <if test="gdUnit != null">gd_unit,</if>
            <if test="gdSelf != null">gd_self,</if>
            <if test="gdSafe != null">gd_safe,</if>
            <if test="gdControl != null">gd_control,</if>
            <if test="gdIns != null">gd_ins,</if>
            <if test="gdOut != null">gd_out,</if>
            <if test="gdOther != null">gd_other,</if>
            <if test="glPressure != null">gl_pressure,</if>
            <if test="glSafe != null">gl_safe,</if>
            <if test="glIns != null">gl_ins,</if>
            <if test="glBurn != null">gl_burn,</if>
            <if test="glCer != null">gl_cer,</if>
            <if test="glWater != null">gl_water,</if>
            <if test="glOther != null">gl_other,</if>
            <if test="approveTime != null">approve_time,</if>
            <if test="buildDate != null">build_date,</if>
            <if test="approveId != null">approve_id,</if>
            <if test="rqRemark != null">rq_remark,</if>
            <if test="gdRemark != null">gd_remark,</if>
            <if test="glRemark != null">gl_remark,</if>
            <if test="glUnit != null">gl_unit,</if>
            <if test="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null">#{plantCode},</if>
            <if test="approveStatus != null">#{approveStatus},</if>
            <if test="checkMonth != null">#{checkMonth},</if>
            <if test="rqUnit != null">#{rqUnit},</if>
            <if test="rqSelf != null">#{rqSelf},</if>
            <if test="rqSafe != null">#{rqSafe},</if>
            <if test="rqProtect != null">#{rqProtect},</if>
            <if test="rqControl != null">#{rqControl},</if>
            <if test="rqIns != null">#{rqIns},</if>
            <if test="rqOut != null">#{rqOut},</if>
            <if test="rqOther != null">#{rqOther},</if>
            <if test="gdUnit != null">#{gdUnit},</if>
            <if test="gdSelf != null">#{gdSelf},</if>
            <if test="gdSafe != null">#{gdSafe},</if>
            <if test="gdControl != null">#{gdControl},</if>
            <if test="gdIns != null">#{gdIns},</if>
            <if test="gdOut != null">#{gdOut},</if>
            <if test="gdOther != null">#{gdOther},</if>
            <if test="glPressure != null">#{glPressure},</if>
            <if test="glSafe != null">#{glSafe},</if>
            <if test="glIns != null">#{glIns},</if>
            <if test="glBurn != null">#{glBurn},</if>
            <if test="glCer != null">#{glCer},</if>
            <if test="glWater != null">#{glWater},</if>
            <if test="glOther != null">#{glOther},</if>
            <if test="approveTime != null">#{approveTime},</if>
            <if test="buildDate != null">#{buildDate},</if>
            <if test="approveId != null">#{approveId},</if>
            <if test="rqRemark != null">#{rqRemark},</if>
            <if test="gdRemark != null">#{gdRemark},</if>
            <if test="glRemark != null">#{glRemark},</if>
            <if test="glUnit != null">#{glUnit},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</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>
         </trim>
    </insert>

    <update id="updateTReportMonth" parameterType="TReportMonth">
        update t_report_month
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null">plant_code = #{plantCode},</if>
            <if test="approveStatus != null">approve_status = #{approveStatus},</if>
            <if test="checkMonth != null">check_month = #{checkMonth},</if>
            <if test="rqUnit != null">rq_unit = #{rqUnit},</if>
            <if test="rqSelf != null">rq_self = #{rqSelf},</if>
            <if test="rqSafe != null">rq_safe = #{rqSafe},</if>
            <if test="rqProtect != null">rq_protect = #{rqProtect},</if>
            <if test="rqControl != null">rq_control = #{rqControl},</if>
            <if test="rqIns != null">rq_ins = #{rqIns},</if>
            <if test="rqOut != null">rq_out = #{rqOut},</if>
            <if test="rqOther != null">rq_other = #{rqOther},</if>
            <if test="gdUnit != null">gd_unit = #{gdUnit},</if>
            <if test="gdSelf != null">gd_self = #{gdSelf},</if>
            <if test="gdSafe != null">gd_safe = #{gdSafe},</if>
            <if test="gdControl != null">gd_control = #{gdControl},</if>
            <if test="gdIns != null">gd_ins = #{gdIns},</if>
            <if test="gdOut != null">gd_out = #{gdOut},</if>
            <if test="gdOther != null">gd_other = #{gdOther},</if>
            <if test="glPressure != null">gl_pressure = #{glPressure},</if>
            <if test="glSafe != null">gl_safe = #{glSafe},</if>
            <if test="glIns != null">gl_ins = #{glIns},</if>
            <if test="glBurn != null">gl_burn = #{glBurn},</if>
            <if test="glCer != null">gl_cer = #{glCer},</if>
            <if test="glWater != null">gl_water = #{glWater},</if>
            <if test="glOther != null">gl_other = #{glOther},</if>
            <if test="approveTime != null">approve_time = #{approveTime},</if>
            <if test="buildDate != null">build_date = #{buildDate},</if>
            <if test="approveId != null">approve_id = #{approveId},</if>
            <if test="rqRemark != null">rq_remark = #{rqRemark},</if>
            <if test="gdRemark != null">gd_remark = #{gdRemark},</if>
            <if test="glRemark != null">gl_remark = #{glRemark},</if>
            <if test="glUnit != null">gl_unit = #{glUnit},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</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>
        </trim>
        where id = #{id}
    </update>

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

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