<?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.yida.data.customForm.mapper.CoreCustomFormMapper">

    <resultMap id="BaseResultMap" type="com.yida.data.common.core.entity.customform.CoreCustomForm">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result property="delFlag" column="del_flag"/>
        <result property="headerImgUrl" column="header_img_url"/>
        <result property="backgroundImgUrl" column="background_img_url"/>
        <result property="createId" column="create_id" />
        <result property="createDate" column="create_date" />
        <result property="draft" column="draft" />
        <result property="endDate" column="end_date" />
        <result property="formRemark" column="form_remark" />
        <result property="formTitle" column="form_title" />
        <result property="formTypeId" column="form_type_id" />
        <result property="groupId" column="group_id" />
        <result property="model" column="model" />
        <result property="open" column="open" />
        <result property="orgId" column="org_id" />
        <result property="pageOneQuestion" column="page_one_question" />
        <result property="progressBar" column="progress_bar" />
        <result property="publishDate" column="publish_date" />
        <result property="publishType" column="publish_type" />
        <result property="receipt" column="receipt" />
        <result property="recever" column="recever" />
        <result property="remind" column="remind" />
        <result property="remindAdmin" column="remind_admin" />
        <result property="remindAdminModel" column="remind_admin_model" />
        <result property="remindHour" column="remind_hour" />
        <result property="remindUser" column="remind_user" />
        <result property="remindUserModel" column="remind_user_model" />
        <result property="saveFormType" column="save_form_type" />
        <result property="sorted" column="sorted" />
        <result property="startDate" column="start_date" />
        <result property="status" column="status" />
        <result property="stopMaxTime" column="stop_max_time" />
        <result property="stopMinTime" column="stop_min_time" />
        <result property="submitNum" column="submit_num" />
        <result property="tableName" column="table_name" />
        <result property="typeName" column="type_name" />
        <result property="updateDate" column="update_date" />
        <result property="updateId" column="update_id" />
        <result property="updateType" column="update_type" />

        <collection property="coreCustomFormItemsList" ofType="com.yida.data.common.core.entity.customform.CoreCustomFormItems">
            <result column="id" property="id"/>
            <result column="form_id" property="formId"/>
            <result column="default_value" property="defaultValue"/>
            <result column="input_height" property="inputHeight"/>
            <result column="file_num" property="fileNum"/>
            <result column="input_max" property="inputMax"/>
            <result column="input_min" property="inputMin"/>
            <result column="input_placeholder" property="inputPlaceholder"/>
            <result column="input_width" property="inputWidth"/>
            <result column="input_verify" property="inputVerify"/>
            <result column="item_filed_name" property="itemFiledName"/>
            <result column="item_sub_title" property="itemSubTitle"/>
            <result column="item_title" property="itemTitle"/>
            <result column="item_type" property="itemType"/>
            <result column="layout" property="layout"/>
            <result column="sort" property="sort"/>
            <result column="needed" property="needed"/>
            <result column="onlyed" property="onlyed"/>
            <result column="del_flag" property="delFlag"/>
        </collection>
        <collection property="coreCustomFormTopical" ofType="com.yida.data.common.core.entity.customform.CoreCustomFormTopical">
            <result property="id" column="id"/>
            <result property="backgroundImgUrl" column="background_img_url"/>
            <result property="logoType" column="logo_type"/>
            <result property="surfacePlotUrl" column="surface_plot_url"/>
            <result property="headerImgUrl" column="header_img_url"/>
            <result property="logoUrl" column="logo_url"/>
        </collection>
    </resultMap>

    <select id="findPageList" resultMap="BaseResultMap"
            parameterType="com.yida.data.common.core.entity.customform.CoreCustomForm">
        select
        cf.*,
        ct.type_name
        from core_custom_form cf
        left join core_custom_form_type ct on cf.form_type_id = ct.id
        where cf.del_flag = 0
        <if test="coreCustomForm.orgId != null">
            and cf.org_id = #{coreCustomForm.orgId}
        </if>
        <if test="coreCustomForm.createId != null">
            and cf.create_id = #{coreCustomForm.createId}
        </if>
        <if test="coreCustomForm.formTypeId != null">
            and cf.form_type_id = #{coreCustomForm.formTypeId}
        </if>
        order by cf.create_date desc
    </select>


    <select id="initSqlReturnInt" resultType="java.lang.Integer">
            ${sql}
    </select>


    <select id="initSqlReturnVoid">
            ${sql}
    </select>
    <select id="appFindAdminFormList" resultType="com.yida.data.common.core.entity.customform.CoreCustomForm">
        SELECT
	        a.*
        FROM
	        `core_custom_form` a
	        LEFT JOIN core_custom_form_relation_admin b ON a.id = b.custom_form_id
        WHERE
	        b.admin_id = #{userId}
	        <if test="tableName !=null and tableName != ''">
                and a.table_name = #{tableName}
            </if>

        and a.status = 1

        and org_id = #{schoolId}
        ORDER BY a.`status` asc,a.create_date desc
    </select>
    <select id="appFindFormList" resultType="com.yida.data.common.core.entity.customform.CoreCustomForm">
    SELECT distinct
        a.*
        <if test="type != 1 ">
            ,b.fill
        </if>

    FROM
	    `core_custom_form` a
	    LEFT JOIN core_custom_form_relation_user b ON a.id = b.custom_form_id
    WHERE
         a.status  = 1
         <if test="userIdList != null and userIdList.size >0">
             and b.user_id in
             <foreach collection="userIdList" item="item" open="(" close=")" separator=",">
                 #{item}
             </foreach>
         </if>

	    and b.type = #{type}
        <if test="tableName !=null and tableName != ''">
            and a.form_title like concat ('%',#{tableName},'%')
        </if>
        and org_id = #{schoolId}
        and a.del_flag = 0
        ORDER BY a.`status` asc,a.create_date desc
    </select>

</mapper>
