<?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.erp.dao.SysEnterpriseConfigErpDao">
    <select id="getSecretKey" resultType="java.lang.String" databaseId="mysql">
        select ace_key
        from sys_group_config
        where  ace_id = #{aceId}  limit 1
    </select>

    <select id="getSecretKey" resultType="java.lang.String" databaseId="oracle">
      select * from (
        select ace_key
        from sys_group_config
        where  ace_id = #{aceId}
      ) tmp where ROWNUM &lt;= 1
    </select>
    <select id="getOrg" resultType="com.dxhy.api.model.config.sys.SysEnterpriseConfigDto" databaseId="mysql">
        SELECT
        DISTINCT qy.nsrsbh ,
        qy.nsrmc ,
        config.db_name dbName,
        qy.company,
        config.ace_id aceId,
        config.ace_key aceKey,
        config.data_ace_id dataAceId,
        config.data_ace_key dataAceKey
          FROM
        sys_group_config config
        JOIN sys_enterprise_config qy ON config.company = qy.company
        where qy.nsrsbh = #{taxno} limit 1
    </select>

    <select id="getOrg" resultType="com.dxhy.api.model.config.sys.SysEnterpriseConfigDto" databaseId="oracle">
        select * from (
        SELECT
        DISTINCT qy.nsrsbh ,
        qy.nsrmc ,
        config.db_name dbName,
        qy.company,
        config.ace_id aceId,
        config.ace_key aceKey,
        config.data_ace_id dataAceId,
        config.data_ace_key dataAceKey
          FROM
        sys_group_config config
        JOIN sys_enterprise_config qy ON config.company = qy.company
        where qy.nsrsbh = #{taxno}
        ) tmp where ROWNUM &lt;= 1
    </select>
<!--
    <select id="getOrg" resultType="com.dxhy.erp.entity.SysDeptEntity" databaseId="mysql">
        select *
        from sys_dept
        where taxno = #{taxno}
          and org_type = '5'
          and del_flag = '0' limit 1
    </select>

    <select id="getOrg" resultType="com.dxhy.erp.entity.SysDeptEntity" databaseId="oracle">
        select *
        from sys_dept
        where taxno = #{taxno}
          and org_type = '5'
          and del_flag = '0'           and rownum = 1
    </select>
-->

    <select id="getOrgByCompany" resultType="com.dxhy.api.model.config.sys.SysEnterpriseConfigDto" databaseId="mysql">
        select db_name dbName
        from sys_group_config
        where company = #{company}
          limit 1
    </select>


    <select id="getOrgByCompany" resultType="com.dxhy.api.model.config.sys.SysEnterpriseConfigDto" databaseId="oracle">
      select * from (
        select db_name dbName
        from sys_group_config
        where company = #{company}
        ) tmp where ROWNUM &lt;= 1
    </select>
<!--
    <select id="getOrgByCompany" resultType="com.dxhy.erp.entity.SysDeptEntity" databaseId="mysql">
        select *
        from sys_dept
        where company = #{company}
          and org_type = '5'
          and del_flag = '0' limit 1
    </select>


    <select id="getOrgByCompany" resultType="com.dxhy.erp.entity.SysDeptEntity" databaseId="oracle">
        select *
        from sys_dept
        where company = #{company}
          and org_type = '5'
          and del_flag = '0' and rownum = 1
    </select>
-->

    <update id="updatePassword">
        update sys_enterprise_config
        set password=#{password}
        where nsrsbh = #{taxno}
    </update>
    <!-- 获取数据源 -->
    <select id="getDbSource" resultType="java.lang.String">
        select db_name
        from sys_group_config
        where db_name is not NULL
        group by db_name
    </select>
<!--
    <select id="getDbSource" resultType="java.lang.String">
        select db_name
        from sys_dept
        where db_name is not NULL
        group by db_name
    </select>
-->

    <!-- 58接口 查询企业编码是否存在 -->
    <select id="checkBuyerEnterpriseCode" resultType="java.lang.Integer">
        select count(1)
        from sys_enterprise_config
        where company = #{enterpriseCode}
    </select>
<!--
    <select id="checkBuyerEnterpriseCode" resultType="java.lang.Integer">
        select count(1)
        from sys_dept
        where company = #{enterpriseCode}
          and org_type = '5'
    </select>
-->

    <!-- 亚宝接口 -->
    <select id="selectByCompany" resultType="com.dxhy.api.model.config.sys.SysEnterpriseConfigEntity">
        select *
        from sys_enterprise_config
        where company = #{company}
    </select>
<!--
    <select id="selectByCompany" resultType="com.dxhy.erp.entity.SysDeptEntity">
        select *
        from sys_dept
        where company = #{company}
          and org_type = '5'
          and del_flag = '0'
    </select>
-->
    <select id="getOrgType" resultType="com.dxhy.api.model.config.sys.SysEnterpriseConfigDto" databaseId="mysql">
        SELECT
        DISTINCT qy.nsrsbh ,
        qy.nsrmc ,
        config.db_name dbName,
        qy.company,
        config.ace_id aceId,
        config.ace_key aceKey,
        config.data_ace_id dataAceId,
        config.data_ace_key dataAceKey
          FROM
        sys_group_config config
        JOIN sys_enterprise_config qy ON config.company = qy.company
        where qy.nsrsbh = #{gfTaxNo} limit 1
    </select>
    <select id="getOrgType" resultType="com.dxhy.api.model.config.sys.SysEnterpriseConfigDto" databaseId="oracle">
        select * from (
        SELECT
        DISTINCT qy.nsrsbh ,
        qy.nsrmc ,
        config.db_name dbName,
        qy.company,
        config.ace_id aceId,
        config.ace_key aceKey,
        config.data_ace_id dataAceId,
        config.data_ace_key dataAceKey
          FROM
        sys_group_config config
        JOIN sys_enterprise_config qy ON config.company = qy.company
        where qy.nsrsbh = #{gfTaxNo}
        ) tmp where ROWNUM &lt;= 1
    </select>
<!--
    <select id="getOrgType" resultType="com.dxhy.erp.entity.SysDeptEntity" databaseId="mysql">
        select *
        from sys_dept
        where taxno = #{gfTaxNo}
          and org_type = '5' limit 1
    </select>
    <select id="getOrgType" resultType="com.dxhy.erp.entity.SysDeptEntity" databaseId="oracle">
        select *
        from sys_dept
        where taxno = #{gfTaxNo}
          and org_type = '5'
          and rownum = 1
    </select>
-->
    <select id="findIdAndKey" resultType="com.dxhy.api.model.config.sys.SysEnterpriseConfigDto">
        SELECT
        DISTINCT qy.nsrsbh ,
        qy.nsrmc ,
        config.db_name dbName,
        qy.company,
        qy.password,
        config.ace_id aceId,
        config.ace_key aceKey,
        config.data_ace_id dataAceId,
        config.data_ace_key dataAceKey
          FROM
        sys_group_config config
        JOIN sys_enterprise_config qy ON config.company = qy.company
        where qy.nsrsbh = #{taxno}
    </select>
<!--
    <select id="findIdAndKey" resultType="com.dxhy.erp.entity.SysDeptEntity">
        select distinct g.taxno, g.db_name, g.company, g.ace_id, g.ace_key, password
        from sys_dept g
        where g.org_type = '5'
          and g.taxno = #{taxno}
    </select>
-->
</mapper>
