package com.engine.htsc.ReimbursementFlow.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.ReimbursementFlow.Dao.TravelUserdepthDaoImpl;
import com.engine.htsc.ReimbursementFlow.Service.Impl.TravelUserdepthServiceImpl;
import com.engine.htsc.ReimbursementFlow.Service.TravelUserdepthService;
import com.google.gson.JsonArray;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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.*;

public class TravelUserdepth {

    TravelUserdepthService getService() {
        return ServiceUtil.getService(TravelUserdepthServiceImpl.class);
    }

    @POST
    @Path("/GetUserDepth")
    @Produces({MediaType.TEXT_PLAIN})
    public String GetUserDepth(@Context HttpServletRequest request,
                                     @Context HttpServletResponse response){
     //  String requestid= request.getParameter("body");

        String value= request.getParameter("detailparams");
       if("".equals(value)){
           return JAVATools.Apiretrun("400","参数不允许为空");
       }
       JSONArray jsonArray=JSONArray.parseArray(value);
        if(jsonArray.size()<0){
        return JAVATools.Apiretrun("400","参数不允许为空");
        }
        List detaillist=new ArrayList<>();
        try {
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonobject = (JSONObject) jsonArray.get(i);
                Map<String, Object> map = JSON.parseObject(jsonobject.toString(), HashMap.class);
                detaillist.add(map);
            }
        }catch (Exception e){
            return JAVATools.Apiretrun("400","json格式有误");
        }
        if(detaillist.size()<=0){
            return JAVATools.Apiretrun("400","json格式有误");
        }
        TravelUserdepthService travelUserdepthService=  getService();
         JSONObject jsonObject= travelUserdepthService.getUserdistdepth(detaillist);
         return  JAVATools.Apiretrun("200",jsonObject);
    }




}


