<?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="org.jeecg.modules.itdmGongDan.mapper.ItdmGongdanDetailMapper">

    <resultMap id="ItdmGongdanDetailResult" type="org.jeecg.modules.itdmGongDan.entity.ItdmGongdanDetail" >
        <result column="id" property="id" jdbcType="VARCHAR"/>
        <result column="wo_id" property="woId" jdbcType="VARCHAR"/>
        <result column="shiji_shebei_id" property="shijiShebeiId" jdbcType="VARCHAR"/>
        <result column="shiji_shiiyan_type" property="shijiShiiyanType" jdbcType="VARCHAR"/>
        <result column="work_date" property="workDate" jdbcType="DATE"/>
        <result column="start_time" property="startTime" jdbcType="VARCHAR"/>
        <result column="end_time" property="endTime" jdbcType="VARCHAR"/>
        <result column="shiji_work_date" property="shijiWorkDate" jdbcType="VARCHAR"/>
        <result column="shiji_start_time" property="shijiStartTime" jdbcType="VARCHAR"/>
        <result column="shiji_end_time" property="shijiEndTime" jdbcType="VARCHAR"/>
        <result column="chuanganqi" property="chuanganqi" jdbcType="VARCHAR"/>
    </resultMap>

    <resultMap id="ItdmGongdanDetailListVOResult" type="org.jeecg.modules.itdmGongDan.vo.ItdmGongdanDetailListVO" >
        <result column="id" property="id" jdbcType="VARCHAR"/>
        <result column="wo_id" property="woId" jdbcType="VARCHAR"/>
        <result column="shiji_shebei_id" property="shijiShebeiId" jdbcType="VARCHAR"/>
        <result column="shiji_shiiyan_type" property="shijiShiiyanType" jdbcType="VARCHAR"/>
        <result column="work_date" property="workDate" jdbcType="DATE"/>
        <result column="start_time" property="startTime" jdbcType="VARCHAR"/>
        <result column="end_time" property="endTime" jdbcType="VARCHAR"/>
        <result column="shiji_work_date" property="shijiWorkDate" jdbcType="VARCHAR"/>
        <result column="shiji_start_time" property="shijiStartTime" jdbcType="VARCHAR"/>
        <result column="shiji_end_time" property="shijiEndTime" jdbcType="VARCHAR"/>
        <result column="chuanganqi" property="chuanganqi" jdbcType="VARCHAR"/>

        <result column="jihua_shiyan_id" property="jihuaShiyanId" jdbcType="VARCHAR"/>
        <result column="test_items_id" property="testItemsId" jdbcType="VARCHAR"/>
        <result column="weituo_yangpin_id" property="weituoYangpinId" jdbcType="VARCHAR"/>
        <result column="shebei_id" property="shebeiId" jdbcType="VARCHAR"/>

        <result column="shiiyan_type" property="shiiyanType" jdbcType="VARCHAR"/>
        <result column="worker" property="worker" jdbcType="VARCHAR"/>
        <result column="yangpin_count" property="yangpinCount" jdbcType="INTEGER"/>

        <result column="weituo_id" property="weituoId" jdbcType="VARCHAR"/>
    </resultMap>


    <select id="getDetailList" parameterType="String"  resultMap="ItdmGongdanDetailListVOResult">
        select d.id, d.wo_id, d.shiji_shebei_id, d.shiji_shiiyan_type, d.work_date, d.start_time, d.end_time,
               d.shiji_work_date, d.shiji_start_time, d.shiji_end_time, d.chuanganqi,
               m.jihua_shiyan_id, m.test_items_id, m.weituo_yangpin_id, m.shebei_id, m.shiiyan_type, m.worker, m.yangpin_count,
               t.weituo_id
        from itdm_gongdan_detail d
left join itdm_gongdan_master m on d.wo_id = m.id
left join itdm_test_plan t on m.jihua_shiyan_id = t.id
        <where>
            <if test="woId != null "> and d.wo_id = #{woId}</if>
        </where>
        order by d.wo_id, d.work_date
    </select>


    <select id="getDetailListByWoIdList" resultMap="ItdmGongdanDetailResult">

        select id,wo_id,shiji_shebei_id,shiji_shiiyan_type,work_date,start_time,end_time,
               shiji_work_date,shiji_start_time,shiji_end_time,chuanganqi

        from itdm_gongdan_detail

        <if test="list!=null and list.size()>0">

        where wo_id in
        <foreach item="item" collection="list" separator="," open="(" close=")" index="">
            #{item}
        </foreach>

        </if>

    </select>


    <!--    查询该月该设备计划工作日期-->
    <select id="workDateList" parameterType="org.jeecg.modules.itdmGongDan.dto.DeviceCalendarQueryDTO"  resultType="java.util.Date">
        select distinct work_date from itdm_gongdan_detail
        <where>
            <if test="workDate != null "> and YEAR(work_date) = YEAR(#{workDate}) and MONTH(work_date) = MONTH(#{workDate})</if>
            <if test="jihuaDeviceId != null and jihuaDeviceId != ''"> and jihua_device_id = #{jihuaDeviceId}</if>
        </where>
    </select>

    <!--    查询该工作日期计划的所有设备（去重去空）-->
    <select id="planDeviceList" parameterType="java.util.Date"  resultType="org.jeecg.modules.itdmGongDan.vo.DeviceCalendarDeviceListVO">
        select distinct igd.jihua_device_id, d.device_name  from itdm_gongdan_detail igd
        left join itdm_device d on igd.jihua_device_id = d.id
        where work_date = #{workDate} and jihua_device_id is not null and jihua_device_id != ''
    </select>

    <!--    查询该工作日期、设备对应的委托列表-->
    <select id="weituoList" parameterType="org.jeecg.modules.itdmGongDan.dto.DeviceCalendarQueryDTO"  resultType="org.jeecg.modules.itdmGongDan.vo.DeviceDateToWeituoInfoVO">
        select w.weituo_no, w.weituo_client from itdm_weituo_info w
where w.id in (
    select distinct t.weituo_id from itdm_test_plan t where t.id in (
        select distinct m.jihua_shiyan_id from itdm_gongdan_master m where m.id in (
            select distinct d.wo_id from itdm_gongdan_detail d
            where d.jihua_device_id = #{jihuaDeviceId} and d.work_date = #{workDate}
            )
        )
    )
    </select>


</mapper>
