package com.engine.htsc.seal.web;

import com.alibaba.fastjson.JSON;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.seal.service.SealInformationService;
import weaver.general.BaseBean;
import weaver.general.Util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

public class SealInformationAction {

    SealInformationService getService(){
        return ServiceUtil.getService(SealInformationService.class);
    }

    @POST
    @Path("/getPrinterInfo")
    @Produces({MediaType.TEXT_PLAIN})
    public String getPrinterInfo(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----getPrinterInfo-----");
        try{
            String userid = request.getParameter("userid");

            SealInformationService service = getService();
            apidatas = service.getPrinterInfo(userid);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

    @POST
    @Path("/print")
    @Produces({MediaType.TEXT_PLAIN})
    public String print(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----print-----");
        try{
            Map<String,Object> param = ParamUtil.request2Map(request);
            String userid = Util.null2String(param.get("userid"));
            String printerIp = Util.null2String(param.get("printerIp"));
            String printDetail = Util.null2String(param.get("printDetail"));

            SealInformationService service = getService();
            apidatas = service.print(userid,printerIp,printDetail);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }
}
