package com.engine.htsc.ydbx.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.ydbx.service.MobileReimbursableService;
import com.engine.htsc.ydbx.service.impl.MobileReimServiceImpl;
import weaver.general.Util;
import weaver.workflow.logging.Logger;
import weaver.workflow.logging.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
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 MobileReimbursable {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private MobileReimbursableService getService() {
        return ServiceUtil.getService(MobileReimServiceImpl.class);
    }

    @GET
    @Path("/getCanCreateWf")
    @Produces({MediaType.APPLICATION_JSON})
    public String getCanCreateWf(@Context HttpServletRequest request) {
        logger.info("==============进入获取指定人指定流程类中所有可以发起的流程");
        String loginId = Util.null2String(request.getParameter("loginId"));
        String bxlx = Util.null2String(request.getParameter("bxlx"));
        Map<String, Object> params = new HashMap<>();
        params.put("loginId", loginId);
        params.put("bxlx", bxlx);
        logger.info("传递的参数是：" + JSONObject.toJSONString(params));
        return JSONObject.toJSONString(getService().getCanCreateWf(params));
    }

    @GET
    @Path("/openWfByDept")
    @Produces({MediaType.APPLICATION_JSON})
    public String openWfByDept(@Context HttpServletRequest request){
        logger.info("==============移动报销，给予部门维度选择需要创建的流程");
        String loginId = Util.null2String(request.getParameter("loginId"));
        String bxlx = Util.null2String(request.getParameter("bxlx"));
        Map<String, Object> params = new HashMap<>();
        params.put("loginId", loginId);
        params.put("bxlx", bxlx);
        logger.info("传递的参数是：" + JSONObject.toJSONString(params));
        return JSONObject.toJSONString(getService().openWfByDeptService(params));
    }
}
