FlowJobUtil.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package jnpf.flowable.job;
  2. import cn.hutool.core.collection.CollectionUtil;
  3. import jnpf.flowable.model.time.FlowTimeModel;
  4. import jnpf.flowable.util.TimeUtil;
  5. import jnpf.util.JsonUtil;
  6. import jnpf.util.RedisUtil;
  7. import jnpf.util.StringUtil;
  8. import lombok.extern.slf4j.Slf4j;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11. /**
  12. * @author JNPF开发平台组
  13. * @version V3.3.0 flowable
  14. * @copyright 引迈信息技术有限公司
  15. * @date 2022/6/15 17:37
  16. */
  17. @Slf4j
  18. public class FlowJobUtil {
  19. /**
  20. * 自动审批
  21. */
  22. public static final String OPERATOR_REDIS_KEY = "flowable_operator";
  23. /**
  24. * 自动转审
  25. */
  26. public static final String OPERATOR_TRANSFER = "flowable_transfer";
  27. /**
  28. * 超时
  29. */
  30. public static final String TIME_REDIS_KEY = "flowable_timeModel";
  31. /**
  32. * 提醒
  33. */
  34. public static final String NOTICE_REDIS_KEY = "flowable_notice";
  35. public static FlowTimeModel getModel(FlowTimeModel model, RedisUtil redisUtil) {
  36. String id = model.getOperatorId();
  37. String hashValues = redisUtil.getHashValues(model.getOverTime() ? TIME_REDIS_KEY : NOTICE_REDIS_KEY, id);
  38. FlowTimeModel integrateModel = StringUtil.isNotEmpty(hashValues) ? JsonUtil.getJsonToBean(hashValues, FlowTimeModel.class) : null;
  39. return integrateModel;
  40. }
  41. public static void insertModel(FlowTimeModel model, RedisUtil redisUtil) {
  42. String integrateId = model.getOperatorId();
  43. redisUtil.insertHash(model.getOverTime() ? TIME_REDIS_KEY : NOTICE_REDIS_KEY, integrateId, JsonUtil.getObjectToString(model));
  44. }
  45. public static void removeModel(FlowTimeModel model, RedisUtil redisUtil) {
  46. redisUtil.removeHash(model.getOverTime() ? TIME_REDIS_KEY : NOTICE_REDIS_KEY, model.getOperatorId());
  47. }
  48. public static void insertOperator(FlowTimeModel model, RedisUtil redisUtil) {
  49. redisUtil.insertHash(OPERATOR_REDIS_KEY, model.getOperatorId(), JsonUtil.getObjectToString(model));
  50. }
  51. public static void remove(FlowTimeModel model, RedisUtil redisUtil) {
  52. redisUtil.removeHash(OPERATOR_TRANSFER, model.getOperatorId());
  53. redisUtil.removeHash(OPERATOR_REDIS_KEY, model.getOperatorId());
  54. redisUtil.removeHash(TIME_REDIS_KEY, model.getOperatorId());
  55. redisUtil.removeHash(NOTICE_REDIS_KEY, model.getOperatorId());
  56. }
  57. public static void removeTransfer(FlowTimeModel model, RedisUtil redisUtil) {
  58. redisUtil.removeHash(OPERATOR_TRANSFER, model.getOperatorId());
  59. }
  60. public static List<FlowTimeModel> getOperator(RedisUtil redisUtil) {
  61. List<FlowTimeModel> list = new ArrayList<>();
  62. List<String> hashValues = redisUtil.getHashValues(OPERATOR_REDIS_KEY);
  63. if (CollectionUtil.isNotEmpty(hashValues)) {
  64. for (String hashValue : hashValues) {
  65. FlowTimeModel integrateModel = StringUtil.isNotEmpty(hashValue) ? JsonUtil.getJsonToBean(hashValue, FlowTimeModel.class) : null;
  66. list.add(integrateModel);
  67. }
  68. }
  69. return list;
  70. }
  71. public static void insertTransfer(FlowTimeModel model, RedisUtil redisUtil) {
  72. redisUtil.insertHash(OPERATOR_TRANSFER, model.getOperatorId(), JsonUtil.getObjectToString(model));
  73. }
  74. public static List<FlowTimeModel> getTransfer(RedisUtil redisUtil) {
  75. List<FlowTimeModel> list = new ArrayList<>();
  76. List<String> hashValues = redisUtil.getHashValues(OPERATOR_TRANSFER);
  77. if (CollectionUtil.isNotEmpty(hashValues)) {
  78. for (String hashValue : hashValues) {
  79. FlowTimeModel integrateModel = StringUtil.isNotEmpty(hashValue) ? JsonUtil.getJsonToBean(hashValue, FlowTimeModel.class) : null;
  80. list.add(integrateModel);
  81. }
  82. }
  83. return list;
  84. }
  85. public static void deleteByOperatorId(String operatorId, RedisUtil redisUtil) {
  86. FlowTimeModel timeModel = new FlowTimeModel();
  87. timeModel.setOperatorId(operatorId);
  88. FlowTimeModel flowTimeModel = FlowJobUtil.getModel(timeModel, redisUtil);
  89. if (null != flowTimeModel) {
  90. TimeUtil.deleteJob(flowTimeModel.getId());
  91. FlowJobUtil.remove(flowTimeModel, redisUtil);
  92. }
  93. timeModel.setOverTime(true);
  94. FlowTimeModel overTimeModel = FlowJobUtil.getModel(timeModel, redisUtil);
  95. if (null != overTimeModel) {
  96. TimeUtil.deleteJob(overTimeModel.getId());
  97. FlowJobUtil.remove(overTimeModel, redisUtil);
  98. }
  99. }
  100. }