package com.hfkj.device.spyun;

import com.hfkj.common.utils.DateUtil;
import com.hfkj.model.GasClassGroupTaskDataCount;
import com.hfkj.model.GasClassGroupTaskOilCount;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.Map;

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

    /**
     * 加油站收银员存根模板
     */
    public static String classGroupCountTemp(GasClassGroupTaskDataCount dataCount, boolean makeUp) {
        String str = "<C>" + dataCount.getClassNum() + "班结流水" + (makeUp?"（补打）":"") + "</C> <BR> " +
                "===============================<BR>" +
                "开始时间：" + DateUtil.date2String(dataCount.getStartTime(), "yyyy-MM-dd HH:mm:ss") + "<BR>" +
                "结束时间：" + DateUtil.date2String(dataCount.getEndTime(), "yyyy-MM-dd HH:mm:ss") + "<BR>" +
                "<BR>" +
                "加油金额汇总：" + dataCount.getRefuelPrice() + "元<BR>" +
                "加油笔数汇总：" + dataCount.getRefuelNum() + "笔<BR>" +
                "加油升数汇总：" + dataCount.getRefuelLiters() + "升<BR>" +
                "<BR>" +
                "退款金额汇总：" + dataCount.getRefundPrice() + "元<BR>" +
                "退款笔数汇总：" + dataCount.getRefundNum() + "笔<BR>" +
                "退款升数汇总：" + dataCount.getRefundLiters() + "升<BR>" +
                "<BR>" +
                "--------------收款-------------<BR>" +
                "油号    金额(元)    升数   笔数<BR>";

                String oilCountStr = "";
                for (GasClassGroupTaskOilCount oilCount : dataCount.getGroupTaskOilCountList()) {
                    oilCountStr += oilCount.getOilNo() + "#   " + oilCount.getRefuelPrice() + "   " + oilCount.getRefuelLiters() + "   " + oilCount.getRefuelNum() + "<BR>";
                }
                str += oilCountStr +
                "================================<BR>" +
                "<C>" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss") +"</C> <BR>";
        return str;
    }

    /**
     * 加油站收银员存根模板
     * @param gasName     油站名称
     * @param orderNo     订单号
     * @param payTime     支付时间
     * @param gunNo       抢号
     * @param oilNo       油号
     * @param oilLiters   升数
     * @param orderPrice 加油金额
     * @param receiptMap 小票配置
     * @param makeUp 重复打印
     * @return
     */
    public static String oilCashierStubTemp(String gasName,
                                            String orderNo,
                                            String payTime,
                                            String phone,
                                            String gunNo,
                                            String oilNo,
                                            String oilLiters,
                                            String orderPrice,
                                            String discountPrice,
                                            String actualPayment,
                                            Map<String, Object> receiptMap,
                                            boolean makeUp) {

        String str = "<C><L1>" + (StringUtils.isNotBlank(MapUtils.getString(receiptMap, "receiptTop"))?MapUtils.getString(receiptMap, "receiptTop"):"嗨加油") + "</L1></C> <BR> " +
                "<C><B>" + gasName + (makeUp?"（补打）":"") + "</B></C> <BR> " +
                "<C>（收银员存根）</C> <BR>" +
                "------------------------------<BR>" +
                "流水：" + orderNo + "<BR>" +
                "------------------------------<BR>" +
                "打印时间：" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss") + "<BR>" +
                "支付时间：" + payTime + "<BR>" +
                "电话：" + (StringUtils.isNotBlank(phone)?phone.substring(0, 3) + "****" + phone.substring(7):"") + "<BR>" +
                "来源：" + (StringUtils.isNotBlank(MapUtils.getString(receiptMap, "receiptSource"))?MapUtils.getString(receiptMap, "receiptSource"):"嗨加油")+ "<BR>" +
                "<L1>油枪："+ gunNo + "号</L1><BR>" +
                "<L1>油品：" + oilNo + "#</L1><BR>" +
                "<L1>升数：" + oilLiters +"升</L1><BR>" +
                "实际加油升数以油站加油机为准！<BR>" +
                "------------------------------<BR>" +
                "<L1>加油金额："+ orderPrice + "</L1><BR>" +
                "<L1>优惠金额：" + discountPrice + "</L1><BR>" +
                "------------------------------<BR>" +
                "<L1>实际支付：" + actualPayment +"</L1><BR>" +
           /*     "<L1>加油金额</L1><BR>" +
                "<L1>￥" + orderPrice + "元</L1><BR>" +*/
                "------------------------------<BR>" +
                "<C><B>"+ (StringUtils.isNotBlank(MapUtils.getString(receiptMap, "receiptBottom"))?MapUtils.getString(receiptMap, "receiptBottom"):"开心又省钱;  来＂嗨加油＂") + "</B></C>";
        return str;
    }

    /**
     * 加油站客户存根模板
     * @param gasName     油站名称
     * @param orderNo     订单号
     * @param payTime     支付时间
     * @param gunNo       抢号
     * @param oilNo       油号
     * @param oilLiters   升数
     * @param orderPrice 加油金额
     * @param receiptMap 小票配置
     * @param makeUp 重复打印
     * @return
     */
    public static String oilClientStubTemp(String gasName,
                                            String orderNo,
                                            String payTime,
                                            String phone,
                                            String gunNo,
                                            String oilNo,
                                            String oilLiters,
                                            String orderPrice,
                                            String discountPrice,
                                            String actualPayment,
                                            Map<String, Object> receiptMap,
                                            boolean makeUp) throws Exception {
        String str = "<C><L1>" + (StringUtils.isNotBlank(MapUtils.getString(receiptMap, "receiptTop"))?MapUtils.getString(receiptMap, "receiptTop"):"嗨加油") + "</L1></C> <BR> " +
                "<C><B>" + gasName + (makeUp?"（补打）":"") + "</B></C> <BR> " +
                "<C>（客户存根）</C> <BR>" +
                "------------------------------<BR>" +
                "流水：" + orderNo + "<BR>" +
                "------------------------------<BR>" +
                "打印时间：" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss") + "<BR>" +
                "支付时间：" + payTime + "<BR>" +
                "电话：" + (StringUtils.isNotBlank(phone)?phone.substring(0, 3) + "****" + phone.substring(7):"") + "<BR>" +
                "来源：" + (StringUtils.isNotBlank(MapUtils.getString(receiptMap, "receiptSource"))?MapUtils.getString(receiptMap, "receiptSource"):"嗨加油")+ "<BR>" +
                "<L1>油枪："+ gunNo + "号</L1><BR>" +
                "<L1>油品：" + oilNo + "#</L1><BR>" +
                "<L1>升数：" + oilLiters +"升</L1><BR>" +
                "实际加油升数以油站加油机为准！<BR>" +
                "------------------------------<BR>" +
                "<L1>加油金额："+ orderPrice + "</L1><BR>" +
                "<L1>优惠金额：" + discountPrice + "</L1><BR>" +
                "------------------------------<BR>" +
                "<L1>实际支付：" + actualPayment +"</L1><BR>" +
/*                "<L1>加油金额</L1><BR>" +
                "<L1>￥" + orderPrice + "元</L1><BR>" +*/
                "------------------------------<BR>" +
                "<C><B>"+ (StringUtils.isNotBlank(MapUtils.getString(receiptMap, "receiptBottom"))?MapUtils.getString(receiptMap, "receiptBottom"):"开心又省钱;  来＂嗨加油＂") + "</B></C>";
        return str;
    }

}
