package com.clx.performance.sqlProvider;

import com.clx.performance.enums.OrderGoodsTruckBindEnum;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;

public class OrderGoodsTruckBindSqlProvider {

    public String saveBatchEntity(String orderNo, String orderGoodsNo, List<String> trackList, String now) {
        StringBuffer sqlList = new StringBuffer();

        sqlList.append(" INSERT INTO order_goods_truck_bind(order_no,order_goods_no,truck_no,create_time,modified_time,status)  VALUES ");
        for (int i = 0; i < trackList.size(); i++) {
            String truckNo = trackList.get(i);
            sqlList.append(" ('").append(orderNo).append("','").append(orderGoodsNo).append("','").append(truckNo).append("','")
                    .append(now).append("','").append(now).append("','").append(OrderGoodsTruckBindEnum.Status.NORMAL.getCode())
                    .append("')");
            if (i < trackList.size() - 1) {
                sqlList.append(",");
            }
        }
        return sqlList.toString();
    }


    public String findUnreleasedTruck(){
        return new SQL(){{
            SELECT(" truck_no ");
            FROM("order_goods_truck_bind");
            WHERE("status IN ("  + OrderGoodsTruckBindEnum.Status.GET.getCode() + "," +
                    OrderGoodsTruckBindEnum.Status.NORMAL.getCode() + ")" );

        }}.toString();
    }

}
