<?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.dxhy.manage.dao.SysDeptDao">

    <select id="queryList" resultType="com.dxhy.manage.entity.SysDeptEntity">
        SELECT
        t1.*,
        ( SELECT t2.name FROM sys_dept t2 WHERE t2.dept_id = t1.parent_id ) parentName
        FROM
        sys_dept t1 where t1.org_type in ('0','1')

        <if test="company != null and company != '' and company != 'null'">
            and t1.company = #{company}
        </if>
    </select>

    <select id="queryListUser" resultType="com.dxhy.manage.entity.SysDeptEntity">
        select t1.*,(select t2.name from sys_dept t2 where t2.dept_id=t1.parent_id)parentName from sys_dept t1 where
        and t1.org_type in ('1','5')
        <if test="company != null and company != '' and company != 'null'">
            and t1.company = #{company}
        </if>
    </select>

    <select id="queryListParent" resultType="com.dxhy.manage.entity.SysDeptEntity">
        select t1.*,(select t2.name from sys_dept t2 where t2.dept_id=t1.parent_id)parentName from sys_dept t1 where
        (t1.parent_id = 0 or t1.parent_id = 1)
        <if test="company != null and company != '' and company != 'null'">
            and t1.company = #{company}
        </if>
    </select>

    <select id="queryDetpIdList" resultType="long">
        select dept_id
        from sys_dept
        where parent_id = #{parentId}
    </select>

    <select id="queryDeptParentId" resultType="com.dxhy.manage.entity.SysDeptEntity">
        select *
        from sys_dept
        where parent_id = #{parentId}
    </select>

    <select id="queryDeptList" resultType="com.dxhy.manage.entity.SysDeptEntity">
        select *
        from sys_dept
        where cj_status = '1'
          and org_type = '5'
    </select>

    <update id="updateDeptCompany">
        update
        sys_dept
        set
        ace_key = #{aceKey} ,
        ace_id = #{aceId} ,
        upgrade_status = #{upgradeStatus},
        <!-- detail_into_where_db = #{detailIntoWhereDb},
        detail_into_where_table = #{detailIntoWhereTable},
        major_into_where_db = #{majorIntoWhereDb},
        major_into_where_table = #{majorIntoWhereTable}, -->
        is_check_yesorno = #{isCheckYesorno},
        is_collect_yesorno = #{isCollectYesorno},
        level_code = #{levelCode},
        is_model = #{isModel}
        where
        company = #{company}
        and org_type != '1'
    </update>


    <select id="getVersion" resultType="com.dxhy.manage.model.VersionModel">
        select *
        from sys_version
        where area = #{area}
    </select>

</mapper>
