package com.engine.htsc.yghmzczysq.web;

import com.alibaba.fastjson.JSON;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.lhcd.Service.impl.LhcdWorkflowBaseServiceimpl;
import com.engine.htsc.yghmzczysq.service.ZysqWorkflowService;
import com.engine.htsc.yghmzczysq.service.impl.ZysqWorkflowServiceImpl;
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 ZysqApi {
    private ZysqWorkflowService zysqWorkflowService(){
        return ServiceUtil.getService(ZysqWorkflowServiceImpl.class);
    }
//    @POST
//    @Path("/noticeSignDeptCoDirector")
//    @Produces({MediaType.TEXT_PLAIN})
//    public String noticeSignDeptCoDirector(@Context HttpServletRequest request, @Context HttpServletResponse response){
//        BaseBean bs = new BaseBean();
//        Map<String, Object> apidatas = new HashMap<String, Object>();
//        bs.writeLog("----UnionSealApplicationAction-----");
//        try{
//            String requestid = request.getParameter("requestid");
//            String nodeid = request.getParameter("nodeid");
//            String deptid = request.getParameter("deptid");
//            apidatas = zysqWorkflowService().noticeSignDeptCoDirector(requestid,nodeid,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("/checkCoDirectorNotice")
//    @Produces({MediaType.TEXT_PLAIN})
//    public String checkCoDirectorNotice(@Context HttpServletRequest request, @Context HttpServletResponse response){
//        BaseBean bs = new BaseBean();
//        Map<String, Object> apidatas = new HashMap<String, Object>();
//        bs.writeLog("----UnionSealApplicationAction-----");
//        try{
//            String requestid = request.getParameter("requestid");
//            String nodename = request.getParameter("nodename");
//            apidatas = zysqWorkflowService().checkCoDirectorNotice(requestid,nodename);
//        }catch (Exception e) {
//            e.printStackTrace();
//            apidatas.put("api_status", false);
//            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
//        }
//
//        return JSON.toJSONString(apidatas);
//    }

    /**
     * 通过人员id获取人员的安全级别
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getSeclevel")
    @Produces({MediaType.TEXT_PLAIN})
    public String getSeclevel(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bb = new BaseBean();
        HashMap<String, String> map = new HashMap<>();
        try{
            String userid = request.getParameter("userid");
            bb.writeLog("人员userid"+userid);
            map = zysqWorkflowService().getSeclevel(userid);
        }catch (Exception e){
            bb.writeLog("通过人员id获取人员的安全级别"+e.getMessage());
        }

        return JSON.toJSONString(map);
    }

    /**
     * 通过拟稿人获取上级部门负责人取值
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getLeader")
    @Produces({MediaType.TEXT_PLAIN})
    public String getLeader(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bb = new BaseBean();
        HashMap<String, Object> map = new HashMap<>();
        try{
            String userid = request.getParameter("userid");
            bb.writeLog("人员userid"+userid);
            map = zysqWorkflowService().getLeader(userid);
        }catch (Exception e){
            bb.writeLog("通过拟稿人获取上级部门负责人取值"+e.getMessage());
        }

        return JSON.toJSONString(map);
    }

    /**
     * 获取内部审核人员
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getNbshUser")
    @Produces({MediaType.TEXT_PLAIN})
    public String getNbshUser(@Context HttpServletRequest request, @Context HttpServletResponse response){

        BaseBean bb = new BaseBean();
        HashMap<String, Object> map = new HashMap<>();
        try{
            String deptid = request.getParameter("deptid");
            map = zysqWorkflowService().getNbshUser(deptid);
        }catch (Exception e){
            bb.writeLog("获取内部审核人员"+e.getMessage());
        }

        return JSON.toJSONString(map);
    }
    @POST
    @Path("/getNbsh")
    @Produces({MediaType.TEXT_PLAIN})
    public String getNbsh(@Context HttpServletRequest request, @Context HttpServletResponse response){

        BaseBean bb = new BaseBean();
        HashMap<String, Object> map = new HashMap<>();
        try{
            String requestid = request.getParameter("requestid");
            String formid = request.getParameter("formid");
            String deptid = request.getParameter("deptid");
            map = zysqWorkflowService().getNbsh(requestid,formid,deptid);
        }catch (Exception e){
            bb.writeLog("获取内部审核人员"+e.getMessage());
        }

        return JSON.toJSONString(map);
    }
}
