<?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.ruoyi.wgz.mapper.WgzMessageMapper">

    <resultMap type="com.ruoyi.wgz.domain.WgzMessage" id="WgzMessageResult">
        <result property="id" column="id"/>
        <result property="senderType" column="sender_type"/>
        <result property="senderId" column="sender_id"/>
        <result property="recipientType" column="recipient_type"/>
        <result property="recipientId" column="recipient_id"/>
        <result property="headline" column="headline"/>
        <result property="subheading" column="subheading"/>
        <result property="tableId" column="table_id"/>
        <result property="tableName" column="table_name"/>
        <result property="messageLargeType" column="message_large_type"/>
        <result property="messageSmallType" column="message_small_type"/>
        <result property="readStatus" column="read_status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <!-- 消息类型统计(先分组再统计) -->
    <select id="userGetMessageList" resultType="com.ruoyi.wgz.bo.res.WgzAppGetMessageListRes">
        SELECT
            a.id,
            a.headline,
            a.subheading,
            a.table_id as tableId,
            a.table_name as tableName,
            a.read_status as readStatus,
            a.create_time as createTime
            <if test="page.largeType == '1'">
                ,c.recruit_name as recruitName
               ,c.id as recruitId
            </if>
            <if test="page.largeType == '2'">
                ,d.id as jsId
                ,d.recruit_name as jsName
            </if>
            <if test="page.largeType == '3' and page.smallType == '0'">
                ,e.id as otherId
                ,e.now_time as otherFillingTime
                ,e.reason as otherReason
                ,f.username as otherApplicant
                ,e.create_time as otherApplicationDate
            </if>
        FROM
            wgz_message as a
            <if test="page.largeType == '1'">
                LEFT JOIN bgt_project_recruit_apply as b ON b.id = a.table_id
                LEFT JOIN bgt_project_recruit as c ON c.id = b.recruit_id
            </if>
            <if test="page.largeType == '2'">
                LEFT JOIN wgz_pay_calculation as d ON d.id = a.table_id
            </if>
            <if test="page.largeType == '3' and page.smallType == '0'">
                LEFT JOIN wgz_reissueacard as e ON e.id = a.table_id
                LEFT JOIN wgz_user as f ON f.id = e.user_id
            </if>
        <where>
            a.recipient_type = "1" AND
            a.recipient_id = #{page.recipientId} AND
            a.del_flag = "0"
            <if test="page.largeType == '1'">
                AND b.del_flag = "0"
                AND c.del_flag = "0"
            </if>
            <if test="page.largeType == '2'">
                AND d.del_flag = "0"
            </if>
            <if test="page.largeType == '3' and page.smallType == '0'">
                AND e.del_flag = "0"
                AND f.del_flag = "0"
            </if>
            <if test="page.largeType == '3' and page.smallType == '1'">
                AND a.sender_type = "0"
            </if>
        </where>
    </select>


    <select id="findByRecruitIdData" resultType="com.ruoyi.wgz.bo.res.WgzAppRegistrationInformationRes">
        SELECT
            a.id as recruitApplyId,
            a.entry_time as entryTime,
            b.id as recruitId,
            b.create_time as createTime,
            b.recruit_name as recruitName,
            b.recruit_amount as recruitAmount,
            b.recruit_staff_num as recruitStaffNum,
            b.sub_describe as subDescribe,
            b.recruit_work_begin_time as recruitWorkBeginTime,
            b.recruit_contact_person as recruitContactPerson,
            b.recruit_contact_phone as recruitContactPhone,
            b.remark,
            c.task_name as taskName,
            c.task_address as taskAddress,
            c.task_img as taskImg
        FROM
            bgt_project_recruit_apply as a
                LEFT JOIN bgt_project_recruit as b on(a.recruit_id = b.id and b.del_flag = 0 )
                LEFT JOIN fbs_project_task as c ON (b.task_id = c.id AND c.del_flag = 0)
        WHERE
            a.id = #{recruitId} AND
            a.del_flag = 0
    </select>

</mapper>
