<?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.SysDeptDao">
    <select id="getSecretKey" resultType="java.lang.String">
        select ace_key
        from sys_dept
        where org_type = '5'
          and ace_id = #{aceId}
          and del_flag = '0' limit 1
    </select>

    <select id="getBlocNoTax" resultType="int">
        select count(1)
        from sys_dept d,
             sys_ip s
        where d.dept_id = s.dept_id
          and d.del_flag = '0'
          and d.org_type = '1'
          and d.ace_id = #{appSecId}
          and s.ip = #{remoteAddr}
    </select>
    <select id="getOrg" resultType="com.dxhy.erp.entity.SysDeptEntity">
        select *
        from sys_dept
        where taxno = #{taxno}
          and org_type = '5'
          and del_flag = '0' limit 1
    </select>

    <select id="getOrgByCompCode" resultType="com.dxhy.erp.entity.SysDeptEntity">
        select *
        from sys_dept
        where org_code = #{compCode}
          and del_flag = '0' limit 1
    </select>

    <select id="getOrgByCompany" resultType="com.dxhy.erp.entity.SysDeptEntity">
        select *
        from sys_dept
        where company = #{company}
          and org_type = '5'
          and del_flag = '0' limit 1
    </select>
    <update id="updatePassword">
        update sys_dept
        set password=#{password}
        where taxno = #{taxno}
          and org_type = '5'
          and del_flag = '0'
    </update>
    <!-- 获取数据源 -->
    <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_dept
        where company = #{enterpriseCode}
          and org_type = '5'
    </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.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.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>
