package com.engine.htsc.payment.web;

import com.engine.common.util.ServiceUtil;
import com.engine.htsc.payment.service.PaymentCubeService;
import com.engine.htsc.payment.service.impl.PaymentCubeServiceImpl;

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.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

public class PaymentCubeAction {

    private Log log = LogFactory.getLog(this.getClass());
    private PaymentCubeService getService(User user){
        return ServiceUtil.getService(PaymentCubeServiceImpl.class,user);
    }


    /**
     * 建模总部出纳付款更新流程阅读状态01
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/updateReadStatus")
    @Produces({MediaType.APPLICATION_JSON})
    public Map<String,Object> updateReadStatus(@Context HttpServletRequest request,
                                             @Context HttpServletResponse response,
                                               @QueryParam("requestid") String requestid){
        Map<String, Object> apidatas = new HashMap<>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apidatas = this.getService(user).updateReadStatus(requestid);
            apidatas.put("api_status", 1);
        }catch (Exception e){
            e.printStackTrace();
            apidatas.put("api_status",-1);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return apidatas;
    }


    /**
     * 建模总部出纳付款更新流程打印状态01
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/updatePrintStatus")
    @Produces({MediaType.APPLICATION_JSON})
    public Map<String,Object> updatePrintStatus(@Context HttpServletRequest request,
                                               @Context HttpServletResponse response,
                                               @QueryParam("ids") String ids){
        Map<String, Object> apidatas = new HashMap<>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            apidatas = this.getService(user).updatePrintStatus(ids);
            apidatas.put("success", true);
        }catch (Exception e){
            e.printStackTrace();
            apidatas.put("success",false);
            apidatas.put("errormsg", "catch exception : " + e.getMessage());
        }
        return apidatas;
    }
}
