<?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.system.mapper.form.MdFormRecordExtMapper">
    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.form.MdFormRecord">
        <id column="id" jdbcType="VARCHAR" property="id"/>
        <result column="form_id" jdbcType="VARCHAR" property="formId"/>
        <result column="status" jdbcType="TINYINT" property="status"/>
        <result column="commit_status" jdbcType="TINYINT" property="commitStatus"/>
        <result column="commit_cycle" jdbcType="VARCHAR" property="commitCycle"/>
        <result column="create_time" jdbcType="BIGINT" property="createTime"/>
        <result column="own_user" jdbcType="VARCHAR" property="ownUser"/>
        <result column="own_dept" jdbcType="VARCHAR" property="ownDept"/>
    </resultMap>
    <sql id="Base_Column_List">
    id, form_id, status, commit_status, commit_cycle, create_time, own_user, own_dept
  </sql>
    <sql id="Blob_Column_List">
    records
  </sql>
    <insert id="insertBatch" parameterType="java.util.List">
        insert into md_form_record (id, form_id, status,
        commit_status, commit_cycle, create_time,
        own_user, own_dept,records)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.id,jdbcType=VARCHAR}, #{item.formId,jdbcType=VARCHAR}, #{item.status,jdbcType=INTEGER},
            #{item.commitStatus,jdbcType=INTEGER}, #{item.commitCycle,jdbcType=VARCHAR},
            #{item.createTime,jdbcType=BIGINT}, #{item.ownUser,jdbcType=VARCHAR},
            #{item.ownDept,jdbcType=VARCHAR},#{item.records,jdbcType=LONGVARCHAR})
        </foreach>
    </insert>
    <select id="getCycleListByBaseId" resultType="com.ruoyi.system.domain.form.vo.FormRecordVo">
        select
       m.id,
       m.form_id formId,
       m.status,
       m.commit_status commitStatus ,
       m.commit_cycle commitCycle,
       m.create_time createTime,
       m.own_user ownUser,
       m.own_dept ownDept,
       form.img img,
       form.name "name",
        form.collect_mode collectMode,
        form.fix_start fixStart,
        form.fix_end fixEnd,
        form.cycle_type cycleType,
        form.cycle_last cycleLast,
        form.cycle_now cycleNow

        from md_form_record m
        inner join md_form form on form.id=m.form_id and form.collect_mode=#{cycle}
        where m.status = #{status}
        <if test="commitStatus !=null">
            and m.commit_status = #{commitStatus}
        </if>
        <if test="publishStatus !=null">
            and form.publish_status=#{publishStatus}
        </if>

        <if test="current !=null and current">
            and form.cycle_now=m.commit_cycle
        </if>

        order by m.commit_status asc ,form.create_time desc
    </select>
    <select id="getFixListByBaseId" resultType="com.ruoyi.system.domain.form.vo.FormRecordVo">
        select
        m.id,
        m.form_id formId,
        m.status,
        m.commit_status commitStatus ,
        m.commit_cycle commitCycle,
        m.create_time createTime,
        m.own_user ownUser,
        m.own_dept ownDept,
        form.img img,
        form.name "name",
        form.collect_mode collectMode,
        form.fix_start fixStart,
        form.fix_end fixEnd,
        form.cycle_type cycleType,
        form.cycle_last cycleLast,
        form.cycle_now cycleNow,
        form.publish_status publishStatus
        from md_form_record m
        inner join md_form form on form.id=m.form_id and form.collect_mode=#{cycle}
        where m.status = #{status}

        <if test="publishStatus !=null">
            and form.publish_status=#{publishStatus}
        </if>

        <if test="commitStatus !=null">
            and m.commit_status = #{commitStatus}
        </if>
        order by m.commit_status asc,form.create_time desc
    </select>
</mapper>