package org.jeecg.modules.toolBorrowingRecord.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.toolBorrowingRecord.entity.ToolBorrowingRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.toolSheet.entity.ToolSheet;

/**
 * @Description: 工器具借用记录
 * @Author: jeecg-boot
 * @Date:   2025-01-15
 * @Version: V1.0
 */
public interface ToolBorrowingRecordMapper extends BaseMapper<ToolBorrowingRecord> {

    @Select("SELECT * FROM bu_tool_borrowing_record WHERE tool_id = (SELECT id FROM bu_tool_sheet WHERE mac =#{deviceMac}) and status=0 order by create_time limit 1")
    ToolBorrowingRecord selectWorkOrderByDeviceMac(@Param("deviceMac") String deviceMac);

//    @Select("SELECT * FROM bu_tool_borrowing_record WHERE tool_id = (SELECT id FROM bu_tool_sheet WHERE code =#{deviceName})")
//    ToolBorrowingRecord selectWorkOrderByDeviceName(@Param("deviceName") String deviceName);

    /**
     * 通过工单id查询所有借用的具体工具信息列表
     * @param workOrder
     * @return
     */
    @Select("SELECT * FROM bu_tool_sheet WHERE id in (SELECT tool_id FROM bu_tool_borrowing_record WHERE work_order=#{workOrder})")
    List<ToolSheet> selectToolSheetByWorkOrder(@Param("workOrder") String workOrder);

}
