package com.hw.printer.controller;

import com.hw.common.core.domain.R;
import com.hw.mes.api.domain.MesBaseBarcodeInfo;
import com.hw.printer.service.IPrinterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 打印机请求处理
 *
 * @author Yinq
 */
@RestController
@RequestMapping("/printService")
public class PrinterController {
    private static final Logger log = LoggerFactory.getLogger(PrinterController.class);

    @Autowired
    private IPrinterService printerService;

    /**
     * 打印条码接口
     * @param barcodeInfo
     * @return
     */
    @PostMapping("/printBarCode")
    public R<MesBaseBarcodeInfo> printBarCode(@RequestBody MesBaseBarcodeInfo barcodeInfo) {
        try {
            return R.ok(printerService.printBarCode(barcodeInfo));
        } catch (Exception e) {
            log.error("打印条码失败", e);
            return R.fail(e.getMessage());
        }
    }

}