<?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.lideeyunji.core.framework.mapper.LideeYunJiMapper">

    <select id="getWebViewFieldList" resultType="string">
      SELECT
            field.field_code as "field_code"
        FROM
            yunji_dbform_field field
            INNER JOIN yunji_dbform_field_web field_web ON field.field_code = field_web.field_code and field.dbform_id = field_web.dbform_id
        WHERE
            field.is_deleted = 0
            AND field_web.is_deleted = 0
            AND field_web.is_db_select = 'Y'
            AND field.dbform_id = #{dbFormId}
        ORDER BY
            field.sort_num ASC,
            field.id ASC
  </select>

    <select id="getDbWhereFieldList" resultType="map">
        SELECT
            field.field_code as "field_code",
            field.field_type as "field_type",
            field_query.query_mode as "query_mode"
        FROM
            yunji_dbform_field field
            INNER JOIN yunji_dbform_field_web field_web ON field.field_code = field_web.field_code  and field.dbform_id = field_web.dbform_id
			INNER JOIN yunji_dbform_field_query field_query ON field.field_code = field_query.field_code and field.dbform_id = field_query.dbform_id
        WHERE
            field.is_deleted = 0
            AND field_web.is_deleted = 0
			AND field_query.is_deleted = 0
            AND field_query.query_is_db = 'Y'
            AND field.is_db='Y'
            AND field.dbform_id = #{dbFormId}
        ORDER BY
            field.sort_num ASC,
            field.id ASC
  </select>

    <select id="getAllDbWhereFieldList" resultType="map">
        SELECT
            field.field_code as "field_code",
            field.field_type as "field_type",
            field_query.query_mode as "query_mode"
        FROM
            yunji_dbform_field field
                INNER JOIN yunji_dbform_field_web field_web ON field.field_code = field_web.field_code  and field.dbform_id = field_web.dbform_id
                INNER JOIN yunji_dbform_field_query field_query ON field.field_code = field_query.field_code and field.dbform_id = field_query.dbform_id
        WHERE
            field.is_deleted = 0
          AND field_web.is_deleted = 0
          AND field_query.is_deleted = 0
          AND field.is_db='Y'
          AND field.dbform_id = #{dbFormId}
        ORDER BY
            field.sort_num ASC,
            field.id ASC
    </select>

    <select id="getReportWhereFieldList" resultType="map">
         SELECT
            field.field_code as "field_code",
            field.field_type as "field_type",
            field.query_mode as "query_mode"
        FROM
			yunji_report report
            INNER JOIN yunji_report_field field on report.id =field.report_id
        WHERE
            report.is_deleted = 0
            AND field.is_deleted = 0
            AND field.query_is_db = 'Y'
            AND report.id = #{reportId}
        ORDER BY
            field.sort_num ASC,
            field.id ASC
  </select>

    <select id="getExcelExportFieldList" resultType="map">
        SELECT
            df.field_code as "field_code",
            df.field_name as "field_name",
            dfe.import_example_txt as "import_example_txt"
        FROM
            yunji_dbform_field df
            INNER JOIN yunji_dbform_field_export dfe ON df.field_code = dfe.field_code  and df.dbform_id = dfe.dbform_id
        WHERE
            df.dbform_id = #{dbFormId}
            AND df.is_deleted = 0
            AND dfe.is_deleted = 0
            AND dfe.is_export = 'Y'
        ORDER BY
            df.sort_num ASC,
            df.id ASC
    </select>

    <select id="getExcelImportFieldList" resultType="map">
        SELECT
            df.field_code as "field_code",
            df.field_name as "field_name",
            df.field_type as "field_type",
            dfe.import_example_txt as "import_example_txt"
        FROM
            yunji_dbform_field df
            INNER JOIN yunji_dbform_field_export dfe ON df.field_code = dfe.field_code  and df.dbform_id = dfe.dbform_id
        WHERE
            df.dbform_id = #{dbFormId}
          AND df.is_deleted = 0
          AND dfe.is_deleted = 0
          AND dfe.is_import = 'Y'
          AND df.is_db = 'Y'
        ORDER BY
            df.sort_num ASC,
            df.id ASC
    </select>

    <select id="getFormCou" resultType="map">
        select
        (select count(id)  from yunji_dbform_enhance_js where is_deleted = 0 and js_type='js' and dbform_id = #{dbFormId})  as "js_cou",
        (select count(id)  from yunji_dbform_enhance_js where is_deleted = 0 and js_type='scss' and dbform_id = #{dbFormId})  as "scss_cou",
        (select count(id)  from yunji_dbform_button where is_deleted = 0 and dbform_id = #{dbFormId})  as "button_cou",
        (select count(id)  from yunji_dbform_enhance_java where is_deleted = 0 and dbform_id = #{dbFormId})   as "java_cou",
        (select count(id)  from yunji_dbform_enhance_sql where is_deleted = 0 and dbform_id = #{dbFormId})  as "sql_cou",
        (select count(id)  from yunji_dbform_field where is_deleted = 0 and dbform_id = #{dbFormId})   as "field_cou"
        from yunji_dbform dbform
        where id = #{dbFormId}
    </select>


    <select id="getDbFormI18nMapList" resultType="map">
        SELECT
          db_web.id,
          dbform.table_name,
          dbform.table_describe,
          db_field.field_name,
          db_web.label_i18n
        FROM
          yunji_dbform dbform
          INNER JOIN yunji_dbform_field db_field ON dbform.id = db_field.dbform_id
          INNER JOIN yunji_dbform_field_web db_web ON db_field.dbform_id = db_web.dbform_id and db_field.field_code = db_web.field_code
        WHERE
          dbform.is_deleted = 0
          AND db_field.is_deleted =0
          AND db_web.is_deleted = 0
          AND dbform.table_name not like 'yunji_zexample_%'
          order by db_web.dbform_id asc,db_web.id asc
    </select>

    <select id="getReportI18nMapList" resultType="map">
        SELECT
          report_field.id,
          report.report_name,
          report.report_code,
          report_field.field_name,
          report_field.label_i18n
        FROM
          yunji_report report
          INNER JOIN yunji_report_field report_field ON report.id = report_field.report_id
        WHERE
          report.is_deleted = 0
          AND report_field.is_deleted =0
          AND report_code not like 'example_%'
          order by report_field.report_id asc,report_field.id asc
    </select>


    <select id="getTabI18nMapList" resultType="map">
        SELECT
        tab_option.id,
        tab.module_name,
        tab_option.tab_name,
        tab_option.tab_i18n
        FROM
        yunji_tab tab
        INNER JOIN yunji_tab_option tab_option ON tab.id = tab_option.tab_id
        WHERE
        tab.is_deleted = 0
        AND tab_option.is_deleted =0
        order by tab_option.tab_id asc,tab_option.id asc
    </select>

    <select id="getDesFormI18nMapList" resultType="map">
        SELECT
          id,
          desform_name,
          i18n_data
        FROM
          yunji_desform
        WHERE
          i18n_data IS NOT NULL
        order by id asc
    </select>

    <select id="getButtonI18nMapList" resultType="map">
        SELECT
          id,
          button_name,
          button_i18n
        FROM
          yunji_dbform_button
        WHERE
          button_i18n IS NOT NULL
        order by id asc
    </select>

</mapper>
