<?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.QgCasePubNbaseinfoMapper">

    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.punishment.entity.QgCasePubNbaseinfo">
        <id column="CASEID" property="caseid" />
        <result column="ACTYPE" property="actype" />
        <result column="PRIPID" property="pripid" />
        <result column="ENTNAME" property="entname" />
        <result column="UNISCID" property="uniscid" />
        <result column="REGNO" property="regno" />
        <result column="INSCERCODE" property="inscercode" />
        <result column="SOCORGCODE" property="socorgcode" />
        <result column="ORGCODE" property="orgcode" />
        <result column="TAXID" property="taxid" />
        <result column="LEREP" property="lerep" />
        <result column="CERTYPE" property="certype" />
        <result column="CERNO" property="cerNo" />
        <result column="NAME" property="name" />
        <result column="AC_CERTYPE" property="acCertype" />
        <result column="AC_CERNO" property="acCerNo" />
        <result column="PENDECNO" property="penDecNo" />
        <result column="ILLEGACTTYPECODE" property="illegActTypeCode" />
        <result column="ILLEGACTTYPE" property="illegActType" />
        <result column="MAINILLEGFACT" property="mainIllegFact" />
        <result column="PENBASIS" property="penBasis" />
        <result column="PENBASIS_CN" property="penBasisCn" />
        <result column="PENTYPE" property="penType" />
        <result column="PENTYPE_CN" property="penTypeCn" />
        <result column="PENAM" property="penam" />
        <result column="FORFAM" property="forfam" />
        <result column="PENDECISSDATE" property="penDecissDate" />
        <result column="PENPERI" property="penPeri" />
        <result column="PENAUTH" property="penAuth" />
        <result column="PENAUTH_CN" property="penAuthCn" />
        <result column="PENAUTHUNISCID" property="penAuthUniscid" />
        <result column="PENCONTENT" property="penContent" />
        <result column="REVLICNUM" property="revLicNum" />
        <result column="PUBLICDATE" property="publicDate" />
        <result column="PUBDEADLINE" property="pubDeadline" />
        <result column="DATADEPT" property="dataDept" />
        <result column="DATADEPTUNISCID" property="dataDeptUniscid" />
        <result column="REMARK" property="remark" />
        <result column="OPFLAG" property="opflag" />
        <result column="S_EXT_DATETIME" property="sExtDatetime" />
        <result column="LASTUPDATETIME" property="lastUpdateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        CASEID, ACTYPE, PRIPID, ENTNAME, UNISCID, REGNO, INSCERCODE, SOCORGCODE, ORGCODE, TAXID,
        LEREP, CERTYPE, CERNO, NAME, AC_CERTYPE, AC_CERNO, PENDECNO, ILLEGACTTYPECODE, ILLEGACTTYPE,
        MAINILLEGFACT, PENBASIS, PENBASIS_CN, PENTYPE, PENTYPE_CN, PENAM, FORFAM, PENDECISSDATE,
        PENPERI, PENAUTH, PENAUTH_CN, PENAUTHUNISCID, PENCONTENT, REVLICNUM, PUBLICDATE, PUBDEADLINE,
        DATADEPT, DATADEPTUNISCID, REMARK, OPFLAG, S_EXT_DATETIME, LASTUPDATETIME
    </sql>

    <!-- 分页查询跨省行政处罚信息 -->
    <select id="searchByPage" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List" />
        FROM QG_CASE_PUB_NBASEINFO
        WHERE ACTYPE = '1'
        <if test="params.uniscid != null and params.uniscid != ''">
            AND (UNISCID = #{params.uniscid} OR REGNO = #{params.uniscid})
        </if>
        <if test="params.entname != null and params.entname != ''">
            AND ENTNAME LIKE '%' || #{params.entname} || '%'
        </if>
        <if test="params.penAuthCn != null and params.penAuthCn != ''">
            AND PENAUTH_CN = #{params.penAuthCn}
        </if>
        <if test="params.penDecNo != null and params.penDecNo != ''">
            AND PENDECNO = #{params.penDecNo}
        </if>
        <!-- 只查询未修复的数据 -->
        <if test="params.excludeRepaired != null and params.excludeRepaired == true">
            AND (OPFLAG IS NULL OR OPFLAG != 'D')
        </if>
    </select>

    <!-- 根据ID查询 -->
    <select id="findById" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List" />
        FROM QG_CASE_PUB_NBASEINFO
        WHERE CASEID = #{caseid}
    </select>

    <!-- 更新修复状态 -->
    <update id="updateForRepair">
        UPDATE QG_CASE_PUB_NBASEINFO
        SET OPFLAG = 'D',
            PUBDEADLINE = #{approvalDate},
            S_EXT_DATETIME = #{now}
        WHERE CASEID = #{caseid}
    </update>

    <insert id="insertQgCasePubNbaseinfoData">
        INSERT INTO QG_CASE_PUB_NBASEINFO_DATA (
            CASEID, ACTYPE, PRIPID, ENTNAME, UNISCID, REGNO, INSCERCODE, SOCORGCODE, ORGCODE, TAXID,
            LEREP, CERTYPE, CERNO, NAME, AC_CERTYPE, AC_CERNO, PENDECNO, ILLEGACTTYPECODE, ILLEGACTTYPE,
            MAINILLEGFACT, PENBASIS, PENBASIS_CN, PENTYPE, PENTYPE_CN, PENAM, FORFAM, PENDECISSDATE,
            PENPERI, PENAUTH, PENAUTH_CN, PENAUTHUNISCID, PENCONTENT, REVLICNUM, PUBLICDATE, PUBDEADLINE,
            DATADEPT, DATADEPTUNISCID, REMARK, OPFLAG, S_EXT_DATETIME, LASTUPDATETIME
        )
        SELECT
            CASEID, ACTYPE, PRIPID, ENTNAME, UNISCID, REGNO, INSCERCODE, SOCORGCODE, ORGCODE, TAXID,
            LEREP, CERTYPE, CERNO, NAME, AC_CERTYPE, AC_CERNO, PENDECNO, ILLEGACTTYPECODE, ILLEGACTTYPE,
            MAINILLEGFACT, PENBASIS, PENBASIS_CN, PENTYPE, PENTYPE_CN, PENAM, FORFAM, PENDECISSDATE,
            PENPERI, PENAUTH, PENAUTH_CN, PENAUTHUNISCID, PENCONTENT, REVLICNUM, PUBLICDATE, SYSDATE(),
            DATADEPT, DATADEPTUNISCID, REMARK, 'D', SYSDATE(), LASTUPDATETIME
        FROM QG_CASE_PUB_NBASEINFO
        WHERE CASEID = #{caseid}
    </insert>

</mapper>
