package com.engine.htsc.xgtyfk.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.trip.util.AjaxResult;
import com.engine.htsc.xgtyfk.service.GetHkHlService;
import com.engine.htsc.xgtyfk.service.impl.GetHkHlServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
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.Map;

/**
 * @Describe 获取港币汇率
 */
public class GetHkHlAction {

    private GetHkHlService getService() {
        return ServiceUtil.getService(GetHkHlServiceImpl.class);
    }

    @POST
    @Path("/getExchangeRate")
    @Produces(MediaType.APPLICATION_JSON)
    public AjaxResult<Map<String, String>> getExchangeRate(@Context HttpServletRequest request) {
        try {
            Map<String, String> resp = this.getService().queryExchangeRate();
            return AjaxResult.ok(resp);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }

    @GET
    @Path("/getHkLv")
    @Produces({MediaType.APPLICATION_JSON})
    public String getHkExchange(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, String> resp = this.getService().queryExchangeRate();
        return JSONObject.toJSONString(resp);
    }
}
