package com.engine.htsc.sfxzdj.web;

import com.alibaba.fastjson.JSON;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.sfxzdj.service.SfxzdjService;
import com.engine.htsc.sfxzdj.service.impl.SfxzdjServiceImpl;
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 SfxzdjAction {
    private SfxzdjService getSfxzdjService()
        {
            return  ServiceUtil.getService(SfxzdjServiceImpl.class);
        }
    //获取已送的,明细表中处理人是否处理
    @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 = getSfxzdjService().getdoneworkflow(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("/getNg")
    @Produces({MediaType.TEXT_PLAIN})
    public String getNg(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----UnionSealApplicationAction-----");
        try{
            apidatas = getSfxzdjService().getNg(ParamUtil.request2Map(request));
            apidatas.put("code","200");
            apidatas.put("msg","success");
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("code","500");
            apidatas.put("msg",e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

    /**
     * 获取客户号码
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getZhhm")
    @Produces({MediaType.TEXT_PLAIN})
    public String getZhhm(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----UnionSealApplicationAction-----");
        try{
            apidatas = getSfxzdjService().getZhhm(ParamUtil.request2Map(request));
            apidatas.put("code","200");
            apidatas.put("msg","success");
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("code","500");
            apidatas.put("msg",e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

    /**
     * 更新明细表七中用印流程的状态
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/updateState")
    @Produces({MediaType.TEXT_PLAIN})
    public String updateState(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----UnionSealApplicationAction-----");
        try{
            apidatas = getSfxzdjService().updateState(ParamUtil.request2Map(request));
            apidatas.put("code","200");
            apidatas.put("msg","success");
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("code","500");
            apidatas.put("msg",e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }
    /**
     * 触发会签节点用印triggerFlow
     */
    @POST
    @Path("/triggerFlow")
    @Produces({MediaType.TEXT_PLAIN})
    public String triggerFlow(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----UnionSealApplicationAction-----");
        try{
            apidatas = getSfxzdjService().triggerFlow(ParamUtil.request2Map(request));

        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("code","500");
            apidatas.put("msg",e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

}
