package com.mortals.xhx.busiz.handler.impl;

import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.handler.BaseReqHandler;
import com.mortals.xhx.busiz.req.ApiReqPdu;
import com.mortals.xhx.busiz.req.PrintReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.PrintQueueResp;
import com.mortals.xhx.module.print.service.PrintService;
import lombok.extern.apachecommons.CommonsLog;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 打印handler
 *
 * @author:
 * @date: 2023/1/5 22:25
 */
@Service
@Slf4j
public class BusizPrintReqHandler extends BaseReqHandler<PrintReq, Void> {

    @Autowired
    private PrintService printService;

    @Override
    protected ApiResp<Void> handle(PrintReq printReq) throws AppException {
        log.info("【打印】【请求体】-->{}", JSON.toJSONString(printReq));
        Rest<Void> rest = printService.executePrint(printReq);
        log.info("【打印】【执行响应】-->{}", JSON.toJSONString(rest));
        if (rest.getCode() == Rest.SUCCESS) {
            return ApiResp.ok(rest.getMsg());
        } else {
            return ApiResp.fail(rest.getMsg());
        }
    }

    @Override
    protected void validData(PrintReq request) throws IllegalArgumentException {

    }


}
