<?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="org.springblade.modules.system.mapper.DictBizMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="dictResultMap" type="org.springblade.modules.system.entity.DictBiz">
        <id column="id" property="id"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="parent_id" property="parentId"/>
        <result column="code" property="code"/>
        <result column="dict_key" property="dictKey"/>
        <result column="dict_value" property="dictValue"/>
        <result column="sort" property="sort"/>
        <result column="remark" property="remark"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="fz" property="fz"/>
        <result column="zgf" property="zgf"/>
    </resultMap>

    <resultMap id="treeNodeResultMap" type="org.springblade.core.tool.node.TreeNode">
        <id column="id" property="id"/>
        <result column="parent_id" property="parentId"/>
        <result column="title" property="title"/>
        <result column="value" property="value"/>
        <result column="key" property="key"/>
    </resultMap>

    <select id="getValue" resultType="java.lang.String">
        select
            dict_value
        from blade_dict_biz where code = #{param1} and dict_key = #{param2} and is_deleted = 0
    </select>

    <select id="getKey" resultType="java.lang.String">
        select
            dict_key
        from blade_dict_biz where code = #{param1} and dict_value = #{param2} and is_deleted = 0
    </select>

    <!-- oracle 版本 -->
    <!--<select id="getValue" resultType="java.lang.String">
        select
            dict_value
        from blade_dict_biz where code = #{param1, jdbcType=VARCHAR} and dict_key = #{param2} and dict_key >= 0  rownum 1
    </select>-->

    <select id="getList" resultMap="dictResultMap">


        SELECT
            id AS value,
            dict_value AS label
        FROM
            blade_dict_biz
        WHERE
            code = #{code}
          AND parent_id > 0
          AND is_sealed = 0
          AND is_deleted = 0
    </select>
    <select id="getListPC" resultMap="dictResultMap">
        select id, parent_id, code, dict_key, dict_value, sort, remark from blade_dict_biz where code = #{param1} and parent_id > 0 and is_sealed = 0
    </select>

    <select id="getDictList" resultType="org.springblade.modules.system.vo.ZdVO">
        SELECT
            dict_key AS value,
            dict_value AS label
        FROM
            blade_dict_biz
        WHERE
            code = #{code}
          AND parent_id > 0
          AND is_sealed = 0
          AND is_deleted = 0
        ORDER BY sort
    </select>

    <select id="tree" resultMap="treeNodeResultMap">
        select id, parent_id, dict_value as title, id as "value", id as "key" from blade_dict_biz where is_deleted = 0
    </select>

    <select id="parentTree" resultMap="treeNodeResultMap">
        select id, parent_id, dict_value as title, id as "value", id as "key" from blade_dict_biz where is_deleted = 0 and parent_id = 0
    </select>

    <select id="selectGzlx" resultType="org.springblade.modules.gzInfo.vo.ZdVo">
        SELECT
            id,
            dict_value AS value,
            dict_value AS label
        FROM
            blade_dict_biz
        WHERE
            parent_id = 0
        <if test="type == 1">
        AND type = #{type}
        </if>
        AND code = 'gzsb'
        ORDER BY sort ASC
    </select>

    <select id="selectGzlxs" resultType="org.springblade.modules.gzInfo.vo.ZdVos">
        SELECT
            id,
            dict_value AS value,
            dict_value AS label,
            zgf AS zgf
        FROM
            blade_dict_biz
        WHERE
            parent_id = #{id}
        <if test="type == 1">
        AND type = #{type}
        </if>
        AND code = 'gzsb'
        ORDER BY sort ASC
    </select>

    <select id="selectGzlxss" resultType="org.springblade.modules.gzInfo.vo.ZdVoss">
        SELECT
            id,
            dict_value AS value,
            dict_value AS label,
            zgf AS zgf,
            fz,
            remark
        FROM
            blade_dict_biz
        WHERE
            parent_id = #{id}
        <if test="type == 1">
        AND type = #{type}
        </if>
        AND code = 'gzsb'
        ORDER BY sort ASC
    </select>

    <select id="getJxcs" resultType="org.springblade.modules.system.vo.ZdVO">
        SELECT
            dict_value as value,
            dict_value as label
        FROM
            blade_dict_biz bdb
        WHERE
            code = 'jxcs'
          AND parent_id = 0
        ORDER BY
            sort ASC
    </select>

    <select id="csxl" resultType="org.springblade.modules.system.vo.ZdVO">
        SELECT
            dict_value as value,
            dict_value as label
        FROM
            blade_dict_biz bdb
        WHERE
            code = 'jxcs'
          AND parent_id != 0
        ORDER BY
            sort ASC
    </select>

    <select id="selectJflx" resultType="org.springblade.modules.gzInfo.vo.ZdVo">
        SELECT
            bdb.id as value,
            bdb.dict_value as label
        FROM
            blade_dict_biz bdb
        WHERE
            bdb.code = 'jflx'
          AND bdb.parent_id :: text = #{params.parentId}
        ORDER BY
            bdb.sort ASC
    </select>

    <select id="selectJflx2" resultType="org.springblade.modules.gzInfo.vo.ZdVo">
        SELECT
            bdb.id as value,
            bdb.dict_value as label
        FROM
            blade_dict_biz bdb
        WHERE
            bdb.code = 'jflx'
          AND bdb.id :: text = #{params.parentId}
    </select>

    <select id="getXmList" resultType="org.springblade.modules.gzInfo.vo.ZdVos">
        SELECT
        id,
        dict_value AS value
        FROM
        blade_dict_biz
        WHERE 1 = 1
        <if test="params.type == 1">
            AND dict_value IN ( '推进智能安防小区建设', '培育平安类社会组织', '服务公安实战', '打造三零社区(村屯)' )
        </if>
        <if test="params.type == 2">
            AND dict_value IN ( '工作纪律', '重点人员动态管控', '道路交通管理', '风险预警预知预防' )
        </if>
    </select>

    <select id="getXmList2" resultType="org.springblade.modules.gzInfo.vo.ZdVoss">
        SELECT
            id,
            dict_value AS value
        FROM
            blade_dict_biz
        WHERE
            parent_id = #{parentId}
    </select>

    <select id="selectDwlb" resultMap="dictResultMap">
        select dict_value from blade_dict_biz where code = 'jxcs' and parent_id = 0 and is_deleted = 0
    </select>

    <select id="getLdphhz" resultType="org.springblade.modules.system.vo.ZdVO">
        SELECT
            id AS value,
            dict_value AS label
        FROM
            jdrh.blade_dict_biz
        WHERE
            code = 'ldphhz'
          AND parent_id > 0
          AND is_sealed = 0
          AND is_deleted = 0
        ORDER BY sort
    </select>

    <select id="getZfcs" resultType="int">
        SELECT
            dict_key
        FROM
            jdrh.blade_dict_biz
        WHERE
            code = 'zfcs'
    </select>

    <select id="getFjsl" resultType="int">
        SELECT
            dict_key
        FROM
            jdrh.blade_dict_biz
        WHERE
            code = 'fjsl'
    </select>

    <select id="getKfsl" resultType="int">
        SELECT
            dict_key
        FROM
            jdrh.blade_dict_biz
        WHERE
            code = 'kfsl'
    </select>

    <select id="getTsrq" resultType="org.springblade.modules.system.vo.ZdVO">
        select
            dict_key as value,
            dict_value as label
        from
            jdrh.blade_dict_biz
        where code = 'tsrq'
    </select>
</mapper>
