#
Junjie
2024-10-17 d835d1b51f832889929cdf69010034a30ef44d02
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.zy.asrs.wcs.asrs.execute;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zy.asrs.wcs.core.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.List;
 
@Component
public class BaseExecute {
 
    @Autowired
    private RedisUtil redisUtil;
 
    public boolean redisSet(String redisKey, String key, Object data) {
        if (redisUtil.hasKey(redisKey)) {
            Object obj = redisUtil.get(redisKey);
            JSONObject object = JSON.parseObject(String.valueOf(obj));
            object.put(key, data);
            redisUtil.set(redisKey, JSON.toJSONString(object));
        } else {
            JSONObject object = new JSONObject();
            object.put(key, data);
            redisUtil.set(redisKey, JSON.toJSONString(object));
        }
        return true;
    }
 
    public Object redisGet(String redisKey, String key) {
        if (redisUtil.hasKey(redisKey)) {
            Object obj = redisUtil.get(redisKey);
            JSONObject object = JSON.parseObject(String.valueOf(obj));
            if (!object.containsKey(key)) {
                return null;
            }
            return object.get(key);
        }
        return null;
    }
 
    public JSONObject findFLow(List<JSONObject> list, String id) {
        for (JSONObject flow : list) {
            if (flow.getString("id").equals(id)) {
                return flow;
            }
        }
        return null;
    }
 
}