package com.weavernorth.nsyh.opinion.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.weavernorth.nsyh.opinion.service.WfOpinionService;
import com.weavernorth.nsyh.opinion.service.impl.WfOpinionServiceImpl;
import weaver.general.BaseBean;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

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;

/**
 * @Author : 孙浩
 * @Date : 2022/3/1 9:40
 * @Version 1.0
 */
public class WfOpinionAction extends BaseBean {

    private WfOpinionService getService(User user) {
        return (WfOpinionServiceImpl) ServiceUtil.getService(WfOpinionServiceImpl.class, user);
    }

    /**
     * 根据流程id获取需要隐藏签字意见相关信息的节点id
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getNodes")
    @Produces({MediaType.TEXT_PLAIN})
    public String getNodes(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apidatas.putAll(getService(user).getNodes(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }
}