<?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.plant.mapper.TManageactivityMapper">

    <resultMap type="TManageactivity" id="TManageactivityResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="serialnumber"    column="serialnumber"    />
        <result property="aclevel"    column="aclevel"    />
        <result property="activity"    column="activity"    />
        <result property="rccode"    column="rccode"    />
        <result property="progfreq"    column="progfreq"    />
        <result property="samplreq"    column="samplreq"    />
        <result property="responsible"    column="responsible"    />
        <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="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="selectTManageactivityVo">
        select d.id, d.plant_code, d.serialnumber, d.aclevel, d.activity, d.rccode, d.progfreq, d.samplreq, d.responsible, 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.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_manageactivity d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTManageactivityList" parameterType="TManageactivity" resultMap="TManageactivityResult">
        <include refid="selectTManageactivityVo"/>
        <where>
            <if test="activity != null  and activity != ''"> and activity like concat(concat('%', #{activity}), '%')</if>
            <if test="year != null "> and year like concat(concat('%', #{year}), '%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.serialnumber asc
    </select>

    <select id="selectTManageactivityById" parameterType="Long" resultMap="TManageactivityResult">
        <include refid="selectTManageactivityVo"/>
        where id = #{id}
    </select>

    <insert id="insertTManageactivity" parameterType="TManageactivity">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_manageactivity.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_manageactivity
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="serialnumber != null">serialnumber,</if>
            <if test="aclevel != null and aclevel != ''">aclevel,</if>
            <if test="activity != null and activity != ''">activity,</if>
            <if test="rccode != null">rccode,</if>
            <if test="progfreq != null">progfreq,</if>
            <if test="samplreq != null">samplreq,</if>
            <if test="responsible != null">responsible,</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="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="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="serialnumber != null">#{serialnumber},</if>
            <if test="aclevel != null and aclevel != ''">#{aclevel},</if>
            <if test="activity != null and activity != ''">#{activity},</if>
            <if test="rccode != null">#{rccode},</if>
            <if test="progfreq != null">#{progfreq},</if>
            <if test="samplreq != null">#{samplreq},</if>
            <if test="responsible != null">#{responsible},</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="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>

    <update id="updateTManageactivity" parameterType="TManageactivity">
        update t_manageactivity
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="serialnumber != null">serialnumber = #{serialnumber},</if>
            <if test="aclevel != null and aclevel != ''">aclevel = #{aclevel},</if>
            <if test="activity != null and activity != ''">activity = #{activity},</if>
            <if test="rccode != null">rccode = #{rccode},</if>
            <if test="progfreq != null">progfreq = #{progfreq},</if>
            <if test="samplreq != null">samplreq = #{samplreq},</if>
            <if test="responsible != null">responsible = #{responsible},</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="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="deleteTManageactivityById" parameterType="Long">
        update t_manageactivity set del_flag = 2 where id = #{id}
    </update>

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

</mapper>