package com.engine.htsc.ReimbursementFlow.web;

import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.ReimbursementFlow.Service.Impl.ReimbursementExcelServiceImpl;
import com.engine.htsc.ReimbursementFlow.Service.ReimbursementExcelService;
import com.engine.htsc.trip.util.AjaxResult;
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;

public class ReimbursementExcel {
    private ReimbursementExcelService getService(User user) {
        return ServiceUtil.getService(ReimbursementExcelServiceImpl.class, user);
    }


    @POST
    @Path("/exportExcel")
    @Produces({MediaType.APPLICATION_JSON})
    public AjaxResult<String> exportExcel(@Context HttpServletRequest request,
                                          @Context HttpServletResponse response) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            String resultStr = this.getService(user).exportPaymentDetailExcel(ParamUtil.request2Map(request));
            return AjaxResult.ok(resultStr);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("catch exception:" + e);
        }

    }
}
