package com.engine.htsc.lhhtsq.Web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.jgxt.service.JgxtVfServer;
import com.engine.htsc.jgxt.service.imp.JgxtVfServerImp;
import com.engine.htsc.lhhtsq.Serivce.LhhtsqBaseService;
import com.engine.htsc.lhhtsq.Serivce.impl.LhhtsqBaseServiceImpl;
import com.engine.htsc.seal.service.UnionSealApplicationService;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

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;

/**
 * @author xf
 * @version 1.0.0
 * @ClassName lhhtsqAction.java
 * @createTime 2021年12月10日 19:54:00
 */
public class LhhtsqAction {

    private LhhtsqBaseService getlhhtsqbaseService()
    {
        return ServiceUtil.getService(LhhtsqBaseServiceImpl.class);
    }


    //获取已送的
    @POST
    @Path("/getsealadmin")
    @Produces({MediaType.TEXT_PLAIN})
    public String getsealadmin(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----UnionSealApplicationAction-----");
        try{
            apidatas = getlhhtsqbaseService().workflowdone(ParamUtil.request2Map(request));
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

    /*
     * @title gettypetoReaduserids
     * @remark 根据类型获取对应的通知阅读人
     * @author xf
     * @Params：
       * @param: request
     * @param: response
     * @updateTime 2021/12/15 14:43
     * @return: java.lang.String
     **/
    @POST
    @Path("/gettypetoReaduserids")
    @Produces({MediaType.TEXT_PLAIN})
    public String gettypetoReaduserids(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        JSONObject  jsonObject=new JSONObject();
        bs.writeLog("----UnionSealApplicationAction-----");
        try{
              jsonObject = getlhhtsqbaseService().gettypetoReaduserids(ParamUtil.request2Map(request));

        }catch (Exception e) {
         //   e.printStackTrace();
            return JAVATools.Apiretrun("400","请检查参数");
           }
        return JAVATools.Apiretrun("200",jsonObject);

    }


    //获取已送的
    @POST
    @Path("/getdoneworkflow")
    @Produces({MediaType.TEXT_PLAIN})
    public String getdoneworkflow(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----UnionSealApplicationAction-----");
        try{
            apidatas = getlhhtsqbaseService().workflowdone(ParamUtil.request2Map(request));
        }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 = getlhhtsqbaseService().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);
    }
    @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 = getlhhtsqbaseService().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("/workflowisend")
    @Produces({MediaType.TEXT_PLAIN})
    public String workflowisend(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        boolean apidatas=true;
        bs.writeLog("----UnionSealApplicationAction-----");
        try{
            apidatas = getlhhtsqbaseService().worklfowisend(ParamUtil.request2Map(request));
        }catch (Exception e) {
            e.printStackTrace();
        }
         return JAVATools.Apiretrun("200",apidatas);
    }

    @POST
    @Path("/firstseal")
    @Produces({MediaType.TEXT_PLAIN})
    public String firstseal(@Context HttpServletRequest request, @Context HttpServletResponse response){
       JSONObject apidatas = getlhhtsqbaseService().firstseal(ParamUtil.request2Map(request));
        if("".equals(Util.null2String(apidatas.get("message"))) ){
            return JAVATools.Apiretrun("200",apidatas);
        }else{
            return JAVATools.Apiretrun("400",apidatas);
        }
    }




}
