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


import com.prolog.eis.dto.inbound.*;
import com.prolog.eis.model.inbound.BizInboundTask;
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 java.util.List;

public interface BizInboundTaskMapper extends BaseMapper<BizInboundTask> {


    @Select("<script>" +
            " SELECT b.id taskId,b.item_id goodsId,b.owner_id ownerId," +
            " b.lot_id lotId,ifnull(b.qty,0) - ifnull(b.real_qty,0) qty,a.container_no containerNo  " +
            " FROM biz_inbound_task  a LEFT JOIN biz_inbound_task_detail b " +
            " on a.id = b.inbound_id " +
            " WHERE b.qty - IFNULL(b.real_qty,0)  <![CDATA[>]]>  0 and IFNULL(a.`status`,0)  <![CDATA[<]]>  20 " +
            " AND IFNULL(b.detail_status,0) <![CDATA[<]]> 20 and  IFNULL(b.is_hang_up,0) = 0 " +
            "<if test=\"containerNo != null and containerNo != ''\"> " +
            " and a.container_no = #{containerNo} " +
            "</if> " +
            "<if test=\"stationId != null \"> " +
            " and b.station_id = #{stationId} " +
            "</if> " +
            "</script>")
    List<GoodsInfoVO> getInboundTaskList(@Param("containerNo") String containerNo, @Param("stationId") Integer stationId);


    @Select("SELECT\n" +
            "\tbiz_inbound_task_detail.id AS taskId, \n" +
            "\tbiz_inbound_task_detail.extend_1 AS hangUpUser, \n" +
            "\tbiz_inbound_task_detail.extend_2 AS hangUpTime, \n" +
            "\tbiz_inbound_task_detail.qty AS qty, \n" +
            "\tbiz_inbound_task_detail.biz_property_id AS bizPropertyId, \n" +
            "\tbiz_inbound_task_detail.create_time AS createTime, \n" +
            "\tbiz_property.goods_id AS goodsId\n" +
            "FROM\n" +
            "\tbiz_inbound_task_detail\n" +
            "\tINNER JOIN\n" +
            "\tbiz_property\n" +
            "\tON \n" +
            "\t\tbiz_inbound_task_detail.biz_property_id = biz_property.id\n" +
            "WHERE\n" +
            "\tbiz_inbound_task_detail.is_hang_up = 1"
    )
    List<GoodsInfoVO> findBasicInfo();

    int updateInboundStatusById(@Param("id") Integer id, @Param("code") Integer code);

    List<ShelvesTaskListDto> shelvesTaskList();

    List<ShelvesTaskDetailRespDto> shelvesTaskDetail(@Param("req") ShelvesTaskDetailReqDto req);

    List<AgainListRespDto> againList(@Param("req") AgainListReqDto req);
}
