<?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.chinaweal.aiccs.aiccs.entbase.mapper.TREntBaseMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.entbase.entity.TREntBase">
        <id column="PRIPID" property="pripid" />
        <result column="BIZSEQ" property="bizseq" />
        <result column="PREENTNAMEID" property="preentnameid" />
        <result column="ENTNAME" property="entname" />
        <result column="REGNO" property="regno" />
        <result column="ENTTYPE" property="enttype" />
        <result column="SUBENTTYPE" property="subenttype" />
        <result column="REGCAP" property="regcap" />
        <result column="NAMEDISTRICT" property="namedistrict" />
        <result column="ENTTRA" property="enttra" />
        <result column="NAMEIND" property="nameind" />
        <result column="ORGFORM" property="orgform" />
        <result column="NAMEORG" property="nameorg" />
        <result column="INDUSTRYPHY" property="industryphy" />
        <result column="INDUSTRYCO" property="industryco" />
        <result column="ESTDATE" property="estdate" />
        <result column="REGORG" property="regorg" />
        <result column="LOCALADM" property="localadm" />
        <result column="ENTSTATE" property="entstate" />
        <result column="ENTBIZSTATE" property="entbizstate" />
        <result column="ENTCAT" property="entcat" />
        <result column="APPRDATE" property="apprdate" />
        <result column="LEREPNAME" property="lerepname" />
        <result column="AICID" property="aicid" />
        <result column="LAUPTIME" property="lauptime" />
        <result column="ENDBIZSTATE" property="endbizstate" />
        <result column="AREA_CODE" property="areaCode" />
        <result column="APPRSUBORG" property="apprsuborg" />
        <result column="OPERATESTATUS" property="operatestatus" />
        <result column="RECORDMODIFYDATE" property="recordmodifydate" />
        <result column="USCC" property="uscc" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        PRIPID, BIZSEQ, PREENTNAMEID, ENTNAME, REGNO, ENTTYPE, SUBENTTYPE, REGCAP, NAMEDISTRICT, ENTTRA, NAMEIND, ORGFORM, NAMEORG, INDUSTRYPHY, INDUSTRYCO, ESTDATE, REGORG, LOCALADM, ENTSTATE, ENTBIZSTATE, ENTCAT, APPRDATE, LEREPNAME, AICID, LAUPTIME, ENDBIZSTATE, AREA_CODE, APPRSUBORG, OPERATESTATUS, RECORDMODIFYDATE, USCC
    </sql>

    <select id="getTrEntBase" resultMap="BaseResultMap" parameterType="com.chinaweal.aiccs.aiccs.entbase.entity.TREntBase">
        select
        <include refid="Base_Column_List"/>
        from TREntBase
        <where>
            <if test="pripid!=null and pripid!=''">
                and pripid=#{pripid}
            </if>
            <if test="regno!=null and  regno!=''">
                <choose>
                    <when test="regno.trim().length() == 18 ">
                        and uscc = #{regno}
                    </when>
                    <otherwise>
                        and regno = #{regno}
                    </otherwise>
                </choose>
            </if>
            <if test="uscc!=null and  uscc!=''">
                and uscc = #{uscc}
            </if>
            <if test="entname!=null and entname!=''">
                and entname=#{entname}
            </if>
        </where>
        order by LaUpTime desc
    </select>
</mapper>
