<?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.punishment.mapper.TaskMapper">

    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.punishment.entity.Tolockentlist">
        <id column="tolockId" property="tolockId" />
        <result column="pripid" property="pripid" />
        <result column="uniscid" property="uniscid" />
        <result column="entName" property="entName" />
        <result column="regno" property="regno" />
        <result column="punishFrom" property="punishFrom" />
        <result column="regstate" property="regstate" />
        <result column="regstateCn" property="regstateCn" />
        <result column="punishInfoId" property="punishInfoId" />
        <result column="state" property="state" />
        <result column="insertTime" property="insertTime" />
        <result column="laupTime" property="laupTime" />
        <result column="regorg" property="regorg" />
    </resultMap>

    <resultMap id="Personlock" type="com.chinaweal.aiccs.aiccs.punishment.entity.Personlock">
        <id column="PLID" property="plid" />
        <result column="IDCARDNO" property="idcardno" />
        <result column="PERNAME" property="pername" />
        <result column="ENTNAME" property="entname" />
        <result column="REGNO" property="regno" />
        <result column="DUTY" property="duty" />
        <result column="ILLEGALITEM" property="illegalitem" />
        <result column="INVOLVEDATE" property="involvedate" />
        <result column="INVOLVEDMONEY" property="involvedmoney" />
        <result column="LOCKREASON" property="lockreason" />
        <result column="LOCKSTARTDATE" property="lockstartdate" />
        <result column="LOCKENDDATE" property="lockenddate" />
        <result column="LOCKUSERNAME" property="lockusername" />
        <result column="LOCKUSERID" property="lockuserid" />
        <result column="LOCKUSERDEPTID" property="lockuserdeptid" />
        <result column="LOCKUSERUNITID" property="lockuserunitid" />
        <result column="UNLOCKUSERNAME" property="unlockusername" />
        <result column="UNLOCKUSERID" property="unlockuserid" />
        <result column="ULDEPTID" property="uldeptid" />
        <result column="ULUNITID" property="ulunitid" />
        <result column="UNLDATE" property="unldate" />
        <result column="LOCKLEVEL" property="locklevel" />
        <result column="LOCKSTATE" property="lockstate" />
        <result column="INPUTDATE" property="inputdate" />
        <result column="RLOCKUSERNAME" property="rlockusername" />
        <result column="RLOCKUSERID" property="rlockuserid" />
        <result column="RLOCKUSERUNITID" property="rlockuserunitid" />
        <result column="RLOCKUSERDEPID" property="rlockuserdepid" />
        <result column="RLOCKDATE" property="rlockdate" />
        <result column="ULOCKSEASON" property="ulockseason" />
        <result column="ENTTYPE" property="enttype" />
        <result column="REGNOID" property="regnoid" />
        <result column="LOCKDUTY" property="lockduty" />
        <result column="WHITELOCKTYPE" property="whitelocktype" />
    </resultMap>

    <resultMap id="EntLock" type="com.chinaweal.aiccs.aiccs.punishment.entity.EntLock">
        <id column="ELID" property="elid" />
        <result column="PRIPID" property="pripid" />
        <result column="ENTNAME" property="entname" />
        <result column="REGNO" property="regno" />
        <result column="UNISCID" property="uniscid" />
        <result column="LOCKREASON" property="lockreason" />
        <result column="LOCKUSERNAME" property="lockusername" />
        <result column="LOCKUSERID" property="lockuserid" />
        <result column="LOCKUSERDEPTID" property="lockuserdeptid" />
        <result column="LOCKUSERUNITID" property="lockuserunitid" />
        <result column="LOCKSTARTDATE" property="lockstartdate" />
        <result column="LOCKTIME" property="lockTime" />
        <result column="UNLOCKTIME" property="unlockTime" />
        <result column="LOCKENDDATE" property="lockenddate" />
        <result column="UNLUSERNAME" property="unlusername" />
        <result column="UNLUSERID" property="unluserid" />
        <result column="ULDEPTID" property="uldeptid" />
        <result column="ULUNITID" property="ulunitid" />
        <result column="UNLDATE" property="unldate" />
        <result column="LOCKTYPE" property="locktype" />
        <result column="MEASURE" property="measure" />
        <result column="LOCKSTATE" property="lockstate" />
        <result column="INPUTDATE" property="inputdate" />
        <result column="ULOCKREASON" property="unlockreason" />
        <result column="LAUPTIME" property="laupTime" />
        <result column="state" property="state" />
        <result column="FILEPATH" property="filepath" />
        <result column="FILENAME" property="filename" />
        <result column="punishFrom" property="punishFrom" />
        <result column="ULOCKSPECIFICREASON" property="uLockSpecificReason" />
        <result column="ulsrcode" property="uLSRCode" />
        <result column="representative" property="representative" />
        <result column="regorg" property="regorg" />
    </resultMap>

    <resultMap id="EntDto" type="com.chinaweal.aiccs.aiccs.punishment.entity.dto.EntDto">
        <id column="elid" property="elid" />
        <result column="regstate" property="regstate" />
    </resultMap>

    <resultMap id="TRBaseCode" type="com.chinaweal.aiccs.aiccs.system.entity.TRBaseCode">
        <id column="BASECODEID" property="basecodeid" />
        <result column="CODEID" property="codeid" />
        <result column="CODE" property="code" />
        <result column="NAME" property="name" />
        <result column="COMM" property="comm" />
        <result column="ISGB" property="isgb" />
        <result column="AREA_CODE" property="areaCode" />
        <result column="LAUPTIME" property="lauptime" />
    </resultMap>

    <select id="queryFromAll" parameterType="String" resultMap="BaseResultMap">
        select aa.F000 as punishInfoId, eb.*
        from ${tableName} aa left join e_baseinfo eb on
        <if test="tableName == 'aqschmd_aj'">
            aa.entName = eb.ENTNAME
        </if>
        <if test="tableName == 'hggjrzqy_md'">
            aa.qyzwmc = eb.ENTNAME
        </if>
        <if test="tableName == 'hgsxrzqymd'">
            aa.qyzwmc = eb.ENTNAME
        </if>
        <if test="tableName == 'scjr_zjh'">
            aa.CFDXMC = eb.ENTNAME
        </if>
        <if test="tableName == 'ndcrjj'">
            aa.JYJYSYSXQYMD = eb.ENTNAME
        </if>
        <if test="tableName == 'yzzlsxqymd' || tableName == 'dzswsxwtzx' || tableName =='sjrhmd'">
            aa.TYSHXYDM = eb.UNISCID
        </if>
        <if test="tableName == 'tqnmggz'">
            aa.DXMC = eb.ENTNAME
        </if>
        where PRIPID is not null
    </select>

    <select id="queryAll" resultMap="BaseResultMap">
        select '1' as punishFrom, aa.F000 as punishInfoId, eb.pripid, eb.uniscid,
        eb.entname, eb.regno, eb.regstate, eb.regstate_Cn regstateCn, eb.regorg
        from crgs.ex_xxzx_09_aqschmd_aj aa left join e_baseinfo eb on
        aa.dwmc = eb.ENTNAME
        where PRIPID is not null
        union all
        select '3' as punishFrom, aa.F000 as punishInfoId, eb.pripid, eb.uniscid,
        eb.entname, eb.regno, eb.regstate, eb.regstate_Cn regstateCn, eb.regorg
        from crgs.ex_xxzx_11_hgsxrzqymd aa left join e_baseinfo eb on
        aa.qyzwmc = eb.ENTNAME
        where PRIPID is not null
        union all
        select '4' as punishFrom, aa.F000 as punishInfoId, eb.pripid, eb.uniscid,
        eb.entname, eb.regno, eb.regstate, eb.regstate_Cn regstateCn, eb.regorg
        from crgs.ex_xxzx_12_2017ndypyz aa left join e_baseinfo eb on
        aa.xm = eb.ENTNAME
        where PRIPID is not null
        union all
        select '5' as punishFrom, aa.F000 as punishInfoId, eb.pripid, eb.uniscid,
        eb.entname, eb.regno, eb.regstate, eb.regstate_Cn regstateCn, eb.regorg
        from crgs.ex_xxzx_13_tjsyzsxqyh aa left join e_baseinfo eb on
        aa.xzxdrmc = eb.ENTNAME
        where PRIPID is not null
        union all
        select '6' as punishFrom, aa.F000 as punishInfoId, eb.pripid, eb.uniscid,
        eb.entname, eb.regno, eb.regstate, eb.regstate_Cn regstateCn, eb.regorg
        from crgs.ex_xxzx_14_scjr_zjh aa left join e_baseinfo eb on
        aa.cfdxmc = eb.ENTNAME
        where PRIPID is not null
        union all
        select '7' as punishFrom, aa.F000 as punishInfoId, eb.pripid, eb.uniscid,
        eb.entname, eb.regno, eb.regstate, eb.regstate_Cn regstateCn, eb.regorg
        from crgs.ex_xxzx_14_2016ndcrjj aa left join e_baseinfo eb on
        aa.jyjysysxqymd = eb.ENTNAME
        where PRIPID is not null
        union all
        select '8' as punishFrom, aa.F000 as punishInfoId, eb.pripid, eb.uniscid,
        eb.entname, eb.regno, eb.regstate, eb.regstate_Cn regstateCn, eb.regorg
        from crgs.ex_xxzx_15_yzzlsxqymd aa left join e_baseinfo eb on
        aa.yzzlsxqymc = eb.ENTNAME
        where PRIPID is not null
        union all
        select '9' as punishFrom, aa.F000 as punishInfoId, eb.pripid, eb.uniscid,
        eb.entname, eb.regno, eb.regstate, eb.regstate_Cn regstateCn, eb.regorg
        from crgs.ex_xxzx_16_zdsswfajds aa left join e_baseinfo eb on
        aa.nsrmc = eb.ENTNAME
        where PRIPID is not null
        union all
        select '11' as punishFrom, aa.F000 as punishInfoId, eb.pripid, eb.uniscid,
        eb.entname, eb.regno, eb.regstate, eb.regstate_Cn regstateCn, eb.regorg
        from crgs.ex_xxzx_19_dzswsxwtzx aa left join e_baseinfo eb on
        aa.qymc = eb.ENTNAME
        where PRIPID is not null
        union all
        select '12' as punishFrom, aa.F000 as punishInfoId, eb.pripid, eb.uniscid,
        eb.entname, eb.regno, eb.regstate, eb.regstate_Cn regstateCn, eb.regorg
        from crgs.ex_xxzx_20_sjrhmd aa left join e_baseinfo eb on
        aa.sxzt = eb.ENTNAME
        where PRIPID is not null
        union all
        select '13' as punishFrom, aa.F000 as punishInfoId, eb.pripid, eb.uniscid,
        eb.entname, eb.regno, eb.regstate, eb.regstate_Cn regstateCn, eb.regorg
        from crgs.ex_xxzx_21_2018tqnmggz aa left join e_baseinfo eb on
        aa.dxmc = eb.ENTNAME
        where PRIPID is not null
    </select>

    <select id="query" resultMap="EntLock">
        SELECT
            e.*
        FROM
            entlock e,
            (
                SELECT
                    '1' AS punishFrom,
                    '信用风险监管处' AS unlusername,
                    aa.F000 AS punishInfoId,
                    aa.s_last_updated AS laupTime,
                    eb.pripid,
                    eb.uniscid,
                    eb.entname AS entname,
                    eb.regno,
                    eb.regstate,
                    eb.regstate_Cn regstateCn,
                    eb.regorg,
                    eb.lerep AS representative
                FROM
                    crgs.ex_xxzx_09_aqschmd_aj aa
                        LEFT JOIN e_baseinfo eb ON aa.dwmc = eb.ENTNAME
                WHERE
                    PRIPID IS NOT NULL
                  AND dwmc = #{entname}

                UNION ALL
                SELECT
                    '2' AS punishFrom,
                    '信用风险监管处' AS unlusername,
                    aa.F000 AS punishInfoId,
                    aa.s_last_updated AS laupTime,
                    eb.pripid,
                    eb.uniscid,
                    eb.entname AS entname,
                    eb.regno,
                    eb.regstate,
                    eb.regstate_Cn regstateCn,
                    eb.regorg,
                    eb.lerep AS representative
                FROM
                    crgs.ex_xxzx_10_hggjrzqymd aa
                    LEFT JOIN e_baseinfo eb ON aa.qyzwmc = eb.ENTNAME
                WHERE
                    PRIPID IS NOT NULL
                  AND qyzwmc = #{entname} UNION ALL
                SELECT
                    '3' AS punishFrom,
                    '信用风险监管处' AS lockusername,
                    aa.F000 AS punishInfoId,
                    aa.s_last_updated AS laupTime,
                    eb.pripid,
                    eb.uniscid,
                    eb.entname AS entname,
                    eb.regno,
                    eb.regstate,
                    eb.regstate_Cn regstateCn,
                    eb.regorg,
                    eb.lerep AS representative
                FROM
                    crgs.ex_xxzx_11_hgsxrzqymd aa
                        LEFT JOIN e_baseinfo eb ON aa.qyzwmc = eb.ENTNAME
                WHERE
                    PRIPID IS NOT NULL
                  AND qyzwmc = #{entname} UNION ALL
                SELECT
                    '5' AS punishFrom,
                    '信用风险监管处' AS lockusername,
                    aa.F000 AS punishInfoId,
                    aa.s_last_updated AS laupTime,
                    eb.pripid,
                    eb.uniscid,
                    eb.entname AS entname,
                    eb.regno,
                    eb.regstate,
                    eb.regstate_Cn regstateCn,
                    eb.regorg,
                    eb.lerep AS representative
                FROM
                    crgs.ex_xxzx_13_tjsyzsxqyh aa
                        LEFT JOIN e_baseinfo eb ON aa.xzxdrmc = eb.ENTNAME
                WHERE
                    PRIPID IS NOT NULL
                  AND xzxdrmc = #{entname} UNION ALL
                SELECT
                    '6' AS punishFrom,
                    '信用风险监管处' AS unlusername,
                    aa.F000 AS punishInfoId,
                    aa.s_last_updated AS laupTime,
                    eb.pripid,
                    eb.uniscid,
                    eb.entname AS entname,
                    eb.regno,
                    eb.regstate,
                    eb.regstate_Cn regstateCn,
                    eb.regorg,
                    eb.lerep AS representative
                FROM
                    crgs.ex_xxzx_14_scjr_zjh aa
                        LEFT JOIN e_baseinfo eb ON aa.cfdxmc = eb.ENTNAME
                WHERE
                    PRIPID IS NOT NULL
                  AND cfdxmc = #{entname} UNION ALL
                SELECT
                    '7' AS punishFrom,
                    '信用风险监管处' AS unlusername,
                    aa.F000 AS punishInfoId,
                    aa.s_last_updated AS laupTime,
                    eb.pripid,
                    eb.uniscid,
                    eb.entname AS entname,
                    eb.regno,
                    eb.regstate,
                    eb.regstate_Cn regstateCn,
                    eb.regorg,
                    eb.lerep AS representative
                FROM
                    crgs.ex_xxzx_14_2016ndcrjj aa
                        LEFT JOIN e_baseinfo eb ON aa.jyjysysxqymd = eb.ENTNAME
                WHERE
                    PRIPID IS NOT NULL
                  AND jyjysysxqymd = #{entname} UNION ALL
                SELECT
                    '8' AS punishFrom,
                    '信用风险监管处' AS unlusername,
                    aa.F000 AS punishInfoId,
                    aa.s_last_updated AS laupTime,
                    eb.pripid,
                    eb.uniscid,
                    eb.entname AS entname,
                    eb.regno,
                    eb.regstate,
                    eb.regstate_Cn regstateCn,
                    eb.regorg,
                    eb.lerep AS representative
                FROM
                    crgs.ex_xxzx_15_yzzlsxqymd aa
                        LEFT JOIN e_baseinfo eb ON aa.yzzlsxqymc = eb.ENTNAME
                WHERE
                    PRIPID IS NOT NULL
                  AND yzzlsxqymc = #{entname} UNION ALL
                SELECT
                    '9' AS punishFrom,
                    '信用风险监管处' AS unlusername,
                    aa.F000 AS punishInfoId,
                    aa.s_last_updated AS laupTime,
                    eb.pripid,
                    eb.uniscid,
                    eb.entname AS entname,
                    eb.regno,
                    eb.regstate,
                    eb.regstate_Cn regstateCn,
                    eb.regorg,
                    eb.lerep AS representative
                FROM
                    crgs.ex_xxzx_16_zdsswfajds aa
                        LEFT JOIN e_baseinfo eb ON aa.nsrmc = eb.ENTNAME
                WHERE
                    PRIPID IS NOT NULL
                  AND nsrmc = #{entname} UNION ALL
                SELECT
                    '10' AS punishFrom,
                    '信用风险监管处' AS unlusername,
                    aa.F000 AS punishInfoId,
                    aa.s_last_updated AS laupTime,
                    eb.pripid,
                    eb.uniscid,
                    eb.entname AS entname,
                    eb.regno,
                    eb.regstate,
                    eb.regstate_Cn regstateCn,
                    eb.regorg,
                    eb.lerep AS representative
                FROM
                    crgs.ex_xxzx_17_10ajnsrmd aa
                        LEFT JOIN e_baseinfo eb ON aa.nsrmc = eb.ENTNAME
                WHERE
                    PRIPID IS NOT NULL
                  AND nsrmc = #{entname} UNION ALL
                SELECT
                    '11' AS punishFrom,
                    '信用风险监管处' AS unlusername,
                    aa.F000 AS punishInfoId,
                    aa.s_last_updated AS laupTime,
                    eb.pripid,
                    eb.uniscid,
                    eb.entname AS entname,
                    eb.regno,
                    eb.regstate,
                    eb.regstate_Cn regstateCn,
                    eb.regorg,
                    eb.lerep AS representative
                FROM
                    crgs.ex_xxzx_19_dzswsxwtzx aa
                        LEFT JOIN e_baseinfo eb ON aa.qymc = eb.ENTNAME
                WHERE
                    PRIPID IS NOT NULL
                  AND qymc = #{entname} UNION ALL
                SELECT
                    '12' AS punishFrom,
                    '信用风险监管处' AS unlusername,
                    aa.F000 AS punishInfoId,
                    aa.s_last_updated AS laupTime,
                    eb.pripid,
                    eb.uniscid,
                    eb.entname AS entname,
                    eb.regno,
                    eb.regstate,
                    eb.regstate_Cn regstateCn,
                    eb.regorg,
                    eb.lerep AS representative
                FROM
                    crgs.ex_xxzx_20_sjrhmd aa
                        LEFT JOIN e_baseinfo eb ON aa.sxzt = eb.ENTNAME
                WHERE
                    PRIPID IS NOT NULL
                  AND aa.sxzt = #{entname} UNION ALL
                SELECT
                    '13' AS punishFrom,
                    '信用风险监管处' AS unlusername,
                    aa.F000 AS punishInfoId,
                    aa.s_last_updated AS laupTime,
                    eb.pripid,
                    eb.uniscid,
                    eb.entname AS entname,
                    eb.regno,
                    eb.regstate,
                    eb.regstate_Cn regstateCn,
                    eb.regorg,
                    eb.lerep AS representative
                FROM
                    crgs.ex_xxzx_21_2018tqnmggz aa
                    LEFT JOIN e_baseinfo eb ON aa.dxmc = eb.ENTNAME
                WHERE
                    PRIPID IS NOT NULL
                  AND aa.dxmc = #{entname}
            ) rs
        WHERE
            e.ENTNAME = rs.ENTNAME
        order by laupTime desc limit 1
    </select>

    <select id="querypersonlock"  resultMap="Personlock">
        SELECT
            distinct p.*
        FROM
            (
                SELECT
                    eb.entname AS entname,
                    eb.regno,
                    eb.lerep AS PERNAME
                FROM
                    crgs.ex_xxzx_09_aqschmd_aj aa

                        LEFT JOIN e_baseinfo eb ON aa.dwmc = eb.ENTNAME
                WHERE
                    eb.LEREP IS NOT NULL
                  AND eb.REGSTATE IN ( '1', '003', '003001' )
                  and eb.LEREP = #{lerep}
                  and eb.entname=#{entname} UNION ALL
                SELECT
                    eb.entname AS entname,
                    eb.regno,
                    eb.lerep AS PERNAME
                FROM
                    crgs.ex_xxzx_13_tjsyzsxqyh aa
                        LEFT JOIN e_baseinfo eb ON aa.xzxdrmc = eb.ENTNAME
                WHERE
                    eb.LEREP IS NOT NULL
                  AND eb.REGSTATE IN ( '1', '003', '003001' )
                  and eb.LEREP=#{lerep}
                  and eb.entname=#{entname} UNION ALL
                SELECT
                    eb.entname AS entname,
                    eb.regno,
                    eb.lerep AS PERNAME
                FROM
                    crgs.ex_xxzx_14_scjr_zjh aa
                        LEFT JOIN e_baseinfo eb ON aa.cfdxmc = eb.ENTNAME
                WHERE
                    eb.LEREP IS NOT NULL
                  AND eb.REGSTATE IN ( '1', '003', '003001' )
                  and eb.LEREP=#{lerep}
                  and eb.entname=#{entname} UNION ALL
                SELECT
                    eb.entname AS entname,
                    eb.regno,
                    eb.lerep AS PERNAME
                FROM
                    crgs.ex_xxzx_14_2016ndcrjj aa
                        LEFT JOIN e_baseinfo eb ON aa.jyjysysxqymd = eb.ENTNAME
                WHERE
                    eb.LEREP IS NOT NULL
                  AND eb.REGSTATE IN ( '1', '003', '003001' )
                  and eb.LEREP=#{lerep}
                  and eb.entname=#{entname} UNION ALL
                SELECT
                    eb.entname AS entname,
                    eb.regno,
                    eb.lerep AS PERNAME
                FROM
                    crgs.ex_xxzx_15_yzzlsxqymd aa
                        LEFT JOIN e_baseinfo eb ON aa.yzzlsxqymc = eb.ENTNAME
                WHERE
                    eb.LEREP IS NOT NULL
                  AND eb.REGSTATE IN ( '1', '003', '003001' )
                  and eb.LEREP=#{lerep}
                  and eb.entname=#{entname} UNION ALL
                SELECT
                    eb.entname AS entname,
                    eb.regno,
                    eb.lerep AS PERNAME
                FROM
                    crgs.ex_xxzx_16_zdsswfajds aa
                        LEFT JOIN e_baseinfo eb ON aa.nsrmc = eb.ENTNAME
                WHERE
                    eb.LEREP IS NOT NULL
                  AND eb.REGSTATE IN ( '1', '003', '003001' )
                  and eb.LEREP=#{lerep}
                  and eb.entname=#{entname} UNION ALL
                SELECT
                    eb.entname AS entname,
                    eb.regno,
                    eb.lerep AS PERNAME
                FROM
                    crgs.ex_xxzx_19_dzswsxwtzx aa
                    LEFT JOIN e_baseinfo eb ON aa.qymc = eb.ENTNAME
                WHERE
                    eb.LEREP IS NOT NULL
                  AND eb.REGSTATE IN ( '1', '003', '003001' )
                  and eb.LEREP=#{lerep}
                  and eb.entname=#{entname} UNION ALL
                SELECT
                    eb.entname AS entname,
                    eb.regno,
                    eb.lerep AS PERNAME
                FROM
                    crgs.ex_xxzx_20_sjrhmd aa
                        LEFT JOIN e_baseinfo eb ON aa.sxzt = eb.ENTNAME
                WHERE
                    eb.LEREP IS NOT NULL
                  AND eb.REGSTATE IN ( '1', '003', '003001' )
                  AND eb.LEREP = #{lerep}
                  and eb.entname=#{entname} UNION ALL
                SELECT
                    eb.entname AS entname,
                    eb.regno,
                    eb.lerep AS PERNAME
                FROM
                    crgs.ex_xxzx_21_2018tqnmggz aa
                    LEFT JOIN e_baseinfo eb ON aa.dxmc = eb.ENTNAME
                WHERE
                    eb.LEREP IS NOT NULL
                  AND eb.REGSTATE IN ( '1', '003', '003001' )
                  and eb.LEREP=#{lerep}
                  and eb.entname=#{entname}
            ) rs
                LEFT JOIN personlock p ON rs.PERNAME = p.PERNAME
    </select>

    <select id="queryByTolockentlistAndTsbizPunishLock" resultType="String">
        select pripid from tolockentlist where PRIPID = #{pripid} and punishFrom = #{punishFrom} and state != '3'
	    union all
	    select pripid from tsbizpunishlock t where pripid = #{pripid} and punishFrom = #{punishFrom} and status in ('9','1')
    </select>

    <select id="queryByPripid" parameterType="String" resultMap="BaseResultMap">
        select * from tolockentlist t
        where pripid = #{pripid}
    </select>

    <delete id="deleteTolockentlistByPripid" parameterType="String">
        delete from tolockentlist where pripid=#{pripid}
    </delete>

    <select id="queryEntLock" resultType="String">
        select e.PRIPID from  entlock e
     	where (select count(1) as num from tolockentlist t where e.PRIPID = t.pripid ) = 0
     	union all
     	select  e.PRIPID from entlock e left join tolockentlist t on e.PRIPID = t.pripid
     	where e.state='0' and t.state = '1'
    </select>

    <update id="updateEntLock" parameterType="java.util.List">
        update entlock set state = '1' where PRIPID in
        <foreach collection="list" open="(" close=")" item="each" separator=",">
            #{each}
        </foreach>
    </update>

    <select id="queryEntDto" resultMap="EntDto">
        select e.elid, eb.regstate from entlock e join e_baseinfo eb on e.PRIPID = eb.PRIPID
        where e.state = '0' and eb.REGSTATE != '1'
    </select>

    <select id="queryAllEntFromPF" resultMap="EntLock">
        select ent.elid from (
        select e.* from  entlock e
        where (select count(1) as num from (
        select '1' as pf, dwmc as entname from crgs.ex_xxzx_09_aqschmd_aj
        union all
        select '2' as pf, qyzwmc as entname from crgs.ex_xxzx_10_hggjrzqymd
        union all
        select '3' as pf, qyzwmc as entname from crgs.ex_xxzx_11_hgsxrzqymd
        union all
        select '4' as pf, xm as entname from crgs.ex_xxzx_12_2017ndypyz
        union all
        select '5' as pf, xzxdrmc as entname from crgs.ex_xxzx_13_tjsyzsxqyh
        union all
        select '6' as pf, cfdxmc as entname from crgs.ex_xxzx_14_scjr_zjh
        union all
        select '7' as pf, jyjysysxqymd as entname from crgs.ex_xxzx_14_2016ndcrjj
        union all
        select '8' as pf, yzzlsxqymc as entname from crgs.ex_xxzx_15_yzzlsxqymd
        union all
        select '9' as pf, nsrmc as entname from crgs.ex_xxzx_16_zdsswfajds
        union all
        select '10' as pf, nsrmc as entname from crgs.ex_xxzx_17_10ajnsrmd
        union all
        select '11' as pf, qymc as entname from crgs.ex_xxzx_19_dzswsxwtzx
        union all
        select '12' as pf, sxzt as entname from crgs.ex_xxzx_20_sjrhmd
        union all
        select '13' as pf, dxmc as entname from crgs.ex_xxzx_21_2018tqnmggz
        ) rs where rs.entname = e.entname and rs.pf = e.punishFrom ) = 0
        ) ent where ent.state = '0'
    </select>

    <select id="queryRegState" resultMap="TRBaseCode">
        select * from trbasecode where codeid = 'CA19'
    </select>

    <select id="checkEntLock" resultType="int">
        select count(*) from ${tableName}
	    where 1=1
        <choose>
            <when test="tableName eq 'crgs.ex_xxzx_09_aqschmd_aj'">
                and dwmc = #{entName}
            </when>
            <when test="tableName eq 'crgs.ex_xxzx_10_hggjrzqymd'">
                and qyzwmc = #{entName}
            </when>
            <when test="tableName eq 'crgs.ex_xxzx_11_hgsxrzqymd'">
                and qyzwmc = #{entName}
            </when>
            <when test="tableName eq 'crgs.ex_xxzx_12_2017ndypyz'">
                and xm = #{entName}
            </when>
            <when test="tableName eq 'crgs.ex_xxzx_13_tjsyzsxqyh'">
                and xzxdrmc = #{entName}
            </when>
            <when test="tableName eq 'crgs.ex_xxzx_14_scjr_zjh'">
                and cfdxmc = #{entName}
            </when>
            <when test="tableName eq 'crgs.ex_xxzx_14_2016ndcrjj'">
                and jyjysysxqymd = #{entName}
            </when>
            <when test="tableName eq 'crgs.ex_xxzx_15_yzzlsxqymd'">
                and yzzlsxqymc = #{entName}
            </when>
            <when test="tableName eq 'crgs.ex_xxzx_16_zdsswfajds'">
                and nsrmc = #{entName}
            </when>
            <when test="tableName eq 'crgs.ex_xxzx_17_10ajnsrmd'">
                and nsrmc = #{entName}
            </when>
            <when test="tableName eq 'crgs.ex_xxzx_19_dzswsxwtzx'">
                and qymc = #{entName}
            </when>
            <when test="tableName eq 'crgs.ex_xxzx_20_sjrhmd'">
                and sxzt = #{entName}
            </when>
            <when test="tableName eq 'crgs.ex_xxzx_21_2018tqnmggz'">
                and dxmc = #{entName}
            </when>
        </choose>
    </select>



</mapper>