package com.engine.htsc.receipt.web;

import com.alibaba.fastjson.JSON;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.receipt.service.ReceiptDirectorService;
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.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.List;
import java.util.Map;

/**
 * create by PTY
 */
public class ReceiptDirectorAction {

    ReceiptDirectorService getService(){
        return ServiceUtil.getService(ReceiptDirectorService.class);
    }

    @POST
    @Path("/getDirector")
    @Produces({MediaType.TEXT_PLAIN})
    public String getDirector(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----receipt-----");
        try{
            String userid = request.getParameter("userid");
            int secLevelMix = Integer.parseInt(request.getParameter("secLevelMix"));
            int secLevelMax = Integer.parseInt(request.getParameter("secLevelMax"));

            ReceiptDirectorService receiptDirectorService = getService();
            List<Map<String,Object>> directorList =  receiptDirectorService.getDirectorByUserid(userid,secLevelMix,secLevelMax);
            apidatas.put("directorList",directorList);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

    @POST
    @Path("/getDepts")
    @Produces({MediaType.TEXT_PLAIN})
    public String getDepts(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----receipt-----");
        try{
            String userids = request.getParameter("userids");

            ReceiptDirectorService receiptDirectorService = getService();
            apidatas = receiptDirectorService.getDepts(userids);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }
}
