<?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="cn.iocoder.yudao.module.knowledge.mapper.TLawsMapper">
    <resultMap id="BaseResultMap" type="cn.iocoder.yudao.module.knowledge.entity.TLaws">
        <id column="ID" property="id" jdbcType="BIGINT"/>
        <result column="CODE" property="code" jdbcType="VARCHAR"/>
        <result column="NAME" property="name" jdbcType="VARCHAR"/>
        <result column="VERSION" property="version" jdbcType="VARCHAR"/>
        <result column="FILE_URL" property="fileUrl" jdbcType="VARCHAR"/>
        <result column="FILE_SIZE" property="fileSize" jdbcType="VARCHAR"/>
        <result column="FILE_NAME" property="fileName" jdbcType="VARCHAR"/>
        <result column="FILE_TIME" property="filingTime" jdbcType="DATE"/>
        <result column="IS_FILING" property="isFiling" jdbcType="INTEGER"/>
        <result column="DELETED" property="deleted" jdbcType="INTEGER"/>
        <result column="CREATOR" property="creator" jdbcType="VARCHAR"/>
        <result column="CREATOR_ID" property="creatorId" jdbcType="BIGINT"/>
        <result column="CREATE_TIME" property="createTime" jdbcType="DATE"/>
        <result column="UPDATE_TIME" property="updateTime" jdbcType="DATE"/>

    </resultMap>
<sql id="column">
    id,CODE,NAME,version,file_url,file_size,file_name,filing_time,is_filing,deleted,laws_a,laws_b,creator,creator_id,create_time,update_time,dept_id,identity_id,describe_info,type,tenant_id
</sql>
    <update id="updateByLawId">
        UPDATE t_laws
        SET
            code = #{dto.code},
            version = #{dto.version},
            file_url = #{dto.fileUrl},
            file_size = #{dto.fileSize},
            file_name = #{dto.fileName},
            describe_info = #{dto.describeInfo}

        WHERE
            id = #{dto.id}
    </update>

    <update id="deleteByIds">
        UPDATE t_laws
        SET
            deleted = 0
        WHERE id = #{id}
    </update>

    <update id="filling">
        UPDATE t_laws
        SET
            is_filing = '1'
        WHERE id = #{id}
    </update>

    <select id="judgeIsFilling" resultType="int">
        SELECT COUNT(1)
           is_filing
        FROM
            t_laws
        WHERE
            is_filing = '1'
          AND
            id = #{id}
          AND
            deleted = 0
    </select>


    <select id="getListPage" resultType="cn.iocoder.yudao.module.knowledge.entity.TLaws">
        SELECT
           <include refid="column"></include>
        FROM
            t_laws
        WHERE
            deleted = 0 AND is_filing!=1
            <if test="dto.name != '' and dto.name != null">
                AND `name` LIKE CONCAT( '%',#{dto.name}, '%')
            </if>
        <if test=" dto.createTime != null">
            AND create_time >= #{dto.createTime}
            AND DATE(create_time) = #{dto.createTime}
        </if>
        ORDER BY create_time DESC
    </select>

    <select id="selectForApp" resultType="cn.iocoder.yudao.module.knowledge.entity.TLaws">
        SELECT
        <include refid="column"></include>
        FROM
        t_laws
        WHERE
        deleted = 0 AND is_filing!=1
        <if test="dto.name != '' and dto.name != null">
            AND `name` LIKE CONCAT( '%',#{dto.name}, '%')
        </if>
        <if test=" dto.createTime != null">
            AND create_time >= #{dto.createTime}
            AND DATE(create_time) = #{dto.createTime}
        </if>
        ORDER BY create_time DESC
    </select>


    <select id="findAllDocuments" resultType="cn.iocoder.yudao.module.knowledge.entity.TLaws">
        SELECT * from
        (select
        id AS id,
        NAME AS NAME,
        file_url AS fileUrl,
        file_name AS fileName,
        creator AS creator,
        create_time AS createTime
        FROM
        t_laws
        WHERE
        deleted = 0
        AND is_filing != 1 UNION
        SELECT
        id AS id,
        NAME AS NAME,
        file_url AS fileUrl,
        file_name AS fileName,
        creator AS creator,
        create_time AS createTime
        FROM
        t_regulatory_framework
        WHERE
        deleted = 0
        AND is_filing != 1 UNION
        SELECT
        id AS id,
        cn_name AS NAME,
        url AS fileUrl,
        file_name AS fileName,
        creator AS creator,
        create_time AS createTime
        FROM
        t_operation_document
        WHERE
        deleted = 0) doc
        <where>
            <if test="dto.name != '' and dto.name != null">
                AND doc.NAME LIKE CONCAT( '%',#{dto.name}, '%')
            </if>
        </where>
        order by createTime desc
    </select>


</mapper>

