YsEntityMapper.xml 6.57 KB
<?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.chinagas.modules.system.mapper.YsEntityMapper">

    <resultMap type="com.chinagas.api.system.domain.YsEntity" id="YsEntityResult">
        <result property="objectId" column="OBJECT_ID"/>
        <result property="parentId" column="PARENT_ID"/>
        <result property="path" column="PATH"/>
        <result property="entity" column="ENTITY"/>
        <result property="entityName" column="ENTITY_NAME"/>
        <result property="typeName" column="TYPE_NAME"/>
        <result property="ancestors" column="ancestors"/>
        <result property="hType" column="H_TYPE"/>
    </resultMap>

    <sql id="selectYsEntityVoLocal">
        select e.OBJECT_ID,
               e.PARENT_ID,
               e.PATH,
               e.ENTITY,
               e.ENTITY_NAME,
               e.TYPE_NAME,
               e.ancestors,
               e.H_TYPE
        from ys_entity e
    </sql>

    <sql id="selectYsEntityVoRemote">
        select OBJECT_ID, PARENT_ID, PATH, ENTITY, ENTITY_NAME, TYPE_NAME
        from HSP_ENTITY_TOZRCLOUD_V
    </sql>

    <select id="selectYsEntityListRemote" parameterType="com.chinagas.api.system.domain.YsEntity"
            resultMap="YsEntityResult">
        <include refid="selectYsEntityVoRemote"/>
        <where>
            <if test="parentId != null ">and PARENT_ID = #{parentId}</if>
            <if test="path != null  and path != ''">and PATH = #{path}</if>
            <if test="entity != null  and entity != ''">and ENTITY = #{entity}</if>
            <if test="entityName != null  and entityName != ''">and ENTITY_NAME like concat('%', #{entityName}, '%')
            </if>
            <if test="typeName != null  and typeName != ''">and TYPE_NAME like concat('%', #{typeName}, '%')</if>
        </where>
    </select>

    <select id="selectYsEntityList" parameterType="com.chinagas.api.system.domain.YsEntity" resultMap="YsEntityResult">
        <include refid="selectYsEntityVoLocal"/>
        <where>
            <if test="parentId != null ">and e.PARENT_ID = #{parentId}</if>
            <if test="path != null  and path != ''">and e.PATH = #{path}</if>
            <if test="entity != null  and entity != ''">and e.ENTITY REGEXP #{entity}</if>
            <if test="entityName != null  and entityName != ''">and e.ENTITY_NAME like concat('%', #{entityName}, '%')
            </if>
            <if test="typeName != null  and typeName != ''">and e.TYPE_NAME like concat('%', #{typeName}, '%')</if>
        </where>
    </select>

    <select id="selectYsEntityByObjectId" parameterType="Long" resultMap="YsEntityResult">
        <include refid="selectYsEntityVoLocal"/>
        where e.OBJECT_ID = #{objectId}
    </select>

    <select id="selectYsEntityChildrenSearch" parameterType="com.chinagas.api.system.domain.YsEntity"
            resultMap="YsEntityResult">
        <include refid="selectYsEntityVoLocal"/>
        where e.ENTITY_NAME like concat('%', #{entityName}, '%')
        and e.ANCESTORS like concat('', #{ancestors}, '%')
    </select>
    <select id="selectYsEntityChildrenbyId" parameterType="Long" resultMap="YsEntityResult">
        <include refid="selectYsEntityVoLocal"/>
        where e.PARENT_ID = #{id}
    </select>
    <select id="selectAllDescendants" parameterType="String" resultType="String">
        select entity
        from ys_entity
        WHERE FIND_IN_SET(#{entity}, ancestors)
    </select>

    <select id="selectAllCompany" resultMap="YsEntityResult">
        <include refid="selectYsEntityVoLocal"/>
        WHERE e.entity not like 'EN%'
    </select>

    <insert id="insertOrUpdateYsEntity" parameterType="com.chinagas.api.system.domain.YsEntity">
        insert into ys_entity (OBJECT_ID,
                               PARENT_ID,
                               PATH,
                               ENTITY,
                               ENTITY_NAME,
                               TYPE_NAME,
                               ANCESTORS) value ( #{objectId},
            #{parentId},
            #{path},
            #{entity},
            #{entityName},
            #{typeName},
            #{ancestors}
            )
        ON DUPLICATE KEY
        UPDATE OBJECT_ID = #{objectId},
            PARENT_ID = #{parentId},
            PATH = #{path},
            ENTITY = #{entity},
            ENTITY_NAME = #{entityName},
            TYPE_NAME = #{typeName},
            ANCESTORS = #{ancestors}
    </insert>

    <select id="selectYsEntityByUserId" resultMap="YsEntityResult">
        <include refid="selectYsEntityVoLocal"/>
        left join ys_entity_user eu on e.entity = eu.entity
        where eu.user_id = #{userId}
    </select>

    <select id="selectYsEntityByUserId3" resultMap="YsEntityResult">
        <include refid="selectYsEntityVoLocal"/>
        left join ys_entity_dept ed on e.entity = ed.entity
        where ed.dept_id = #{deptId}
    </select>

    <select id="selectYsEntityFkChildrenbyId" parameterType="String" resultMap="YsEntityResult">
        <include refid="selectYsEntityVoLocal"/>
        where e.h_type = '1' and find_in_set(#{entity}, e.ancestors)
    </select>

    <select id="selectYsEntityByName" parameterType="com.chinagas.api.system.domain.YsEntity"
            resultMap="YsEntityResult">
        <include refid="selectYsEntityVoLocal"/>
        where e.ENTITY_NAME like concat('%', #{entityName}, '%')
        limit 15
    </select>

    <select id="selectYsEntityByEntity" parameterType="com.chinagas.api.system.domain.YsEntity"
            resultMap="YsEntityResult">
        <include refid="selectYsEntityVoLocal"/>
        <where>
            <if test="entity != null  and entity != ''">and e.ENTITY = #{entity}</if>
        </where>
    </select>

    <select id="getEntitCount" resultType="int">
        select count(*)
        from ys_entity
        WHERE RIGHT (ys_entity.ENTITY_NAME, 4) = '预算主体';
    </select>

    <select id="selectQYYsEntity" parameterType="com.chinagas.api.system.domain.YsEntity" resultMap="YsEntityResult">
        SELECT *
        FROM `ys_entity`
        WHERE ANCESTORS REGEXP #{entity}
          AND ENTITY_NAME LIKE '%预算主体'
    </select>

    <select id="selectAccounting" parameterType="Long" resultMap="YsEntityResult">
        <include refid="selectYsEntityVoLocal"/>
        where e.PARENT_ID = #{id}
    </select>

    <select id="selectAllEntity" parameterType="com.chinagas.api.system.domain.YsEntity" resultMap="YsEntityResult">
        SELECT *
        FROM `ys_entity`
        WHERE ENTITY_NAME LIKE '%预算主体'
    </select>
</mapper>