package com.prolog.eis.dao.out;

import com.prolog.eis.model.container.ContainerInfoDetail;
import com.prolog.eis.vo.GoodsInfoVO;
import com.prolog.framework.dao.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author zhanghan
 */
@Repository
public interface ContainerInfoDetailMapper extends BaseMapper<ContainerInfoDetail> {

    /**
     * 查找调用托盘编号获取商品信息
     * @param palletLocation 托盘点位
     * @return
     */
    List<GoodsInfoVO> findCallPalletNo(@Param("palletLocation") String palletLocation,@Param("location") String location);

    @Select(" SELECT a.id,a.container_sub_no containerSubNo from container_info_detail a" +
            " where a.container_sub_no = #{containerSubNo} and (a.item_id != #{goodsId} or a.owner_id != #{ownerId} " +
            " or a.lot_id != #{lotId} or a.pack_id != #{packId})")
    List<ContainerInfoDetail> findLocationOtherStore(@Param("containerSubNo") String containerSubNo, @Param("goodsId") String goodsId,
                                                     @Param("ownerId") String ownerId, @Param("lotId") String lotId,@Param("packId") String packId);

    @Update("UPDATE container_info_detail SET qty = qty + #{qty} where container_sub_no = #{containerSubNo} and item_id = #{itemId} AND owner_id = #{ownerId} AND lot_id = #{lotId} AND pack_id = #{packId}  AND container_no = #{containerNo} AND area_type = #{areaType}")
    long updateContainerStore(@Param("containerNo") String containerNo, @Param("containerSubNo") String containerSubNo, @Param("itemId") String itemId,@Param("ownerId") String ownerId,@Param("lotId") String lotId,@Param("packId") String packId,
                              @Param("qty") BigDecimal qty, @Param("areaType") Integer areaType);

}