package com.mortals.xhx.busiz.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.mortals.framework.common.Rest;
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.IdCardResp;
import com.mortals.xhx.busiz.rsp.PrintListResp;
import com.mortals.xhx.busiz.rsp.PrintQueueResp;
import com.mortals.xhx.common.code.BusizTypeEnum;
import com.mortals.xhx.module.idCard.model.IdCardCons;
import com.mortals.xhx.module.idCard.service.IdCardService;
import com.mortals.xhx.module.print.model.Printer;
import com.mortals.xhx.module.print.model.PrinterQueue;
import com.mortals.xhx.module.print.service.PrintService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * api controller
 *
 * @author: zxfei
 * @date: 2022/12/26 10:21
 */
@RestController
@Slf4j
public class ApiController extends BaseAbstractApiController {

    @Autowired
    private PrintService printService;
    @Autowired
    private IdCardService idCardService;

    @RequestMapping(value = "GetHardWareInfo", method = {RequestMethod.POST, RequestMethod.GET})
    public Object GetHardWareInfo(@RequestParam Map<String, Object> reqMap) {
        String getType = (String) reqMap.getOrDefault("GetType", "");
        String reqJson = (String) reqMap.getOrDefault("PrinterJson", "");
        String printerName = (String) reqMap.getOrDefault("printerName", "");
        String waitTime = (String) reqMap.getOrDefault("waitTime", "120");
        String signType = (String) reqMap.getOrDefault("signType", "");
        String socialType = (String) reqMap.getOrDefault("socialType", "");
        log.info("getType:" + getType);
        try {
            switch (BusizTypeEnum.getByValue(getType)) {
                case BUSIZ_CAPTURE:  //高拍仪
                    ApiResp<Object> captureResp = handle(waitTime, "busizCaptureReqHandler");
                    return captureResp;
                case BUSIZ_ASSESSMENT: //评价
                    ApiResp<Object> assessResp = handle(JSON.parseObject(reqJson, new TypeReference<PrintReq>() {
                    }), "busizAssessmentReqHandler");
                    return assessResp;
                case BUSIZ_PRINT:  //打印
                    ApiResp<Object> rest = handle(JSON.parseObject(reqJson, new TypeReference<PrintReq>() {
                    }), "busizPrintReqHandler");
                    return rest;
                case BUSIZ_PRINTLIST:  //打印机列表
                    //获取打印机列表
                    ApiResp<Object> printListResp = handle("", "busizPrintListReqHandler");
                    return printListResp;
                case BUSIZ_PRINT_QUEUE:  //查看指定打印机打印队列
                    ApiResp<Object> printQueueResp = handle(printerName, "busizPrintQueueReqHandler");
                    return printQueueResp;
                case BUSIZ_IDCARD_RECOGNITION:  //身份证读取
                    ApiResp<Object> idCardResp = handle("", "busizIdcardRecognitionReqHandler");
                    return idCardResp;
                case BUSIZ_CAMERA:  //双目摄像头
                    log.info("双目摄像头");
                    return null;
                case BUSIZ_SIGN:  //签名板
                    ApiResp<Object> signResp = handle(signType, "busizSignReqHandler");
                    return signResp;
                case BUSIZ_SOCIAL:  //社保卡  德卡T10三合一
                    ApiResp<Object> socialResp = handle(socialType, "busizSocialReqHandler");
                    return socialResp;
                case BUSIZ_FINGER:  //指纹
                    log.info("指纹");
                    return null;


            }
        } catch (Exception e) {
            log.error("接收数据失败", e);
            return ApiResp.fail(e.getMessage());
        }
        return ApiResp.ok();
    }
}
