jiazx0107@163.com
2023-10-26 57ce50108ffe8d85f9508529dbffea0c064c44a2
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.fzzy.gateway.service;
 
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.utils.RedisConst;
import com.fzzy.api.utils.RedisUtil;
import com.fzzy.gateway.GatewayUtils;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.service.repository.GatewayDeviceRep;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Component
public class GatewayDeviceService {
 
    @Resource
    private GatewayDeviceRep gatewayDeviceRep;
 
    /**
     * gatewayDeviceService#listAll
     *
     * @return
     */
    @DataProvider
    public List<GatewayDevice> listAll() {
        return gatewayDeviceRep.findAll();
    }
 
    /**
     * gatewayDeviceService#updateSave
     *
     * @param entity
     */
    @DataResolver
    public void updateSave(GatewayDevice entity) {
        GatewayDevice data = new GatewayDevice();
        BeanUtils.copyProperties(entity, data);
 
        if (null == data.getId()) {
            data.setId(ContextUtil.getUUID());
        }
 
 
        if (null == data.getDeviceSn()) {
            if (null != entity.getIp()) {
                data.setDeviceSn(entity.getIp());
            } else {
                data.setDeviceSn(data.getDeviceId());
            }
        }
 
        gatewayDeviceRep.save(data);
 
        flushCache();
    }
 
    /**
     * gatewayDeviceService#delData
     *
     * @param data
     */
    @Expose
    public String delData(GatewayDevice data) {
        GatewayDevice data2 = new GatewayDevice();
        BeanUtils.copyProperties(data, data2);
        gatewayDeviceRep.delete(data2);
 
        GatewayUtils.removeCache(data2);
 
        flushCache();
        return null;
    }
 
 
    /**
     * gatewayDeviceService#flushCache
     */
    @Expose
    public void flushCache() {
        List<GatewayDevice> list = listAll();
        if (null == list || list.isEmpty()) return;
        for (GatewayDevice device : list) {
            GatewayUtils.add2Cache(device);
        }
    }
}