<?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.pay.mapper.PayDayWorkHoursMapper">

    <resultMap type="com.ruoyi.pay.domain.PayDayWorkHours" id="PayDayWorkHoursResult">
        <result property="id" column="id"/>
        <result property="tenantId" column="tenant_id"/>
        <result property="deptId" column="dept_id"/>
        <result property="deptName" column="dept_name"/>
        <result property="employeeId" column="employee_id"/>
        <result property="empName" column="emp_name"/>
        <result property="date" column="date"/>
        <result property="dwYearMonth" column="dw_year_month"/>
        <result property="note" column="note"/>
    </resultMap>

    <resultMap type="PayDayWorkHoursQuery" id="PayDayWorkHoursQueryResult">
        <result property="id"    column="id"    />
        <result property="tenantId" column="tenant_id"/>
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="employeeId"    column="employee_id"    />
        <result property="empName"    column="emp_name"    />
        <result property="date"    column="date"    />
        <result property="dwYearMonth"    column="dw_year_month"    />
        <result property="note"    column="note"    />
        <collection property="dwHoursContrasts" ofType="PayDwHoursContrast">
            <result property="startTime"    column="con_start"    />
            <result property="endTime"    column="con_end"    />
            <result property="isHelper"    column="con_helper"    />
            <result property="deptId"    column="con_dept_id"    />
            <result property="deptName"    column="con_dept_name"    />
            <result property="hours"    column="con_hours"    />
            <result property="salesman"    column="con_salesman"    />
        </collection>
    </resultMap>

    <select id="selectPayDayWorkHoursList2" parameterType="PayDayWorkHoursQuery" resultMap="PayDayWorkHoursQueryResult">
        select d.*,c.start_time con_start,c.end_time con_end,c.is_helper con_helper,c.hours con_hours,c.salesman con_salesman from pay_day_work_hours  d  join  pay_dw_hours_contrast c
        on d.id=c.dw_hours_id
        /* select d.*  from sgr_day_work_hours d  inner join  sgr_dw_hours_contrast c   on d.id=c.dw_hours_id*/
        <where>
            <if test="deptId != null "> and d.dept_id = #{deptId}</if>
            <if test="tenantId != null "> and d.tenant_id = #{tenantId}</if>
            <if test="deptName != null  and deptName != ''"> and d.dept_name like concat('%', #{deptName}, '%')</if>
            <if test="employeeId != null "> and employee_id = #{employeeId}</if>
            <if test="empName != null  and empName != ''"> and emp_name like concat('%', #{empName}, '%')</if>
            <if test="date != null "> and date = #{date}</if>
            <if test="dwYearMonth != null  and dwYearMonth != ''"> and `dw_year_month` = #{dwYearMonth}</if>
            <if test="salesman != null  and salesman != ''"> and c.`salesman` = #{salesman}</if>
            <if test="note != null  and note != ''"> and note = #{note}</if>
        </where>
    </select>

    <select id="selectVoPage2"  resultMap="PayDayWorkHoursQueryResult">
        select d.*,c.start_time con_start,c.end_time con_end,c.is_helper con_helper,c.hours con_hours,c.salesman con_salesman from pay_day_work_hours  d  join  pay_dw_hours_contrast c
        on d.id=c.dw_hours_id
            ${ew.customSqlSegment}
    </select>

    <select id="selectDetailById" parameterType="Long" resultMap="PayDayWorkHoursQueryResult">
        select d.*,c.start_time con_start,c.end_time con_end,c.is_helper con_helper, c.dept_id con_dept_id,c.dept_name con_dept_name ,c.hours con_hours,c.salesman con_salesman from pay_day_work_hours  d , pay_dw_hours_contrast c
        where d.id=c.dw_hours_id and  d.id = #{id}
    </select>

</mapper>
