package com.engine.htsc.seal.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.seal.service.ManualSignHandleService;
import org.apache.commons.lang.StringUtils;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.comInfo.PropBean;

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;

public class ManualSignHandleAction {

    @GET
    @Path("/receiveSeal")
    @Produces({MediaType.TEXT_PLAIN})
    public String receiveSeal(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        PropBean pb = new PropBean();
        JSONObject apidatas = new JSONObject();
        bs.writeLog("receiveSeal get new message" );

        String recordvalue = Util.null2String(request.getParameter("recordvalue"));
        String newDocid = Util.null2String(request.getParameter("newDocid"));
        try {

            if(StringUtils.isNotBlank(recordvalue))
            {
                JSONObject recordsObject = JSONObject.parseObject(recordvalue);
                bs.writeLog("recordvalue:"+recordvalue);
                bs.writeLog("recordvalue:"+newDocid);
                String flowNum = recordsObject.getString("flowNumber");

                String requestid = JAVATools.getRequestidByRequestMark(flowNum);
                String workflowid = JAVATools.getWorkflowidByRequestid(requestid);
                String workflowType = pb.getWorkflowUnNumberByid(workflowid);
                ManualSignHandleService manualSignHandleService = ServiceUtil.getService(ManualSignHandleService.class);
                return manualSignHandleService.receiveSealNew(recordsObject,requestid,workflowType,newDocid);
            }else{
                apidatas.put("resultMsg","接口参数为空");
                apidatas.put("status", "-1");
            }
        }catch (Exception e){
            bs.writeLog("e99999:"+e);
            apidatas.put("resultMsg","异常");
            apidatas.put("status", "-1");
        }
        return apidatas.toJSONString();
    }
}
