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

    <resultMap type="cn.iocoder.yudao.module.knowledge.entity.TBidConfirmation" id="tBidConfirmationMap">
        <result property="id" column="id"/>
        <result property="tag" column="tag"/>
        <result property="companyName" column="company_name"/>
        <result property="title" column="title"/>
        <result property="bigCode" column="big_code"/>
        <result property="projectName" column="project_name"/>
        <result property="tenderee" column="tenderee"/>
        <result property="letterDateYear" column="letter_date_year"/>
        <result property="letterDateMonth" column="letter_date_month"/>
        <result property="winBidTime" column="win_bid_time"/>
        <result property="letterDateDay" column="letter_date_day"/>
        <result property="winBidDes" column="win_bid_des"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="deptId" column="dept_id"/>
        <result property="identityId" column="identity_id"/>
        <result property="deleted" column="deleted"/>
    </resultMap>

    <select id="pageAllTag" resultType="cn.iocoder.yudao.module.knowledge.controller.requestdto.BidManagementRequest">
        SELECT
            *
        FROM
            (
                (
                    SELECT
                        tbc.id AS id,
                        tbc.tag AS tag,
                        tbc.title AS title,
                        tbc.create_time AS createTime,
                        tbc.file_size AS fileSize,
                        tbc.file_name AS fileName,
                        tbc.file_url AS fileUrl
                    FROM
                        t_bid_confirmation tbc
                            LEFT JOIN t_fileinfo tfi ON tfi.bind_id = tbc.id AND tfi.deleted = 0
                    WHERE
                        tbc.deleted = 0
                ) UNION ALL
                (
                    SELECT
                        tbp.id AS id,
                        tbp.tag AS tag,
                        tbp.project_name AS title,
                        tbp.create_time AS createTime,
                        tbp.file_size AS fileSize,
                        tbp.file_name AS fileName,
                        tbp.file_url AS fileUrl
                    FROM
                        t_bid_plan tbp
                            LEFT JOIN t_fileinfo tfi ON tfi.bind_id = tbp.id AND tfi.deleted = 0
                    WHERE
                        tbp.deleted = 0
                )
            ) AS t
        <where>
            <if test="dto.title != '' and dto.title != null">
                AND t.title LIKE CONCAT( '%',#{dto.title}, '%')
            </if>
            <if test="dto.tag != '' and dto.tag != null">
                AND t.tag = #{dto.tag}
            </if>
            <if test="dto.createTime != null">
                AND DATE(t.createTime) = #{dto.createTime}
            </if>
        </where>
        ORDER BY
            t.createTime DESC
    </select>

    <select id="appPage" resultType="cn.iocoder.yudao.module.knowledge.controller.requestdto.BidManagementRequest">
        SELECT
        *
        FROM
        (
        (
        SELECT
        tbc.id AS id,
        tbc.tag AS tag,
        tbc.title AS title,
        tbc.create_time AS createTime,
        tbc.file_size AS fileSize,
        tbc.file_name AS fileName,
        tbc.file_url AS fileUrl
        FROM
        t_bid_confirmation tbc
        LEFT JOIN t_fileinfo tfi ON tfi.bind_id = tbc.id AND tfi.deleted = 0
        WHERE
        tbc.deleted = 0
        ) UNION ALL
        (
        SELECT
        tbp.id AS id,
        tbp.tag AS tag,
        tbp.project_name AS title,
        tbp.create_time AS createTime,
        tbp.file_size AS fileSize,
        tbp.file_name AS fileName,
        tbp.file_url AS fileUrl
        FROM
        t_bid_plan tbp
        LEFT JOIN t_fileinfo tfi ON tfi.bind_id = tbp.id AND tfi.deleted = 0
        WHERE
        tbp.deleted = 0
        )
        ) AS t
        <where>
            <if test="dto.title != '' and dto.title != null">
                AND t.title LIKE CONCAT( '%',#{dto.title}, '%')
            </if>
            <if test="dto.tag != '' and dto.tag != null">
                AND t.tag = #{dto.tag}
            </if>
            <if test="dto.createTime != null">
                AND DATE(t.createTime) = #{dto.createTime}
            </if>
        </where>
        ORDER BY
        t.createTime DESC
    </select>

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

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



</mapper>
