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

    <resultMap type="com.ruoyi.wgz.domain.WgzPayCalculation" id="WgzPayCalculationResult">
        <result property="id" column="id"/>
        <result property="taskId" column="task_id"/>
        <result property="recruitId" column="recruit_id"/>
        <result property="userId" column="user_id"/>
        <result property="taskName" column="task_name"/>
        <result property="taskAddress" column="task_address"/>
        <result property="recruitName" column="recruit_name"/>
        <result property="userName" column="user_name"/>
        <result property="entryTime" column="entry_time"/>
        <result property="recruitAmount" column="recruit_amount"/>
        <result property="num" column="num"/>
        <result property="workingState" column="working_state"/>
        <result property="phone" column="phone"/>
        <result property="bank" column="bank"/>
        <result property="cardNo" column="card_no"/>
        <result property="auditorUserId" column="auditor_user_id"/>
        <result property="auditorType" column="auditor_type"/>
        <result property="auditorOpinion" column="auditor_opinion"/>
        <result property="auditorTime" column="auditor_time"/>
        <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>


    <!-- 定义 resultMap 用于映射主表数据 -->
    <resultMap id="WgzAppApplyForPayrollSettlementListResResultMap" type="com.ruoyi.wgz.bo.res.WgzAppApplyForPayrollSettlementListRes">
        <id property="id" column="id"/>
        <result property="taskId" column="task_id"/>
        <result property="recruitId" column="recruit_id"/>
        <result property="userId" column="user_id"/>
        <result property="taskName" column="task_name"/>
        <result property="taskAddress" column="task_address"/>
        <result property="recruitName" column="recruit_name"/>
        <result property="userName" column="user_name"/>
        <result property="entryTime" column="entry_time"/>
        <result property="recruitAmount" column="recruit_amount"/>
        <result property="num" column="num"/>
        <result property="workingState" column="working_state"/>
        <result property="phone" column="phone"/>
        <result property="bank" column="bank"/>
        <result property="cardNo" column="card_no"/>
        <result property="auditorUserId" column="auditor_user_id"/>
        <result property="auditorType" column="auditor_type"/>
        <result property="auditorOpinion" column="auditor_opinion"/>
        <result property="auditorTime" column="auditor_time"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="remark" column="remark"/>

        <!-- 定义 collection 用于映射关联的从表数据 -->
        <collection property="payCalculation" ofType="com.ruoyi.wgz.domain.WgzPayCalculationFiles">
            <id property="id" column="file_id"/>
            <result property="calculationId" column="calculation_id"/>
            <result property="typeOfAttachment" column="type_of_attachment"/>
            <result property="name" column="name"/>
            <result property="type" column="type"/>
            <result property="address" column="address"/>
            <result property="delFlag" column="del_flag"/>
            <result property="createBy" column="file_create_by"/>
            <result property="createTime" column="file_create_time"/>
            <result property="updateBy" column="file_update_by"/>
            <result property="updateTime" column="file_update_time"/>
            <result property="remark" column="file_remark"/>
        </collection>
    </resultMap>

    <!-- 定义 SQL 查询语句 -->
    <select id="userApplyForPayrollSettlementList" resultMap="WgzAppApplyForPayrollSettlementListResResultMap">
        SELECT
            w.id,
            w.task_id,
            w.recruit_id,
            w.user_id,
            w.task_name,
            w.task_address,
            w.recruit_name,
            w.user_name,
            w.entry_time,
            w.recruit_amount,
            w.num,
            w.working_state,
            w.phone,
            w.bank,
            w.card_no,
            w.auditor_user_id,
            w.auditor_type,
            w.auditor_opinion,
            w.auditor_time,
            w.create_by,
            w.create_time,
            w.remark,
            f.id AS file_id,
            f.calculation_id,
            f.type_of_attachment,
            f.name,
            f.type,
            f.address,
            f.del_flag,
            f.create_by AS file_create_by,
            f.create_time AS file_create_time,
            f.update_by AS file_update_by,
            f.update_time AS file_update_time,
            f.remark AS file_remark
        FROM
            wgz_pay_calculation w
                LEFT JOIN
            wgz_pay_calculation_files f ON w.id = f.calculation_id
        <where>
            <choose>
                <when test="page.auditorType != null and taskId != '' and auditorType == '0'">
                    AND w.auditor_type in ('0', '1') and
                </when>
                <when test="page.auditorType != null and taskId != '' and auditorType == '1'">
                    AND w.auditor_type = '2' and
                </when>
                <when test="page.auditorType != null and taskId != '' and auditorType == '2'">
                    AND w.auditor_type = '3' and
                </when>
                <when test="page.auditorType != null and taskId != '' and auditorType == '2'">
                    AND w.auditor_type = in ('0', '1','3') and
                </when>
            </choose>
            w.del_flag = 0
        </where>
    </select>



    <select id="appQueryPageList" resultMap="WgzAppApplyForPayrollSettlementListResResultMap">
        SELECT
            w.id,
            w.task_id,
            w.recruit_id,
            w.user_id,
            w.task_name,
            w.task_address,
            w.recruit_name,
            w.user_name,
            w.entry_time,
            w.leave_time,
            w.recruit_amount,
            w.num,
            w.working_state,
            w.phone,
            w.bank,
            w.card_no,
            w.auditor_user_id,
            w.auditor_user_name,
            w.auditor_type,
            w.auditor_opinion,
            w.auditor_time,
            w.create_by,
            w.create_time,
            w.remark,
            f.id AS file_id,
            f.calculation_id,
            f.type_of_attachment,
            f.name,
            f.type,
            f.address,
            f.del_flag,
            f.create_by AS file_create_by,
            f.create_time AS file_create_time,
            f.update_by AS file_update_by,
            f.update_time AS file_update_time,
            f.remark AS file_remark
        FROM
            wgz_pay_calculation w
                LEFT JOIN
            wgz_pay_calculation_files f ON w.id = f.calculation_id
        where w.auditor_user_id = #{dto.auditorUserId}
        and a.task_id = #{dto.taskId}
        <if test="dto.username != null and dto.username != ''">
           and w.user_name like concat('%', #{dto.userName}, '%')
        </if>
        <if test="dto.auditorTypes != null and dto.auditorTypes.size() > 0">
            AND bpra.auditor_type IN
            <foreach collection="dto.auditorTypes" item="auditorType" open="(" separator="," close=")">
                #{auditorType}
            </foreach>
        </if>
    </select>



</mapper>
