package com.hfkj.config;

import com.hfkj.common.utils.DateUtil;
import com.hfkj.entity.BsMealTableOrder;
import com.hfkj.entity.BsMealTableOrderChild;
import com.hfkj.entity.BsMealTableOrderChildProduct;
import com.hfkj.entity.BsMealTableOrderProduct;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * 商鹏打印机模板
 * @author hurui
 */
public class SpPrinterTemplate {


    /**
     * 扫码点餐，点餐订单
     * @param mealTableOrder   交易订单
     * @param productList     产品列表
     * @return
     */
    public static String mealOrder(BsMealTableOrder mealTableOrder, BsMealTableOrderChild mealTableOrderChild,List<BsMealTableOrderChildProduct> productList) {
        String str = "<C><L1>（点菜单）</L1></C>\n" +
                "<C><L1>"+mealTableOrder.getTableName()+"</L1></C>\n" +
                "订单号："+mealTableOrder.getOrderNo() +"\n"+
                "用餐人数："+mealTableOrder.getPeopleNum()+"人\n" +
                "================================\n" +
                "品名                        数量\n" +
                "================================\n";
        for (BsMealTableOrderChildProduct product : productList) {
            str+=limitStr(13,product.getProductName())+"   "+product.getProductNum()+"\n";
        }
        str+="================================\n" +
             "备注：" + (mealTableOrderChild.getRemark()==null?"":mealTableOrderChild.getRemark())+"\n" +
             "打印时间：" + DateUtil.date2String(new Date(), DateUtil.Y_M_D_HMS) +"\n";
        return str;
    }

    /**
     * 加油站客户存根模板
     * @param mealTableOrder   交易订单
     * @param productList     产品列表
     * @return
     */
    public static String mealOrderBill(BsMealTableOrder mealTableOrder,List<BsMealTableOrderProduct> productList) {
        String str = "<C><L1>"+mealTableOrder.getStoreName()+"</L1></C>\n" +
                "<C><L1>"+mealTableOrder.getTableName()+"</L1></C>\n" +
                "订单号："+mealTableOrder.getOrderNo() +"\n"+
                "用餐人数："+mealTableOrder.getPeopleNum()+"人\n" +
                "开台时间：" + DateUtil.date2String(mealTableOrder.getCreateTime(), DateUtil.Y_M_D_HMS) +"\n"+
                "打印时间：" + DateUtil.date2String(new Date(), DateUtil.Y_M_D_HMS) +"\n"+
                "================================\n" +
                "品名             数量 单价 金额\n" +
                "================================\n";
                for (BsMealTableOrderProduct product : productList) {
                    str+=limitStr(8,product.getProductName())+"  "+product.getProductNum()+" "+product.getProductPrice()+" "+product.getProductTotalPrice()+"\n";
                }
                str+="================================\n" +
                "<R>合计："+mealTableOrder.getOrderAmount()+"元</R>\n" +
                "--------------------------------\n" +
                "<C>谢谢光临，欢迎下次惠顾！</C>\n";
        return str;
    }

    private static String limitStr(int limit,String str) {
        if (str.length() >= limit) {
            return str.substring(0, limit-1);
        }
        // 补位长度
        int repairLength = limit - str.length();
        for (int i = 0; i < repairLength;i++) {
            str+="  ";
        }
        return str;
    }

}
