/*
 *  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 com.youchain.businessdata.domain.InventoryLog;
import com.youchain.businessdata.service.vo.InventoryExcelDto;
import com.youchain.businessdata.service.vo.InventoryExcelVO;
import org.springframework.data.domain.Pageable;
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;

/**
 * @author houjianlan
 * @website https://eladmin.vip
 * @date 2023-08-31
 **/
public interface InventoryLogRepository extends JpaRepository<InventoryLog, Long>, JpaSpecificationExecutor<InventoryLog> {
    @Query(value = "select log.id,area.name as areaName, item.code as itemCode,item.name as itemName,log.log_type as logType, " +
            "log.inc_dec as incDec,log.src_point_code as srcPoint,log.dst_point_code as dstPoint, " +
            "log.src_qty as srcQty,log.dst_qty as dstQty,log.occur_quantity as occurQuantity, " +
            "log.related_bill as relatedBill,log.description,log.create_by as createBy,log.occur_time as occurTime " +
            "from data_inventory_log log " +
            "join data_item_key ik on ik.id=log.item_key_id " +
            "join base_item item on item.id=ik.item_id " +
            "join base_area area on area.id=log.area_id " +
            "where (:itemCode is null or item.code = :itemCode) " +
            "and log.id > :lastId " +
            "order by  log.id asc ", nativeQuery = true)
    List<InventoryExcelDto> listByInventoryLogs(Long lastId, String itemCode, Pageable pageable);


}