package com.engine.htsc.seal.web;


import com.alibaba.fastjson.JSON;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.seal.service.SubSealApplicationService;
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 SubSealApplicationAction {

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

    @POST
    @Path("/getNotThroughType")
    @Produces({MediaType.TEXT_PLAIN})
    public String getNotThroughType(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----subSealApplication-----");
        try{
            SubSealApplicationService subSealApplicationService = getService();
            apidatas = subSealApplicationService.getNotThroughType();
        }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("----subSealApplication-----");
        try{
            String szbm = request.getParameter("szbm");

            SubSealApplicationService subSealApplicationService = getService();
            apidatas = subSealApplicationService.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("/getMember")
    @Produces({MediaType.TEXT_PLAIN})
    public String getMember(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            String szbm = request.getParameter("szbm");

            SubSealApplicationService subSealApplicationService = getService();
            apidatas = subSealApplicationService.getMember(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("/getLeader")
    @Produces({MediaType.TEXT_PLAIN})
    public String getLeader(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----subSealApplication-----");
        try{
            String yz = request.getParameter("yz");
            String szbm = request.getParameter("szbm");

            SubSealApplicationService subSealApplicationService = getService();
            apidatas = subSealApplicationService.getLeader(yz,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("/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("----subSealApplication-----");
        try{
            String yz = request.getParameter("yz");
            String wjlb = request.getParameter("wjlb");
            String wjlx = request.getParameter("wjlx");
            String szbm = request.getParameter("szbm");

            SubSealApplicationService subSealApplicationService = getService();
            apidatas = subSealApplicationService.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("/getNextValue")
    @Produces({MediaType.TEXT_PLAIN})
    public String getNextValue(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----sealApplication-----");
        try{
            String requestid = request.getParameter("requestid");
            String yz = request.getParameter("yz");
            String wjlb = request.getParameter("wjlb");
            String wjlx = request.getParameter("wjlx");

            SubSealApplicationService subSealApplicationService = getService();
            apidatas = subSealApplicationService.getNextValue(requestid,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("/getSubordinateDept")
    @Produces({MediaType.TEXT_PLAIN})
    public String getSubordinateDept(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----subSealApplication-----");
        try{
            String deptid = request.getParameter("deptid");

            SubSealApplicationService subSealApplicationService = getService();
            apidatas = subSealApplicationService.getSubordinateDeptid(deptid);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

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

            SubSealApplicationService subSealApplicationService = getService();
            apidatas = subSealApplicationService.getLicenseList(zzlx,deptid);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

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

            SubSealApplicationService subSealApplicationService = getService();
            apidatas = subSealApplicationService.checkMailLabel(requestid,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("/getOptionRange")
    @Produces({MediaType.TEXT_PLAIN})
    public String getOptionRange(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            String ywzgbm = request.getParameter("ywzgbm");

            SubSealApplicationService subSealApplicationService = getService();
            apidatas = subSealApplicationService.getOptionRange(ywzgbm);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }
}
