package com.yunzhupaas.flowable.job;

import com.yunzhupaas.flowable.model.trigger.TimeTriggerModel;
import com.yunzhupaas.util.JsonUtil;
import com.yunzhupaas.util.RedisUtil;
import com.yunzhupaas.util.StringUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 类的描述
 *
 * @author YUNZHUPAASYUNZHUPAAS开发组
 * @version 5.0.x
 * @since 2024/9/20 10:22
 */
@Slf4j
public class TriggerJobUtil {
    public static final String TRIGGER_MODEL = "trigger_model";

    public static TimeTriggerModel getModel(TimeTriggerModel model, RedisUtil redisUtil) {
        String hashValues = redisUtil.getHashValues(TRIGGER_MODEL, model.getId());
        TimeTriggerModel timeTriggerModel = StringUtil.isNotEmpty(hashValues)
                ? JsonUtil.getJsonToBean(hashValues, TimeTriggerModel.class)
                : null;
        return timeTriggerModel;
    }

    public static void insertModel(TimeTriggerModel model, RedisUtil redisUtil) {
        String id = model.getId();
        redisUtil.insertHash(TRIGGER_MODEL, id, JsonUtil.getObjectToString(model));
    }

    public static void removeModel(TimeTriggerModel model, RedisUtil redisUtil) {
        redisUtil.removeHash(TRIGGER_MODEL, model.getId());
    }

}
