package com.prolog.eis.dao.shelves;


import com.prolog.eis.model.inbound.BizInboundTaskDetail;
import com.prolog.eis.model.shelves.PalletLocation;
import com.prolog.eis.vo.GoodsInfoVO;
import com.prolog.eis.vo.GoodsShelvesVO;
import com.prolog.framework.dao.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface BizInboundTaskDetailMapper extends BaseMapper<BizInboundTaskDetail> {

    @Select("<script>SELECT b.item_id itemId from biz_inbound_task a  LEFT JOIN biz_inbound_task_detail b\n" +
            " on a.id = b.inbound_id " +
            " where a.container_no =#{containerNo}  and a.status <![CDATA[<]]>  20 " +
            " and ifnull(b.is_hang_up,0) <![CDATA[<>]]> 1 " +
            " and ifnull(b.detail_status,0) <![CDATA[<]]> 20 and b.qty-IFNULL(b.real_qty,0) <![CDATA[>]]> 0 and " +
            " a.wms_location_code =  #{wmsLocationCode} and a.container_no = #{containerNo} group by b.item_id</script>")
    List<String> findInboundTask(@Param("containerNo") String containerNo, @Param("wmsLocationCode") String wmsLocationCode);

    /**
     * 查询货架信息
     *
     * @param palletNos
     * @param palletTypes
     * @param abcTypes
     * @param bizPropertyId
     * @param subArea
     * @return
     */
    List<GoodsShelvesVO> findPalletNo(@Param("palletNos") List<String> palletNos, @Param("palletTypes") List<String> palletTypes, @Param("abcTypes") List<String> abcTypes, @Param("bizPropertyId") Integer bizPropertyId, @Param("subArea") String subArea);

    List<GoodsInfoVO> findNowPalletNo(@Param("palletNo") String palletNo, @Param("itemId") String itemId, @Param("lotId") String lotId, @Param("packId") String packId, @Param("ownerId") String ownerId);

    List<GoodsInfoVO> findNewPalletNo(@Param("palletNo") String palletNo, @Param("palletLocation") String palletLocation, @Param("stationArea") String stationArea, @Param("areaNo") String areaNo, @Param("itemId") String itemId, @Param("lotId") String lotId, @Param("ownerId") String ownerId, @Param("itemHealthCategory") String itemHealthCategory, @Param("locationType") String locationType, @Param("abcType") String abcType);

    List<PalletLocation> findLocation(@Param("palletLocation") String palletLocation);


    @Select("<script>" +
            " SELECT COUNT(1)\n" +
            " from pallet_location a LEFT JOIN container_info_detail b \n" +
            " on a.pallet_location = b.container_sub_no\n" +
            " where\n" +
            " ((a.abc_type = #{abcType} and a.pallet_location = #{palletLocation}) or b.container_sub_no = #{palletLocation})\n" +
            " and a.pallet_no = #{palletNo} " +
            "</script>")
    int queryConfirmABC(@Param("abcType") String abcType, @Param("bizPropertyId") Long bizPropertyId, @Param("palletNo") String palletNo, @Param("palletLocation") String palletLocation);


    @Select("<script>" +
            " SELECT d.container_sub_no palletLocation,x.angle,d.item_id itemId,d.lot_id lotId ,d.owner_id ownerId,e.planes,a.container_no from biz_inbound_task_detail b\n" +
            " LEFT JOIN container_info_detail d on d.item_id  = b.item_id  and d.lot_id  = b.lot_id and d.owner_id  = b.owner_id \n" +
            " LEFT JOIN pallet_location e on e.pallet_location = d.container_sub_no\n" +
            " LEFT JOIN biz_inbound_task a on a.id = b.inbound_id\n" +
            " LEFT JOIN pallet_info x on d.container_no=x.pallet_no\n" +
            " where a.status <![CDATA[<]]> 20  \n" +
            " and  d.container_sub_no  is not null  \n" +
            " and  e.planes is not null  \n" +
            " and ifnull(b.is_hang_up,0) <![CDATA[<>]]> 1 and ifnull(b.detail_status,0) <![CDATA[<]]> 20 \n" +
            " and  a.wms_location_code =  #{wmsLocationCode} " +
            "<if test=\"stationId!=null \"> " +
            " and b.station_id = #{stationId} " +
            "</if> " +
            "</script>")
    List<GoodsShelvesVO> findCacheTasks(@Param("stationId") Integer stationId, @Param("wmsLocationCode") String wmsLocationCode);
}