package com.engine.htsc.mhjc.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.mhjc.service.HtscMhjcService;
import com.engine.htsc.mhjc.service.impl.HtscMhjcServiceImpl;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
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 htscMhjcAction {

    public HtscMhjcService getService(){
        return ServiceUtil.getService(HtscMhjcServiceImpl.class);
    }

    /**
     * 看阅新门户集成接口，列表数据
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getkanyuelist")
    @Produces({MediaType.TEXT_PLAIN})
    public String getkanyuelist(@Context HttpServletRequest request, @Context HttpServletResponse response){

        BaseBean bb = new BaseBean();
        String htuserid = request.getHeader("iv-user");
        bb.writeLog("htuserid:"+htuserid);

        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            if(!"".equals(htuserid) && !"null".equals(htuserid) && htuserid !=null)
            {
                param.put("workcode",htuserid);
            }
            apidatas = getService().queryKanyueList(param);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }


    /***
     * 看阅新门户集成接口，总数
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getkanyueTotal")
    @Produces({MediaType.TEXT_PLAIN})
    public String getkanyueTotal(@Context HttpServletRequest request, @Context HttpServletResponse response){

        BaseBean bb = new BaseBean();
        String htuserid = request.getHeader("iv-user");
        bb.writeLog("htuserid:"+htuserid);

        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            if(!"".equals(htuserid) && !"null".equals(htuserid) && htuserid !=null)
            {
                param.put("workcode",htuserid);
            }
            apidatas = getService().queryKanyueTotal(param);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }


    /***
     * 协作门户集成接口，列表数据
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getcoworklist")
    @Produces({MediaType.TEXT_PLAIN})
    public String getCoworkList(@Context HttpServletRequest request, @Context HttpServletResponse response){

        BaseBean bb = new BaseBean();
        String htuserid = request.getHeader("iv-user");
        bb.writeLog("htuserid:"+htuserid);

        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            if(!"".equals(htuserid) && !"null".equals(htuserid) && htuserid !=null)
            {
                param.put("workcode",htuserid);
            }
            apidatas = getService().getCoworkList(param);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /***
     * 协助门户集成接口，总数
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getcoworktotle")
    @Produces({MediaType.TEXT_PLAIN})
    public String getCoworkTotle(@Context HttpServletRequest request, @Context HttpServletResponse response){

        BaseBean bb = new BaseBean();
        String htuserid = request.getHeader("iv-user");
        bb.writeLog("htuserid:"+htuserid);

        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            if(!"".equals(htuserid) && !"null".equals(htuserid) && htuserid !=null)
            {
                param.put("workcode",htuserid);
            }
            apidatas = getService().getCoworTotal(param);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }


    /***
     * 看阅老门户集成接口，列表,名字写错了的
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getcoworklistforold")
    @Produces({MediaType.TEXT_PLAIN})
    public String getCoworkListForOld(@Context HttpServletRequest request, @Context HttpServletResponse response){

        BaseBean bb = new BaseBean();
        String htuserid = request.getHeader("iv-user");
        bb.writeLog("htuserid:"+htuserid);
        String dataString = "" ;
        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            if(!"".equals(htuserid) && !"null".equals(htuserid) && htuserid !=null)
            {
                param.put("workcode",htuserid);
            }
            String callback = Util.null2String(param.get("callback"));
            apidatas = getService().queryKanyueListForOld(param);
            dataString = callback+"("+JSONObject.toJSONString(apidatas)+")";
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return dataString;
    }

    /***
     * 看阅老门户集成接口，列表
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getkanyuelistforold")
    @Produces({MediaType.TEXT_PLAIN})
    public String getkanyuelistforold(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bb = new BaseBean();
        String htuserid = request.getHeader("iv-user");
        bb.writeLog("htuserid:"+htuserid);
        String dataString = "" ;
        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            if(!"".equals(htuserid) && !"null".equals(htuserid) && htuserid !=null)
            {
                param.put("workcode",htuserid);
            }
            String callback = Util.null2String(param.get("callback"));
            apidatas = getService().queryKanyueListForOld(param);
            dataString = callback+"("+JSONObject.toJSONString(apidatas)+")";
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return dataString;
    }

    /***
     * 看阅接口，列表
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getkanyuelistforpage")
    @Produces({MediaType.TEXT_PLAIN})
    public String getkanyuelistforpage(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bb = new BaseBean();
        ResourceComInfo resourceComInfo = null;
        String dataString = "" ;
        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            resourceComInfo = new ResourceComInfo();
            User user = HrmUserVarify.getUser(request, response);
            Map<String,Object> param = ParamUtil.request2Map(request);
            int userid = user.getUID();
            String htuserid = resourceComInfo.getWorkcode(userid+"");
            if(!"".equals(htuserid) && !"null".equals(htuserid) && htuserid !=null)
            {
                param.put("workcode",htuserid);
            }
            String callback = Util.null2String(param.get("callback"));
            apidatas = getService().queryKanyueListForOld(param);
            dataString = callback+"("+JSONObject.toJSONString(apidatas)+")";
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return dataString;
    }


    @GET
    @Path("/getcoworktasklist")
    @Produces({MediaType.TEXT_PLAIN})
    public String getCoworkTaskList(@Context HttpServletRequest request, @Context HttpServletResponse response){

        BaseBean bb = new BaseBean();
        String htuserid = request.getHeader("iv-user");
        bb.writeLog("htuserid:"+htuserid);
        String dataString = "" ;
        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            if(!"".equals(htuserid) && !"null".equals(htuserid) && htuserid !=null)
            {
                param.put("workcode",htuserid);
            }
            String callback = Util.null2String(param.get("callback"));
            apidatas = getService().getCoworkTaskList(param);
            dataString = callback+"("+JSONObject.toJSONString(apidatas)+")";
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return dataString;
    }



    @GET
    @Path("/getgonggaoklist")
    @Produces({MediaType.TEXT_PLAIN})
    public String getGongGaoklist(@Context HttpServletRequest request, @Context HttpServletResponse response){

        BaseBean bb = new BaseBean();
        String htuserid = request.getHeader("iv-user");
        bb.writeLog("htuserid:"+htuserid);
        String dataString = "" ;
        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            if(!"".equals(htuserid) && !"null".equals(htuserid) && htuserid !=null)
            {
                param.put("workcode",htuserid);
            }
            String callback = Util.null2String(param.get("callback"));
            apidatas = getService().getGongGaoklist(param);
            dataString = callback+"("+JSONObject.toJSONString(apidatas)+")";
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return dataString;
    }



    @GET
    @Path("/getTzydZylist")
    @Produces({MediaType.TEXT_PLAIN})
    public String getTzydZylist(@Context HttpServletRequest request, @Context HttpServletResponse response){

        BaseBean bb = new BaseBean();
        String htuserid = request.getHeader("iv-user");
        bb.writeLog("htuserid:"+htuserid);
        String dataString = "" ;
        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            if(!"".equals(htuserid) && !"null".equals(htuserid) && htuserid !=null)
            {
                param.put("workcode",htuserid);
            }
            String callback = Util.null2String(param.get("callback"));
            apidatas = getService().getTzydZylist(param);
            dataString = callback+"("+JSONObject.toJSONString(apidatas)+")";
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return dataString;
    }



    @GET
    @Path("/getkanyuelistforportal")
    @Produces({MediaType.TEXT_PLAIN})
    public String getkanyuelistforportal(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bb = new BaseBean();
        bb.writeLog("1："+System.currentTimeMillis());
        String htuserid = request.getHeader("iv-user");
        bb.writeLog("htuserid:"+htuserid);
        String dataString = "" ;
        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            if(!"".equals(htuserid) && !"null".equals(htuserid) && htuserid !=null)
            {
                param.put("workcode",htuserid);
            }
            bb.writeLog("2："+System.currentTimeMillis());
            String callback = Util.null2String(param.get("callback"));
            bb.writeLog("3："+System.currentTimeMillis());
            apidatas = getService().getkanyuelistforportal(param);
            dataString = callback+"("+JSONObject.toJSONString(apidatas)+")";
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return dataString;
    }


    @GET
    @Path("/getgonggaolistforportal")
    @Produces({MediaType.TEXT_PLAIN})
    public String getgonggaolistforportal(@Context HttpServletRequest request, @Context HttpServletResponse response){

        BaseBean bb = new BaseBean();
        String htuserid = request.getHeader("iv-user");
        bb.writeLog("htuserid:"+htuserid);
        String dataString = "" ;
        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            if(!"".equals(htuserid) && !"null".equals(htuserid) && htuserid !=null)
            {
                param.put("workcode",htuserid);
            }
            String callback = Util.null2String(param.get("callback"));
            apidatas = getService().getgonggaolistforportal(param);
            dataString = callback+"("+JSONObject.toJSONString(apidatas)+")";
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return dataString;
    }




}
