/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.youchain.businessdata.repository;

import cn.hutool.core.date.DateTime;
import com.youchain.businessdata.domain.AgvTask;
import com.youchain.businessdata.domain.PickDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @website https://eladmin.vip
* @author huojin
* @date 2023-08-16
**/
public interface PickDetailRepository extends JpaRepository<PickDetail, Long>, JpaSpecificationExecutor<PickDetail> {
    /**
     * 查询前后桶出库的数量
     * @param time 2023-12-09 00:00:00
     * @param status PICK_ALL 已完成  ALLOCATE 待执行
     * @return
     */
    @Query(value = "select a.* from data_pick_detail a INNER JOIN base_item b on a.item_id = b.id " +
            "WHERE b.name = '后桶' and a.create_time > :time  and a.`status` = :status " +
            "UNION select a.* from data_pick_detail a INNER JOIN base_item b on a.item_id = b.id " +
            "WHERE b.name = '前桶' and a.create_time > :time and a.`status` = :status ", nativeQuery = true)
    List<PickDetail> queryOutQHData(String time, String status);

    /**
     * 查询前后桶出库全部数据
     * @param time 2023-12-09 00:00:00
     * @return
     */
    @Query(value = "select a.* from data_pick_detail a INNER JOIN base_item b on a.item_id = b.id " +
            "WHERE b.name = '后桶' and a.create_time > :time " +
            " UNION select a.* from data_pick_detail a INNER JOIN base_item b on a.item_id = b.id " +
            "WHERE b.name = '前桶' and a.create_time > :time ", nativeQuery = true)
    List<PickDetail> queryOutQHAllData(String time);
}