GraphCache.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.persagy.old.cache;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.persagy.fm.common.constant.DataRequestPathUtil;
  4. import com.persagy.fm.common.old.utils.StringUtil;
  5. import com.persagy.old.common.RedisConstant;
  6. import com.persagy.old.dao.DBConst;
  7. import com.persagy.fm.sop.service.BaseService;
  8. import org.apache.log4j.Logger;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.data.redis.core.HashOperations;
  11. import org.springframework.data.redis.core.RedisOperations;
  12. import org.springframework.stereotype.Service;
  13. import javax.annotation.Resource;
  14. /**
  15. * Created by DOOM on 2017/9/6.
  16. */
  17. @Service("graphCache")
  18. public class GraphCache {
  19. @Autowired
  20. private BaseService baseService;
  21. private static final Logger log = Logger.getLogger(GraphCache.class);
  22. @Resource(name="dataPlatformRedisTemplate")
  23. private RedisOperations<String, Object> dataPlatformRedisTemplate;
  24. public String getGraphIdByProjectIdAndGraph(String projectId, String graph) {
  25. String key = projectId + ":" + graph;
  26. HashOperations<String, Object, Object> opsForHash = dataPlatformRedisTemplate.opsForHash();
  27. String graphId = (String) opsForHash.get(RedisConstant.ALL_GRAPH_INSTANCE_KEY, key);
  28. if (StringUtil.isNull(graphId)) {
  29. log.error("GraphCache未获取到缓存:" + key);
  30. }
  31. return graphId;
  32. }
  33. /**
  34. * 功能描述:创建图示例
  35. *
  36. * @param projectId
  37. * @param graph
  38. * @return
  39. * @throws Exception
  40. */
  41. public String createGraphInstance(String projectId, String graph )throws Exception {
  42. String graphId = "";
  43. JSONObject jsonObject = new JSONObject();
  44. jsonObject.put("graph_type", graph);
  45. jsonObject.put("projectId", projectId);
  46. String requestUrl = baseService.getDataPlatformPath(DataRequestPathUtil.dataPlat_relation_graph_instance_create);
  47. String queryResult = baseService.httpPostRequestDataPlatform(requestUrl, jsonObject.toJSONString());
  48. JSONObject queryJson = JSONObject.parseObject(queryResult);
  49. if (DBConst.Result.SUCCESS.equals(queryJson.getString(DBConst.Result.RESULT))) {
  50. graphId = queryJson.getString("graph_id");
  51. HashOperations<String, String, Object> opsForHash = dataPlatformRedisTemplate.opsForHash();
  52. opsForHash.put(RedisConstant.ALL_GRAPH_INSTANCE_KEY, projectId + ":" + graph, graphId);
  53. }
  54. return graphId;
  55. }
  56. }