FlowContextHolder.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package jnpf.flowable.model.util;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import jnpf.constant.JnpfConst;
  4. import jnpf.util.JsonUtil;
  5. import jnpf.util.StringUtil;
  6. import java.util.ArrayList;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. /**
  11. * 事件数据添加
  12. *
  13. * @author JNPF开发平台组
  14. * @version V3.1.0
  15. * @copyright 引迈信息技术有限公司
  16. * @date 2022/8/20 8:49
  17. */
  18. public class FlowContextHolder {
  19. // 子流程表单数据
  20. private static final ThreadLocal<Map<String, Map<String, Object>>> CHILD_DATA = new ThreadLocal<>();
  21. // 保存表单的Key集合
  22. private static final ThreadLocal<List<String>> WRITE_ID_LIST = new ThreadLocal<>();
  23. // 表单权限
  24. private static final ThreadLocal<Map<String, List<Map<String, Object>>>> FORM_OPERATES_DATA = new ThreadLocal<>();
  25. /**
  26. * 获取数据
  27. */
  28. public static Map<String, Map<String, Object>> getAllData() {
  29. Map<String, Map<String, Object>> data = CHILD_DATA.get() != null ? CHILD_DATA.get() : new HashMap<>();
  30. return data;
  31. }
  32. /**
  33. * 获取保存的Key集合
  34. */
  35. public static List<String> getWriteIdList() {
  36. return WRITE_ID_LIST.get() != null ? WRITE_ID_LIST.get() : new ArrayList<>();
  37. }
  38. /**
  39. * 清除数据
  40. */
  41. public static void clearAll() {
  42. CHILD_DATA.remove();
  43. WRITE_ID_LIST.remove();
  44. FORM_OPERATES_DATA.remove();
  45. }
  46. /**
  47. * 添加数据
  48. */
  49. public static void addChildData(String taskId, String formId, Map<String, Object> parameterMap, List<Map<String, Object>> formOperates, boolean isWrite) {
  50. if (StringUtil.isNotEmpty(taskId) && StringUtil.isNotEmpty(formId)) {
  51. Map<String, Map<String, Object>> map = CHILD_DATA.get() != null ? CHILD_DATA.get() : new HashMap<>();
  52. String key = taskId + JnpfConst.SIDE_MARK + formId;
  53. map.put(key, JsonUtil.entityToMap(parameterMap));
  54. CHILD_DATA.set(map);
  55. Map<String, List<Map<String, Object>>> formMap = FORM_OPERATES_DATA.get() != null ? FORM_OPERATES_DATA.get() : new HashMap<>();
  56. if (ObjectUtil.isEmpty(formMap.get(key))) {
  57. formMap.put(key, formOperates);
  58. FORM_OPERATES_DATA.set(formMap);
  59. }
  60. if (isWrite) {
  61. List<String> writeList = getWriteIdList();
  62. writeList.add(key);
  63. WRITE_ID_LIST.set(writeList);
  64. }
  65. }
  66. }
  67. /**
  68. * 获取权限
  69. */
  70. public static Map<String, List<Map<String, Object>>> getFormOperates() {
  71. Map<String, List<Map<String, Object>>> data = FORM_OPERATES_DATA.get() != null ? FORM_OPERATES_DATA.get() : new HashMap<>();
  72. return data;
  73. }
  74. /**
  75. * 删除数据
  76. */
  77. public static void delete(String taskId, String formId) {
  78. Map<String, Map<String, Object>> data = CHILD_DATA.get() != null ? CHILD_DATA.get() : new HashMap<>();
  79. String key = taskId + JnpfConst.SIDE_MARK + formId;
  80. data.remove(key);
  81. CHILD_DATA.set(data);
  82. }
  83. /**
  84. * 删除权限
  85. */
  86. public static void deleteFormOperator() {
  87. FORM_OPERATES_DATA.remove();
  88. }
  89. }