package com.prolog.eis.dao.out.shelves;

import com.prolog.eis.dto.shelves.ShelvesInfoDTO;
import com.prolog.eis.dto.shelves.ShelvesInfoPage;
import com.prolog.eis.model.shelves.PalletInfo;
import com.prolog.eis.vo.PalletInfoVo;
import com.prolog.framework.dao.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 货架表接口
 *
 * @author zhanghan
 */
@Mapper
public interface PalletInfoMapper extends BaseMapper<PalletInfo> {

    /**
     * 分页查询货架信息
     *
     * @param page 分页参数
     * @return List<ShelvesInfoDTO>
     */
    List<ShelvesInfoDTO> getPalletInfoPage(@Param("page") ShelvesInfoPage page);


    @Select("<script>SELECT b.pallet_no palletNo,b.pallet_location palletLocation," +
            " a.pallet_type palletType,b.abc_type abcType,b.planes,a.sub_area subArea,a.angle  FROM `pallet_info` a LEFT JOIN pallet_location b \n" +
            " on a.pallet_no = b.pallet_no\n" +
            " where a.is_lock = 0 and b.is_lock = 0\n" +
            " and a.`status` = 0 and ifnull(a.pallet_type,'0') = '0'" +
            "<if test=\"subAreas!=null and subAreas.size() > 0 \"> " +
            " and a.sub_area in " +
            " <foreach collection='subAreas' item='subArea' open='(' separator=',' close=')'>\n" +
            "  #{subArea}\n" +
            " </foreach>\n" +
            "</if> </script>")
    List<PalletInfoVo> queryEmptyPalletList(@Param("subAreas") List<String> subAreas);

    @Update("UPDATE pallet_info p SET p.pallet_type = #{palletType},update_time = SYSDATE() WHERE p.pallet_no = #{palletNo}")
    long updatePalletTypeByPalletNo(@Param("palletNo") String palletNo, @Param("palletType") String palletType);

}