package com.engine.htsc.equipment.web;

import com.alibaba.fastjson.JSON;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.equipment.service.EquipmentPurchaseService;
import weaver.general.BaseBean;

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;

public class EquipmentPurchaseAction {

    EquipmentPurchaseService getService(){
        return ServiceUtil.getService(EquipmentPurchaseService.class);
    }

    @POST
    @Path("/getEquipmentInfoByRequestid")
    @Produces({MediaType.TEXT_PLAIN})
    public String getEquipmentInfoByRequestid(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----EquipmentPurchaseAction-----");
        try{
            String gllc = request.getParameter("gllc");

            EquipmentPurchaseService service = getService();
            apidatas = service.getEquipmentInfoByRequestid(gllc);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

    @POST
    @Path("/getAllFinish")
    @Produces({MediaType.TEXT_PLAIN})
    public String getAllFinish(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----EquipmentPurchaseAction-----");
        try{
            EquipmentPurchaseService service = getService();
            apidatas = service.getAllFinish();
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

    @POST
    @Path("/restoreEquipmentInfoAfterTerminate")
    @Produces({MediaType.TEXT_PLAIN})
    public String restoreEquipmentInfoAfterTerminate(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----EquipmentPurchaseAction-----");
        try{
            String requestid = request.getParameter("requestid");

            EquipmentPurchaseService service = getService();
            apidatas = service.restoreEquipmentInfoAfterTerminate(requestid);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

}
