package com.sw.mes.yb.mcs.dao;

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.mcs.dto.McsFbInventoryDto;
import com.sw.mes.yb.mcs.entity.McsSquareInventoryLog;
import com.sw.mes.yb.mcs.entity.RecycledMaterialCase;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @Author
* @Description：
* @Date:
* @Modified By:
*/
public interface McsSquareInventoryLogDao extends BaseDao<McsSquareInventoryLog, Long>{

    @Query(value = "SELECT * FROM `mcs_square_inventory_log` WHERE crystal_no = ?1  and inventory_type='out' ", nativeQuery = true)
    McsSquareInventoryLog queryByCrystalNo(String crystalNo);


    @Modifying
    @Query(value = "delete FROM `mcs_square_inventory_log` WHERE crystal_no = ?1  and inventory_type='out' ", nativeQuery = true)
    int deleteByCrystalNoName(String crystalNo);

    @Query(value = "SELECT * FROM `mcs_square_inventory_log` WHERE crystal_no = ?1  and inventory_type=?2 ", nativeQuery = true)
    McsSquareInventoryLog queryByCrystalNo(String crystalNo, String inventoryType);

    @Query(value = "SELECT * FROM `mcs_square_inventory_log` WHERE crystal_no = ?1", nativeQuery = true)
    List<McsSquareInventoryLog> queryAllByCrystalNo(String crystalNo);

    @Modifying
    @Query(value = "delete FROM `mcs_square_inventory_log` WHERE crystal_no = ?1   ", nativeQuery = true)
    int deleteByCrystalNo(String sectionNo);

    @Modifying
    @Query(value = "delete FROM `mcs_square_inventory_log` WHERE crystal_no = ?1  and inventory_type=?2 ", nativeQuery = true)
    int deleteByCrystalNoAndInventoryType(String sectionNo, String inventoryType);

    @Query(value = "select * from mcs_square_inventory_log where group_id=?1  ", nativeQuery = true)
    List<McsSquareInventoryLog> queryByGroupId(String groupId);

    @Modifying
    @Query(value = "update  `mcs_square_inventory_log` set inventory_type=?2  WHERE crystal_no = ?1 and inventory_type=?3 ", nativeQuery = true)
    void updateInventoryType(String sectionNo, String newInventoryType,String oldInventoryType);
}
