<?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="pwc.taxtech.atms.dao.OrganizationMapper">
  <resultMap id="BaseResultMap" type="pwc.taxtech.atms.entitiy.Organization">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="ID" jdbcType="VARCHAR" property="ID" />
    <result column="ClientCode" jdbcType="VARCHAR" property="clientCode" />
    <result column="Name" jdbcType="VARCHAR" property="name" />
    <result column="Code" jdbcType="VARCHAR" property="code" />
    <result column="ParentID" jdbcType="VARCHAR" property="parentID" />
    <result column="TaxPayerNumber" jdbcType="VARCHAR" property="taxPayerNumber" />
    <result column="RegionID" jdbcType="VARCHAR" property="regionID" />
    <result column="StructureID" jdbcType="VARCHAR" property="structureID" />
    <result column="IndustryID" jdbcType="VARCHAR" property="industryID" />
    <result column="BusinessUnitID" jdbcType="VARCHAR" property="businessUnitID" />
    <result column="IsActive" jdbcType="SMALLINT" property="isActive" />
    <result column="PLevel" jdbcType="INTEGER" property="pLevel" />
    <result column="CreateTime" jdbcType="TIMESTAMP" property="createTime" />
    <result column="UpdateTime" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="AreaID" jdbcType="VARCHAR" property="areaID" />
    <result column="EnglishName" jdbcType="VARCHAR" property="englishName" />
    <result column="Abbreviation" jdbcType="VARCHAR" property="abbreviation" />
    <result column="InvoiceType" jdbcType="VARCHAR" property="invoiceType" />
    <result column="LegalPersonName" jdbcType="VARCHAR" property="legalPersonName" />
    <result column="ManufactureAddress" jdbcType="VARCHAR" property="manufactureAddress" />
    <result column="RegisterAddress" jdbcType="VARCHAR" property="registerAddress" />
    <result column="BankAccountName" jdbcType="VARCHAR" property="bankAccountName" />
    <result column="BankAccountNumber" jdbcType="VARCHAR" property="bankAccountNumber" />
    <result column="PhoneNumber" jdbcType="VARCHAR" property="phoneNumber" />
    <result column="RegistrationType" jdbcType="VARCHAR" property="registrationType" />
    <result column="Remark" jdbcType="VARCHAR" property="remark" />
    <result column="Vehicleroutinglocation" jdbcType="VARCHAR" property="vehicleroutinglocation" />
    <result column="Ratepayer" jdbcType="VARCHAR" property="ratepayer" />
    <result column="Address" jdbcType="VARCHAR" property="address" />
    <result column="FoundationDate" jdbcType="DATE" property="foundationDate" />
    <result column="RegistrationDate" jdbcType="DATE" property="registrationDate" />
    <result column="RegistrationLocation" jdbcType="VARCHAR" property="registrationLocation" />
    <result column="RegistrationCapital" jdbcType="VARCHAR" property="registrationCapital" />
    <result column="BusinessAllottedTimeFrom" jdbcType="DATE" property="businessAllottedTimeFrom" />
    <result column="BusinessAllottedTimeTo" jdbcType="DATE" property="businessAllottedTimeTo" />
    <result column="LegalCode" jdbcType="VARCHAR" property="legalCode" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    ID, ClientCode, Name, Code, ParentID, TaxPayerNumber, RegionID, StructureID, IndustryID, 
    BusinessUnitID, IsActive, PLevel, CreateTime, UpdateTime, AreaID, EnglishName, Abbreviation, 
    InvoiceType, LegalPersonName, ManufactureAddress, RegisterAddress, BankAccountName, 
    BankAccountNumber, PhoneNumber, RegistrationType, Remark, Vehicleroutinglocation, 
    Ratepayer, Address, FoundationDate, RegistrationDate, RegistrationLocation, RegistrationCapital, 
    BusinessAllottedTimeFrom, BusinessAllottedTimeTo, LegalCode
  </sql>
  <select id="selectByExample" parameterType="pwc.taxtech.atms.entitiy.OrganizationExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from Organization
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select 
    <include refid="Base_Column_List" />
    from Organization
    where ID = #{ID,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from Organization
    where ID = #{ID,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="pwc.taxtech.atms.entitiy.OrganizationExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from Organization
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="pwc.taxtech.atms.entitiy.Organization">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into Organization (ID, ClientCode, Name, 
      Code, ParentID, TaxPayerNumber, 
      RegionID, StructureID, IndustryID, 
      BusinessUnitID, IsActive, PLevel, 
      CreateTime, UpdateTime, AreaID, 
      EnglishName, Abbreviation, InvoiceType, 
      LegalPersonName, ManufactureAddress, RegisterAddress, 
      BankAccountName, BankAccountNumber, PhoneNumber, 
      RegistrationType, Remark, Vehicleroutinglocation, 
      Ratepayer, Address, FoundationDate, 
      RegistrationDate, RegistrationLocation, RegistrationCapital, 
      BusinessAllottedTimeFrom, BusinessAllottedTimeTo, 
      LegalCode)
    values (#{ID,jdbcType=VARCHAR}, #{clientCode,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
      #{code,jdbcType=VARCHAR}, #{parentID,jdbcType=VARCHAR}, #{taxPayerNumber,jdbcType=VARCHAR}, 
      #{regionID,jdbcType=VARCHAR}, #{structureID,jdbcType=VARCHAR}, #{industryID,jdbcType=VARCHAR}, 
      #{businessUnitID,jdbcType=VARCHAR}, #{isActive,jdbcType=SMALLINT}, #{pLevel,jdbcType=INTEGER}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{areaID,jdbcType=VARCHAR}, 
      #{englishName,jdbcType=VARCHAR}, #{abbreviation,jdbcType=VARCHAR}, #{invoiceType,jdbcType=VARCHAR}, 
      #{legalPersonName,jdbcType=VARCHAR}, #{manufactureAddress,jdbcType=VARCHAR}, #{registerAddress,jdbcType=VARCHAR}, 
      #{bankAccountName,jdbcType=VARCHAR}, #{bankAccountNumber,jdbcType=VARCHAR}, #{phoneNumber,jdbcType=VARCHAR}, 
      #{registrationType,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{vehicleroutinglocation,jdbcType=VARCHAR}, 
      #{ratepayer,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, #{foundationDate,jdbcType=DATE}, 
      #{registrationDate,jdbcType=DATE}, #{registrationLocation,jdbcType=VARCHAR}, #{registrationCapital,jdbcType=VARCHAR}, 
      #{businessAllottedTimeFrom,jdbcType=DATE}, #{businessAllottedTimeTo,jdbcType=DATE}, 
      #{legalCode,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="pwc.taxtech.atms.entitiy.Organization">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into Organization
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="ID != null">
        ID,
      </if>
      <if test="clientCode != null">
        ClientCode,
      </if>
      <if test="name != null">
        Name,
      </if>
      <if test="code != null">
        Code,
      </if>
      <if test="parentID != null">
        ParentID,
      </if>
      <if test="taxPayerNumber != null">
        TaxPayerNumber,
      </if>
      <if test="regionID != null">
        RegionID,
      </if>
      <if test="structureID != null">
        StructureID,
      </if>
      <if test="industryID != null">
        IndustryID,
      </if>
      <if test="businessUnitID != null">
        BusinessUnitID,
      </if>
      <if test="isActive != null">
        IsActive,
      </if>
      <if test="pLevel != null">
        PLevel,
      </if>
      <if test="createTime != null">
        CreateTime,
      </if>
      <if test="updateTime != null">
        UpdateTime,
      </if>
      <if test="areaID != null">
        AreaID,
      </if>
      <if test="englishName != null">
        EnglishName,
      </if>
      <if test="abbreviation != null">
        Abbreviation,
      </if>
      <if test="invoiceType != null">
        InvoiceType,
      </if>
      <if test="legalPersonName != null">
        LegalPersonName,
      </if>
      <if test="manufactureAddress != null">
        ManufactureAddress,
      </if>
      <if test="registerAddress != null">
        RegisterAddress,
      </if>
      <if test="bankAccountName != null">
        BankAccountName,
      </if>
      <if test="bankAccountNumber != null">
        BankAccountNumber,
      </if>
      <if test="phoneNumber != null">
        PhoneNumber,
      </if>
      <if test="registrationType != null">
        RegistrationType,
      </if>
      <if test="remark != null">
        Remark,
      </if>
      <if test="vehicleroutinglocation != null">
        Vehicleroutinglocation,
      </if>
      <if test="ratepayer != null">
        Ratepayer,
      </if>
      <if test="address != null">
        Address,
      </if>
      <if test="foundationDate != null">
        FoundationDate,
      </if>
      <if test="registrationDate != null">
        RegistrationDate,
      </if>
      <if test="registrationLocation != null">
        RegistrationLocation,
      </if>
      <if test="registrationCapital != null">
        RegistrationCapital,
      </if>
      <if test="businessAllottedTimeFrom != null">
        BusinessAllottedTimeFrom,
      </if>
      <if test="businessAllottedTimeTo != null">
        BusinessAllottedTimeTo,
      </if>
      <if test="legalCode != null">
        LegalCode,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="ID != null">
        #{ID,jdbcType=VARCHAR},
      </if>
      <if test="clientCode != null">
        #{clientCode,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        #{code,jdbcType=VARCHAR},
      </if>
      <if test="parentID != null">
        #{parentID,jdbcType=VARCHAR},
      </if>
      <if test="taxPayerNumber != null">
        #{taxPayerNumber,jdbcType=VARCHAR},
      </if>
      <if test="regionID != null">
        #{regionID,jdbcType=VARCHAR},
      </if>
      <if test="structureID != null">
        #{structureID,jdbcType=VARCHAR},
      </if>
      <if test="industryID != null">
        #{industryID,jdbcType=VARCHAR},
      </if>
      <if test="businessUnitID != null">
        #{businessUnitID,jdbcType=VARCHAR},
      </if>
      <if test="isActive != null">
        #{isActive,jdbcType=SMALLINT},
      </if>
      <if test="pLevel != null">
        #{pLevel,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="areaID != null">
        #{areaID,jdbcType=VARCHAR},
      </if>
      <if test="englishName != null">
        #{englishName,jdbcType=VARCHAR},
      </if>
      <if test="abbreviation != null">
        #{abbreviation,jdbcType=VARCHAR},
      </if>
      <if test="invoiceType != null">
        #{invoiceType,jdbcType=VARCHAR},
      </if>
      <if test="legalPersonName != null">
        #{legalPersonName,jdbcType=VARCHAR},
      </if>
      <if test="manufactureAddress != null">
        #{manufactureAddress,jdbcType=VARCHAR},
      </if>
      <if test="registerAddress != null">
        #{registerAddress,jdbcType=VARCHAR},
      </if>
      <if test="bankAccountName != null">
        #{bankAccountName,jdbcType=VARCHAR},
      </if>
      <if test="bankAccountNumber != null">
        #{bankAccountNumber,jdbcType=VARCHAR},
      </if>
      <if test="phoneNumber != null">
        #{phoneNumber,jdbcType=VARCHAR},
      </if>
      <if test="registrationType != null">
        #{registrationType,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="vehicleroutinglocation != null">
        #{vehicleroutinglocation,jdbcType=VARCHAR},
      </if>
      <if test="ratepayer != null">
        #{ratepayer,jdbcType=VARCHAR},
      </if>
      <if test="address != null">
        #{address,jdbcType=VARCHAR},
      </if>
      <if test="foundationDate != null">
        #{foundationDate,jdbcType=DATE},
      </if>
      <if test="registrationDate != null">
        #{registrationDate,jdbcType=DATE},
      </if>
      <if test="registrationLocation != null">
        #{registrationLocation,jdbcType=VARCHAR},
      </if>
      <if test="registrationCapital != null">
        #{registrationCapital,jdbcType=VARCHAR},
      </if>
      <if test="businessAllottedTimeFrom != null">
        #{businessAllottedTimeFrom,jdbcType=DATE},
      </if>
      <if test="businessAllottedTimeTo != null">
        #{businessAllottedTimeTo,jdbcType=DATE},
      </if>
      <if test="legalCode != null">
        #{legalCode,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="pwc.taxtech.atms.entitiy.OrganizationExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from Organization
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update Organization
    <set>
      <if test="record.ID != null">
        ID = #{record.ID,jdbcType=VARCHAR},
      </if>
      <if test="record.clientCode != null">
        ClientCode = #{record.clientCode,jdbcType=VARCHAR},
      </if>
      <if test="record.name != null">
        Name = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.code != null">
        Code = #{record.code,jdbcType=VARCHAR},
      </if>
      <if test="record.parentID != null">
        ParentID = #{record.parentID,jdbcType=VARCHAR},
      </if>
      <if test="record.taxPayerNumber != null">
        TaxPayerNumber = #{record.taxPayerNumber,jdbcType=VARCHAR},
      </if>
      <if test="record.regionID != null">
        RegionID = #{record.regionID,jdbcType=VARCHAR},
      </if>
      <if test="record.structureID != null">
        StructureID = #{record.structureID,jdbcType=VARCHAR},
      </if>
      <if test="record.industryID != null">
        IndustryID = #{record.industryID,jdbcType=VARCHAR},
      </if>
      <if test="record.businessUnitID != null">
        BusinessUnitID = #{record.businessUnitID,jdbcType=VARCHAR},
      </if>
      <if test="record.isActive != null">
        IsActive = #{record.isActive,jdbcType=SMALLINT},
      </if>
      <if test="record.pLevel != null">
        PLevel = #{record.pLevel,jdbcType=INTEGER},
      </if>
      <if test="record.createTime != null">
        CreateTime = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateTime != null">
        UpdateTime = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.areaID != null">
        AreaID = #{record.areaID,jdbcType=VARCHAR},
      </if>
      <if test="record.englishName != null">
        EnglishName = #{record.englishName,jdbcType=VARCHAR},
      </if>
      <if test="record.abbreviation != null">
        Abbreviation = #{record.abbreviation,jdbcType=VARCHAR},
      </if>
      <if test="record.invoiceType != null">
        InvoiceType = #{record.invoiceType,jdbcType=VARCHAR},
      </if>
      <if test="record.legalPersonName != null">
        LegalPersonName = #{record.legalPersonName,jdbcType=VARCHAR},
      </if>
      <if test="record.manufactureAddress != null">
        ManufactureAddress = #{record.manufactureAddress,jdbcType=VARCHAR},
      </if>
      <if test="record.registerAddress != null">
        RegisterAddress = #{record.registerAddress,jdbcType=VARCHAR},
      </if>
      <if test="record.bankAccountName != null">
        BankAccountName = #{record.bankAccountName,jdbcType=VARCHAR},
      </if>
      <if test="record.bankAccountNumber != null">
        BankAccountNumber = #{record.bankAccountNumber,jdbcType=VARCHAR},
      </if>
      <if test="record.phoneNumber != null">
        PhoneNumber = #{record.phoneNumber,jdbcType=VARCHAR},
      </if>
      <if test="record.registrationType != null">
        RegistrationType = #{record.registrationType,jdbcType=VARCHAR},
      </if>
      <if test="record.remark != null">
        Remark = #{record.remark,jdbcType=VARCHAR},
      </if>
      <if test="record.vehicleroutinglocation != null">
        Vehicleroutinglocation = #{record.vehicleroutinglocation,jdbcType=VARCHAR},
      </if>
      <if test="record.ratepayer != null">
        Ratepayer = #{record.ratepayer,jdbcType=VARCHAR},
      </if>
      <if test="record.address != null">
        Address = #{record.address,jdbcType=VARCHAR},
      </if>
      <if test="record.foundationDate != null">
        FoundationDate = #{record.foundationDate,jdbcType=DATE},
      </if>
      <if test="record.registrationDate != null">
        RegistrationDate = #{record.registrationDate,jdbcType=DATE},
      </if>
      <if test="record.registrationLocation != null">
        RegistrationLocation = #{record.registrationLocation,jdbcType=VARCHAR},
      </if>
      <if test="record.registrationCapital != null">
        RegistrationCapital = #{record.registrationCapital,jdbcType=VARCHAR},
      </if>
      <if test="record.businessAllottedTimeFrom != null">
        BusinessAllottedTimeFrom = #{record.businessAllottedTimeFrom,jdbcType=DATE},
      </if>
      <if test="record.businessAllottedTimeTo != null">
        BusinessAllottedTimeTo = #{record.businessAllottedTimeTo,jdbcType=DATE},
      </if>
      <if test="record.legalCode != null">
        LegalCode = #{record.legalCode,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update Organization
    set ID = #{record.ID,jdbcType=VARCHAR},
      ClientCode = #{record.clientCode,jdbcType=VARCHAR},
      Name = #{record.name,jdbcType=VARCHAR},
      Code = #{record.code,jdbcType=VARCHAR},
      ParentID = #{record.parentID,jdbcType=VARCHAR},
      TaxPayerNumber = #{record.taxPayerNumber,jdbcType=VARCHAR},
      RegionID = #{record.regionID,jdbcType=VARCHAR},
      StructureID = #{record.structureID,jdbcType=VARCHAR},
      IndustryID = #{record.industryID,jdbcType=VARCHAR},
      BusinessUnitID = #{record.businessUnitID,jdbcType=VARCHAR},
      IsActive = #{record.isActive,jdbcType=SMALLINT},
      PLevel = #{record.pLevel,jdbcType=INTEGER},
      CreateTime = #{record.createTime,jdbcType=TIMESTAMP},
      UpdateTime = #{record.updateTime,jdbcType=TIMESTAMP},
      AreaID = #{record.areaID,jdbcType=VARCHAR},
      EnglishName = #{record.englishName,jdbcType=VARCHAR},
      Abbreviation = #{record.abbreviation,jdbcType=VARCHAR},
      InvoiceType = #{record.invoiceType,jdbcType=VARCHAR},
      LegalPersonName = #{record.legalPersonName,jdbcType=VARCHAR},
      ManufactureAddress = #{record.manufactureAddress,jdbcType=VARCHAR},
      RegisterAddress = #{record.registerAddress,jdbcType=VARCHAR},
      BankAccountName = #{record.bankAccountName,jdbcType=VARCHAR},
      BankAccountNumber = #{record.bankAccountNumber,jdbcType=VARCHAR},
      PhoneNumber = #{record.phoneNumber,jdbcType=VARCHAR},
      RegistrationType = #{record.registrationType,jdbcType=VARCHAR},
      Remark = #{record.remark,jdbcType=VARCHAR},
      Vehicleroutinglocation = #{record.vehicleroutinglocation,jdbcType=VARCHAR},
      Ratepayer = #{record.ratepayer,jdbcType=VARCHAR},
      Address = #{record.address,jdbcType=VARCHAR},
      FoundationDate = #{record.foundationDate,jdbcType=DATE},
      RegistrationDate = #{record.registrationDate,jdbcType=DATE},
      RegistrationLocation = #{record.registrationLocation,jdbcType=VARCHAR},
      RegistrationCapital = #{record.registrationCapital,jdbcType=VARCHAR},
      BusinessAllottedTimeFrom = #{record.businessAllottedTimeFrom,jdbcType=DATE},
      BusinessAllottedTimeTo = #{record.businessAllottedTimeTo,jdbcType=DATE},
      LegalCode = #{record.legalCode,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="pwc.taxtech.atms.entitiy.Organization">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update Organization
    <set>
      <if test="clientCode != null">
        ClientCode = #{clientCode,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        Name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        Code = #{code,jdbcType=VARCHAR},
      </if>
      <if test="parentID != null">
        ParentID = #{parentID,jdbcType=VARCHAR},
      </if>
      <if test="taxPayerNumber != null">
        TaxPayerNumber = #{taxPayerNumber,jdbcType=VARCHAR},
      </if>
      <if test="regionID != null">
        RegionID = #{regionID,jdbcType=VARCHAR},
      </if>
      <if test="structureID != null">
        StructureID = #{structureID,jdbcType=VARCHAR},
      </if>
      <if test="industryID != null">
        IndustryID = #{industryID,jdbcType=VARCHAR},
      </if>
      <if test="businessUnitID != null">
        BusinessUnitID = #{businessUnitID,jdbcType=VARCHAR},
      </if>
      <if test="isActive != null">
        IsActive = #{isActive,jdbcType=SMALLINT},
      </if>
      <if test="pLevel != null">
        PLevel = #{pLevel,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        CreateTime = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        UpdateTime = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="areaID != null">
        AreaID = #{areaID,jdbcType=VARCHAR},
      </if>
      <if test="englishName != null">
        EnglishName = #{englishName,jdbcType=VARCHAR},
      </if>
      <if test="abbreviation != null">
        Abbreviation = #{abbreviation,jdbcType=VARCHAR},
      </if>
      <if test="invoiceType != null">
        InvoiceType = #{invoiceType,jdbcType=VARCHAR},
      </if>
      <if test="legalPersonName != null">
        LegalPersonName = #{legalPersonName,jdbcType=VARCHAR},
      </if>
      <if test="manufactureAddress != null">
        ManufactureAddress = #{manufactureAddress,jdbcType=VARCHAR},
      </if>
      <if test="registerAddress != null">
        RegisterAddress = #{registerAddress,jdbcType=VARCHAR},
      </if>
      <if test="bankAccountName != null">
        BankAccountName = #{bankAccountName,jdbcType=VARCHAR},
      </if>
      <if test="bankAccountNumber != null">
        BankAccountNumber = #{bankAccountNumber,jdbcType=VARCHAR},
      </if>
      <if test="phoneNumber != null">
        PhoneNumber = #{phoneNumber,jdbcType=VARCHAR},
      </if>
      <if test="registrationType != null">
        RegistrationType = #{registrationType,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        Remark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="vehicleroutinglocation != null">
        Vehicleroutinglocation = #{vehicleroutinglocation,jdbcType=VARCHAR},
      </if>
      <if test="ratepayer != null">
        Ratepayer = #{ratepayer,jdbcType=VARCHAR},
      </if>
      <if test="address != null">
        Address = #{address,jdbcType=VARCHAR},
      </if>
      <if test="foundationDate != null">
        FoundationDate = #{foundationDate,jdbcType=DATE},
      </if>
      <if test="registrationDate != null">
        RegistrationDate = #{registrationDate,jdbcType=DATE},
      </if>
      <if test="registrationLocation != null">
        RegistrationLocation = #{registrationLocation,jdbcType=VARCHAR},
      </if>
      <if test="registrationCapital != null">
        RegistrationCapital = #{registrationCapital,jdbcType=VARCHAR},
      </if>
      <if test="businessAllottedTimeFrom != null">
        BusinessAllottedTimeFrom = #{businessAllottedTimeFrom,jdbcType=DATE},
      </if>
      <if test="businessAllottedTimeTo != null">
        BusinessAllottedTimeTo = #{businessAllottedTimeTo,jdbcType=DATE},
      </if>
      <if test="legalCode != null">
        LegalCode = #{legalCode,jdbcType=VARCHAR},
      </if>
    </set>
    where ID = #{ID,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="pwc.taxtech.atms.entitiy.Organization">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update Organization
    set ClientCode = #{clientCode,jdbcType=VARCHAR},
      Name = #{name,jdbcType=VARCHAR},
      Code = #{code,jdbcType=VARCHAR},
      ParentID = #{parentID,jdbcType=VARCHAR},
      TaxPayerNumber = #{taxPayerNumber,jdbcType=VARCHAR},
      RegionID = #{regionID,jdbcType=VARCHAR},
      StructureID = #{structureID,jdbcType=VARCHAR},
      IndustryID = #{industryID,jdbcType=VARCHAR},
      BusinessUnitID = #{businessUnitID,jdbcType=VARCHAR},
      IsActive = #{isActive,jdbcType=SMALLINT},
      PLevel = #{pLevel,jdbcType=INTEGER},
      CreateTime = #{createTime,jdbcType=TIMESTAMP},
      UpdateTime = #{updateTime,jdbcType=TIMESTAMP},
      AreaID = #{areaID,jdbcType=VARCHAR},
      EnglishName = #{englishName,jdbcType=VARCHAR},
      Abbreviation = #{abbreviation,jdbcType=VARCHAR},
      InvoiceType = #{invoiceType,jdbcType=VARCHAR},
      LegalPersonName = #{legalPersonName,jdbcType=VARCHAR},
      ManufactureAddress = #{manufactureAddress,jdbcType=VARCHAR},
      RegisterAddress = #{registerAddress,jdbcType=VARCHAR},
      BankAccountName = #{bankAccountName,jdbcType=VARCHAR},
      BankAccountNumber = #{bankAccountNumber,jdbcType=VARCHAR},
      PhoneNumber = #{phoneNumber,jdbcType=VARCHAR},
      RegistrationType = #{registrationType,jdbcType=VARCHAR},
      Remark = #{remark,jdbcType=VARCHAR},
      Vehicleroutinglocation = #{vehicleroutinglocation,jdbcType=VARCHAR},
      Ratepayer = #{ratepayer,jdbcType=VARCHAR},
      Address = #{address,jdbcType=VARCHAR},
      FoundationDate = #{foundationDate,jdbcType=DATE},
      RegistrationDate = #{registrationDate,jdbcType=DATE},
      RegistrationLocation = #{registrationLocation,jdbcType=VARCHAR},
      RegistrationCapital = #{registrationCapital,jdbcType=VARCHAR},
      BusinessAllottedTimeFrom = #{businessAllottedTimeFrom,jdbcType=DATE},
      BusinessAllottedTimeTo = #{businessAllottedTimeTo,jdbcType=DATE},
      LegalCode = #{legalCode,jdbcType=VARCHAR}
    where ID = #{ID,jdbcType=VARCHAR}
  </update>
  <select id="selectByExampleWithRowbounds" parameterType="pwc.taxtech.atms.entitiy.OrganizationExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from Organization
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  
  <!-- user defined start -->
  <resultMap extends="BaseResultMap" id="ResultMapWithAssociation" type="pwc.taxtech.atms.entitiy.Organization">
  	<association column="areaID" property="area" select="pwc.taxtech.atms.dao.AreaMapper.selectByPrimaryKey" />
  	<association column="businessUnitID" property="businessUnit" select="pwc.taxtech.atms.dao.BusinessUnitMapper.selectByPrimaryKey" />
  </resultMap>
  <select id="selectByPrimaryKeyWithAssociation" parameterType="java.lang.String" resultMap="ResultMapWithAssociation">
  	select 
    <include refid="Base_Column_List" />
    from Organization
    where ID = #{ID,jdbcType=VARCHAR}
  </select>
  <select id="selectByExampleWithAssociation" parameterType="pwc.taxtech.atms.entitiy.OrganizationExample" resultMap="ResultMapWithAssociation">
  	select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from Organization
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>

  <resultMap id="OrgBasicDto" type="pwc.taxtech.atms.dto.organization.OrgBasicDto">
    <id column="ID" jdbcType="VARCHAR" property="ID" />
    <result column="ParentID" jdbcType="VARCHAR" property="parentID" />
    <result column="Code" jdbcType="VARCHAR" property="code" />
    <result column="Name" jdbcType="VARCHAR" property="name" />
    <result column="BusinessUnitID" jdbcType="VARCHAR" property="businessUnitID" />
    <result column="BusinessUnitName" jdbcType="VARCHAR" property="businessUnitName" />
    <result column="AreaID" jdbcType="VARCHAR" property="areaID" />
    <result column="AreaName" jdbcType="VARCHAR" property="areaName" />
    <result column="IndustryID" jdbcType="VARCHAR" property="industryID" />
    <result column="IndustryName" jdbcType="VARCHAR" property="industryName" />
    <result column="StructureID" jdbcType="VARCHAR" property="structureID" />
    <result column="StructureName" jdbcType="VARCHAR" property="structureName" />
    <result column="TaxPayerNumber" jdbcType="VARCHAR" property="taxPayerNumber" />
    <result column="RegionID" jdbcType="VARCHAR" property="regionID" />
    <result column="RegionName" jdbcType="VARCHAR" property="regionName" />
    <result column="IsActive" jdbcType="SMALLINT" property="isActive" />
  </resultMap>
  <select id="selectIndBusiunitAreaOrgstrctReg" parameterType="map" resultMap="OrgBasicDto">
	select org.ID as ID, org.ParentID as ParentID, org.Code as Code, org.Name as Name, 
	bu.ID as BusinessUnitID, bu.Name as BusinessUnitName,
	area.ID as AreaID, area.Name as AreaName,
	ind.ID as IndustryID, ind.Name as IndustryName, 
	os.ID as StructureID, os.Name as StructureName,
	org.TaxPayerNumber as TaxPayerNumber, 
	org.RegionID as RegionID, 
	reg.MergerName as RegionName,
	org.IsActive as IsActive
	from Organization as org
	left join Industry as ind on org.IndustryID = ind.ID
	left join BusinessUnit as bu on org.BusinessUnitID = bu.ID
	left join Area as area on org.AreaID = area.ID 
	left join OrganizationStructure as os on org.StructureID = os.ID
	left join Region as reg on org.RegionID = reg.ID
	<if test="orgIsActive != null and orgIsActive == true">
     	where org.IsActive = 1
    </if>
	order by Name
  </select>
  
  <resultMap id="OrganizationDto" type="pwc.taxtech.atms.dto.organization.OrganizationDto">
    <id column="ID" jdbcType="VARCHAR" property="ID" />
    <!-- 注意! OrganizationName 对应 name-->
 	<result column="OrganizationName" jdbcType="VARCHAR" property="name" />
    <result column="ParentID" jdbcType="VARCHAR" property="parentID" />
    <result column="IndustryName" jdbcType="VARCHAR" property="industryName" />
    <result column="BusinessUnitName" jdbcType="VARCHAR" property="businessUnitName" />
    <result column="AreaName" jdbcType="VARCHAR" property="areaName" />
    <result column="BusinessUnitID" jdbcType="VARCHAR" property="businessUnitID" />
    <result column="AreaID" jdbcType="VARCHAR" property="areaID" />
    <result column="RegionID" jdbcType="VARCHAR" property="regionID" />
    <result column="IndustryID" jdbcType="VARCHAR" property="industryID" />
    <!-- 注意! OrgStructureID 对应 structureID -->
    <result column="OrgStructureID" jdbcType="VARCHAR" property="structureID" />
    <!-- 注意! OrgStructureName 对应 structureName -->
    <result column="OrgStructureName" jdbcType="VARCHAR" property="structureName" />
    <result column="PLevel" jdbcType="INTEGER" property="pLevel" /> 
    <result column="Code" jdbcType="VARCHAR" property="code" />
    <result column="TaxPayerNumber" jdbcType="VARCHAR" property="taxPayerNumber" />
    <result column="IsActive" jdbcType="SMALLINT" property="isActive" />
  </resultMap>
  <select id="selectIndBusiunitAreaOrgstrct" parameterType="map" resultMap="OrganizationDto">
	select 
		org.ID as ID, 
		org.Name as OrganizationName, 
		org.ParentID as ParentID,
		ind.Name as IndustryName, 
		ind.ID as IndustryID, 
		bu.Name as BusinessUnitName, 
		bu.ID as BusinessUnitID,
		area.Name as AreaName, 
		area.ID as AreaID,
		org.RegionID as RegionID, 
		os.ID as OrgStructureID, 
		os.Name as OrgStructureName,
		org.PLevel as PLevel, 
		org.Code as Code, 
		org.TaxPayerNumber as TaxPayerNumber, 
		org.IsActive as IsActive
		from Organization as org
	left join Industry as ind on org.IndustryID = ind.ID
	left join BusinessUnit as bu on org.BusinessUnitID = bu.ID
	left join Area as area on org.AreaID = area.ID 
	left join OrganizationStructure as os on org.StructureID = os.ID
	<if test="orgIsActive != null and orgIsActive == true ">
     	where org.IsActive = 1
    </if>
  </select>
  
  <select id="selectIndBusUnitAreaOrgStrctReg" parameterType="map" resultMap="OrganizationDtoForAreaRegIndBusList">
    select 
      p.Name          as Name, 
      p.ID            as ID, 
      unit.ID         as BusinessUnitID, 
      unit.Name       as BusinessUnitName, 
      p.RegionID      as RegionID,
      p.IndustryID    as IndustryID,
      industry.Name   as IndustryName,
      p.ParentID      as ParentID,
      p.StructureID   as StructureID,
      structure.Name  as StructureName,
      p.AreaID        as AreaID,
      area.Name       as AreaName,
      city.Name       as RegionName,
      city.ParentID   as ParentName

      from dbo.Organization p
      left join dbo.BusinessUnit unit on p.BusinessUnitID = unit.ID   --tempq
      left join dbo.Industry industry on p.IndustryID = industry.ID --industryReal
      left join dbo.OrganizationStructure structure on p.StructureID = structure.ID --structureReal
      left join dbo.Area area on p.AreaID = area.ID --areaReal
      left join dbo.Region city on p.RegionID = city.ID --cityReal
      where p.AreaID = #{areaId,jdbcType=VARCHAR}       --input areaId
      and city.LevelType = #{regionLevelType,jdbcType=INTEGER} --City Level Type
      <if test="orgIsActive != null and orgIsActive == true ">
         and p.IsActive = 1
      </if>
      <if test="orgIsActive != null and orgIsActive == false ">
         and p.IsActive = 0
      </if>
  </select>
  
  <resultMap id="OrganizationDtoForAreaRegIndBusList" type="pwc.taxtech.atms.dto.organization.OrganizationDto">
    <id column="ID" jdbcType="VARCHAR" property="ID" />
    <result column="Name" jdbcType="VARCHAR" property="name" />
    <result column="BusinessUnitID" jdbcType="VARCHAR" property="businessUnitID" />
    <result column="BusinessUnitName" jdbcType="VARCHAR" property="businessUnitName" />
    <result column="RegionID" jdbcType="VARCHAR" property="regionID" />
    <result column="IndustryID" jdbcType="VARCHAR" property="industryID" />
    <result column="IndustryName" jdbcType="VARCHAR" property="industryName" />
    <result column="ParentID" jdbcType="VARCHAR" property="parentID" />
    <result column="StructureID" jdbcType="VARCHAR" property="structureID" />
    <result column="StructureName" jdbcType="VARCHAR" property="structureName" />
    <result column="AreaID" jdbcType="VARCHAR" property="areaID" />
    <result column="AreaName" jdbcType="VARCHAR" property="areaName" />
    <result column="RegionName" jdbcType="VARCHAR" property="regionName" />
    <result column="ParentName" jdbcType="VARCHAR" property="parentName" />
  </resultMap>
  
  <resultMap id="OrganizationDtoForCDOrgList" type="pwc.taxtech.atms.dto.organization.OrganizationDto">
    <id column="ID" jdbcType="VARCHAR" property="ID" />
 	<result column="Name" jdbcType="VARCHAR" property="name" />
 	<result column="AttributeID" jdbcType="VARCHAR" property="attributeID" />
 	<result column="AttributeName" jdbcType="VARCHAR" property="attributeName" />
 	<result column="DimensionID" jdbcType="VARCHAR" property="dimensionID" />
 	<result column="DimensionName" jdbcType="VARCHAR" property="dimensionName" />
 	<result column="DimensionValueID" jdbcType="VARCHAR" property="dimensionValueID" />
 	<result column="DimensionValueName" jdbcType="VARCHAR" property="dimensionValueName" />
  </resultMap>
  <!--
   * 由于C#中OrganizationService.cs line 2356~2357以下代码被注释,故JAVA中未join
   * statDimension表做联合查询。 join sd in stat Dimension on d.ID equals sd.DimensionID
   * from sdTp in sdTemp.DefaultIfEmpty()
  -->
  <select id="getCustomDimensionOrgList" resultMap="OrganizationDtoForCDOrgList">
SELECT DISTINCT org.id        AS ID, 
                org.NAME      AS NAME, 
                d.attributeid AS AttributeID, 
                s.NAME        AS AttributeName, 
                d.id          AS DimensionID, 
                d.NAME        AS DimensionName, 
                dv.id         AS DimensionValueID, 
                dv.NAME       AS DimensionValueName 
FROM   organization AS org 
       JOIN dimensionvalueorg AS dvg 
         ON org.id = dvg.organizationid 
       JOIN dimensionvalue AS dv 
         ON dvg.dimensionvalueid = dv.id 
       JOIN dimension AS d 
         ON dv.dimensionid = d.id 
       JOIN statisticattribute AS s 
         ON d.attributeid = s.id 
WHERE  org.isactive = 1 
       AND s.isactive = 1 
       AND d.isactive = 1 
       AND dv.isactive = 1 
  </select>
  <resultMap id="OrgDtoForGetDimValueOrgList" type="pwc.taxtech.atms.dto.DimensionValueOrgDto">
    <id column="ID" jdbcType="VARCHAR" property="ID" />
 	<result column="DimensionValueID" jdbcType="VARCHAR" property="dimensionValueID" />
 	<result column="OrganizationID" jdbcType="VARCHAR" property="organizationID" />
 	<result column="OrganizationName" jdbcType="VARCHAR" property="organizationName" />
 	<result column="DimensionID" jdbcType="VARCHAR" property="dimensionID" />
 	<result column="DimensionName" jdbcType="VARCHAR" property="dimensionName" />
 	<result column="DimensionValue" jdbcType="VARCHAR" property="dimensionValue" />
  </resultMap>
  <select id="getDimensionValueOrgDtoList" resultMap="OrgDtoForGetDimValueOrgList">
		select
	dvq.DimensionValueID as DimensionValueID,
	dvgq.OrganizationID as OrganizationID,
	dvgq.Name as OrganizationName,
	dvq.DimensionID as DimensionID,
	d.Name as DimensionName,
	dvq.DimensionValueName as DimensionValue,
	dvgq.OrganizationID as ID
	from
	(
		select org.ID as DimensionValueID, org.Name as DimensionValueName,
		org.IsActive as IsActive, 'c61a5bd6-a996-4952-9869-d053966537e8' DimensionID,
		org.CreateTime as CreateTime,
		org.UpdateTime as UpdateTime
		from Organization as org
		where org.IsActive = 1
	
		union
		select bu.ID as DimensionValueID, bu.Name as DimensionValueName,
		bu.IsActive as IsActive, 'c61a5bd6-a996-4952-9869-d053995237e5' DimensionID,
		bu.CreateTime as CreateTime,
		bu.UpdateTime as UpdateTime
		from BusinessUnit as bu
		where bu.IsActive = 1
	
		union
		select area.ID as DimensionValueID, area.Name as DimensionValueName,
		area.IsActive as IsActive, 'c61a5bd6-a996-4952-9869-d053995237e6' DimensionID,
		now() as CreateTime,
		now() as UpdateTime
		from Area as area
		where area.IsActive = 1
	
		union
		select dv.ID as DimensionValueID, dv.Name as DimensionValueName,
		dv.IsActive as IsActive, dv.DimensionID as DimensionID,
		dv.CreateTime as CreateTime,
		dv.UpdateTime as UpdateTime
		from DimensionValue as dv
	) as dvq
	join (select ID, Name from Dimension where IsActive = 1) as d
	on dvq.DimensionID = d.ID
	join (
		select 'c61a5bd6-a996-4952-9869-d053966537e8' ID, 
		org.StructureID as DimensionValueID, 
		org.ID as OrganizationID, org.Name as Name
		from Organization as org
		where org.IsActive = 1
	
		union
		select 'c61a5bd6-a996-4952-9869-d053995237e5' ID, 
		org.BusinessUnitID as DimensionValueID, 
		org.ID as OrganizationID, org.Name as Name
		from Organization as org
		where org.IsActive = 1
	
		union
		select 'c61a5bd6-a996-4952-9869-d053995237e6' ID, 
		org.AreaID as DimensionValueID, 
		org.ID as OrganizationID, org.Name as Name
		from Organization as org
		where org.IsActive = 1
	
		union
		select dv.ID as ID, dv.DimensionValueID as DimensionValueID,
		dv.OrganizationID as OrganizationID, org.Name as Name
		from DimensionValueOrg as dv
		join Organization as org on dv.OrganizationID = org.ID
		where org.IsActive = 1
	) as dvgq on dvq.DimensionValueID = dvgq.DimensionValueID
  </select>
  <resultMap id="OrgDtoForGetAllCusDimOrgList" type="pwc.taxtech.atms.dto.organization.OrganizationDto">
    <id column="ID" jdbcType="VARCHAR" property="ID" />
 	<result column="Name" jdbcType="VARCHAR" property="name" />
 	<result column="AttributeID" jdbcType="VARCHAR" property="attributeID" />
 	<result column="AttributeName" jdbcType="VARCHAR" property="attributeName" />
 	<result column="DimensionID" jdbcType="VARCHAR" property="dimensionID" />
 	<result column="DimensionName" jdbcType="VARCHAR" property="dimensionName" />
 	<result column="DimensionValueID" jdbcType="VARCHAR" property="dimensionValueID" />
 	<result column="DimensionValueName" jdbcType="VARCHAR" property="dimensionValueName" />
  </resultMap>
  
  <select id="getAllCustomDimensionOrgList" resultMap="OrgDtoForGetAllCusDimOrgList">
  	  	select 
	q.ID as ID,
	q.Name as Name,
	d.AttributeID as AttributeID,
	s.Name as AttributeName,
	d.ID as DimensionID,
	d.Name as DimensionName,
	dv.ID as DimensionValueID,
	dv.Name as DimensionValueName
	from
		(
			select ID, Name
			from Organization as p
			where p.IsActive = 1
		)as q
	join DimensionValueOrg as dvg on q.ID = dvg.OrganizationID
	join DimensionValue as dv on dvg.DimensionValueID = dv.ID
	join Dimension as d on dv.DimensionID = d.ID
	join StatisticAttribute as s on d.AttributeID = s.ID
	where s.IsActive = 1
  </select>
  
   <resultMap id="OrgDtoForGetSingleOrgByOrgID" type="pwc.taxtech.atms.dto.organization.OrganizationDto">
    <id column="ID" jdbcType="VARCHAR" property="ID" />
 	<result column="ClientCode" jdbcType="VARCHAR" property="clientCode" />
 	<result column="Name" jdbcType="VARCHAR" property="name" />
 	<result column="EnglishName" jdbcType="VARCHAR" property="englishName" />
 	<result column="Abbreviation" jdbcType="VARCHAR" property="abbreviation" />
 	<result column="Code" jdbcType="VARCHAR" property="code" />
 	<result column="InvoiceType" jdbcType="VARCHAR" property="invoiceType" />
 	<result column="ParentID" jdbcType="VARCHAR" property="parentID" />
 	<result column="TaxPayerNumber" jdbcType="VARCHAR" property="taxPayerNumber" />
 	<result column="RegionID" jdbcType="VARCHAR" property="regionID" />
 	<result column="StructureID" jdbcType="VARCHAR" property="structureID" />
 	<result column="IndustryID" jdbcType="VARCHAR" property="industryID" />
 	<result column="LegalPersonName" jdbcType="VARCHAR" property="legalPersonName" />
 	<result column="ManufactureAddress" jdbcType="VARCHAR" property="manufactureAddress" />
 	<result column="RegisterAddress" jdbcType="VARCHAR" property="registerAddress" />
 	<result column="BankAccountName" jdbcType="VARCHAR" property="bankAccountName" />
 	<result column="BankAccountNumber" jdbcType="VARCHAR" property="bankAccountNumber" />
 	<result column="PhoneNumber" jdbcType="VARCHAR" property="phoneNumber" />
 	<result column="RegistrationType" jdbcType="VARCHAR" property="registrationType" />
 	<result column="BusinessUnitID" jdbcType="VARCHAR" property="businessUnitID" />
 	<result column="IsActive" jdbcType="VARCHAR" property="isActive" />
 	<result column="PLevel" jdbcType="VARCHAR" property="pLevel" />
 	<result column="CreateTime" jdbcType="VARCHAR" property="createTime" />
 	<result column="UpdateTime" jdbcType="VARCHAR" property="updateTime" />
 	<result column="AreaID" jdbcType="VARCHAR" property="areaID" />
 	<result column="Remark" jdbcType="VARCHAR" property="remark" />
 	<result column="Vehicleroutinglocation" jdbcType="VARCHAR" property="vehicleroutinglocation" />
 	
 	<result column="IndustryName" jdbcType="VARCHAR" property="industryName" />
 	<result column="RegionName" jdbcType="VARCHAR" property="regionName" />
 	<result column="StructureName" jdbcType="VARCHAR" property="structureName" />
 	<result column="ParentRegionID" jdbcType="VARCHAR" property="parentRegionID" />
 	<result column="AreaName" jdbcType="VARCHAR" property="areaName" />
 	<result column="BusinessUnitName" jdbcType="VARCHAR" property="businessUnitName" />
  </resultMap>
  <select id="getSingleOrgByOrgIDToOrgDto" parameterType="map" resultMap="OrgDtoForGetSingleOrgByOrgID">
	select m.ID, 
       m.ClientCode, 
       m.Name, 
       m.Code, 
       m.ParentID, 
       m.TaxPayerNumber, 
       m.RegionID, 
       m.StructureID, 
       m.IndustryID, 
       m.BusinessUnitID, 
       m.IsActive, 
       m.PLevel, 
       m.CreateTime, 
       m.UpdateTime, 
       m.AreaID, 
       m.EnglishName, 
       m.Abbreviation, 
       m.InvoiceType, 
       m.LegalPersonName, 
       m.ManufactureAddress, 
       m.RegisterAddress, 
       m.BankAccountName, 
       m.BankAccountNumber, 
       m.PhoneNumber, 
       m.RegistrationType, 
       m.Remark, 
       m.Vehicleroutinglocation, 
       n.Name                as IndustryName, 
       pregion.Name + t.Name as RegionName, 
       s.Name                as StructureName, 
       t.ParentID            as ParentRegionID, 
       ar.Name               as AreaName, 
       bu.Name               as BusinessUnitName 
from   Organization as m 
       left join Industry as n 
              on m.IndustryID = n.ID 
       left join Region as t 
              on m.RegionID = t.ID 
       left join Region as pregion 
              on t.ParentID = pregion.ID 
       left join Area as ar 
              on m.AreaID = ar.ID 
       left join OrganizationStructure as s 
              on m.StructureID = s.ID 
       left join BusinessUnit as bu 
              on m.BusinessUnitID = bu.ID 
where  m.ID = #{orgId} 
  </select>
  <select id="countForCodeUniqueValidate" parameterType="map" resultType="java.lang.Integer">
  	select count(*) 
	from Organization 
	where ('' = #{innerId} or ID != #{innerId}) 
	and Code = #{innerCode}
  </select>
  <resultMap id="OrgGeneralInfoMiddleDto" type="pwc.taxtech.atms.dto.organization.OrgGeneralInfoMiddleDto">
    <id column="ID" jdbcType="VARCHAR" property="ID" />
    <result column="OrgName" jdbcType="VARCHAR" property="orgName" />
    <result column="TaxPayerNumber" jdbcType="VARCHAR" property="taxPayerNumber" />
    <result column="AccountSetName" jdbcType="VARCHAR" property="accountSetName" />
    <result column="ServiceName" jdbcType="VARCHAR" property="serviceName" />
    <result column="BusinessUnitName" jdbcType="VARCHAR" property="businessUnitName" />
    <result column="IndustryName" jdbcType="VARCHAR" property="industryName" />
    <result column="AreaName" jdbcType="VARCHAR" property="areaName" />
    <result column="AreaID" jdbcType="VARCHAR" property="areaID" />
    <result column="BusinessUnitID" jdbcType="VARCHAR" property="businessUnitID" />
  </resultMap>
  <select id="selectJoinToOrgGeneralInfo" parameterType="map" resultMap="OrgGeneralInfoMiddleDto">
  	SELECT m.id             AS ID, 
       m.NAME           AS OrgName, 
       m.taxpayernumber AS TaxPayerNumber, 
       accSet.NAME      AS AccountSetName, 
       st.NAME          AS ServiceName, 
       t.NAME           AS BusinessUnitName, 
       n.NAME           AS IndustryName, 
       ar.NAME          AS AreaName, 
       m.areaid         AS AreaID, 
       m.businessunitid AS BusinessUnitID 
	FROM   organization AS m 
       LEFT JOIN industry AS n 
              ON m.industryid = n.id 
       LEFT JOIN organizationservicetemplategroup AS stg 
              ON m.id = stg.organizationid 
       LEFT JOIN servicetype AS st 
              ON stg.servicetypeid = st.id 
       LEFT JOIN businessunit AS t 
              ON t.isactive = 1 
                 AND m.businessunitid = t.id 
       LEFT JOIN area AS ar 
              ON ar.isactive = 1 
                 AND m.areaid = ar.id 
       LEFT JOIN enterpriseaccountsetorg AS setOrg 
              ON m.id = setOrg.organizationid 
       LEFT JOIN enterpriseaccountset AS accSet 
              ON accSet.isactive = 1 
                 AND setOrg.enterpriseaccountsetid = accSet.id 
  </select>
</mapper>