package com.engine.htsc.workflow.web;

import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.payment.service.PaymentWorkflowService;
import com.engine.htsc.payment.service.impl.PaymentWorkflowServiceImpl;
import com.engine.htsc.response.utils.ResultVoUtil;
import com.engine.htsc.response.vo.ResultVo;
import com.engine.htsc.workflow.service.WorkflowShelveService;
import com.engine.htsc.workflow.service.impl.WorkflowShelveServiceImpl;
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.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 WorkflowShelveAction {
    private Log log = LogFactory.getLog(this.getClass());
    private WorkflowShelveService getService(User user){
        return ServiceUtil.getService(WorkflowShelveServiceImpl.class,user);
    }

    /**
     * 流程实现搁置功能
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/shelvebtn")
    @Produces({MediaType.APPLICATION_JSON})
    public Map<String,Object> shelveButton(@Context HttpServletRequest request,
                                             @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apidatas = this.getService(user).workflowShelveButton(ParamUtil.request2Map(request),user);
            //postman测试
            //apidatas = ServiceUtil.getService(PaymentWorkflowServiceImpl.class).getVirtualDept();
            apidatas.put("code", 200);
        }catch (Exception e){
            e.printStackTrace();
            apidatas.put("code",500);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
            log.error("shelveButton catch exception");
        }
        return apidatas;
    }

    @GET
    @Path("/receiveTime")
    @Produces({MediaType.APPLICATION_JSON})
    public ResultVo getReceiveTime(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apidatas = getService(user).getReceiveTime(ParamUtil.request2Map(request));
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultVoUtil.success("操作成功",apidatas);
    }


}
