<?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.document.mapper.TPlantproglistMapper">

    <resultMap type="TPlantproglist" id="TPlantproglistResult">
        <result property="id"    column="id"    />
        <result property="department"    column="department"    />
        <result property="fileno"    column="fileno"    />
        <result property="filename"    column="filename"    />
        <result property="revision"    column="revision"    />
        <result property="rccode"    column="rccode"    />
        <result property="carrier"    column="carrier"    />
        <result property="responsibility"    column="responsibility"    />
        <result property="filedate"    column="filedate"    />
        <result property="reviewdate"    column="reviewdate"    />
        <result property="nextreviewdate"    column="nextreviewdate"    />
        <result property="nexteditdate"    column="nexteditdate"    />
        <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="classify"    column="classify"    />
        <result property="reviewFrequency"    column="review_frequency"    />
        <result property="reviewResult"    column="review_result"    />
        <result property="versionKzs"    column="version_kzs"    />
        <result property="versionPan"    column="version_pan"    />
        <result property="attachmentNo"    column="attachment_no"    />
        <result property="attachmentName"    column="attachment_name"    />
        <result property="attachmentRevision"    column="attachment_revision"    />
        <result property="revisionDate"    column="revision_date"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
        <result property="dataCount" column="data_count" />
        <result property="dataMonth" column="data_month" />
    </resultMap>

    <sql id="selectTPlantproglistVo">
        select d.id, d.department, d.fileno, d.filename, d.revision, d.rccode, d.carrier, d.responsibility, d.filedate, d.reviewdate, d.nextreviewdate, d.nexteditdate, d.item, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.classify, d.dept_id, d.filenolastnum, d.review_frequency, d.review_result, d.version_kzs, d.version_pan, d.attachment_no, d.attachment_name, d.attachment_revision, d.revision_date ,s.dept_name from t_plantproglist d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTPlantproglistList" parameterType="TPlantproglist" resultMap="TPlantproglistResult">
        <include refid="selectTPlantproglistVo"/>
        <where>
            <if test="department != null  and department != ''"> and department = #{department}</if>
            <if test="fileno != null  and fileno != ''"> and fileno = #{fileno}</if>
            <if test="filename != null  and filename != ''"> and filename like concat(concat('%', #{filename}), '%')</if>
            <if test="revision != null  and revision != ''"> and revision = #{revision}</if>
            <if test="rccode != null  and rccode != ''"> and rccode = #{rccode}</if>
            <if test="carrier != null  and carrier != ''"> and carrier = #{carrier}</if>
            <if test="responsibility != null  and responsibility != ''"> and responsibility like concat(concat('%',#{responsibility}),'%')</if>
            <if test="filedate != null "> and filedate = #{filedate}</if>
            <if test="reviewdate != null "> and reviewdate = #{reviewdate}</if>
            <if test="nextreviewdate != null "> and nextreviewdate = #{nextreviewdate}</if>
            <if test="nexteditdate != null "> and nexteditdate = #{nexteditdate}</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="classify != null  and classify != ''"> and classify = #{classify}</if>
            <if test="reviewFrequency != null  and reviewFrequency != ''"> and review_frequency = #{reviewFrequency}</if>
            <if test="reviewResult != null  and reviewResult != ''"> and review_result = #{reviewResult}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.rccode asc, d.fileno asc
    </select>

    <select id="selectList" parameterType="TPlantproglist" resultMap="TPlantproglistResult">
        <include refid="selectTPlantproglistVo"/>
        <where>
            and d.del_flag = 0
            <if test="deptId != null "> and d.dept_id = #{deptId}</if>
            <if test="responsibility != null "> and d.responsibility = #{responsibility}</if>
        </where>
        <!-- 数据范围过滤 -->
        order by d.fileno asc
    </select>

    <select id="selectTPlantproglistById" parameterType="Long" resultMap="TPlantproglistResult">
        <include refid="selectTPlantproglistVo"/>
        where id = #{id}
    </select>

    <select id="countNextEditDate" parameterType="TPlantproglist" resultMap="TPlantproglistResult">
        SELECT
            #{startDate} data_month,
            count( 1 ) data_count
        FROM
            t_Plantproglist
        WHERE
            to_char(NEXTEDITDATE, 'YYYY/MM' ) =  #{startDate}
                AND DEL_FLAG=0
                AND DEPT_ID=10010
        ORDER BY
            data_month
    </select>

    <select id="countNextReviewDate" parameterType="TPlantproglist" resultMap="TPlantproglistResult">
        SELECT
            #{startDate} data_month,
            count( 1 ) data_count
        FROM
            t_Plantproglist
        WHERE
            to_char(NEXTREVIEWDATE, 'YYYY/MM' ) =  #{startDate}
                AND DEL_FLAG=0
                AND DEPT_ID=10010
        ORDER BY
            data_month
    </select>

    <insert id="insertTPlantproglist" parameterType="TPlantproglist">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_plantproglist.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_plantproglist
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="department != null and department != ''">department,</if>
            <if test="fileno != null and fileno != ''">fileno,</if>
            <if test="filename != null">filename,</if>
            <if test="revision != null">revision,</if>
            <if test="rccode != null">rccode,</if>
            <if test="carrier != null">carrier,</if>
            <if test="responsibility != null">responsibility,</if>
            <if test="filedate != null">filedate,</if>
            <if test="reviewdate != null">reviewdate,</if>
            <if test="nextreviewdate != null">nextreviewdate,</if>
            <if test="nexteditdate != null">nexteditdate,</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="classify != null">classify,</if>
            <if test="reviewFrequency != null">review_frequency,</if>
            <if test="reviewResult != null">review_result,</if>
            <if test="versionKzs != null">version_kzs,</if>
            <if test="versionPan != null">version_pan,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="attachmentNo != null">attachment_no,</if>
            <if test="attachmentName != null">attachment_name,</if>
            <if test="attachmentRevision != null">attachment_revision,</if>
            <if test="revisionDate != null">revision_date,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="department != null and department != ''">#{department},</if>
            <if test="fileno != null and fileno != ''">#{fileno},</if>
            <if test="filename != null">#{filename},</if>
            <if test="revision != null">#{revision},</if>
            <if test="rccode != null">#{rccode},</if>
            <if test="carrier != null">#{carrier},</if>
            <if test="responsibility != null">#{responsibility},</if>
            <if test="filedate != null">#{filedate},</if>
            <if test="reviewdate != null">#{reviewdate},</if>
            <if test="nextreviewdate != null">#{nextreviewdate},</if>
            <if test="nexteditdate != null">#{nexteditdate},</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="classify != null">#{classify},</if>
            <if test="reviewFrequency != null">#{reviewFrequency},</if>
            <if test="reviewResult != null">#{reviewResult},</if>
            <if test="versionKzs != null">#{versionKzs},</if>
            <if test="versionPan != null">#{versionPan},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="attachmentNo != null">#{attachmentNo},</if>
            <if test="attachmentName != null">#{attachmentName},</if>
            <if test="attachmentRevision != null">#{attachmentRevision},</if>
            <if test="revisionDate != null">#{revisionDate},</if>
        </trim>
    </insert>

    <update id="updateTPlantproglist" parameterType="TPlantproglist">
        update t_plantproglist
        <trim prefix="SET" suffixOverrides=",">
            <if test="department != null and department != ''">department = #{department},</if>
            <if test="fileno != null and fileno != ''">fileno = #{fileno},</if>
            <if test="filename != null">filename = #{filename},</if>
            <if test="revision != null">revision = #{revision},</if>
            <if test="rccode != null">rccode = #{rccode},</if>
            <if test="carrier != null">carrier = #{carrier},</if>
            <if test="responsibility != null">responsibility = #{responsibility},</if>
            <if test="filedate != null">filedate = #{filedate},</if>
            <if test="reviewdate != null">reviewdate = #{reviewdate},</if>
            <if test="nextreviewdate != null">nextreviewdate = #{nextreviewdate},</if>
            <if test="nexteditdate != null">nexteditdate = #{nexteditdate},</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="classify != null">classify = #{classify},</if>
            <if test="reviewFrequency != null">review_frequency = #{reviewFrequency},</if>
            <if test="reviewResult != null">review_result = #{reviewResult},</if>
            <if test="versionKzs != null">version_kzs = #{versionKzs},</if>
            <if test="versionPan != null">version_pan = #{versionPan},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="attachmentNo != null">attachment_no = #{attachmentNo},</if>
            <if test="attachmentName != null">attachment_name = #{attachmentName},</if>
            <if test="attachmentRevision != null">attachment_revision = #{attachmentRevision},</if>
            <if test="revisionDate != null">revision_date = #{revisionDate},</if>
        </trim>
        where id = #{id}
    </update>

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

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

    <select id="selectRcData" resultType="com.ruoyi.project.common.domain.DataEntity">
        SELECT count(1) as dataNum,d.rccode as dataName FROM t_plantproglist d
        <where>
            and d.del_flag = 0
            <if test="item != null  and item != ''"> and item = #{item}</if>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        GROUP BY rccode
        order by dataName
    </select>

    <select id="selectclassifyData" resultType="com.ruoyi.project.common.domain.DataEntity">
        SELECT count(1) as dataNum,d.classify as dataName FROM t_plantproglist d
        <where>
            and d.del_flag = 0
            <if test="item != null  and item != ''"> and item = #{item}</if>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        GROUP BY classify
        order by dataName
    </select>

</mapper>
