package com.engine.htsc.tripInfo.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.tripInfo.service.TripInfoService;
import com.engine.htsc.tripInfo.service.impl.TripInfoServiceImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

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.HashMap;
import java.util.Map;

/**
 * Author:DTY-PC
 * Date:2020/10/29 11:11
 * Description:
 * Copyright:上海泛微网络科技股份有限公司
 */
public class TripInfoAction {
    private Log log = LogFactory.getLog(this.getClass());
    private TripInfoService getService(User user){
        return ServiceUtil.getService(TripInfoServiceImpl.class,user);
    }

    @POST
    @Path("/getTripInfo")
    @Produces(MediaType.TEXT_PLAIN)
    public String getTripInfo(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            Map<String,Object> para = ParamUtil.request2Map(request);
            apidatas.putAll(getService(user).getTripInfo(para));
            apidatas.put("api_status", true);
        }catch (Exception e){
            e.printStackTrace();
            apidatas.put("api_status",false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
            log.error("getTripInfo catch exception");
        }
        return JSONObject.toJSONString(apidatas);

    }
}
