| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package com.persagy.old.cache;
- import com.alibaba.fastjson.JSONObject;
- import com.persagy.fm.common.constant.DataRequestPathUtil;
- import com.persagy.fm.common.old.utils.StringUtil;
- import com.persagy.old.common.RedisConstant;
- import com.persagy.old.dao.DBConst;
- import com.persagy.fm.sop.service.BaseService;
- import org.apache.log4j.Logger;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.core.HashOperations;
- import org.springframework.data.redis.core.RedisOperations;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- /**
- * Created by DOOM on 2017/9/6.
- */
- @Service("graphCache")
- public class GraphCache {
- @Autowired
- private BaseService baseService;
- private static final Logger log = Logger.getLogger(GraphCache.class);
- @Resource(name="dataPlatformRedisTemplate")
- private RedisOperations<String, Object> dataPlatformRedisTemplate;
- public String getGraphIdByProjectIdAndGraph(String projectId, String graph) {
- String key = projectId + ":" + graph;
- HashOperations<String, Object, Object> opsForHash = dataPlatformRedisTemplate.opsForHash();
- String graphId = (String) opsForHash.get(RedisConstant.ALL_GRAPH_INSTANCE_KEY, key);
- if (StringUtil.isNull(graphId)) {
- log.error("GraphCache未获取到缓存:" + key);
- }
- return graphId;
- }
- /**
- * 功能描述:创建图示例
- *
- * @param projectId
- * @param graph
- * @return
- * @throws Exception
- */
- public String createGraphInstance(String projectId, String graph )throws Exception {
- String graphId = "";
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("graph_type", graph);
- jsonObject.put("projectId", projectId);
- String requestUrl = baseService.getDataPlatformPath(DataRequestPathUtil.dataPlat_relation_graph_instance_create);
- String queryResult = baseService.httpPostRequestDataPlatform(requestUrl, jsonObject.toJSONString());
- JSONObject queryJson = JSONObject.parseObject(queryResult);
- if (DBConst.Result.SUCCESS.equals(queryJson.getString(DBConst.Result.RESULT))) {
- graphId = queryJson.getString("graph_id");
- HashOperations<String, String, Object> opsForHash = dataPlatformRedisTemplate.opsForHash();
- opsForHash.put(RedisConstant.ALL_GRAPH_INSTANCE_KEY, projectId + ":" + graph, graphId);
- }
- return graphId;
- }
- }
|