package com.sagacloud.endpoints;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sagacloud.endpoints.customDict.CtmDictFollower;
import com.sagacloud.endpoints.customDict.CtmNode;
import com.sagacloud.utils.Const;
import com.sagacloud.utils.DpUtils;
import com.sagacloud.utils.OssUtils;
import org.apache.commons.collections.ListUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.*;
import javax.ws.rs.container.ResourceContext;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.*;

@Path("dict")
public class Dictionary {
    private static final Logger log = LoggerFactory.getLogger(Dictionary.class);

    @Context
    private ResourceContext resourceContext;

    private static Hashtable<String, String> dict = new Hashtable<>();
    static String returnJson = "{\"Result\": \"success\", \"Content\": {},\"ResultMsg\": \"\" }";
    final static String dictBasepath = "property/Dictionary/";
    public final static String newFacilityPath = dictBasepath + "Facility_new.json";
    public final static String eqFamilyPath = dictBasepath + "EqFamily.json";
    public final static String geographyPath = dictBasepath + "Geography.json";
    public final static String climatePath = dictBasepath + "B_climate.json";
    public final static String developPath = dictBasepath + "C_developingLevel.json";
    public final static String weatherPath = dictBasepath + "D_weatherCondition.json";
    public final static String windPath = dictBasepath + "E_wind.json";
    public final static String directionPath = dictBasepath + "F_direction.json";
    public final static String buildingFunctionPath = dictBasepath + "G_buildingFunction.json";
    public final static String spaceFunctionPath = dictBasepath + "H_spaceFunction.json";
    public final static String rentalPath = dictBasepath + "I_rental.json";
    //
    public final static String dustproofPath = dictBasepath + "K_dustproofLevel.json";
    public final static String waterproofPath = dictBasepath + "K_waterproofLevel.json";
    public final static String dangerAreaPath = dictBasepath + "M_dangerArea.json";
    public final static String explosionproofEquipmentPath = dictBasepath + "M_explosionproofEquipment.json";
    public final static String explosionproofGasAndTemperaturePath = dictBasepath + "M_explosionproofGas&Temperature.json";
    public final static String explosionproofTypePath = dictBasepath + "M_explosionproofType.json";
    public final static String globalReltionDefination = dictBasepath + "GlobalRelation.json";
    public final static String standardEnergyItem = dictBasepath + "StandardEnergyItem.json";

    public final static String pollutionLevel = dictBasepath + "PollutionLevel.json";
    public final static String contaminationLevel = dictBasepath + "ContaminationLevel.json";
    public final static String avgTemperature2016 = dictBasepath + "averageTemperature2016.json";
    public final static String antiEarthquake = dictBasepath + "10_SeismicPrecautionaryIntensity.json";//抗震设防烈度
    public final static String virtualObject = dictBasepath + "VirtualObject.json";//虚拟对象类型
    public final static String CALENDAR_TAG = dictBasepath + "CalendarTag.json";//日历标签
    public final static String CALENDAR_INTERVAL = dictBasepath + "CalendarInterval.json";//日历标签
    public final static String CONSUMABLE_PATH = dictBasepath + "consumableRel.json";
    public final static String TOOL_PATH = dictBasepath + "toolRel.json";


    // get转post
    @Path("/query/equipment_all")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String equipment_all_keyPost(@QueryParam(Const.PROJECT_ID) String projectId, String jsonStr) {
        if(projectId == null && OssUtils.getProperty("default.project.id") != null){
            projectId = OssUtils.getProperty("default.project.id");
        }
        JSONObject jsonObject = JSONObject.parseObject(jsonStr);
        Boolean format = jsonObject.getBoolean("format");
        return equipment_all_key(projectId, format);
    }

    private void rmFields(JSONArray arr) {
        String fields[] = {"code", "name", "content"};
        arr.forEach(o -> {
            JSONObject item = (JSONObject) o;
            List<String> toDels = ListUtils.subtract(new ArrayList(item.keySet()), Arrays.asList(fields));
            toDels.forEach(del -> item.remove(del));
            if (item.get("content") != null) {
                this.rmFields(item.getJSONArray("content"));
            }
        });
    }

    /**
     * 查询项目follow的自定义字典id
     *
     * @param pjId
     * @return
     */
    public String queryDictId(String pjId) {
        JSONObject queDictBody = new JSONObject().fluentPut("project_id", pjId);
        JSONArray arr = JSONObject.parseObject(resourceContext.getResource(CtmDictFollower.class).queryFollower(queDictBody.toString())).getJSONArray("Content");
        if (arr.isEmpty()) {
            return null;
        }
        return arr.getJSONObject(0).getString("id");
    }

    /**
     * 返回项目的自定义字典的设备内容
     *
     * @param pjId
     * @param format
     * @return
     * @throws Exception
     */
    private String queryCtmEq(String pjId, boolean format) throws Exception {
        if (pjId == null) {
            return null;
        }
        String dictId = this.queryDictId(pjId);
        if (dictId == null) {
            return null;
        }
        JSONObject body = new JSONObject().fluentPut("dict_id", dictId).fluentPut("show_as_tree", true);
        JSONObject reJson = JSONObject.parseObject(resourceContext.getResource(CtmNode.class).queryAllEqNodes(body.toString()));
        this.rmFields(reJson.getJSONArray("Content"));
        if (format) {
            return reJson.toString();
        }
        reJson.getJSONArray("Content").forEach(o -> {
            JSONObject major = (JSONObject) o;
            major.fluentPut("class", major.getString("name")).fluentRemove("name");
            if (major.get("content") == null) {
                return;
            }
            major.getJSONArray("content").forEach(o1 -> {
                JSONObject sys = (JSONObject) o1;
                sys.fluentPut("system", sys.getString("name")).fluentRemove("name");
                if (sys.get("content") == null) {
                    return;
                }
                sys.getJSONArray("content").forEach(o2 -> {
                    JSONObject eq = (JSONObject) o2;
                    eq.fluentPut("facility", eq.getString("name")).fluentRemove("name");
                    if (eq.get("content") == null) {
                        return;
                    }
                    eq.getJSONArray("content").forEach(o3 -> {
                        JSONObject pe = (JSONObject) o3;
                        pe.fluentPut("component", pe.getString("name")).fluentRemove("name");
                    });
                    eq.fluentPut("components", eq.get("content")).fluentRemove("content");
                });
            });
        });
        return reJson.fluentRemove("Count").toString();
    }

    @Path("/query/equipment_all")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String equipment_all_key(@QueryParam(Const.PROJECT_ID) String projectId, @QueryParam("format") Boolean format) {
        if(projectId == null && OssUtils.getProperty("default.project.id") != null){
            projectId = OssUtils.getProperty("default.project.id");
        }
        try {
            if (format == null) {
                format = false;
            }
            //先查询自定义内容
            if (projectId != null) {
                String re = this.queryCtmEq(projectId, format);
                if (re != null) {
                    return re;
                }
            }
            if (!dict.containsKey(newFacilityPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(newFacilityPath))).get("all"));
                dict.put(newFacilityPath, json.toJSONString());
            }
        } catch (Exception ex) {
            log.error("", ex);
            return "{\"error\":\"获取设备信息失败!\"}";
        }
        if (format != null && format) {
            JSONObject resp = JSONObject.parseObject(returnJson);
            JSONArray content = JSONObject.parseObject(dict.get(newFacilityPath)).getJSONArray("Content");
            for (int majorInx = 0; majorInx < content.size(); ++majorInx) {
                JSONObject majorNode = content.getJSONObject(majorInx);
                majorNode.put("name", majorNode.get("class"));
                majorNode.remove("class");
                JSONArray sysArr = majorNode.getJSONArray("content");
                if (sysArr == null) {
                    continue;
                }
                for (int sysInx = 0; sysInx < sysArr.size(); ++sysInx) {
                    JSONObject sysNode = sysArr.getJSONObject(sysInx);
                    sysNode.put("name", sysNode.get("system"));
                    sysNode.remove("system");
                    JSONArray eqArr = sysNode.getJSONArray("content");
                    if (eqArr == null) {
                        continue;
                    }
                    for (int eqInx = 0; eqInx < eqArr.size(); ++eqInx) {
                        JSONObject eqNode = eqArr.getJSONObject(eqInx);
                        eqNode.put("name", eqNode.get("facility"));
                        eqNode.remove("facility");
                        JSONArray ecArr = eqNode.getJSONArray("components");
                        if (ecArr == null) {
                            continue;
                        }
                        for (int ecInx = 0; ecInx < ecArr.size(); ++ecInx) {
                            JSONObject ecNode = ecArr.getJSONObject(ecInx);
                            ecNode.put("name", ecNode.get("component"));
                            ecNode.remove("component");
                        }
                        eqNode.put("content", ecArr);
                        eqNode.remove("components");
                    }
                }
            }
            resp.put("Content", content);
            return resp.toString();
        } else {
            return dict.get(newFacilityPath);
        }
    }

    /**
     * 返回项目自定义字典的资产内容
     *
     * @param pjId
     * @return
     * @throws Exception
     */
    private String queryCtmFamily(String pjId) throws Exception {
        String dictId = this.queryDictId(pjId);
        if (dictId == null) {
            return null;
        }
        JSONObject body = new JSONObject().fluentPut("dict_id", dictId).fluentPut("show_as_tree", false);
        JSONObject reJson = JSONObject.parseObject(resourceContext.getResource(CtmNode.class).queryAllEqNodes(body.toString()));
        //family -> eq
        Map<String, List<JSONObject>> fa2Eqs = new HashMap<>();
        reJson.getJSONArray("Content").forEach(o -> {
            JSONObject item = (JSONObject) o;
            if (item.get("family") == null) {
                return;
            }
            String fCode = item.getString("family");
            if (fa2Eqs.get(fCode) == null) {
                fa2Eqs.put(fCode, new ArrayList<>());
            }
            fa2Eqs.get(fCode).add(item.fluentRemove("dict_id").fluentRemove("parent").fluentRemove("ref").fluentRemove("type").fluentRemove("family"));
        });
        reJson = JSONObject.parseObject(resourceContext.getResource(CtmNode.class).queryAllFamilyNodes(body.toString()));
        reJson.getJSONArray("Content").forEach(o -> {
            JSONObject item = (JSONObject) o;
            item.fluentRemove("dict_id").fluentRemove("ref").fluentRemove("type").fluentPut("content", fa2Eqs.get(item.getString("code")));
        });
        return reJson.fluentRemove("Count").toString();
    }

    @Path("/query/equipment_family")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String equipmentFamily(@QueryParam(Const.PROJECT_ID) String projectId) {
        try {
            if (projectId != null) {
                String re = this.queryCtmFamily(projectId);
                if (re != null) {
                    return re;
                }
            }
            if (!dict.containsKey(eqFamilyPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(eqFamilyPath))).get("all"));
                dict.put(eqFamilyPath, json.toJSONString());
            }
        } catch (Exception ex) {
//            return "{\"error\":\"获取种族信息失败!\"}";
            ex.printStackTrace();
            return DpUtils.errorJsonMsg(ex.getMessage());

        }
        return dict.get(eqFamilyPath);
    }


    @Path("/query/geography")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryGeography() {
        try {
            if (!dict.containsKey(geographyPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", JSONObject.parseObject(OssUtils.getFileAsString(geographyPath)));
                dict.put(geographyPath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取省市信息失败!");
        }
        return dict.get(geographyPath);
    }

    @Path("/query/climate")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryClimate() {
        try {
            if (!dict.containsKey(climatePath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(climatePath))).get("all"));
                dict.put(climatePath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取气候区信息失败!");
        }
        return dict.get(climatePath);
    }

    @Path("/query/develop")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryDevelop() {
        try {
            if (!dict.containsKey(developPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(developPath))).get("all"));
                dict.put(developPath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取发展水平信息失败!");
        }
        return dict.get(developPath);
    }

    @Path("/query/weather")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryWeatherCondition() {
        try {
            if (!dict.containsKey(weatherPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(weatherPath))).get("all"));
                dict.put(weatherPath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取天气状态信息失败!");
        }
        return dict.get(weatherPath);
    }

    @Path("/query/wind")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryWind() {
        try {
            if (!dict.containsKey(windPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(windPath))).get("all"));
                dict.put(windPath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取空气风力等级信息失败!");
        }
        return dict.get(windPath);
    }

    @Path("/query/direction")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryDirection() {
        try {
            if (!dict.containsKey(directionPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(directionPath))).get("all"));
                dict.put(directionPath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取方位信息失败!");
        }
        return dict.get(directionPath);
    }

    @Path("/query/building")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryBuildingFunction() {
        try {
            if (!dict.containsKey(buildingFunctionPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(buildingFunctionPath))).get("all"));
                dict.put(buildingFunctionPath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取建筑功能类型信息失败!");
        }
        return dict.get(buildingFunctionPath);
    }

    @Path("/query/space")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String querySpaceFunction() {
        try {
            if (!dict.containsKey(spaceFunctionPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(spaceFunctionPath))).get("all"));
                dict.put(spaceFunctionPath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取空间功能类型信息失败!");
        }
        return dict.get(spaceFunctionPath);
    }

    @Path("/query/rental")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryRental() {
        try {
            if (!dict.containsKey(rentalPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(rentalPath))).get("all"));
                dict.put(rentalPath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取租赁业态信息失败!");
        }
        return dict.get(rentalPath);
    }


    @Path("/query/dustproof")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryDustproof() {
        try {
            if (!dict.containsKey(dustproofPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(dustproofPath))).get("all"));
                dict.put(dustproofPath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取防尘等级信息失败!");
        }
        return dict.get(dustproofPath);
    }


    @Path("/query/waterproof")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryWaterproof() {
        try {
            if (!dict.containsKey(waterproofPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(waterproofPath))).get("all"));
                dict.put(waterproofPath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取防水等级信息失败!");
        }
        return dict.get(waterproofPath);
    }


    @Path("/query/danger")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryDanger() {
        try {
            if (!dict.containsKey(dangerAreaPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(dangerAreaPath))).get("all"));
                dict.put(dangerAreaPath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取危险区域等级信息失败!");
        }
        return dict.get(dangerAreaPath);
    }


    @Path("/query/explosionproof/equipment")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryExplosionproofEquipment() {
        try {
            if (!dict.containsKey(explosionproofEquipmentPath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(explosionproofEquipmentPath))).get("all"));
                dict.put(explosionproofEquipmentPath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取防爆设备信息失败!");
        }
        return dict.get(explosionproofEquipmentPath);
    }


    @Path("/query/explosionproof/gas_temperature")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryExplosionproofGasAndTemperature() {
        try {
            if (!dict.containsKey(explosionproofGasAndTemperaturePath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(explosionproofGasAndTemperaturePath))).get("all"));
                dict.put(explosionproofGasAndTemperaturePath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取气体类型和温度类型信息失败!");
        }
        return dict.get(explosionproofGasAndTemperaturePath);
    }


    @Path("/query/explosionproof/type")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryExplosionType() {
        try {
            if (!dict.containsKey(explosionproofTypePath)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(explosionproofTypePath))).get("all"));
                dict.put(explosionproofTypePath, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取防爆型式信息失败!");
        }
        return dict.get(explosionproofTypePath);
    }

    @Path("/query/global_relation_defination")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryGlobalRelation() {
        try {
            if (!dict.containsKey(globalReltionDefination)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(globalReltionDefination))).get("all"));
                dict.put(globalReltionDefination, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取全局关系定义失败!");
        }
        return dict.get(globalReltionDefination);
    }

    @Path("/query/standard_energy_item")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryStandardEi() {
        try {
            if (!dict.containsKey(standardEnergyItem)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(standardEnergyItem))).get("all"));
                dict.put(standardEnergyItem, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取全局关系定义失败!");
        }
        return dict.get(standardEnergyItem);
    }

    @Path("/query/pollution_level")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryPollutionLevel() {
        try {
            if (!dict.containsKey(pollutionLevel)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(pollutionLevel))).get("all"));
                dict.put(pollutionLevel, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取污染等级失败!");
        }
        return dict.get(pollutionLevel);
    }

    @Path("/query/contamination_level")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryContaminationLevel() {
        try {
            if (!dict.containsKey(contaminationLevel)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(contaminationLevel))).get("all"));
                dict.put(contaminationLevel, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取污秽等级失败!");
        }
        return dict.get(contaminationLevel);
    }

    public static void clearCache() {
        dict.clear();
    }

    @Path("/query/avg_temp/2016")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryAverageTemperature2016() {
        try {
            if (!dict.containsKey(avgTemperature2016)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(avgTemperature2016))).get("all"));
                dict.put(avgTemperature2016, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取2016年城市平均温度失败!");
        }
        return dict.get(avgTemperature2016);
    }

    @Path("/query/seismic_precautionary_intensity")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryAntiEarthquake() {
        try {
            if (!dict.containsKey(antiEarthquake)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(antiEarthquake))).get("all"));
                dict.put(antiEarthquake, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取抗震设防烈度失败!");
        }
        return dict.get(antiEarthquake);
    }

    @Path("/query/virtual_object")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryVirtualObject() {
        try {
            if (!dict.containsKey(virtualObject)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(virtualObject))).get("all"));
                dict.put(virtualObject, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取虚拟对象类型失败!");
        }
        return dict.get(virtualObject);
    }

    @Path("/query/calendar_tag")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryCalendarTag() {
        try {
            if (!dict.containsKey(CALENDAR_TAG)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(CALENDAR_TAG))).get("all"));
                dict.put(CALENDAR_TAG, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取虚拟对象类型失败!");
        }
        return dict.get(CALENDAR_TAG);
    }

    @Path("/query/calendar_interval")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String queryCalendarInterval() {
        try {
            if (!dict.containsKey(CALENDAR_INTERVAL)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(CALENDAR_INTERVAL))).get("all"));
                dict.put(CALENDAR_INTERVAL, json.toJSONString());
            }
        } catch (Exception ex) {
            return DpUtils.errorJsonMsg("获取虚拟对象类型失败!");
        }
        return dict.get(CALENDAR_INTERVAL);
    }

    @Path("/query/consumable_all")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String consumableAll() {
        try {
            if (!dict.containsKey(CONSUMABLE_PATH)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(CONSUMABLE_PATH))).get("all"));
                dict.put(CONSUMABLE_PATH, json.toJSONString());
            }
        } catch (Exception ex) {
            log.error("", ex);
            return "{\"error\":\"获取耗材信息失败!\"}";
        }
        return dict.get(CONSUMABLE_PATH);
    }

    @Path("/query/tool_all")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String toolAll() {
        try {
            if (!dict.containsKey(TOOL_PATH)) {
                JSONObject json = JSONObject.parseObject(returnJson);
                json.put("Content", (JSONObject.parseObject(OssUtils.getFileAsString(TOOL_PATH))).get("all"));
                dict.put(TOOL_PATH, json.toJSONString());
            }
        } catch (Exception ex) {
            log.error("", ex);
            return "{\"error\":\"获取耗材信息失败!\"}";
        }
        return dict.get(TOOL_PATH);
    }

    @Path("/query/equipment_family")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String equipmentFamilyPost(@QueryParam(Const.PROJECT_ID) String projectId) {
        return equipmentFamily(projectId);
    }


    @Path("/query/geography")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryGeographyPost() {
        return queryGeography();
    }

    @Path("/query/climate")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryClimatePost() {
        return queryClimate();
    }

    @Path("/query/develop")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryDevelopPost() {
        return queryDevelop();
    }

    @Path("/query/weather")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryWeatherConditionPost() {
        return queryWeatherCondition();
    }

    @Path("/query/wind")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryWindPost() {
        return queryWind();
    }

    @Path("/query/direction")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryDirectionPost() {
        return queryDirection();
    }

    @Path("/query/building")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryBuildingFunctionPost() {
        return queryBuildingFunction();
    }

    @Path("/query/space")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String querySpaceFunctionPost() {
        return querySpaceFunction();
    }

    @Path("/query/rental")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryRentalPost() {
        return queryRental();
    }


    @Path("/query/dustproof")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryDustproofPost() {
        return queryDustproof();
    }


    @Path("/query/waterproof")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryWaterproofPost() {
        return queryWaterproof();
    }


    @Path("/query/danger")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryDangerPost() {
        return queryDanger();
    }


    @Path("/query/explosionproof/equipment")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryExplosionproofEquipmentPost() {
        return queryExplosionproofEquipment();
    }


    @Path("/query/explosionproof/gas_temperature")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryExplosionproofGasAndTemperaturePost() {
        return queryExplosionproofGasAndTemperature();
    }


    @Path("/query/explosionproof/type")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryExplosionTypePost() {
        return queryExplosionType();
    }

    @Path("/query/global_relation_defination")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryGlobalRelationPost() {
        return queryGlobalRelation();
    }

    @Path("/query/standard_energy_item")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryStandardEiPost() {
        return queryStandardEi();
    }

    @Path("/query/pollution_level")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryPollutionLevelPost() {
        return queryPollutionLevel();
    }

    @Path("/query/contamination_level")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryContaminationLevelPost() {
        return queryContaminationLevel();
    }

    @Path("/query/avg_temp/2016")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryAverageTemperature2016Post() {
        return queryAverageTemperature2016();
    }

    @Path("/query/seismic_precautionary_intensity")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryAntiEarthquakePost() {
        return queryAntiEarthquake();
    }

    @Path("/query/virtual_object")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryVirtualObjectPost() {
        return queryVirtualObject();
    }

    @Path("/query/calendar_tag")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryCalendarTagPost() {
        return queryCalendarTag();
    }

    @Path("/query/calendar_interval")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String queryCalendarIntervalPost() {
        return queryCalendarInterval();
    }

    @Path("/query/consumable_all")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String consumableAllPOST() {
        return consumableAll();
    }

    @Path("/query/tool_all")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String toolAllPost() {
        return toolAll();
    }


}
