package com.engine.htsc.clsysq.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.clsysq.service.ClsysqService;
import com.engine.htsc.clsysq.service.impl.ClsysqServiceImpl;
import org.apache.commons.collections.map.HashedMap;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;

import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;


public class ClsysqAction {

    private ClsysqService getService() {
        return ServiceUtil.getService(ClsysqServiceImpl.class);
    }

    /**
     * 根据当前节点操作者获取对应的部门类型
     * */
    @GET
    @Path("/getngrbm/{ngrid}")
    @Produces({MediaType.APPLICATION_JSON})
    public String getNgrbmlx(
            @PathParam("ngrid") String ngrid,
            @Context HttpServletRequest request,
            @Context HttpServletResponse response) {
        Map<String,Object> map = new HashMap<>();
        BaseBean bb = new BaseBean();
        User user = HrmUserVarify.getUser(request, response);
        bb.writeLog("前端传递的拟稿人id是："+ngrid);
        Map<String, Object> params = new HashMap<>();
        params.put("id",ngrid);
        Map<String,Object> bmlxMap = getService().getBmlx(params,user);
        String bmlx = Util.null2String(bmlxMap.get("bmid"));
        bb.writeLog("从数据库中查询的部门类型结果是：" + bmlx);
        if ("JGLX01".equals(bmlx)){
            map.put("bmlx","0");
        }else if ("JGLX02".equals(bmlx)){
            map.put("bmlx","3");
        }else if ("JGLX03".equals(bmlx)){
            map.put("bmlx","1");
        }else if ("JGLX04".equals(bmlx)){
            map.put("bmlx","2");
        }
        bb.writeLog("传给前端的值是："+JSONObject.toJSONString(map));
        return JSONObject.toJSONString(map);
    }


}
