<?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.force.mapper.XrForceDeregisterSpeMapper">
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.force.entity.XrForceDeregisterSpe">
        <result column="forcespeid" property="forceSpeId"/>
        <result column="forceresid" property="forceResId"/>
        <result column="forceid" property="forceId"/>
        <result column="pripid" property="pripId"/>
        <result column="entname" property="entName"/>
        <result column="unisc_id" property="uniscId"/>
        <result column="regno" property="regno"/>
        <result column="reg_org" property="regOrg"/>
        <result column="reg_org_cn" property="regOrgCn"/>
        <result column="notice_title" property="noticeTitle"/>
        <result column="notice_content" property="noticeContent"/>
        <result column="status" property="status"/>
        <result column="biz_seq_no" property="bizSeqNo"/>
        <result column="judauth" property="judauth"/>
        <result column="judauth_cn" property="judauthCn"/>
        <result column="notice_from" property="noticeFrom"/>
        <result column="notice_to" property="noticeTo"/>
        <result column="forcerra" property="forceRra"/>
        <result column="forcerra_date" property="forceRraDate"/>
        <result column="forceregopi" property="forceRegopi"/>
        <result column="forceres" property="forceRes"/>
        <result column="forceres_date" property="forceResDate"/>
        <result column="apply_time" property="applyTime"/>
        <result column="force_type" property="forceType"/>
        <result column="forcerra_cn" property="forceRraCn"/>
        <result column="decision_content" property="decisionContent"/>
        <result column="force_notice_content" property="forceNoticeContent"/>
        <result column="accept_org" property="acceptOrg"/>
    </resultMap>

    <select id="selectXrForceDeregisterSpeTodo" resultType="com.chinaweal.aiccs.aiccs.force.entity.vo.XrForceDeregisterSpeVo">
        select distinct
        task.biz_seq_no as bizSeqNo,
        biz.forcerra as forceRra,
        biz.status as status,
        biz.notice_from as noticeFrom,
        biz.notice_to as noticeTo,
        DATE_FORMAT(biz.apply_time, '%Y-%m-%d') as applyTime,
        biz.force_type as forceType,
        task.accept_no as acceptNo,
        task.bus_name as busName,
        task.bus_status as busStatus,
        activity.link_type as linkType,
        activity.link_name as linkName
        from xr_task_list task
        inner join xr_force_deregister_spe biz on task.biz_seq_no = biz.biz_seq_no
        inner join xr_activity activity on task.task_like_id = activity.task_id
        <where>
            activity.link_status = '1'
            and biz.status != '5'
            <if test="param.authList.size > 0">
                and activity.ident in
                <foreach collection="param.authList" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="param.forceType != null and param.forceType != ''">
                and biz.force_type = #{param.forceType}
            </if>
            <if test="param.busStatus != null and param.busStatus != ''">
                and task.bus_status = #{param.busStatus}
            </if>
            <if test="param.searchUscc != null and param.searchUscc != ''">
                and (biz.unisc_id = #{param.searchUscc} or biz.regno = #{param.searchUscc})
            </if>
            <if test="param.entName != null and param.entName != ''">
                and biz.entname like concat('%', #{param.entName}, '%')
            </if>
            <if test="param.forceRra != null and param.forceRra != ''">
                and biz.forcerra = #{param.forceRra}
            </if>
            <if test="param.status != null and param.status != ''">
                and biz.status = #{param.status}
            </if>
        </where>
        order by applyTime desc
    </select>

    <select id="selectXrForceDeregisterSpeHistory" resultType="com.chinaweal.aiccs.aiccs.force.entity.vo.XrForceDeregisterSpeVo">
        select
        biz.forcespeid as forceSpeId,
        biz.biz_seq_no as bizSeqNo,
        biz.pripid as pripId,
        biz.entname as entName,
        biz.unisc_id as uniscId,
        biz.regno as regno,
        biz.reg_org as regOrg,
        biz.reg_org_cn as regorgCn,
        biz.forcerra as forceRra,
        biz.forcerra_date as forceRraDate,
        biz.status as status,
        biz.notice_from as noticeFrom,
        biz.notice_to as noticeTo,
        biz.apply_time as applyTime,
        biz.judauth as judauth,
        biz.judauth_cn as judauthCn,
        biz.forceres as forceRes,
        biz.forceres_date as forceResDate,
        biz.force_type as forceType
        from xr_force_deregister_spe biz
        <where>
            1=1
            <if test="param.forceType != null and param.forceType != ''">
                and biz.force_type = #{param.forceType}
            </if>
            <if test="param.searchUscc != null and param.searchUscc != ''">
                and (biz.unisc_id = #{param.searchUscc} or biz.regno = #{param.searchUscc})
            </if>
            <if test="param.entName != null and param.entName != ''">
                and biz.entname like concat('%', #{param.entName}, '%')
            </if>
            <if test="param.forceRra != null and param.forceRra != ''">
                and biz.forcerra = #{param.forceRra}
            </if>
            <if test="param.regOrg != null and param.regOrg != ''">
                and biz.reg_org like #{param.regOrg}
            </if>
            <if test="param.judauth != null and param.judauth != ''">
                and biz.judauth like #{param.judauth}
            </if>
            <if test="param.status != null and param.status != ''">
                and biz.status = #{param.status}
            </if>
            <if test="param.status == null or param.status == ''">
                and biz.status != '5'
            </if>
        </where>
        order by biz.apply_time desc
    </select>

    <select id="xrForceDeregisterPageByRegOrg" resultType="com.chinaweal.aiccs.aiccs.force.entity.XrForceDeregisterSpe">
        select distinct
        biz.forceid as forceId,
        biz.notice_title as noticeTitle,
        biz.notice_content as noticeContent,
        biz.forcerra as forceRra,
        biz.notice_from as noticeFrom,
        biz.notice_to as noticeTo,
        biz.force_type as forceType,
        biz.forceres as forceRes
        from xr_force_deregister_spe biz
        <where>
            <if test="param.forceRes != null and param.forceRes != ''">
                and biz.forceres = #{param.forceRes}
            </if>
            <if test="param.forceResList != null and param.forceResList.size() > 0">
                and biz.forceres in
                <foreach collection="param.forceResList" item="res" open="(" separator="," close=")">
                    #{res}
                </foreach>
            </if>
            <if test="param.regOrg != null and param.regOrg != ''">
                and biz.reg_org = #{param.regOrg}
            </if>
            <if test="param.searchUscc != null and param.searchUscc != ''">
                and (biz.unisc_id = #{param.searchUscc} or biz.regno = #{param.searchUscc})
            </if>
            <if test="param.entName != null and param.entName != ''">
                and biz.entname like concat('%', #{param.entName}, '%')
            </if>
            <if test="param.forceRra != null and param.forceRra != ''">
                and biz.forcerra = #{param.forceRra}
            </if>
            <if test="param.status != null and param.status != ''">
                and biz.status = #{param.status}
            </if>
            <if test="param.status == null or param.status == ''">
                and biz.status != '5'
            </if>
            <if test="param.soon != null and param.soon != ''">
                and timestampdiff(DAY, curdate(), biz.notice_to) &lt;= 10
            </if>
        </where>
        order by notice_to
    </select>

    <select id="baseinfoListByRegOrg" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo">
        select
        b.PRIPID as pripid,
        b.UNISCID as uniscid,
        b.REGNO as regno,
        b.ENTNAME as entname,
        b.ENTTYPE as enttype,
        b.ENTTYPE_CN as enttypeCn,
        b.INDUSTRYPHY as industryphy,
        b.INDUSTRYCO as industryco,
        b.ESTDATE as estdate,
        b.REGORG as regorg,
        b.REGORG_CN as regorgCn,
        b.OPSCOTYPE as opscotype,
        b.OPSCOTYPE_CN as opscotypeCn,
        b.OPSCOPE as opscope,
        b.OPFROM as opfrom,
        b.OPTO as opto,
        b.REGSTATE as regstate,
        b.REGSTATE_CN as regstateCn,
        b.DOMDISTRICT as domdistrict,
        b.DOM as dom,
        b.REGCAP as regcap,
        b.REGCAPCUR as regcapcur,
        b.REGCAPCUR_CN as regcapcurCn,
        b.REGCAPUSD as regcapusd,
        b.RECCAP as reccap,
        b.RECCAPUSD as reccapusd,
        b.COUNTRY as country,
        b.EMPNUM as empnum,
        b.TOWN as town,
        b.NAME as name,
        b.REPORTTYPE as reporttype,
        b.APPRDATE as apprdate,
        b.S_EXT_FROMNODE as sExtFromnode,
        b.s_Ext_Datatime as sExtDatatime,
        b.regulatory as regulatory,
        b.regulatory_name_temp as regulatoryNameTemp,
        b.open_from as openFrom,
        b.open_to as openTo,
        b.score as score,
        b.level as level,
        b.update_by as updateBy,
        b.update_time as updateTime,
        b.create_by as createBy,
        b.create_time as createTime,
        b.label as label,
        b.branch as branch,
        b.investment as investment,
        b.traname as traname,
        b.fundam as fundam,
        b.compform as compform,
        b.compform_Cn as compformCn,
        b.localadm as localadm,
        b.oplocdistrict as oplocdistrict,
        b.oploc as oploc,
        b.tel as tel,
        b.postalcode as postalcode,
        b.region as region,
        b.street_long as streetLong,
        b.street_name as streetName,
        b.ENTSTATUS as entStatus,
        b.SAREACODE_JX as sareacodeJx,
        b.SAREANAME_JX as sareanameJx,
        b.SAREACODE_JXMX as sareacodeJxmx,
        b.SAREANAME_JXMX as sareanameJxmx,
        b.ACCEPTREGORG as acceptRegorg,
        b.ACCEPTREGORG_CN as acceptregorgCn,
        b.LEREP as lerep,
        b.CERTYPE as certype,
        b.CERNO as cerno,
        b.SUPORG as suporg,
        b.SUPORG_CN as suporgCn,
        b.sareacode_temp as sareacodeTemp,
        b.sareaname_temp as sareanameTemp,
        b.regulatory_temp as regulatoryTemp,
        b.assign_id as assignId,
        r.REVDATE as revDate
        from e_baseinfo b
        left join E_REVOKE r on b.PRIPID = r.PRIPID
        <where>
            <if test="param.regOrg != null and param.regOrg != ''">
                and b.REGORG = #{param.regOrg}
            </if>
            and b.REGSTATE != '4'
            and (
                b.ENTTYPE like '1%'
                or b.ENTTYPE like '2%'
                or b.ENTTYPE like '5%'
                or b.ENTTYPE like '6%'
            )
            <if test="param.entName != null and param.entName != ''">
                and b.ENTNAME like concat('%', #{param.entName}, '%')
            </if>
            <if test="param.searchUscc != null and param.searchUscc != ''">
                and (b.UNISCID = #{param.searchUscc} or b.REGNO = #{param.searchUscc})
            </if>
            <if test="param.industryphy != null and param.industryphy != ''">
                and b.INDUSTRYPHY = #{param.industryphy}
            </if>
            <if test="param.revStartDate != null and param.revEndDate != null">
                and b.REGSTATE = '2'
                and r.REVDATE &gt;= #{param.revStartDate}
                and r.REVDATE &lt;= #{param.revEndDate}
            </if>
            <if test="param.acceptRegorg != null and param.acceptRegorg != ''">
                and b.ACCEPTREGORG = #{param.acceptRegorg}
            </if>
        </where>
        order by b.APPRDATE desc
    </select>

    <!-- 更新公告期满的拟强制注销企业状态 -->
    <update id="updateForceDeregisterNoticeExpired">
        UPDATE xr_force_deregister_spe
        SET forceres = '2',
            forceres_date = CURDATE()
        WHERE force_type = '1'
          AND forceres = '1'
          AND notice_to &lt;= CURDATE()
          AND status != '5'
    </update>

</mapper>
