package com.engine.htsc.seal.web;

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

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 ZgSealApplicationAction {

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

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

            ZgSealApplicationService service = getService();
            apidatas = service.getDeptBySealAndFileType(yz,wjlb,wjlx,szbm);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }


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

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

        return JSON.toJSONString(apidatas);
    }

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

            ZgSealApplicationService service = getService();
            apidatas = service.getPassLeader(requestid,nodeUnNumber);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

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

            ZgSealApplicationService service = getService();
            apidatas = service.getSendType(yz,wjlb,wjlx);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

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

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

        return JSON.toJSONString(apidatas);
    }
}
