<?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.production.mapper.TMonthplanMapper">

    <resultMap type="TMonthplan" id="TMonthplanResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="year"    column="year"    />
        <result property="ethylene"    column="ethylene"    />
        <result property="btx"    column="btx"    />
        <result property="kpi"    column="kpi"    />
        <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="ytd"    column="ytd"    />
        <result property="target"    column="target"    />
        <result property="sort"    column="sort"    />
        <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="selectTMonthplanVo">
        select d.id, d.plant_code, d.year, d.ethylene, d.btx, d.kpi, 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.ytd, d.target, d.sort, 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_monthplan d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTMonthplanList" parameterType="TMonthplan" resultMap="TMonthplanResult">
        <include refid="selectTMonthplanVo"/>
        <where>
            <if test="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="year != null "> and year = #{year}</if>
            <if test="ethylene != null  and ethylene != ''"> and ethylene = #{ethylene}</if>
            <if test="btx != null  and btx != ''"> and btx = #{btx}</if>
            <if test="kpi != null  and kpi != ''"> and kpi = #{kpi}</if>
            <if test="jan != null "> and jan = #{jan}</if>
            <if test="feb != null "> and feb = #{feb}</if>
            <if test="mar != null "> and mar = #{mar}</if>
            <if test="apr != null "> and apr = #{apr}</if>
            <if test="may != null "> and may = #{may}</if>
            <if test="jun != null "> and jun = #{jun}</if>
            <if test="jul != null "> and jul = #{jul}</if>
            <if test="aug != null "> and aug = #{aug}</if>
            <if test="sep != null "> and sep = #{sep}</if>
            <if test="oct != null "> and oct = #{oct}</if>
            <if test="nov != null "> and nov = #{nov}</if>
            <if test="dec != null "> and dec = #{dec}</if>
            <if test="ytd != null "> and ytd = #{ytd}</if>
            <if test="target != null "> and target = #{target}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="item != null "> and item = #{item}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.sort
    </select>

    <select id="selectTMonthplanById" parameterType="Long" resultMap="TMonthplanResult">
        <include refid="selectTMonthplanVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMonthplan" parameterType="TMonthplan">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_monthplan.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_monthplan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="year != null">year,</if>
            <if test="ethylene != null">ethylene,</if>
            <if test="btx != null">btx,</if>
            <if test="kpi != null">kpi,</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="ytd != null">ytd,</if>
            <if test="target != null">target,</if>
            <if test="sort != null">sort,</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="year != null">#{year},</if>
            <if test="ethylene != null">#{ethylene},</if>
            <if test="btx != null">#{btx},</if>
            <if test="kpi != null">#{kpi},</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="ytd != null">#{ytd},</if>
            <if test="target != null">#{target},</if>
            <if test="sort != null">#{sort},</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="updateTMonthplan" parameterType="TMonthplan">
        update t_monthplan
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="year != null">year = #{year},</if>
            <if test="ethylene != null">ethylene = #{ethylene},</if>
            <if test="btx != null">btx = #{btx},</if>
            <if test="kpi != null">kpi = #{kpi},</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="ytd != null">ytd = #{ytd},</if>
            <if test="target != null">target = #{target},</if>
            <if test="sort != null">sort = #{sort},</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="deleteTMonthplanById" parameterType="Long">
        update t_monthplan set del_flag = 2 where id = #{id}
    </update>

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

</mapper>
