package com.sagacloud.endpoints;

import com.sagacloud.json.JSONObject;
import com.sagacloud.json.JSONValue;
import com.sagacloud.utils.DpUtils;
import com.sagacloud.utils.ZillionAgentProvider;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
 * Created by Xiaoyu on 2018/2/27
 */
@Path("dao")
public class DAO {
    @Path("/{dataBase}/{dataTable}/{queryType}")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String query(@PathParam("dataBase") String dataBase,@PathParam("dataTable") String dataTable,@PathParam("queryType") String queryType,String jsonStr) {
        JSONObject json = (JSONObject) JSONValue.parse(jsonStr);
        json.put("Database",dataBase);
        json.put("Datatable",dataTable);
        json.put("QueryType",queryType);
        /*if(dataBase.equals(OssUtils.getProperty("database.name")))
            return DpUtils.errorJsonMsg("无权操作该数据库："+dataBase);*/
//        return json.toString();
        try {
            return ZillionAgentProvider.GetAgent().Query(json).toString();
        } catch (Exception e) {
            e.printStackTrace();
            return DpUtils.errorJsonMsg("数据库请求出错");
        }
    }
}
