package com.hw.printer.service;

import com.hw.common.core.utils.DateUtils;
import com.hw.common.core.utils.StringUtils;
import com.hw.mes.api.domain.MesBaseBarcodeInfo;
import com.hw.printer.utils.HwPrintUtil;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Value;

import java.util.HashMap;

/**
 * 打印机服务Service
 *
 * @author Yinq
 */
@Service
public class PrinterServiceImpl implements IPrinterService {

    /**
     * 打印机映射路径
     */
    @Value("${print.path}")
    public String localPrintPath;

    /**
     * PDF模板路径
     */
    @Value("${print.pdfTemplatePath}")
    public String pdfTemplatePath;

    /**
     * 生成PDF文件路径
     */
    @Value("${print.generatePath}")
    public String generatePath;

    /**
     * 打印条码接口
     *
     * @param barcodeInfo
     * @return
     * @throws Exception
     */
    @Override
    public MesBaseBarcodeInfo printBarCode(MesBaseBarcodeInfo barcodeInfo) throws Exception {
        HashMap<String, String> params = new HashMap<>();
        params.put("localPrintPath", localPrintPath);
        params.put("pdfTemplatePath", pdfTemplatePath);
        params.put("generatePath", generatePath);
        params.put("barcodeInfo", barcodeInfo.getBarcodeInfo());
        params.put("batchCode", barcodeInfo.getBatchCode());
        params.put("materialName", barcodeInfo.getMaterialName());
        params.put("date", DateUtils.getDate());
        String machineName = HwPrintUtil.printBarCode(params);
        barcodeInfo.setMachineName(machineName);
        return barcodeInfo;
    }


}
